|
@@ -4,7 +4,6 @@ const webpack = require("webpack");
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
const NodeExternals = require("webpack-node-externals");
|
|
const NodeExternals = require("webpack-node-externals");
|
|
-const Inliner = require("web-resource-inliner");
|
|
|
|
const glob = require("glob");
|
|
const glob = require("glob");
|
|
const path = require("path");
|
|
const path = require("path");
|
|
const UglifyJSWebpackPlugin = require("uglifyjs-webpack-plugin");
|
|
const UglifyJSWebpackPlugin = require("uglifyjs-webpack-plugin");
|
|
@@ -50,18 +49,16 @@ module.exports = function (grunt) {
|
|
|
|
|
|
grunt.registerTask("prod",
|
|
grunt.registerTask("prod",
|
|
"Creates a production-ready build. Use the --msg flag to add a compile message.",
|
|
"Creates a production-ready build. Use the --msg flag to add a compile message.",
|
|
- ["eslint", "clean:prod", "clean:config", "exec:generateConfig", "webpack:web", "inline", "chmod"]);
|
|
|
|
|
|
+ [
|
|
|
|
+ "eslint", "clean:prod", "clean:config", "exec:generateConfig", "webpack:web",
|
|
|
|
+ "copy:standalone", "zip:standalone", "clean:standalone", "chmod"
|
|
|
|
+ ]);
|
|
|
|
|
|
grunt.registerTask("default",
|
|
grunt.registerTask("default",
|
|
"Lints the code base",
|
|
"Lints the code base",
|
|
["eslint", "exec:repoSize"]);
|
|
["eslint", "exec:repoSize"]);
|
|
|
|
|
|
- grunt.registerTask("inline",
|
|
|
|
- "Compiles a production build of CyberChef into a single, portable web page.",
|
|
|
|
- ["exec:generateConfig", "webpack:webInline", "runInliner", "clean:inlineScripts"]);
|
|
|
|
|
|
|
|
-
|
|
|
|
- grunt.registerTask("runInliner", runInliner);
|
|
|
|
grunt.registerTask("doc", "docs");
|
|
grunt.registerTask("doc", "docs");
|
|
grunt.registerTask("tests", "test");
|
|
grunt.registerTask("tests", "test");
|
|
grunt.registerTask("lint", "eslint");
|
|
grunt.registerTask("lint", "eslint");
|
|
@@ -79,6 +76,7 @@ module.exports = function (grunt) {
|
|
grunt.loadNpmTasks("grunt-accessibility");
|
|
grunt.loadNpmTasks("grunt-accessibility");
|
|
grunt.loadNpmTasks("grunt-concurrent");
|
|
grunt.loadNpmTasks("grunt-concurrent");
|
|
grunt.loadNpmTasks("grunt-contrib-connect");
|
|
grunt.loadNpmTasks("grunt-contrib-connect");
|
|
|
|
+ grunt.loadNpmTasks("grunt-zip");
|
|
|
|
|
|
|
|
|
|
// Project configuration
|
|
// Project configuration
|
|
@@ -101,32 +99,6 @@ module.exports = function (grunt) {
|
|
},
|
|
},
|
|
moduleEntryPoints = listEntryModules();
|
|
moduleEntryPoints = listEntryModules();
|
|
|
|
|
|
- /**
|
|
|
|
- * Compiles a production build of CyberChef into a single, portable web page.
|
|
|
|
- */
|
|
|
|
- function runInliner() {
|
|
|
|
- const done = this.async();
|
|
|
|
- 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) {
|
|
|
|
- if (error instanceof Error) {
|
|
|
|
- done(error);
|
|
|
|
- } else {
|
|
|
|
- done(new Error(error));
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- grunt.file.write("build/prod/cyberchef.htm", result);
|
|
|
|
- done(true);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Generates an entry list for all the modules.
|
|
* Generates an entry list for all the modules.
|
|
@@ -137,7 +109,7 @@ module.exports = function (grunt) {
|
|
glob.sync("./src/core/config/modules/*.mjs").forEach(file => {
|
|
glob.sync("./src/core/config/modules/*.mjs").forEach(file => {
|
|
const basename = path.basename(file);
|
|
const basename = path.basename(file);
|
|
if (basename !== "Default.mjs" && basename !== "OpModules.mjs")
|
|
if (basename !== "Default.mjs" && basename !== "OpModules.mjs")
|
|
- entryModules[basename.split(".mjs")[0]] = path.resolve(file);
|
|
|
|
|
|
+ entryModules["modules/" + basename.split(".mjs")[0]] = path.resolve(file);
|
|
});
|
|
});
|
|
|
|
|
|
return entryModules;
|
|
return entryModules;
|
|
@@ -150,7 +122,7 @@ module.exports = function (grunt) {
|
|
node: ["build/node/*"],
|
|
node: ["build/node/*"],
|
|
config: ["src/core/config/OperationConfig.json", "src/core/config/modules/*", "src/code/operations/index.mjs", "src/node/index.mjs", "src/node/config/OperationConfig.json"],
|
|
config: ["src/core/config/OperationConfig.json", "src/core/config/modules/*", "src/code/operations/index.mjs", "src/node/index.mjs", "src/node/config/OperationConfig.json"],
|
|
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico", "!docs/*.png"],
|
|
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico", "!docs/*.png"],
|
|
- inlineScripts: ["build/prod/scripts.js"],
|
|
|
|
|
|
+ standalone: ["build/prod/CyberChef*.html"]
|
|
},
|
|
},
|
|
eslint: {
|
|
eslint: {
|
|
options: {
|
|
options: {
|
|
@@ -202,7 +174,10 @@ module.exports = function (grunt) {
|
|
}, moduleEntryPoints),
|
|
}, moduleEntryPoints),
|
|
output: {
|
|
output: {
|
|
path: __dirname + "/build/prod",
|
|
path: __dirname + "/build/prod",
|
|
- // globalObject: "this"
|
|
|
|
|
|
+ filename: chunkData => {
|
|
|
|
+ return chunkData.chunk.name === "main" ? "assets/[name].js": "[name].js";
|
|
|
|
+ },
|
|
|
|
+ globalObject: "this"
|
|
},
|
|
},
|
|
resolve: {
|
|
resolve: {
|
|
alias: {
|
|
alias: {
|
|
@@ -232,46 +207,6 @@ module.exports = function (grunt) {
|
|
]
|
|
]
|
|
};
|
|
};
|
|
},
|
|
},
|
|
- webInline: {
|
|
|
|
- mode: "production",
|
|
|
|
- target: "web",
|
|
|
|
- entry: "./src/web/index.js",
|
|
|
|
- output: {
|
|
|
|
- filename: "scripts.js",
|
|
|
|
- path: __dirname + "/build/prod"
|
|
|
|
- },
|
|
|
|
- plugins: [
|
|
|
|
- new webpack.DefinePlugin(Object.assign({}, BUILD_CONSTANTS, {
|
|
|
|
- INLINE: "true"
|
|
|
|
- })),
|
|
|
|
- new HtmlWebpackPlugin({
|
|
|
|
- filename: "cyberchef.htm",
|
|
|
|
- template: "./src/web/html/index.html",
|
|
|
|
- compileTime: compileTime,
|
|
|
|
- version: pkg.version + "s",
|
|
|
|
- inline: true,
|
|
|
|
- minify: {
|
|
|
|
- removeComments: true,
|
|
|
|
- collapseWhitespace: true,
|
|
|
|
- minifyJS: true,
|
|
|
|
- minifyCSS: true
|
|
|
|
- }
|
|
|
|
- }),
|
|
|
|
- ]
|
|
|
|
- },
|
|
|
|
- tests: {
|
|
|
|
- mode: "development",
|
|
|
|
- target: "node",
|
|
|
|
- entry: "./test/index.mjs",
|
|
|
|
- externals: [NodeExternals()],
|
|
|
|
- output: {
|
|
|
|
- filename: "index.js",
|
|
|
|
- path: __dirname + "/build/test/node"
|
|
|
|
- },
|
|
|
|
- plugins: [
|
|
|
|
- new webpack.DefinePlugin(BUILD_CONSTANTS),
|
|
|
|
- ]
|
|
|
|
- },
|
|
|
|
node: {
|
|
node: {
|
|
mode: NODE_PROD ? "production" : "development",
|
|
mode: NODE_PROD ? "production" : "development",
|
|
target: "node",
|
|
target: "node",
|
|
@@ -381,6 +316,18 @@ module.exports = function (grunt) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ zip: {
|
|
|
|
+ standalone: {
|
|
|
|
+ cwd: "build/prod/",
|
|
|
|
+ src: [
|
|
|
|
+ "build/prod/**/*",
|
|
|
|
+ "!build/prod/index.html",
|
|
|
|
+ "!build/prod/BundleAnalyzerReport.html",
|
|
|
|
+ "!build/prod/sitemap.js"
|
|
|
|
+ ],
|
|
|
|
+ dest: `build/prod/CyberChef_v${pkg.version}.zip`
|
|
|
|
+ }
|
|
|
|
+ },
|
|
connect: {
|
|
connect: {
|
|
prod: {
|
|
prod: {
|
|
options: {
|
|
options: {
|
|
@@ -393,10 +340,16 @@ module.exports = function (grunt) {
|
|
ghPages: {
|
|
ghPages: {
|
|
options: {
|
|
options: {
|
|
process: function (content, srcpath) {
|
|
process: function (content, srcpath) {
|
|
- // Add Google Analytics code to index.html
|
|
|
|
if (srcpath.indexOf("index.html") >= 0) {
|
|
if (srcpath.indexOf("index.html") >= 0) {
|
|
|
|
+ // Add Google Analytics code to index.html
|
|
content = content.replace("</body></html>",
|
|
content = content.replace("</body></html>",
|
|
grunt.file.read("src/web/static/ga.html") + "</body></html>");
|
|
grunt.file.read("src/web/static/ga.html") + "</body></html>");
|
|
|
|
+
|
|
|
|
+ // Add Structured Data for SEO
|
|
|
|
+ content = content.replace("</head>",
|
|
|
|
+ "<script type='application/ld+json'>" +
|
|
|
|
+ JSON.stringify(JSON.parse(grunt.file.read("src/web/static/structuredData.json"))) +
|
|
|
|
+ "</script></head>");
|
|
return grunt.template.process(content, srcpath);
|
|
return grunt.template.process(content, srcpath);
|
|
} else {
|
|
} else {
|
|
return content;
|
|
return content;
|
|
@@ -415,6 +368,28 @@ module.exports = function (grunt) {
|
|
dest: "build/prod/"
|
|
dest: "build/prod/"
|
|
},
|
|
},
|
|
]
|
|
]
|
|
|
|
+ },
|
|
|
|
+ standalone: {
|
|
|
|
+ options: {
|
|
|
|
+ process: function (content, srcpath) {
|
|
|
|
+ if (srcpath.indexOf("index.html") >= 0) {
|
|
|
|
+ // Replace download link with version number
|
|
|
|
+ content = content.replace(/<a [^>]+>Download CyberChef.+?<\/a>/,
|
|
|
|
+ `<span>Version ${pkg.version}</span>`);
|
|
|
|
+
|
|
|
|
+ return grunt.template.process(content, srcpath);
|
|
|
|
+ } else {
|
|
|
|
+ return content;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ noProcess: ["**", "!**/*.html"]
|
|
|
|
+ },
|
|
|
|
+ files: [
|
|
|
|
+ {
|
|
|
|
+ src: "build/prod/index.html",
|
|
|
|
+ dest: `build/prod/CyberChef_v${pkg.version}.html`
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
}
|
|
}
|
|
},
|
|
},
|
|
chmod: {
|
|
chmod: {
|
|
@@ -477,7 +452,7 @@ module.exports = function (grunt) {
|
|
command: "node --experimental-modules --no-warnings --no-deprecation tests/operations/index.mjs"
|
|
command: "node --experimental-modules --no-warnings --no-deprecation tests/operations/index.mjs"
|
|
},
|
|
},
|
|
browserTests: {
|
|
browserTests: {
|
|
- command: "./node_modules/.bin/nightwatch --env prod,inline"
|
|
|
|
|
|
+ command: "./node_modules/.bin/nightwatch --env prod"
|
|
},
|
|
},
|
|
nodeTests: {
|
|
nodeTests: {
|
|
command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs"
|
|
command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs"
|