mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 06:55:08 -04:00
fix: improve platform-dependent command execution in grunt tasks
Fixes #2010
This commit is contained in:
parent
7c8be12d52
commit
13d776f78b
1 changed files with 20 additions and 42 deletions
62
Gruntfile.js
62
Gruntfile.js
|
@ -4,10 +4,20 @@ const webpack = require("webpack");
|
||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||||
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
||||||
const glob = require("glob");
|
const glob = require("glob");
|
||||||
const path = require("path");
|
const path = require("node:path");
|
||||||
|
const cp = require("node:child_process");
|
||||||
|
|
||||||
const nodeFlags = "--experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings --no-deprecation";
|
const nodeFlags = "--experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings --no-deprecation";
|
||||||
|
|
||||||
|
// Prepare platform-dependent commands
|
||||||
|
|
||||||
|
// Older MacOS versions don't come with `sha256sum`, but they all come with `shasum`
|
||||||
|
const sha256sumCmd = process.platform === "darwin" ? "shasum -a 256" : "sha256sum";
|
||||||
|
|
||||||
|
// MacOS (and FreeBSD, but not OpenBSD) require an argument to `-i`.
|
||||||
|
// However, users may have installed GNU sed, so let's check what `sed` says itself.
|
||||||
|
const sedCmd = cp.execSync("sed -i 2>&1 | head -n1").toString().includes("option requires an argument") ? "sed -i ''" : "sed -i";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grunt configuration for building the app in various formats.
|
* Grunt configuration for building the app in various formats.
|
||||||
*
|
*
|
||||||
|
@ -60,7 +70,7 @@ module.exports = function (grunt) {
|
||||||
|
|
||||||
grunt.registerTask("findModules",
|
grunt.registerTask("findModules",
|
||||||
"Finds all generated modules and updates the entry point list for Webpack",
|
"Finds all generated modules and updates the entry point list for Webpack",
|
||||||
function(arg1, arg2) {
|
function (arg1, arg2) {
|
||||||
const moduleEntryPoints = listEntryModules();
|
const moduleEntryPoints = listEntryModules();
|
||||||
|
|
||||||
grunt.log.writeln(`Found ${Object.keys(moduleEntryPoints).length} modules.`);
|
grunt.log.writeln(`Found ${Object.keys(moduleEntryPoints).length} modules.`);
|
||||||
|
@ -112,7 +122,7 @@ module.exports = function (grunt) {
|
||||||
output: {
|
output: {
|
||||||
path: __dirname + "/build/prod",
|
path: __dirname + "/build/prod",
|
||||||
filename: chunkData => {
|
filename: chunkData => {
|
||||||
return chunkData.chunk.name === "main" ? "assets/[name].js": "[name].js";
|
return chunkData.chunk.name === "main" ? "assets/[name].js" : "[name].js";
|
||||||
},
|
},
|
||||||
globalObject: "this"
|
globalObject: "this"
|
||||||
},
|
},
|
||||||
|
@ -329,20 +339,10 @@ module.exports = function (grunt) {
|
||||||
},
|
},
|
||||||
exec: {
|
exec: {
|
||||||
calcDownloadHash: {
|
calcDownloadHash: {
|
||||||
command: function () {
|
command: chainCommands([
|
||||||
switch (process.platform) {
|
`${sha256sumCmd} build/prod/CyberChef_v${pkg.version}.zip | awk '{print $1;}' > build/prod/sha256digest.txt`,
|
||||||
case "darwin":
|
`${sedCmd} -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html`,
|
||||||
return chainCommands([
|
]),
|
||||||
`shasum -a 256 build/prod/CyberChef_v${pkg.version}.zip | awk '{print $1;}' > build/prod/sha256digest.txt`,
|
|
||||||
`sed -i '' -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html`
|
|
||||||
]);
|
|
||||||
default:
|
|
||||||
return chainCommands([
|
|
||||||
`sha256sum build/prod/CyberChef_v${pkg.version}.zip | awk '{print $1;}' > build/prod/sha256digest.txt`,
|
|
||||||
`sed -i -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html`
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
repoSize: {
|
repoSize: {
|
||||||
command: chainCommands([
|
command: chainCommands([
|
||||||
|
@ -411,37 +411,15 @@ module.exports = function (grunt) {
|
||||||
stdout: false,
|
stdout: false,
|
||||||
},
|
},
|
||||||
fixCryptoApiImports: {
|
fixCryptoApiImports: {
|
||||||
command: function () {
|
command: `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 ${sedCmd} -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'`,
|
||||||
switch (process.platform) {
|
|
||||||
case "darwin":
|
|
||||||
return `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 sed -i '' -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'`;
|
|
||||||
default:
|
|
||||||
return `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 sed -i -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
stdout: false
|
stdout: false
|
||||||
},
|
},
|
||||||
fixSnackbarMarkup: {
|
fixSnackbarMarkup: {
|
||||||
command: function () {
|
command: `${sedCmd} 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`,
|
||||||
switch (process.platform) {
|
|
||||||
case "darwin":
|
|
||||||
return `sed -i '' 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`;
|
|
||||||
default:
|
|
||||||
return `sed -i 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
stdout: false
|
stdout: false
|
||||||
},
|
},
|
||||||
fixJimpModule: {
|
fixJimpModule: {
|
||||||
command: function () {
|
command: `${sedCmd} 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json`,
|
||||||
switch (process.platform) {
|
|
||||||
case "darwin":
|
|
||||||
// Space added before comma to prevent multiple modifications
|
|
||||||
return `sed -i '' 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json`;
|
|
||||||
default:
|
|
||||||
return `sed -i 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
stdout: false
|
stdout: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue