@@ -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,15 +115,15 @@ 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 : {
150
122
configFile : "./.eslintrc.json"
151
123
} ,
152
124
configs : [ "*.{js,mjs}" ] ,
153
125
core : [ "src/core/**/*.{js,mjs}" , "!src/core/vendor/**/*" , "!src/core/operations/legacy/**/*" ] ,
154
- web : [ "src/web/**/*.{js,mjs}" ] ,
126
+ web : [ "src/web/**/*.{js,mjs}" , "!src/web/static/**/*" ] ,
155
127
node : [ "src/node/**/*.{js,mjs}" ] ,
156
128
tests : [ "tests/**/*.{js,mjs}" ] ,
157
129
} ,
@@ -195,6 +167,9 @@ module.exports = function (grunt) {
195
167
} , moduleEntryPoints ) ,
196
168
output : {
197
169
path : __dirname + "/build/prod" ,
170
+ filename : chunkData => {
171
+ return chunkData . chunk . name === "main" ? "assets/[name].js" : "[name].js" ;
172
+ } ,
198
173
globalObject : "this"
199
174
} ,
200
175
resolve : {
@@ -225,33 +200,6 @@ module.exports = function (grunt) {
225
200
]
226
201
} ;
227
202
} ,
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
203
node : {
256
204
mode : "production" ,
257
205
target : "node" ,
@@ -284,7 +232,8 @@ module.exports = function (grunt) {
284
232
warningsFilter : [
285
233
/ s o u r c e - m a p / ,
286
234
/ d e p e n d e n c y i s a n e x p r e s s i o n / ,
287
- / e x p o r t ' d e f a u l t ' /
235
+ / e x p o r t ' d e f a u l t ' / ,
236
+ / C a n ' t r e s o l v e ' s o d i u m ' /
288
237
] ,
289
238
}
290
239
} ,
@@ -316,6 +265,18 @@ module.exports = function (grunt) {
316
265
}
317
266
}
318
267
} ,
268
+ zip : {
269
+ standalone : {
270
+ cwd : "build/prod/" ,
271
+ src : [
272
+ "build/prod/**/*" ,
273
+ "!build/prod/index.html" ,
274
+ "!build/prod/BundleAnalyzerReport.html" ,
275
+ "!build/prod/sitemap.js"
276
+ ] ,
277
+ dest : `build/prod/CyberChef_v${ pkg . version } .zip`
278
+ }
279
+ } ,
319
280
connect : {
320
281
prod : {
321
282
options : {
@@ -328,10 +289,16 @@ module.exports = function (grunt) {
328
289
ghPages : {
329
290
options : {
330
291
process : function ( content , srcpath ) {
331
- // Add Google Analytics code to index.html
332
292
if ( srcpath . indexOf ( "index.html" ) >= 0 ) {
293
+ // Add Google Analytics code to index.html
333
294
content = content . replace ( "</body></html>" ,
334
295
grunt . file . read ( "src/web/static/ga.html" ) + "</body></html>" ) ;
296
+
297
+ // Add Structured Data for SEO
298
+ content = content . replace ( "</head>" ,
299
+ "<script type='application/ld+json'>" +
300
+ JSON . stringify ( JSON . parse ( grunt . file . read ( "src/web/static/structuredData.json" ) ) ) +
301
+ "</script></head>" ) ;
335
302
return grunt . template . process ( content , srcpath ) ;
336
303
} else {
337
304
return content ;
@@ -350,6 +317,28 @@ module.exports = function (grunt) {
350
317
dest : "build/prod/"
351
318
} ,
352
319
]
320
+ } ,
321
+ standalone : {
322
+ options : {
323
+ process : function ( content , srcpath ) {
324
+ if ( srcpath . indexOf ( "index.html" ) >= 0 ) {
325
+ // Replace download link with version number
326
+ content = content . replace ( / < a [ ^ > ] + > D o w n l o a d C y b e r C h e f .+ ?< \/ a > / ,
327
+ `<span>Version ${ pkg . version } </span>` ) ;
328
+
329
+ return grunt . template . process ( content , srcpath ) ;
330
+ } else {
331
+ return content ;
332
+ }
333
+ } ,
334
+ noProcess : [ "**" , "!**/*.html" ]
335
+ } ,
336
+ files : [
337
+ {
338
+ src : "build/prod/index.html" ,
339
+ dest : `build/prod/CyberChef_v${ pkg . version } .html`
340
+ }
341
+ ]
353
342
}
354
343
} ,
355
344
chmod : {
@@ -405,7 +394,7 @@ module.exports = function (grunt) {
405
394
command : "node --experimental-modules --no-warnings --no-deprecation tests/operations/index.mjs"
406
395
} ,
407
396
browserTests : {
408
- command : "./node_modules/.bin/nightwatch --env prod,inline "
397
+ command : "./node_modules/.bin/nightwatch --env prod"
409
398
}
410
399
} ,
411
400
} ) ;
0 commit comments