|
3 | 3 | const webpack = require("webpack");
|
4 | 4 | const HtmlWebpackPlugin = require("html-webpack-plugin");
|
5 | 5 | const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
6 |
| -const glob = require("glob"); |
7 |
| -const path = require("path"); |
| 6 | +const glob = require("node:glob"); |
| 7 | +const path = require("node:path"); |
| 8 | +const cp = require("node:child_process"); |
8 | 9 |
|
9 | 10 | const nodeFlags = "--experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings --no-deprecation";
|
10 | 11 |
|
| 12 | +// Prepare platform-dependent commands |
| 13 | + |
| 14 | +// Older MacOS versions don't come with `sha256sum`, but they all come with `shasum` |
| 15 | +const sha256sumCmd = process.platform === "darwin" ? "shasum -a 256" : "sha256sum"; |
| 16 | + |
| 17 | +// MacOS (and FreeBSD, but not OpenBSD) require an argument to `-i`. |
| 18 | +// However, users may have installed GNU sed, so let's check what `sed` says itself. |
| 19 | +const sedCmd = cp.execSync("sed -i 2>&1 | head -n1").toString().includes("option requires an argument") ? "sed -i ''" : "sed -i"; |
| 20 | + |
11 | 21 | /**
|
12 | 22 | * Grunt configuration for building the app in various formats.
|
13 | 23 | *
|
@@ -60,7 +70,7 @@ module.exports = function (grunt) {
|
60 | 70 |
|
61 | 71 | grunt.registerTask("findModules",
|
62 | 72 | "Finds all generated modules and updates the entry point list for Webpack",
|
63 |
| - function(arg1, arg2) { |
| 73 | + function (arg1, arg2) { |
64 | 74 | const moduleEntryPoints = listEntryModules();
|
65 | 75 |
|
66 | 76 | grunt.log.writeln(`Found ${Object.keys(moduleEntryPoints).length} modules.`);
|
@@ -112,7 +122,7 @@ module.exports = function (grunt) {
|
112 | 122 | output: {
|
113 | 123 | path: __dirname + "/build/prod",
|
114 | 124 | filename: chunkData => {
|
115 |
| - return chunkData.chunk.name === "main" ? "assets/[name].js": "[name].js"; |
| 125 | + return chunkData.chunk.name === "main" ? "assets/[name].js" : "[name].js"; |
116 | 126 | },
|
117 | 127 | globalObject: "this"
|
118 | 128 | },
|
@@ -329,20 +339,10 @@ module.exports = function (grunt) {
|
329 | 339 | },
|
330 | 340 | exec: {
|
331 | 341 | calcDownloadHash: {
|
332 |
| - command: function () { |
333 |
| - switch (process.platform) { |
334 |
| - case "darwin": |
335 |
| - return chainCommands([ |
336 |
| - `shasum -a 256 build/prod/CyberChef_v${pkg.version}.zip | awk '{print $1;}' > build/prod/sha256digest.txt`, |
337 |
| - `sed -i '' -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html` |
338 |
| - ]); |
339 |
| - default: |
340 |
| - return chainCommands([ |
341 |
| - `sha256sum build/prod/CyberChef_v${pkg.version}.zip | awk '{print $1;}' > build/prod/sha256digest.txt`, |
342 |
| - `sed -i -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html` |
343 |
| - ]); |
344 |
| - } |
345 |
| - }, |
| 342 | + command: chainCommands([ |
| 343 | + `${sha256sumCmd} build/prod/CyberChef_v${pkg.version}.zip | awk '{print $1;}' > build/prod/sha256digest.txt`, |
| 344 | + `${sedCmd} -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html`, |
| 345 | + ]), |
346 | 346 | },
|
347 | 347 | repoSize: {
|
348 | 348 | command: chainCommands([
|
@@ -411,37 +411,15 @@ module.exports = function (grunt) {
|
411 | 411 | stdout: false,
|
412 | 412 | },
|
413 | 413 | fixCryptoApiImports: {
|
414 |
| - command: function () { |
415 |
| - switch (process.platform) { |
416 |
| - case "darwin": |
417 |
| - 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'`; |
418 |
| - default: |
419 |
| - 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'`; |
420 |
| - } |
421 |
| - }, |
| 414 | + 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'`, |
422 | 415 | stdout: false
|
423 | 416 | },
|
424 | 417 | fixSnackbarMarkup: {
|
425 |
| - command: function () { |
426 |
| - switch (process.platform) { |
427 |
| - case "darwin": |
428 |
| - return `sed -i '' 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`; |
429 |
| - default: |
430 |
| - return `sed -i 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`; |
431 |
| - } |
432 |
| - }, |
| 418 | + command: `${sedCmd} 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`, |
433 | 419 | stdout: false
|
434 | 420 | },
|
435 | 421 | fixJimpModule: {
|
436 |
| - command: function () { |
437 |
| - switch (process.platform) { |
438 |
| - case "darwin": |
439 |
| - // Space added before comma to prevent multiple modifications |
440 |
| - return `sed -i '' 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json`; |
441 |
| - default: |
442 |
| - return `sed -i 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json`; |
443 |
| - } |
444 |
| - }, |
| 422 | + command: `${sedCmd} 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json`, |
445 | 423 | stdout: false
|
446 | 424 | }
|
447 | 425 | },
|
|
0 commit comments