mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[rrm] Update init command to use Promise style
This commit is contained in:
committed by
Dan Abramov
parent
8c94467aad
commit
742c33f6f4
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user