@@ -4,7 +4,6 @@ const webpack = require("webpack");
4
4
const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
5
5
const BundleAnalyzerPlugin = require ( "webpack-bundle-analyzer" ) . BundleAnalyzerPlugin ;
6
6
const NodeExternals = require ( "webpack-node-externals" ) ;
7
- const Inliner = require ( "web-resource-inliner" ) ;
8
7
const glob = require ( "glob" ) ;
9
8
const path = require ( "path" ) ;
10
9
@@ -43,18 +42,16 @@ module.exports = function (grunt) {
43
42
44
43
grunt . registerTask ( "prod" ,
45
44
"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
+ ] ) ;
47
49
48
50
grunt . registerTask ( "default" ,
49
51
"Lints the code base" ,
50
52
[ "eslint" , "exec:repoSize" ] ) ;
51
53
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" ] ) ;
55
54
56
-
57
- grunt . registerTask ( "runInliner" , runInliner ) ;
58
55
grunt . registerTask ( "doc" , "docs" ) ;
59
56
grunt . registerTask ( "tests" , "test" ) ;
60
57
grunt . registerTask ( "lint" , "eslint" ) ;
@@ -72,6 +69,7 @@ module.exports = function (grunt) {
72
69
grunt . loadNpmTasks ( "grunt-accessibility" ) ;
73
70
grunt . loadNpmTasks ( "grunt-concurrent" ) ;
74
71
grunt . loadNpmTasks ( "grunt-contrib-connect" ) ;
72
+ grunt . loadNpmTasks ( "grunt-zip" ) ;
75
73
76
74
77
75
// Project configuration
@@ -94,32 +92,6 @@ module.exports = function (grunt) {
94
92
} ,
95
93
moduleEntryPoints = listEntryModules ( ) ;
96
94
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
- }
123
95
124
96
/**
125
97
* Generates an entry list for all the modules.
@@ -130,7 +102,7 @@ module.exports = function (grunt) {
130
102
glob . sync ( "./src/core/config/modules/*.mjs" ) . forEach ( file => {
131
103
const basename = path . basename ( file ) ;
132
104
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 ) ;
134
106
} ) ;
135
107
136
108
return entryModules ;
@@ -143,7 +115,7 @@ module.exports = function (grunt) {
143
115
node : [ "build/node/*" ] ,
144
116
config : [ "src/core/config/OperationConfig.json" , "src/core/config/modules/*" , "src/code/operations/index.mjs" ] ,
145
117
docs : [ "docs/*" , "!docs/*.conf.json" , "!docs/*.ico" , "!docs/*.png" ] ,
146
- inlineScripts : [ "build/prod/scripts.js" ] ,
118
+ standalone : [ "build/prod/CyberChef*.html" ]
147
119
} ,
148
120
eslint : {
149
121
options : {
@@ -225,33 +197,6 @@ module.exports = function (grunt) {
225
197
]
226
198
} ;
227
199
} ,
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
- } ,
255
200
node : {
256
201
mode : "production" ,
257
202
target : "node" ,
@@ -317,6 +262,18 @@ module.exports = function (grunt) {
317
262
}
318
263
}
319
264
} ,
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
+ } ,
320
277
connect : {
321
278
prod : {
322
279
options : {
@@ -329,10 +286,16 @@ module.exports = function (grunt) {
329
286
ghPages : {
330
287
options : {
331
288
process : function ( content , srcpath ) {
332
- // Add Google Analytics code to index.html
333
289
if ( srcpath . indexOf ( "index.html" ) >= 0 ) {
290
+ // Add Google Analytics code to index.html
334
291
content = content . replace ( "</body></html>" ,
335
292
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>" ) ;
336
299
return grunt . template . process ( content , srcpath ) ;
337
300
} else {
338
301
return content ;
@@ -351,6 +314,28 @@ module.exports = function (grunt) {
351
314
dest : "build/prod/"
352
315
} ,
353
316
]
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 [ ^ > ] + > D o w n l o a d C y b e r C h e f .+ ?< \/ 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
+ ]
354
339
}
355
340
} ,
356
341
chmod : {
@@ -406,7 +391,7 @@ module.exports = function (grunt) {
406
391
command : "node --experimental-modules --no-warnings --no-deprecation tests/operations/index.mjs"
407
392
} ,
408
393
browserTests : {
409
- command : "./node_modules/.bin/nightwatch --env prod,inline "
394
+ command : "./node_modules/.bin/nightwatch --env prod"
410
395
}
411
396
} ,
412
397
} ) ;
0 commit comments