From 200439fd3104775d53f18b213482a7b8330fb32f Mon Sep 17 00:00:00 2001 From: coderaiser Date: Thu, 25 Jul 2019 17:42:14 +0300 Subject: [PATCH] feature(madrun) add nupdate support --- bin/init.js | 28 ++++++++++++---------- bin/madrun.js | 65 ++++++++++++++++++++++++++++----------------------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/bin/init.js b/bin/init.js index b3fbf69..049e5fd 100644 --- a/bin/init.js +++ b/bin/init.js @@ -9,6 +9,7 @@ const { } = require('fs'); const tryCatch = require('try-catch'); +const nupdate = require('nupdate'); const info = require(`${CWD}/package`); @@ -37,7 +38,21 @@ module.exports.patchPackage = () => { }; module.exports.patchNpmIgnore = () => { - updateNpmIgnore(); + const [, file = ''] = tryCatch(readFileSync, './.npmignore'); + + if (file.includes('madrun.js')) + return; + + const data = file + 'madrun.js\n\n'; + writeFileSync('./.npmignore', data); +} + +module.exports.addMadrunToPackage = () => { + return nupdate('madrun', { + install: true, + dev: true, + add: true, + }); }; function preparePackage(info, scripts) { @@ -61,14 +76,3 @@ function patchPackage(scripts) { return result; } - -function updateNpmIgnore() { - const [, file = ''] = tryCatch(readFileSync, './.npmignore'); - - if (file.includes('madrun.js')) - return; - - const data = file + 'madrun.js\n\n'; - writeFileSync('./.npmignore', data); -} - diff --git a/bin/madrun.js b/bin/madrun.js index 72f86c9..36d77f2 100755 --- a/bin/madrun.js +++ b/bin/madrun.js @@ -44,46 +44,53 @@ if (init) { const init = require('./init'); fix = true; - init.create(); - init.patchNpmIgnore(); - init.patchPackage(); + return init.addMadrunToPackage().then(() => { + init.create(); + init.patchNpmIgnore(); + init.patchPackage(); + next(); + }); } -const names = args._; -const options = getOptions(args['--']); -const [dir, script] = getScript(); +next(); + +function next() { + const names = args._; + const options = getOptions(args['--']); + const [dir, script] = getScript(); + + const problems = check(script); -const problems = check(script); + if (problems) { + const result = putoutMadrun(dir, {fix}); + + if (fix) { + process.exit(); + } else { + console.log(result); + process.exit(1); + } + } -if (problems) { - const result = putoutMadrun(dir, {fix}); + if (init) + return; - if (fix) { - process.exit(); - } else { - console.log(result); + if (problems) { + execute(`echo '${problems}'`); process.exit(1); } -} - -if (init) - return; -if (problems) { - execute(`echo '${problems}'`); - process.exit(1); -} - -if (!names.length) { - console.log(Object.keys(script).join('\n')); - exit(); -} + if (!names.length) { + console.log(Object.keys(script).join('\n')); + exit(); + } -const cmd = series(names, options, script); + const cmd = series(names, options, script); -console.log(`> ${cmd}`); + console.log(`> ${cmd}`); -execute(cmd); + execute(cmd); +} function execute(cmd) { const {execSync} = require('child_process');