From 8816b0292b1bcc67d7958e41fa4fef06311e1890 Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Sun, 29 Oct 2023 13:04:21 +0100 Subject: [PATCH] Remove automatic first run --- config/nodecid.schema.json | 3 +++ deploy/start.js | 12 +++++++----- index.js | 3 ++- package.json | 2 +- types.d.js | 1 + 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/config/nodecid.schema.json b/config/nodecid.schema.json index 227412a..da885f3 100644 --- a/config/nodecid.schema.json +++ b/config/nodecid.schema.json @@ -30,6 +30,9 @@ }, "redeploy_path": { "type": "string" + }, + "first_run": { + "type": "boolean" } }, "required": ["start", "preflight"] diff --git a/deploy/start.js b/deploy/start.js index 22278e6..8435523 100755 --- a/deploy/start.js +++ b/deploy/start.js @@ -31,12 +31,14 @@ let childProcess = null; * @param {string[] | string} param0.preflight * @param {string} param0.redeploy_file * @param {string | number} [param0.port] + * @param {boolean} [param0.first_run] - Whether to run the preflight on first run. Default `false` */ -function startProcess({ command, preflight, redeploy_file, port }) { +function startProcess({ command, preflight, redeploy_file, port, first_run }) { try { - console.log("First Run ..."); - - const runPreflight = preflightFn(preflight); + if (first_run) { + console.log("First Run ..."); + const runPreflight = preflightFn(preflight); + } if (!preflight) { console.log( @@ -164,7 +166,7 @@ function preflightFn(preflight) { } else if (typeof preflight == "object" && preflight?.[0]) { preflight.forEach((cmd, index) => { try { - execSync(cmd, options); + const execCmd = execSync(cmd, options); } catch (error) { console.log( `${colors.FgRed}Error:${colors.Reset} Preflight command ${cmd} Failed! => ${error.message}` diff --git a/index.js b/index.js index 1e29542..fa4993c 100755 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ try { /** @type {NodeCIConfig} */ const config = JSON.parse(configText); - const { start, preflight, redeploy_path } = config; + const { start, preflight, redeploy_path, first_run } = config; /** @type {string | undefined} */ let redeployFile; @@ -53,6 +53,7 @@ try { command: start, preflight, redeploy_file: redeployFile, + first_run, }); } catch (error) { console.log( diff --git a/package.json b/package.json index 202daa0..81c2ba1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodecid", - "version": "1.0.1", + "version": "1.0.2", "description": "Simple CI/CD process", "main": "index.js", "bin": { diff --git a/types.d.js b/types.d.js index 1cd096f..333c71e 100644 --- a/types.d.js +++ b/types.d.js @@ -5,4 +5,5 @@ * the application starts, or a single `.sh` file path. * @property {string} [redeploy_path] - The path to the file that will trigger a * redeployment if content is changed. Default file path is `./REDEPLOY` + * @property {boolean} [first_run] - Whether to run the preflight on first run. Default `false` */