Skip to content

Commit

Permalink
Modified step check logic to do an explicit process exit
Browse files Browse the repository at this point in the history
  • Loading branch information
keikhosro committed Dec 3, 2018
1 parent 2c078e3 commit 49e71a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,26 @@ const npm = spawn('npm', args, {
shell: true
});

function checkStep(step, count) {
if (count > step) {
process.exit(1);
}
}

let count = 0;
npm.stdout.on('data', (data) => {
const str = data.toString();
process.stdout.write(str);
if (str.match(/username/i)) {
if (count > 0) {
npm.stdin.end();
return;
}
checkStep(0, count);
process.stdout.write(`${username}\n`);
npm.stdin.write(username + '\n');
} else if (str.match(/password/i)) {
if (count > 1) {
npm.stdin.end();
return;
}
checkStep(1, count);
process.stdout.write('\n');
npm.stdin.write(password + '\n');
} else if (str.match(/email/i)) {
if (count > 2) {
npm.stdin.end();
return;
}
checkStep(2, count);
process.stdout.write(`${email}\n`);
npm.stdin.write(email + '\n');
npm.stdin.end();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "npm-cli-adduser",
"version": "1.1.1",
"version": "1.1.2",
"description": "A script to perform `npm adduser` without having to interact with the shell",
"bin": {
"npm-cli-adduser": "./index.js"
Expand Down

0 comments on commit 49e71a6

Please sign in to comment.