2017-03-22 16:12:53 +00:00
|
|
|
var webpack = require("webpack"),
|
2017-03-27 15:08:36 +00:00
|
|
|
ExtractTextPlugin = require("extract-text-webpack-plugin"),
|
|
|
|
HtmlWebpackPlugin = require("html-webpack-plugin"),
|
|
|
|
Inliner = require("web-resource-inliner");
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2017-03-23 00:33:40 +00:00
|
|
|
module.exports = function (grunt) {
|
2016-11-28 10:42:58 +00:00
|
|
|
grunt.file.defaultEncoding = "utf8";
|
|
|
|
grunt.file.preserveBOM = false;
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
// Tasks
|
|
|
|
grunt.registerTask("dev",
|
|
|
|
"A persistent task which creates a development build whenever source files are modified.",
|
2017-03-27 15:08:36 +00:00
|
|
|
["clean:dev", "webpack:webDev"]);
|
2017-03-21 22:41:44 +00:00
|
|
|
|
|
|
|
grunt.registerTask("node",
|
|
|
|
"Compiles CyberChef into a single NodeJS module.",
|
|
|
|
["clean:node", "webpack:node", "chmod:build"]);
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2017-02-23 18:59:58 +00:00
|
|
|
grunt.registerTask("test",
|
2017-02-24 23:50:17 +00:00
|
|
|
"A task which runs all the tests in test/tests.",
|
2017-03-27 15:08:36 +00:00
|
|
|
["clean:test", "webpack:tests", "execute:test"]);
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
grunt.registerTask("docs",
|
|
|
|
"Compiles documentation in the /docs directory.",
|
|
|
|
["clean:docs", "jsdoc", "chmod:docs"]);
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2017-03-27 15:08:36 +00:00
|
|
|
grunt.registerTask("prod",
|
|
|
|
"Creates a production-ready build. Use the --msg flag to add a compile message.",
|
2017-04-07 22:01:37 +00:00
|
|
|
["eslint", "clean:prod", "webpack:webProd", "inline", "chmod"]);
|
2016-12-03 00:37:38 +00:00
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
grunt.registerTask("default",
|
2017-03-29 20:51:42 +00:00
|
|
|
"Lints the code base",
|
|
|
|
["eslint", "exec:repoSize"]);
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2017-03-27 15:08:36 +00:00
|
|
|
grunt.registerTask("inline",
|
|
|
|
"Compiles a production build of CyberChef into a single, portable web page.",
|
|
|
|
runInliner);
|
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
grunt.registerTask("doc", "docs");
|
2017-02-28 17:08:36 +00:00
|
|
|
grunt.registerTask("tests", "test");
|
2016-12-14 16:39:17 +00:00
|
|
|
grunt.registerTask("lint", "eslint");
|
|
|
|
|
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
// Load tasks provided by each plugin
|
2016-12-14 16:39:17 +00:00
|
|
|
grunt.loadNpmTasks("grunt-eslint");
|
2017-03-27 15:08:36 +00:00
|
|
|
grunt.loadNpmTasks("grunt-webpack");
|
2016-11-28 10:42:58 +00:00
|
|
|
grunt.loadNpmTasks("grunt-jsdoc");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-clean");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-copy");
|
|
|
|
grunt.loadNpmTasks("grunt-chmod");
|
|
|
|
grunt.loadNpmTasks("grunt-exec");
|
2017-02-28 17:08:36 +00:00
|
|
|
grunt.loadNpmTasks("grunt-execute");
|
2017-04-05 20:30:22 +00:00
|
|
|
grunt.loadNpmTasks("grunt-accessibility");
|
2016-12-14 16:39:17 +00:00
|
|
|
|
|
|
|
|
2017-03-27 15:08:36 +00:00
|
|
|
// Project configuration
|
2017-03-22 16:55:21 +00:00
|
|
|
var compileTime = grunt.template.today("dd/mm/yyyy HH:MM:ss") + " UTC",
|
2017-03-23 00:33:40 +00:00
|
|
|
banner = "/**\n" +
|
|
|
|
"* CyberChef - The Cyber Swiss Army Knife\n" +
|
|
|
|
"*\n" +
|
|
|
|
"* @copyright Crown Copyright 2016\n" +
|
|
|
|
"* @license Apache-2.0\n" +
|
|
|
|
"*\n" +
|
|
|
|
"* Copyright 2016 Crown Copyright\n" +
|
|
|
|
"*\n" +
|
|
|
|
'* Licensed under the Apache License, Version 2.0 (the "License");\n' +
|
|
|
|
"* you may not use this file except in compliance with the License.\n" +
|
|
|
|
"* You may obtain a copy of the License at\n" +
|
|
|
|
"*\n" +
|
|
|
|
"* http://www.apache.org/licenses/LICENSE-2.0\n" +
|
|
|
|
"*\n" +
|
|
|
|
"* Unless required by applicable law or agreed to in writing, software\n" +
|
|
|
|
'* distributed under the License is distributed on an "AS IS" BASIS,\n' +
|
|
|
|
"* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" +
|
|
|
|
"* See the License for the specific language governing permissions and\n" +
|
|
|
|
"* limitations under the License.\n" +
|
|
|
|
"*/\n";
|
2016-11-28 10:42:58 +00:00
|
|
|
|
2017-03-27 15:08:36 +00:00
|
|
|
/**
|
|
|
|
* Compiles a production build of CyberChef into a single, portable web page.
|
|
|
|
*/
|
|
|
|
function runInliner() {
|
|
|
|
var inlinerError = false;
|
|
|
|
Inliner.html({
|
|
|
|
relativeTo: "build/prod/",
|
|
|
|
fileContent: grunt.file.read("build/prod/cyberchef.htm"),
|
|
|
|
images: true,
|
|
|
|
svgs: true,
|
|
|
|
scripts: true,
|
|
|
|
links: true,
|
|
|
|
strict: true
|
|
|
|
}, function(error, result) {
|
|
|
|
if (error) {
|
|
|
|
console.log(error);
|
|
|
|
inlinerError = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
grunt.file.write("build/prod/cyberchef.htm", result);
|
|
|
|
});
|
|
|
|
|
|
|
|
return !inlinerError;
|
|
|
|
}
|
2016-12-14 16:39:17 +00:00
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
grunt.initConfig({
|
2017-03-27 15:08:36 +00:00
|
|
|
clean: {
|
|
|
|
dev: ["build/dev/*"],
|
|
|
|
prod: ["build/prod/*"],
|
|
|
|
test: ["build/test/*"],
|
|
|
|
node: ["build/node/*"],
|
|
|
|
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
|
|
|
|
},
|
2016-12-14 16:39:17 +00:00
|
|
|
eslint: {
|
2016-11-28 10:42:58 +00:00
|
|
|
options: {
|
2017-03-23 00:33:40 +00:00
|
|
|
configFile: "src/.eslintrc.json"
|
2016-11-28 10:42:58 +00:00
|
|
|
},
|
2017-03-27 18:39:04 +00:00
|
|
|
configs: ["Gruntfile.js"],
|
2017-03-23 00:33:40 +00:00
|
|
|
core: ["src/core/**/*.js", "!src/core/lib/**/*"],
|
|
|
|
web: ["src/web/**/*.js"],
|
|
|
|
node: ["src/node/**/*.js"],
|
2017-02-28 17:08:36 +00:00
|
|
|
tests: ["test/**/*.js"],
|
2016-11-28 10:42:58 +00:00
|
|
|
},
|
|
|
|
jsdoc: {
|
|
|
|
options: {
|
|
|
|
destination: "docs",
|
|
|
|
template: "node_modules/ink-docstrap/template",
|
|
|
|
recurse: true,
|
|
|
|
readme: "./README.md",
|
|
|
|
configure: "docs/jsdoc.conf.json"
|
|
|
|
},
|
|
|
|
all: {
|
|
|
|
src: [
|
2017-03-23 00:33:40 +00:00
|
|
|
"src/**/*.js",
|
|
|
|
"!src/core/lib/**/*",
|
2016-11-28 10:42:58 +00:00
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
2017-04-05 20:30:22 +00:00
|
|
|
accessibility: {
|
|
|
|
options: {
|
2017-04-07 16:00:32 +00:00
|
|
|
accessibilityLevel: "WCAG2A",
|
|
|
|
verbose: false,
|
|
|
|
ignore: [
|
|
|
|
"WCAG2A.Principle1.Guideline1_3.1_3_1.H42.2"
|
|
|
|
]
|
2017-04-05 20:30:22 +00:00
|
|
|
},
|
|
|
|
test: {
|
|
|
|
src: ["build/**/*.html"]
|
|
|
|
}
|
|
|
|
},
|
2017-03-21 22:41:44 +00:00
|
|
|
webpack: {
|
|
|
|
options: {
|
|
|
|
plugins: [
|
|
|
|
new webpack.ProvidePlugin({
|
|
|
|
$: "jquery",
|
|
|
|
jQuery: "jquery",
|
|
|
|
moment: "moment-timezone"
|
2017-03-22 16:55:21 +00:00
|
|
|
}),
|
|
|
|
new webpack.BannerPlugin({
|
2017-03-27 15:08:36 +00:00
|
|
|
banner: banner,
|
|
|
|
raw: true,
|
|
|
|
entryOnly: true
|
2017-03-22 16:55:21 +00:00
|
|
|
}),
|
|
|
|
new webpack.DefinePlugin({
|
|
|
|
COMPILE_TIME: JSON.stringify(compileTime),
|
|
|
|
COMPILE_MSG: JSON.stringify(grunt.option("compile-msg") || grunt.option("msg") || "")
|
|
|
|
}),
|
2017-03-23 18:41:36 +00:00
|
|
|
new ExtractTextPlugin("styles.css"),
|
2017-03-21 22:41:44 +00:00
|
|
|
],
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
jquery: "jquery/src/jquery"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
module: {
|
2017-03-27 15:08:36 +00:00
|
|
|
rules: [
|
2017-03-22 16:12:53 +00:00
|
|
|
{
|
|
|
|
test: /\.js$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: "babel-loader?compact=false"
|
2017-03-27 15:08:36 +00:00
|
|
|
},
|
2017-03-22 16:12:53 +00:00
|
|
|
{
|
|
|
|
test: /\.css$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
2017-03-27 15:08:36 +00:00
|
|
|
use: "css-loader?minimize"
|
2017-03-22 16:12:53 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /\.less$/,
|
|
|
|
use: ExtractTextPlugin.extract({
|
|
|
|
use: [
|
2017-03-27 15:08:36 +00:00
|
|
|
{ loader: "css-loader?minimize" },
|
2017-03-22 16:12:53 +00:00
|
|
|
{ loader: "less-loader" }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
2017-03-27 15:08:36 +00:00
|
|
|
test: /\.(ico|eot|ttf|woff|woff2)$/,
|
2017-03-22 16:12:53 +00:00
|
|
|
loader: "url-loader",
|
|
|
|
options: {
|
|
|
|
limit: 10000
|
|
|
|
}
|
2017-03-27 15:08:36 +00:00
|
|
|
},
|
|
|
|
{ // First party images are saved as files to be cached
|
|
|
|
test: /\.(png|jpg|gif|svg)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
loader: "file-loader",
|
|
|
|
options: {
|
|
|
|
name: "images/[name].[ext]"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ // Third party images are inlined
|
|
|
|
test: /\.(png|jpg|gif|svg)$/,
|
|
|
|
exclude: /web\/static/,
|
|
|
|
loader: "url-loader",
|
|
|
|
options: {
|
|
|
|
limit: 10000
|
|
|
|
}
|
|
|
|
},
|
2017-03-22 16:12:53 +00:00
|
|
|
]
|
2017-03-27 15:08:36 +00:00
|
|
|
},
|
|
|
|
stats: {
|
|
|
|
children: false
|
2017-03-23 18:41:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
webDev: {
|
|
|
|
target: "web",
|
|
|
|
entry: "./src/web/index.js",
|
|
|
|
output: {
|
|
|
|
filename: "scripts.js",
|
2017-03-27 15:20:43 +00:00
|
|
|
path: __dirname + "/build/dev"
|
2017-03-27 15:08:36 +00:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
filename: "index.html",
|
|
|
|
template: "./src/web/html/index.html",
|
2017-03-29 20:51:42 +00:00
|
|
|
compileTime: compileTime
|
2017-03-27 15:08:36 +00:00
|
|
|
})
|
|
|
|
],
|
|
|
|
watch: true
|
2017-03-23 18:41:36 +00:00
|
|
|
},
|
|
|
|
webProd: {
|
|
|
|
target: "web",
|
|
|
|
entry: "./src/web/index.js",
|
|
|
|
output: {
|
|
|
|
filename: "scripts.js",
|
2017-03-27 15:20:43 +00:00
|
|
|
path: __dirname + "/build/prod"
|
2017-03-22 16:12:53 +00:00
|
|
|
},
|
|
|
|
plugins: [
|
2017-03-23 18:41:36 +00:00
|
|
|
new webpack.optimize.UglifyJsPlugin({
|
|
|
|
compress: {
|
|
|
|
"screw_ie8": true,
|
|
|
|
"dead_code": true,
|
|
|
|
"unused": true,
|
|
|
|
"warnings": false
|
|
|
|
},
|
|
|
|
comments: false,
|
|
|
|
}),
|
2017-03-27 15:08:36 +00:00
|
|
|
new HtmlWebpackPlugin({ // Main version
|
|
|
|
filename: "index.html",
|
|
|
|
template: "./src/web/html/index.html",
|
|
|
|
compileTime: compileTime,
|
|
|
|
minify: {
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
minifyJS: true,
|
|
|
|
minifyCSS: true
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new HtmlWebpackPlugin({ // Inline version
|
|
|
|
filename: "cyberchef.htm",
|
|
|
|
template: "./src/web/html/index.html",
|
|
|
|
compileTime: compileTime,
|
|
|
|
inline: true,
|
|
|
|
minify: {
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
minifyJS: true,
|
|
|
|
minifyCSS: true
|
|
|
|
}
|
|
|
|
}),
|
2017-03-22 16:12:53 +00:00
|
|
|
]
|
2017-03-21 22:41:44 +00:00
|
|
|
},
|
|
|
|
tests: {
|
|
|
|
target: "node",
|
2017-03-25 13:32:35 +00:00
|
|
|
entry: "./test/index.js",
|
2017-03-21 22:41:44 +00:00
|
|
|
output: {
|
|
|
|
filename: "index.js",
|
2017-03-27 15:20:43 +00:00
|
|
|
path: __dirname + "/build/test"
|
2017-03-21 22:41:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
node: {
|
|
|
|
target: "node",
|
2017-03-25 13:32:35 +00:00
|
|
|
entry: "./src/node/index.js",
|
2017-03-21 22:41:44 +00:00
|
|
|
output: {
|
|
|
|
filename: "CyberChef.js",
|
2017-03-27 15:20:43 +00:00
|
|
|
path: __dirname + "/build/node",
|
2017-03-21 22:41:44 +00:00
|
|
|
library: "CyberChef",
|
|
|
|
libraryTarget: "commonjs2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-11-28 10:42:58 +00:00
|
|
|
copy: {
|
2017-01-31 18:24:56 +00:00
|
|
|
ghPages: {
|
2016-12-03 00:37:38 +00:00
|
|
|
options: {
|
2017-03-23 00:33:40 +00:00
|
|
|
process: function (content, srcpath) {
|
2016-12-03 00:37:38 +00:00
|
|
|
// Add Google Analytics code to index.html
|
|
|
|
content = content.replace("</body></html>",
|
2017-03-31 09:56:08 +00:00
|
|
|
grunt.file.read("src/web/static/ga.html") + "</body></html>");
|
2017-03-27 15:08:36 +00:00
|
|
|
return grunt.template.process(content);
|
2016-12-03 00:37:38 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
src: "build/prod/index.html",
|
|
|
|
dest: "build/prod/index.html"
|
2016-11-28 10:42:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
chmod: {
|
|
|
|
build: {
|
|
|
|
options: {
|
|
|
|
mode: "755",
|
|
|
|
},
|
2017-03-27 15:08:36 +00:00
|
|
|
src: ["build/**/*", "build/"]
|
2016-11-28 10:42:58 +00:00
|
|
|
},
|
|
|
|
docs: {
|
|
|
|
options: {
|
|
|
|
mode: "755",
|
|
|
|
},
|
|
|
|
src: ["docs/**/*", "docs/"]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
exec: {
|
2017-01-31 18:24:56 +00:00
|
|
|
repoSize: {
|
2016-11-28 10:42:58 +00:00
|
|
|
command: [
|
2016-12-14 16:39:17 +00:00
|
|
|
"git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
|
|
|
|
"du -hs | egrep -o '^[^\t]*' | xargs printf '%b\trepository size\n'"
|
|
|
|
].join(";"),
|
2016-11-28 10:42:58 +00:00
|
|
|
stderr: false
|
|
|
|
},
|
2017-01-31 18:24:56 +00:00
|
|
|
cleanGit: {
|
2016-11-28 10:42:58 +00:00
|
|
|
command: "git gc --prune=now --aggressive"
|
|
|
|
},
|
|
|
|
},
|
2017-02-28 17:08:36 +00:00
|
|
|
execute: {
|
2017-03-21 22:41:44 +00:00
|
|
|
test: "build/test/index.js"
|
2017-02-28 17:08:36 +00:00
|
|
|
},
|
2016-11-28 10:42:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
};
|