From 742c33f6f400b71b9c112894efac55ea73296d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20O=E2=80=99Shannessy?= Date: Tue, 6 Sep 2016 15:35:13 -0700 Subject: [PATCH] [rrm] Update init command to use Promise style --- scripts/release-manager/commands/init.js | 91 ++++++++++++------------ 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/scripts/release-manager/commands/init.js b/scripts/release-manager/commands/init.js index 033bbbf9b8..ae0b67d9d2 100644 --- a/scripts/release-manager/commands/init.js +++ b/scripts/release-manager/commands/init.js @@ -14,54 +14,57 @@ module.exports = function(vorpal, app) { vorpal .command('init') .description('Initializes a .config.json file for use') - .action(function(args, cb) { - fs.stat(app.PATH_TO_CONFIG, (err, stats) => { - if (stats) { - this.log('Config file exists, nothing to do.'); - cb(); - } + .action(function(args) { + return new Promise((resolve, reject) => { + fs.stat(app.PATH_TO_CONFIG, (err, stats) => { + if (stats) { + this.log('Config file exists, nothing to do.'); + reject(); + return; + } - this.prompt([ - { - name: 'githubToken', - type: 'input', - message: `${chalk.bold('GitHub token?')} ${chalk.grey('(needs "repo" privs)')} `, - }, - { - name: 'reactPath', - type: 'input', - message: `${chalk.bold('Location of local React checkout?')} `, - validate: (input) => { - let npath = path.normalize(untildify(input)); - - if (npath === '.') { - return 'Cannot be `.`'; - } - - let stats; - try { - stats = fs.statSync(npath); - } catch (e) { - return `Error: ${e}`; - } - - if (!stats.isDirectory()) { - return `${npath} is not a directory.`; - } - - // TODO: Look for markers indicating this is a React checkout. - return true; + this.prompt([ + { + name: 'githubToken', + type: 'input', + message: `${chalk.bold('GitHub token?')} ${chalk.grey('(needs "repo" privs)')} `, }, - }, - ]).then((answers) => { - fs.writeFile(app.PATH_TO_CONFIG, JSON.stringify(answers, null, 2), (err) => { - if (err) { - this.log('Error writing config file.', err); - } - cb(); + { + name: 'reactPath', + type: 'input', + message: `${chalk.bold('Location of local React checkout?')} `, + validate: (input) => { + let npath = path.normalize(untildify(input)); + + if (npath === '.') { + return 'Cannot be `.`'; + } + + let stats; + try { + stats = fs.statSync(npath); + } catch (e) { + return `Error: ${e}`; + } + + if (!stats.isDirectory()) { + return `${npath} is not a directory.`; + } + + // TODO: Look for markers indicating this is a React checkout. + return true; + }, + }, + ]).then((answers) => { + fs.writeFile(app.PATH_TO_CONFIG, JSON.stringify(answers, null, 2), (err) => { + if (err) { + this.log('Error writing config file.', err); + reject(); + } + resolve(); + }); }); }); - }); }); };