@@ -4,7 +4,8 @@ const webpack = require("webpack");
44const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
55const NodeExternals = require ( "webpack-node-externals" ) ;
66const Inliner = require ( "web-resource-inliner" ) ;
7- const fs = require ( "fs" ) ;
7+ const glob = require ( "glob" ) ;
8+ const path = require ( "path" ) ;
89
910/**
1011 * Grunt configuration for building the app in various formats.
@@ -21,23 +22,23 @@ module.exports = function (grunt) {
2122 // Tasks
2223 grunt . registerTask ( "dev" ,
2324 "A persistent task which creates a development build whenever source files are modified." ,
24- [ "clean:dev" , "concurrent: dev" ] ) ;
25+ [ "clean:dev" , "clean:config" , "webpack- dev-server:start "] ) ;
2526
2627 grunt . registerTask ( "node" ,
2728 "Compiles CyberChef into a single NodeJS module." ,
28- [ "clean:node" , "webpack:metaConf " , "webpack:node" , "chmod:build" ] ) ;
29+ [ "clean:node" , "clean:config " , "webpack:node" , "chmod:build" ] ) ;
2930
3031 grunt . registerTask ( "test" ,
3132 "A task which runs all the tests in test/tests." ,
32- [ "clean:test" , "webpack:metaConf" , "webpack: tests" , "execute:test "] ) ;
33+ [ "exec: tests" ] ) ;
3334
3435 grunt . registerTask ( "docs" ,
3536 "Compiles documentation in the /docs directory." ,
3637 [ "clean:docs" , "jsdoc" , "chmod:docs" ] ) ;
3738
3839 grunt . registerTask ( "prod" ,
3940 "Creates a production-ready build. Use the --msg flag to add a compile message." ,
40- [ "eslint" , "clean:prod" , "webpack:metaConf " , "webpack:web" , "inline" , "chmod" ] ) ;
41+ [ "eslint" , "clean:prod" , "clean:config " , "webpack:web" , "inline" , "chmod" ] ) ;
4142
4243 grunt . registerTask ( "default" ,
4344 "Lints the code base" ,
@@ -62,9 +63,7 @@ module.exports = function (grunt) {
6263 grunt . loadNpmTasks ( "grunt-contrib-copy" ) ;
6364 grunt . loadNpmTasks ( "grunt-chmod" ) ;
6465 grunt . loadNpmTasks ( "grunt-exec" ) ;
65- grunt . loadNpmTasks ( "grunt-execute" ) ;
6666 grunt . loadNpmTasks ( "grunt-accessibility" ) ;
67- grunt . loadNpmTasks ( "grunt-concurrent" ) ;
6867
6968
7069 // Project configuration
@@ -118,12 +117,12 @@ module.exports = function (grunt) {
118117 * Generates an entry list for all the modules.
119118 */
120119 function listEntryModules ( ) {
121- const path = "./src/core/config/modules/" ;
122120 let entryModules = { } ;
123121
124- fs . readdirSync ( path ) . forEach ( file => {
125- if ( file !== "Default.js" && file !== "OpModules.js" )
126- entryModules [ file . split ( ".js" ) [ 0 ] ] = path + file ;
122+ glob . sync ( "./src/core/config/modules/*.mjs" ) . forEach ( file => {
123+ const basename = path . basename ( file ) ;
124+ if ( basename !== "Default.mjs" && basename !== "OpModules.mjs" )
125+ entryModules [ basename . split ( ".mjs" ) [ 0 ] ] = path . resolve ( file ) ;
127126 } ) ;
128127
129128 return entryModules ;
@@ -132,9 +131,9 @@ module.exports = function (grunt) {
132131 grunt . initConfig ( {
133132 clean : {
134133 dev : [ "build/dev/*" ] ,
135- prod : [ "build/prod/*" , "src/core/config/MetaConfig.js" ] ,
136- test : [ "build/test/*" , "src/core/config/MetaConfig.js "] ,
137- node : [ "build/node/* " , "src/core/config/MetaConfig.js " ] ,
134+ prod : [ "build/prod/*" ] ,
135+ node : [ "build/node/* " ] ,
136+ config : [ "src/core/config/OperationConfig.json " , "src/core/config/modules/* " ] ,
138137 docs : [ "docs/*" , "!docs/*.conf.json" , "!docs/*.ico" , "!docs/*.png" ] ,
139138 inlineScripts : [ "build/prod/scripts.js" ] ,
140139 } ,
@@ -143,10 +142,10 @@ module.exports = function (grunt) {
143142 configFile : "./.eslintrc.json"
144143 } ,
145144 configs : [ "Gruntfile.js" ] ,
146- core : [ "src/core/**/*.js " , "!src/core/lib /**/*" , "!src/core/config/MetaConfig.js "] ,
147- web : [ "src/web/**/*.js " ] ,
148- node : [ "src/node/**/*.js " ] ,
149- tests : [ "test/**/*.js " ] ,
145+ core : [ "src/core/**/*.{js,mjs} " , "!src/core/vendor /**/*" ] ,
146+ web : [ "src/web/**/*.{js,mjs} " ] ,
147+ node : [ "src/node/**/*.{js,mjs} " ] ,
148+ tests : [ "test/**/*.{js,mjs} " ] ,
150149 } ,
151150 jsdoc : {
152151 options : {
@@ -159,17 +158,11 @@ module.exports = function (grunt) {
159158 all : {
160159 src : [
161160 "src/**/*.js" ,
162- "! src/core/lib/ **/*" ,
163- "!src/core/config/MetaConfig.js "
161+ "src/**/*.mjs " ,
162+ "!src/core/vendor/**/* "
164163 ] ,
165164 }
166165 } ,
167- concurrent : {
168- options : {
169- logConcurrentOutput : true
170- } ,
171- dev : [ "webpack:metaConfDev" , "webpack-dev-server:start" ]
172- } ,
173166 accessibility : {
174167 options : {
175168 accessibilityLevel : "WCAG2A" ,
@@ -184,39 +177,6 @@ module.exports = function (grunt) {
184177 } ,
185178 webpack : {
186179 options : webpackConfig ,
187- metaConf : {
188- mode : "production" ,
189- target : "node" ,
190- entry : [
191- "babel-polyfill" ,
192- "./src/core/config/OperationConfig.js"
193- ] ,
194- output : {
195- filename : "MetaConfig.js" ,
196- path : __dirname + "/src/core/config/" ,
197- library : "MetaConfig" ,
198- libraryTarget : "commonjs2" ,
199- libraryExport : "default"
200- } ,
201- externals : [ NodeExternals ( ) ] ,
202- } ,
203- metaConfDev : {
204- mode : "development" ,
205- target : "node" ,
206- entry : [
207- "babel-polyfill" ,
208- "./src/core/config/OperationConfig.js"
209- ] ,
210- output : {
211- filename : "MetaConfig.js" ,
212- path : __dirname + "/src/core/config/" ,
213- library : "MetaConfig" ,
214- libraryTarget : "commonjs2" ,
215- libraryExport : "default"
216- } ,
217- externals : [ NodeExternals ( ) ] ,
218- watch : true
219- } ,
220180 web : {
221181 mode : "production" ,
222182 target : "web" ,
@@ -229,7 +189,7 @@ module.exports = function (grunt) {
229189 } ,
230190 resolve : {
231191 alias : {
232- "./config/modules/OpModules.js " : "./config/modules/Default.js "
192+ "./config/modules/OpModules" : "./config/modules/Default"
233193 }
234194 } ,
235195 plugins : [
@@ -279,7 +239,7 @@ module.exports = function (grunt) {
279239 tests : {
280240 mode : "development" ,
281241 target : "node" ,
282- entry : "./test/index.js " ,
242+ entry : "./test/index.mjs " ,
283243 externals : [ NodeExternals ( ) ] ,
284244 output : {
285245 filename : "index.js" ,
@@ -292,7 +252,7 @@ module.exports = function (grunt) {
292252 node : {
293253 mode : "production" ,
294254 target : "node" ,
295- entry : "./src/node/index.js " ,
255+ entry : "./src/node/index.mjs " ,
296256 externals : [ NodeExternals ( ) ] ,
297257 output : {
298258 filename : "CyberChef.js" ,
@@ -330,7 +290,7 @@ module.exports = function (grunt) {
330290 } , moduleEntryPoints ) ,
331291 resolve : {
332292 alias : {
333- "./config/modules/OpModules.js " : "./config/modules/Default.js "
293+ "./config/modules/OpModules" : "./config/modules/Default"
334294 }
335295 } ,
336296 plugins : [
@@ -401,10 +361,10 @@ module.exports = function (grunt) {
401361 } ,
402362 sitemap : {
403363 command : "node build/prod/sitemap.js > build/prod/sitemap.xml"
364+ } ,
365+ tests : {
366+ command : "node --experimental-modules test/index.mjs"
404367 }
405368 } ,
406- execute : {
407- test : "build/test/index.js"
408- } ,
409369 } ) ;
410370} ;
0 commit comments