Skip to content

Commit 8f45050

Browse files
committed
Downloadble version is now a .zip file instead of a single .htm file
1 parent b3ae0e5 commit 8f45050

9 files changed

+631
-433
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ deploy:
3030
skip_cleanup: true
3131
api_key:
3232
secure: "HV1WSKv4l/0Y2bKKs1iBJocBcmLj08PCRUeEM/jTwA4jqJ8EiLHWiXtER/D5sEg2iibRVKd2OQjfrmS6bo4AiwdeVgAKmv0FtS2Jw+391N8Nd5AkEANHa5Om/IpHLTL2YRAjpJTsDpY72bMUTJIwjQA3TFJkgrpOw6KYfohOcgbxLpZ4XuNJRU3VL4Hsxdv5V9aOVmfFOmMOVPQlakXy7NgtW5POp1f2WJwgcZxylkR1CjwaqMyXmSoVl46pyH3tr5+dptsQoKSGdi6sIHGA60oDotFPcm+0ifa47wZw+vapuuDi4tdNxhrHGaDMG8xiE0WFDHwQUDlk2/+W7j9SEX0H3Em7us371JXRp56EDwEcDa34VpVkC6i8HGcHK55hnxVbMZXGf3qhOFD8wY7qMbjMRvIpucrMHBi86OfkDfv0vDj2LyvIl5APj/AX50BrE0tfH1MZbH26Jkx4NdlkcxQ14GumarmUqfmVvbX/fsoA6oUuAAE9ZgRRi3KHO4wci6KUcRfdm+XOeUkaBFsL86G3EEYIvrtBTuaypdz+Cx7nd1iPZyWMx5Y1gXnVzha4nBdV4+7l9JIsFggD8QVpw2uHXQiS1KXFjOeqA3DBD8tjMB7q26Fl2fD3jkOo4BTbQ2NrRIZUu/iL+fOmMPsyMt2qulB0yaSBCfkbEq8xrUA="
33+
file_glob: true
3334
file:
34-
- build/prod/cyberchef.htm
35+
- build/prod/*.zip
3536
- build/node/CyberChef.js
3637
on:
3738
repo: gchq/CyberChef

Gruntfile.js

+49-64
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const webpack = require("webpack");
44
const HtmlWebpackPlugin = require("html-webpack-plugin");
55
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
66
const NodeExternals = require("webpack-node-externals");
7-
const Inliner = require("web-resource-inliner");
87
const glob = require("glob");
98
const path = require("path");
109

@@ -43,18 +42,16 @@ module.exports = function (grunt) {
4342

4443
grunt.registerTask("prod",
4544
"Creates a production-ready build. Use the --msg flag to add a compile message.",
46-
["eslint", "clean:prod", "clean:config", "exec:generateConfig", "webpack:web", "inline", "chmod"]);
45+
[
46+
"eslint", "clean:prod", "clean:config", "exec:generateConfig", "webpack:web",
47+
"copy:standalone", "zip:standalone", "clean:standalone", "chmod"
48+
]);
4749

4850
grunt.registerTask("default",
4951
"Lints the code base",
5052
["eslint", "exec:repoSize"]);
5153

52-
grunt.registerTask("inline",
53-
"Compiles a production build of CyberChef into a single, portable web page.",
54-
["exec:generateConfig", "webpack:webInline", "runInliner", "clean:inlineScripts"]);
5554

56-
57-
grunt.registerTask("runInliner", runInliner);
5855
grunt.registerTask("doc", "docs");
5956
grunt.registerTask("tests", "test");
6057
grunt.registerTask("lint", "eslint");
@@ -72,6 +69,7 @@ module.exports = function (grunt) {
7269
grunt.loadNpmTasks("grunt-accessibility");
7370
grunt.loadNpmTasks("grunt-concurrent");
7471
grunt.loadNpmTasks("grunt-contrib-connect");
72+
grunt.loadNpmTasks("grunt-zip");
7573

7674

7775
// Project configuration
@@ -94,32 +92,6 @@ module.exports = function (grunt) {
9492
},
9593
moduleEntryPoints = listEntryModules();
9694

97-
/**
98-
* Compiles a production build of CyberChef into a single, portable web page.
99-
*/
100-
function runInliner() {
101-
const done = this.async();
102-
Inliner.html({
103-
relativeTo: "build/prod/",
104-
fileContent: grunt.file.read("build/prod/cyberchef.htm"),
105-
images: true,
106-
svgs: true,
107-
scripts: true,
108-
links: true,
109-
strict: true
110-
}, function(error, result) {
111-
if (error) {
112-
if (error instanceof Error) {
113-
done(error);
114-
} else {
115-
done(new Error(error));
116-
}
117-
} else {
118-
grunt.file.write("build/prod/cyberchef.htm", result);
119-
done(true);
120-
}
121-
});
122-
}
12395

