Browse Source

Do not mangle names on minification for Node prod build - property names are used for search in bake

d98762625 6 years ago
parent
commit
48f3a3b18f
4 changed files with 289 additions and 247 deletions
  1. 39 1
      Gruntfile.js
  2. 245 239
      package-lock.json
  3. 1 0
      package.json
  4. 4 7
      src/node/repl-index.mjs

+ 39 - 1
Gruntfile.js

@@ -6,6 +6,7 @@ const NodeExternals = require("webpack-node-externals");
 const Inliner = require("web-resource-inliner");
 const glob = require("glob");
 const path = require("path");
+const UglifyJSWebpackPlugin = require("uglifyjs-webpack-plugin");
 
 /**
  * Grunt configuration for building the app in various formats.
@@ -26,7 +27,7 @@ module.exports = function (grunt) {
 
     grunt.registerTask("node",
         "Compiles CyberChef into a single NodeJS module.",
-        ["clean", "exec:generateConfig", "exec:generateNodeIndex",  "webpack:node", "chmod:build"]);
+        ["clean", "exec:generateConfig", "exec:generateNodeIndex",  "webpack:node", "webpack:nodeRepl", "chmod:build"]);
 
     grunt.registerTask("test",
         "A task which runs all the tests in test/tests.",
@@ -267,6 +268,43 @@ module.exports = function (grunt) {
                 plugins: [
                     new webpack.DefinePlugin(BUILD_CONSTANTS)
                 ],
+                // Need to preserve property names for bake, search
+                optimization: {
+                    minimizer: [
+                        new UglifyJSWebpackPlugin({
+                            uglifyOptions: {
+                                mangle: false,
+                            }
+                        })
+                    ]
+                },
+            },
+            nodeRepl: {
+                mode: "production",
+                target: "node",
+                entry: "./src/node/repl-index.mjs",
+                externals: [NodeExternals({
+                    whitelist: ["crypto-api/src/crypto-api"]
+                })],
+                output: {
+                    filename: "CyberChef-repl.js",
+                    path: __dirname + "/build/node",
+                    library: "CyberChef",
+                    libraryTarget: "commonjs2"
+                },
+                plugins: [
+                    new webpack.DefinePlugin(BUILD_CONSTANTS)
+                ],
+                // Need to preserve property names for bake, search
+                optimization: {
+                    minimizer: [
+                        new UglifyJSWebpackPlugin({
+                            uglifyOptions: {
+                                mangle: false,
+                            }
+                        })
+                    ]
+                }
             }
         },
         "webpack-dev-server": {

File diff suppressed because it is too large
+ 245 - 239
package-lock.json


+ 1 - 0
package.json

@@ -66,6 +66,7 @@
     "sass-loader": "^7.1.0",
     "sitemap": "^1.13.0",
     "style-loader": "^0.21.0",
+    "uglifyjs-webpack-plugin": "^2.0.1",
     "url-loader": "^1.0.1",
     "web-resource-inliner": "^4.2.1",
     "webpack": "^4.16.4",

+ 4 - 7
src/node/repl-index.mjs

@@ -7,9 +7,7 @@
  * @license Apache-2.0
  */
 
-import { operations } from "./index";
 import chef from "./index";
-import { decapitalise } from "./apiUtils";
 import repl from "repl";
 import "babel-polyfill";
 
@@ -28,10 +26,9 @@ const replServer = repl.start({
     prompt: "chef > ",
 });
 
-operations.forEach((op) => {
-    replServer.context[decapitalise(op.opName)] = op;
+Object.keys(chef).forEach((key) => {
+    if (key !== "operations") {
+        replServer.context[key] = chef[key];
+    }
 });
 
-replServer.context.help = chef.help;
-replServer.context.bake = chef.bake;
-replServer.context.Dish = chef.Dish;

Some files were not shown because too many files changed in this diff