[rrm] Update init command to use Promise style
Paul O’Shannessy committed
Sep 6, 2016 at 15:35 UTC
823030d26bce59a6682f58f5fd4837e5101d6088
1 file changed
+43
-40
scripts/release-manager/commands/init.js
+43
-40
@@ -14,54 +14,57 @@ module.exports = function(vorpal, app) {
14
vorpal
15
.command('init')
16
.description('Initializes a .config.json file for use')
17
- .action(function(args, cb) {
18
- fs.stat(app.PATH_TO_CONFIG, (err, stats) => {
19
- if (stats) {
20
- this.log('Config file exists, nothing to do.');
21
- cb();
22
- }
17
+ .action(function(args) {
18
+ return new Promise((resolve, reject) => {
19
+ fs.stat(app.PATH_TO_CONFIG, (err, stats) => {
20
+ if (stats) {
21
+ this.log('Config file exists, nothing to do.');
22
+ reject();
23
+ return;
24
+ }
25
24
- this.prompt([
25
- {
26
- name: 'githubToken',
27
- type: 'input',
28
- message: `${chalk.bold('GitHub token?')} ${chalk.grey('(needs "repo" privs)')} `,
29
- },
30
- {
31
- name: 'reactPath',
32
- type: 'input',
33
- message: `${chalk.bold('Location of local React checkout?')} `,
34
- validate: (input) => {
35
- let npath = path.normalize(untildify(input));
26
+ this.prompt([
27
+ {
28
+ name: 'githubToken',
29
+ type: 'input',
30
+ message: `${chalk.bold('GitHub token?')} ${chalk.grey('(needs "repo" privs)')} `,
31
+ },
32
+ {
33
+ name: 'reactPath',
34
+ type: 'input',
35
+ message: `${chalk.bold('Location of local React checkout?')} `,
36
+ validate: (input) => {
37
+ let npath = path.normalize(untildify(input));
38
37
- if (npath === '.') {
38
- return 'Cannot be `.`';
39
- }
39
+ if (npath === '.') {
40
+ return 'Cannot be `.`';
41
+ }
42
41
- let stats;
42
- try {
43
- stats = fs.statSync(npath);
44
- } catch (e) {
45
- return `Error: ${e}`;
46
- }
43
+ let stats;
44
+ try {
45
+ stats = fs.statSync(npath);
46
+ } catch (e) {
47
+ return `Error: ${e}`;
48
+ }
49
48
- if (!stats.isDirectory()) {
49
- return `${npath} is not a directory.`;
50
- }
50
+ if (!stats.isDirectory()) {
51
+ return `${npath} is not a directory.`;
52
+ }
53
52
- // TODO: Look for markers indicating this is a React checkout.
53
- return true;
54
+ // TODO: Look for markers indicating this is a React checkout.
55
+ return true;
56
+ },
57
},
55
- },
56
- ]).then((answers) => {
57
- fs.writeFile(app.PATH_TO_CONFIG, JSON.stringify(answers, null, 2), (err) => {
58
- if (err) {
59
- this.log('Error writing config file.', err);
60
- }
61
- cb();
58
+ ]).then((answers) => {
59
+ fs.writeFile(app.PATH_TO_CONFIG, JSON.stringify(answers, null, 2), (err) => {
60
+ if (err) {
61
+ this.log('Error writing config file.', err);
62
+ reject();
63
+ }
64
+ resolve();
65
+ });
66
});
67
});
64
-
68
});
69
});
70
};