From b81f7349effef36bf3e918413fc976b7b56604d3 Mon Sep 17 00:00:00 2001 From: Timo Hocker Date: Wed, 4 Mar 2020 12:59:16 +0100 Subject: [PATCH] jenkins snippet set ci script --- snippets/jenkins/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/snippets/jenkins/index.js b/snippets/jenkins/index.js index b76ac71..1c5c658 100644 --- a/snippets/jenkins/index.js +++ b/snippets/jenkins/index.js @@ -20,10 +20,12 @@ const path = require ('path'); * @param {Array} args function arguments */ function run (folder, args) { + const is_node = args.length === 1 && (/^node$/ui).test (args[0]); + const template = path.join ( __dirname, 'template', - args.length === 1 && (/^node$/ui).test + is_node ? 'node' : 'general' ); @@ -35,6 +37,15 @@ function run (folder, args) { { filter: (src, dest) => !fs.existsSync (dest) } ); } + + if (is_node) { + const pkg = path.join (folder, 'package.json'); + if (fs.existsSync (pkg)) { + const json = JSON.parse (fs.readFileSync (pkg, 'utf-8')); + json.scripts.ci = 'yarn && node jenkins.js'; + fs.writeFileSync (pkg, JSON.stringify (json, null, 2), 'utf-8'); + } + } } /**