Skip to content

Commit

Permalink
feature(madrun) add nupdate support
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jul 25, 2019
1 parent e5c6d3e commit 200439f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
28 changes: 16 additions & 12 deletions bin/init.js
Expand Up @@ -9,6 +9,7 @@ const {
} = require('fs');

const tryCatch = require('try-catch');
const nupdate = require('nupdate');

const info = require(`${CWD}/package`);

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}

65 changes: 36 additions & 29 deletions bin/madrun.js
Expand Up @@ -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');
Expand Down

0 comments on commit 200439f

Please sign in to comment.