mirror of
https://github.com/gchq/CyberChef
synced 2025-01-06 01:28:48 +00:00
ESM: The operations index is now generated automatically
This commit is contained in:
parent
eeb1d0a891
commit
fbb3a02315
7 changed files with 87 additions and 18 deletions
|
@ -133,7 +133,7 @@ module.exports = function (grunt) {
|
||||||
dev: ["build/dev/*"],
|
dev: ["build/dev/*"],
|
||||||
prod: ["build/prod/*"],
|
prod: ["build/prod/*"],
|
||||||
node: ["build/node/*"],
|
node: ["build/node/*"],
|
||||||
config: ["src/core/config/OperationConfig.json", "src/core/config/modules/*"],
|
config: ["src/core/config/OperationConfig.json", "src/core/config/modules/*", "src/code/operations/index.mjs"],
|
||||||
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico", "!docs/*.png"],
|
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico", "!docs/*.png"],
|
||||||
inlineScripts: ["build/prod/scripts.js"],
|
inlineScripts: ["build/prod/scripts.js"],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/generateConfig.mjs
|
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateConfig.mjs
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
* @copyright Crown Copyright 2018
|
* @copyright Crown Copyright 2018
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/generateConfig.mjs
|
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateConfig.mjs
|
||||||
*
|
*
|
||||||
* Imports all modules for builds which do not load modules separately.
|
* Imports all modules for builds which do not load modules separately.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* This script automatically generates OperationConfig.json, containing metadata
|
* This script automatically generates OperationConfig.json, containing metadata
|
||||||
* for each opeartion in the src/core/operations directory.
|
* for each operation in the src/core/operations directory.
|
||||||
* It also generates modules in the src/core/config/modules directory to separate
|
* It also generates modules in the src/core/config/modules directory to separate
|
||||||
* out operations into logical collections.
|
* out operations into logical collections.
|
||||||
*
|
*
|
||||||
|
@ -14,13 +14,13 @@
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import process from "process";
|
import process from "process";
|
||||||
import * as Ops from "../operations/index";
|
import * as Ops from "../../operations/index";
|
||||||
|
|
||||||
const dir = path.join(process.cwd() + "/src/core/config/");
|
const dir = path.join(process.cwd() + "/src/core/config/");
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
console.log("\nCWD: " + process.cwd());
|
console.log("\nCWD: " + process.cwd());
|
||||||
console.log("Error: generateConfig.mjs should be run from the project root");
|
console.log("Error: generateConfig.mjs should be run from the project root");
|
||||||
console.log("Example> node --experimental-modules src/core/config/generateConfig.mjs");
|
console.log("Example> node --experimental-modules src/core/config/scripts/generateConfig.mjs");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ fs.writeFile(
|
||||||
*/
|
*/
|
||||||
for (const module in modules) {
|
for (const module in modules) {
|
||||||
let code = `/**
|
let code = `/**
|
||||||
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/generateConfig.mjs
|
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateConfig.mjs
|
||||||
*
|
*
|
||||||
* @author n1474335 [n1474335@gmail.com]
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
* @copyright Crown Copyright ${new Date().getUTCFullYear()}
|
* @copyright Crown Copyright ${new Date().getUTCFullYear()}
|
||||||
|
@ -113,7 +113,7 @@ export default OpModules;
|
||||||
* Write OpModules wrapper.
|
* Write OpModules wrapper.
|
||||||
*/
|
*/
|
||||||
let opModulesCode = `/**
|
let opModulesCode = `/**
|
||||||
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/generateConfig.mjs
|
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateConfig.mjs
|
||||||
*
|
*
|
||||||
* Imports all modules for builds which do not load modules separately.
|
* Imports all modules for builds which do not load modules separately.
|
||||||
*
|
*
|
59
src/core/config/scripts/generateOpsIndex.mjs
Normal file
59
src/core/config/scripts/generateOpsIndex.mjs
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* This script automatically generates src/core/operations/index.mjs, containing
|
||||||
|
* imports for all operations in src/core/operations.
|
||||||
|
*
|
||||||
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2018
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*eslint no-console: ["off"] */
|
||||||
|
|
||||||
|
import path from "path";
|
||||||
|
import fs from "fs";
|
||||||
|
import process from "process";
|
||||||
|
|
||||||
|
const dir = path.join(process.cwd() + "/src/core/config/");
|
||||||
|
if (!fs.existsSync(dir)) {
|
||||||
|
console.log("\nCWD: " + process.cwd());
|
||||||
|
console.log("Error: generateOpsIndex.mjs should be run from the project root");
|
||||||
|
console.log("Example> node --experimental-modules src/core/config/scripts/generateOpsIndex.mjs");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find all operation files
|
||||||
|
const opObjs = [];
|
||||||
|
fs.readdirSync(path.join(dir, "../operations")).forEach(file => {
|
||||||
|
if (!file.endsWith(".mjs") || file === "index.mjs") return;
|
||||||
|
opObjs.push(file.split(".mjs")[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Construct index file
|
||||||
|
let code = `/**
|
||||||
|
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateOpsIndex.mjs
|
||||||
|
*
|
||||||
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @copyright Crown Copyright ${new Date().getUTCFullYear()}
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
`;
|
||||||
|
|
||||||
|
opObjs.forEach(obj => {
|
||||||
|
code += `import ${obj} from "./${obj}";\n`;
|
||||||
|
});
|
||||||
|
|
||||||
|
code += `
|
||||||
|
export {
|
||||||
|
`;
|
||||||
|
|
||||||
|
opObjs.forEach(obj => {
|
||||||
|
code += ` ${obj},\n`;
|
||||||
|
});
|
||||||
|
|
||||||
|
code += "};\n";
|
||||||
|
|
||||||
|
// Write file
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(dir, "../operations/index.mjs"),
|
||||||
|
code
|
||||||
|
);
|
|
@ -1,17 +1,24 @@
|
||||||
import ToBase64 from "./ToBase64";
|
/**
|
||||||
import FromBase64 from "./FromBase64";
|
* THIS FILE IS AUTOMATICALLY GENERATED BY src/core/config/scripts/generateOpsIndex.mjs
|
||||||
import ToBase32 from "./ToBase32";
|
*
|
||||||
|
* @author n1474335 [n1474335@gmail.com]
|
||||||
|
* @copyright Crown Copyright 2018
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
import FromBase32 from "./FromBase32";
|
import FromBase32 from "./FromBase32";
|
||||||
import ShowBase64Offsets from "./ShowBase64Offsets";
|
import FromBase64 from "./FromBase64";
|
||||||
import ToHex from "./ToHex";
|
|
||||||
import FromHex from "./FromHex";
|
import FromHex from "./FromHex";
|
||||||
|
import ShowBase64Offsets from "./ShowBase64Offsets";
|
||||||
|
import ToBase32 from "./ToBase32";
|
||||||
|
import ToBase64 from "./ToBase64";
|
||||||
|
import ToHex from "./ToHex";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
ToBase64,
|
|
||||||
FromBase64,
|
|
||||||
ToBase32,
|
|
||||||
FromBase32,
|
FromBase32,
|
||||||
|
FromBase64,
|
||||||
|
FromHex,
|
||||||
ShowBase64Offsets,
|
ShowBase64Offsets,
|
||||||
|
ToBase32,
|
||||||
|
ToBase64,
|
||||||
ToHex,
|
ToHex,
|
||||||
FromHex
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,7 +45,10 @@ module.exports = {
|
||||||
}),
|
}),
|
||||||
new ExtractTextPlugin("styles.css"),
|
new ExtractTextPlugin("styles.css"),
|
||||||
new WebpackShellPlugin({
|
new WebpackShellPlugin({
|
||||||
onBuildStart: ["node --experimental-modules src/core/config/generateConfig.mjs"],
|
onBuildStart: [
|
||||||
|
"node --experimental-modules src/core/config/scripts/generateOpsIndex.mjs",
|
||||||
|
"node --experimental-modules src/core/config/scripts/generateConfig.mjs",
|
||||||
|
],
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|
Loading…
Reference in a new issue