2018-04-02 19:24:25 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-11-14 08:55:27 +00:00
|
|
|
/* eslint no-console: ["off"] */
|
2018-04-02 19:24:25 +01:00
|
|
|
|
|
|
|
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 => {
|
2019-02-15 16:11:13 +00:00
|
|
|
if (!file.endsWith(".mjs") || file === "index.mjs") return;
|
2018-04-02 19:24:25 +01:00
|
|
|
opObjs.push(file.split(".mjs")[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Construct index file
|
|
|
|
let code = `/**
|
2024-06-11 18:07:22 +01:00
|
|
|
* 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
|
|
|
|
*/
|
2018-04-02 19:24:25 +01:00
|
|
|
`;
|
|
|
|
|
|
|
|
opObjs.forEach(obj => {
|
2019-07-09 12:23:59 +01:00
|
|
|
code += `import ${obj} from "./${obj}.mjs";\n`;
|
2018-04-02 19:24:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
code += `
|
|
|
|
export {
|
|
|
|
`;
|
|
|
|
|
|
|
|
opObjs.forEach(obj => {
|
|
|
|
code += ` ${obj},\n`;
|
|
|
|
});
|
|
|
|
|
|
|
|
code += "};\n";
|
|
|
|
|
|
|
|
// Write file
|
|
|
|
fs.writeFileSync(
|
|
|
|
path.join(dir, "../operations/index.mjs"),
|
|
|
|
code
|
|
|
|
);
|
2018-04-11 17:58:40 +00:00
|
|
|
console.log("Written operation index.");
|