From c28999ec6f9e0d48e7d439b77a75c2bbc95e15fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Heinrichs?= Date: Thu, 3 Oct 2019 02:23:18 +0200 Subject: [PATCH 1/2] Fixed building on Windows On Windows OperationConfig was not generated. See #360 #645 for more Information. --- Gruntfile.js | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 92a2d550..5cae1f04 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,6 +14,17 @@ const path = require("path"); * @license Apache-2.0 */ +const chainCommands = function(cmds) { + const win = process.platform === "win32"; + if (!win) { + return cmds.join(";"); + } + return cmds + // Chain Command is different here + .join("&&") + // Windows does not support \n properly + .replace("\n", "\\n"); +}; module.exports = function (grunt) { grunt.file.defaultEncoding = "utf8"; @@ -316,10 +327,10 @@ module.exports = function (grunt) { }, exec: { repoSize: { - command: [ + command: chainCommands([ "git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'", "du -hs | egrep -o '^[^\t]*' | xargs printf '%b\trepository size\n'" - ].join(";"), + ]), stderr: false }, cleanGit: { @@ -329,20 +340,20 @@ module.exports = function (grunt) { command: "node --experimental-modules --no-warnings --no-deprecation src/web/static/sitemap.mjs > build/prod/sitemap.xml" }, generateConfig: { - command: [ + command: chainCommands([ "echo '\n--- Regenerating config files. ---'", "echo [] > src/core/config/OperationConfig.json", "node --experimental-modules --no-warnings --no-deprecation src/core/config/scripts/generateOpsIndex.mjs", "node --experimental-modules --no-warnings --no-deprecation src/core/config/scripts/generateConfig.mjs", "echo '--- Config scripts finished. ---\n'" - ].join(";") + ]) }, generateNodeIndex: { - command: [ + command: chainCommands([ "echo '\n--- Regenerating node index ---'", "node --experimental-modules --no-warnings --no-deprecation src/node/config/scripts/generateNodeIndex.mjs", "echo '--- Node index generated. ---\n'" - ].join(";"), + ]), }, opTests: { command: "node --experimental-modules --no-warnings --no-deprecation tests/operations/index.mjs" @@ -354,40 +365,40 @@ module.exports = function (grunt) { command: "node --experimental-modules --no-warnings --no-deprecation tests/node/index.mjs" }, setupNodeConsumers: { - command: [ + command: chainCommands([ "echo '\n--- Testing node conumers ---'", "npm link", `mkdir ${nodeConsumerTestPath}`, `cp tests/node/consumers/* ${nodeConsumerTestPath}`, `cd ${nodeConsumerTestPath}`, "npm link cyberchef" - ].join(";"), + ]), }, teardownNodeConsumers: { - command: [ + command: chainCommands([ `rm -rf ${nodeConsumerTestPath}`, "echo '\n--- Node consumer tests complete ---'" - ].join(";"), + ]), }, testCJSNodeConsumer: { - command: [ + command: chainCommands([ `cd ${nodeConsumerTestPath}`, "node --no-warnings cjs-consumer.js", - ].join(";"), + ]), stdout: false, }, testESMNodeConsumer: { - command: [ + command: chainCommands([ `cd ${nodeConsumerTestPath}`, "node --no-warnings --experimental-modules esm-consumer.mjs", - ].join(";"), + ]), stdout: false, }, testESMDeepImportNodeConsumer: { - command: [ + command: chainCommands([ `cd ${nodeConsumerTestPath}`, "node --no-warnings --experimental-modules esm-deep-import-consumer.mjs", - ].join(";"), + ]), stdout: false, }, }, From 17c9ffe10733f987f8d86396c47d08f4e49abda8 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 16 Oct 2019 16:32:06 +0100 Subject: [PATCH 2/2] Tidied up chainCommands function in Gruntfile --- Gruntfile.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index ce4dd863..b25553b7 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,18 +14,6 @@ const path = require("path"); * @license Apache-2.0 */ -const chainCommands = function(cmds) { - const win = process.platform === "win32"; - if (!win) { - return cmds.join(";"); - } - return cmds - // Chain Command is different here - .join("&&") - // Windows does not support \n properly - .replace("\n", "\\n"); -}; - module.exports = function (grunt) { grunt.file.defaultEncoding = "utf8"; grunt.file.preserveBOM = false; @@ -113,6 +101,26 @@ module.exports = function (grunt) { return entryModules; } + /** + * Detects the correct delimiter to use to chain shell commands together + * based on the current OS. + * + * @param {string[]} cmds + * @returns {string} + */ + function chainCommands(cmds) { + const win = process.platform === "win32"; + if (!win) { + return cmds.join(";"); + } + return cmds + // && means that subsequent commands will not be executed if the + // previous one fails. & would coninue on a fail + .join("&&") + // Windows does not support \n properly + .replace("\n", "\\n"); + } + grunt.initConfig({ clean: { dev: ["build/dev/*"],