12496
/**
12597
* Generates an entry list for all the modules.
@@ -130,7 +102,7 @@ module.exports = function (grunt) {
130102
glob.sync("./src/core/config/modules/*.mjs").forEach(file => {
131103
const basename = path.basename(file);
132104
if (basename !== "Default.mjs" && basename !== "OpModules.mjs")
133-
entryModules[basename.split(".mjs")[0]] = path.resolve(file);
105+
entryModules["modules/" + basename.split(".mjs")[0]] = path.resolve(file);
134106
});
135107

136108
return entryModules;
@@ -143,7 +115,7 @@ module.exports = function (grunt) {
143115
node: ["build/node/*"],
144116
config: ["src/core/config/OperationConfig.json", "src/core/config/modules/*", "src/code/operations/index.mjs"],
145117
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico", "!docs/*.png"],
146-
inlineScripts: ["build/prod/scripts.js"],
118+
standalone: ["build/prod/CyberChef*.html"]
147119
},
148120
eslint: {
149121
options: {
@@ -225,33 +197,6 @@ module.exports = function (grunt) {
225197
]
226198
};
227199
},
228-
webInline: {
229-
mode: "production",
230-
target: "web",
231-
entry: "./src/web/index.js",
232-
output: {
233-
filename: "scripts.js",
234-
path: __dirname + "/build/prod"
235-
},
236-
plugins: [
237-
new webpack.DefinePlugin(Object.assign({}, BUILD_CONSTANTS, {
238-
INLINE: "true"
239-
})),
240-
new HtmlWebpackPlugin({
241-
filename: "cyberchef.htm",
242-
template: "./src/web/html/index.html",
243-
compileTime: compileTime,
244-
version: pkg.version + "s",
245-
inline: true,
246-
minify: {
247-
removeComments: true,
248-
collapseWhitespace: true,
249-
minifyJS: true,
250-
minifyCSS: true
251-
}
252-
}),
253-
]
254-
},
255200
node: {
256201
mode: "production",
257202
target: "node",
@@ -317,6 +262,18 @@ module.exports = function (grunt) {
317262
}
318263
}
319264
},
265+
zip: {
266+
standalone: {
267+
cwd: "build/prod/",
268+
src: [
269+
"build/prod/**/*",
270+
"!build/prod/index.html",
271+
"!build/prod/BundleAnalyzerReport.html",
272+
"!build/prod/sitemap.js"
273+
],
274+
dest: `build/prod/CyberChef_v${pkg.version}.zip`
275+
}
276+
},
320277
connect: {
321278
prod: {
322279
options: {
@@ -329,10 +286,16 @@ module.exports = function (grunt) {
329286
ghPages: {
330287
options: {
331288
process: function (content, srcpath) {
332-
// Add Google Analytics code to index.html
333289
if (srcpath.indexOf("index.html") >= 0) {
290+
// Add Google Analytics code to index.html
334291
content = content.replace("</body></html>",
335292
grunt.file.read("src/web/static/ga.html") + "</body></html>");
293+
294+
// Add Structured Data for SEO
295+
content = content.replace("</head>",
296+
"<script type='application/ld+json'>" +
297+
JSON.stringify(grunt.file.read("src/web/static/structuredData.json")) +
298+
"</script>");
336299
return grunt.template.process(content, srcpath);
337300
} else {
338301
return content;
@@ -351,6 +314,28 @@ module.exports = function (grunt) {
351314
dest: "build/prod/"
352315
},
353316
]
317+
},
318+
standalone: {
319+
options: {
320+
process: function (content, srcpath) {
321+
if (srcpath.indexOf("index.html") >= 0) {
322+
// Replace download link with version number
323+
content = content.replace(/<a [^>]+>Download CyberChef.+?<\/a>/,
324+
`<span>Version ${pkg.version}</span>`);
325+
326+
return grunt.template.process(content, srcpath);
327+
} else {
328+
return content;
329+
}
330+
},
331+
noProcess: ["**", "!**/*.html"]
332+
},
333+
files: [
334+
{
335+
src: "build/prod/index.html",
336+
dest: `build/prod/CyberChef_v${pkg.version}.html`
337+
}
338+
]
354339
}
355340
},
356341
chmod: {
@@ -406,7 +391,7 @@ module.exports = function (grunt) {
406391
command: "node --experimental-modules --no-warnings --no-deprecation tests/operations/index.mjs"
407392
},
408393
browserTests: {
409-
command: "./node_modules/.bin/nightwatch --env prod,inline"
394+
command: "./node_modules/.bin/nightwatch --env prod"
410395
}
411396
},
412397
});

nightwatch.json

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

2424
"prod": {
2525
"launch_url": "http://localhost:8000/index.html"
26-
},
27-
28-
"inline": {
29-
"launch_url": "http://localhost:8000/cyberchef.htm"
3026
}
3127

3228
}

0 commit comments

Comments
 (0)