Skip to content

Commit 943cb32

Browse files
author
Cam Tullos
committed
Setup project start command to be the same as init.
1 parent 220d9a3 commit 943cb32

File tree

8 files changed

+79
-55
lines changed

8 files changed

+79
-55
lines changed

bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const generator = require('./lib/generator');
2222
const Hook = require('@atomic-reactor/reactium-sdk-core/lib/hook').default;
2323

2424
const spinner = ora({ spinner: 'dots', color: 'cyan' });
25+
spinner.message = (...args) => spinner.start(args.join(' '));
2526

2627
const initialize = props => {
2728

commands/project/init/actions/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ const fs = require('fs-extra');
44
const _ = require('underscore');
55
const op = require('object-path');
66

7-
module.exports = spinner => {
8-
const message = text => {
9-
if (spinner) {
10-
spinner.text = text;
11-
}
12-
};
7+
module.exports = () => {
8+
let Hook, spinner;
139

1410
return {
15-
create: ({ action, params, props }) => {
16-
message(`Creating ${chalk.cyan('something')}...`);
11+
init: ({ arcli, params, props }) => {
12+
Hook = op.get(arcli, 'Hook');
13+
spinner = op.get(arcli, 'spinner');
14+
},
15+
create: ({ params, props }) => {
16+
spinner.message('Creating', chalk.cyan('something'), '...');
1717
},
1818
};
1919
};

commands/project/init/generator.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ module.exports = ({ arcli, params, props }) => {
66

77
const { Hook, spinner } = arcli;
88

9-
spinner.start();
10-
119
const actions = require('./actions')(spinner);
1210

1311
const onError = error => {

commands/project/init/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const CONFORM = ({ input, props }) =>
102102
const HELP = () =>
103103
console.log(`
104104
Example:
105-
$ arcli project <init> -h
105+
$ arcli project init -h
106106
`);
107107

108108
/**
@@ -173,7 +173,7 @@ const SCHEMA = ({ props }) => {
173173
* @param props Object The CLI props passed from the calling class `orcli.js`.
174174
* @since 2.0.0
175175
*/
176-
const ACTION = ({ opt, props, arcli }) => {
176+
const ACTION = ({ arcli, opt, props }) => {
177177
const { cwd, prompt } = props;
178178
const schema = SCHEMA({ props });
179179
const ovr = FLAGS_TO_PARAMS({ opt });
@@ -200,7 +200,7 @@ const ACTION = ({ opt, props, arcli }) => {
200200
});
201201
})
202202
.then(() => CONFIRM({ props, params }))
203-
.then(() => GENERATOR({ params, props, arcli }))
203+
.then(() => GENERATOR({ arcli, params, props }))
204204
.then(() => prompt.stop())
205205
.then(results => {
206206
console.log('');
@@ -215,11 +215,11 @@ const ACTION = ({ opt, props, arcli }) => {
215215
* COMMAND Function
216216
* @description Function that executes program.command()
217217
*/
218-
const COMMAND = ({ program, props, arcli }) =>
218+
const COMMAND = ({ arcli, program, props }) =>
219219
program
220220
.command(NAME)
221221
.description(DESC)
222-
.action(opt => ACTION({ opt, props, arcli }))
222+
.action(opt => ACTION({ arcli, opt, props }))
223223
.option('-s, --sample [sample]', 'Sample parameter.')
224224
.option('-o, --overwrite [overwrite]', 'Overwrite existing file.')
225225
.on('--help', HELP);

commands/project/start/actions.js

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const path = require('path');
2+
const chalk = require('chalk');
3+
const fs = require('fs-extra');
4+
const _ = require('underscore');
5+
const op = require('object-path');
6+
7+
module.exports = () => {
8+
let Hook, spinner;
9+
10+
return {
11+
init: ({ arcli, params, props }) => {
12+
Hook = op.get(arcli, 'Hook');
13+
spinner = op.get(arcli, 'spinner');
14+
},
15+
create: ({ params, props }) => {
16+
spinner.message('Creating', chalk.cyan('something'), '...');
17+
},
18+
};
19+
};
Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,54 @@
1-
const ora = require('ora');
1+
const op = require('object-path');
22
const ActionSequence = require('action-sequence');
33

4-
module.exports = ({ params, props }) => {
4+
module.exports = ({ arcli, params, props }) => {
55
console.log('');
6-
const spinner = ora({
7-
spinner: 'dots',
8-
color: 'cyan',
9-
});
106

11-
spinner.start();
7+
const { Hook, spinner } = arcli;
128

139
const actions = require('./actions')(spinner);
1410

11+
const onError = error => {
12+
let message = op.get(error, 'message', error);
13+
Hook.runSync('project-start-error', {
14+
arcli,
15+
message,
16+
params,
17+
props,
18+
});
19+
spinner.fail(message);
20+
return new Error(message);
21+
};
22+
23+
// Run actions hook
24+
try {
25+
Hook.runSync('project-start-actions', { actions, arcli, params, props });
26+
} catch (error) {
27+
onError(error);
28+
}
29+
1530
return ActionSequence({
1631
actions,
17-
options: { params, props },
32+
options: { arcli, params, props },
1833
})
1934
.then(success => {
20-
spinner.succeed('complete!');
21-
console.log('');
35+
let message = 'project init complete!';
36+
37+
// Run complete hook
38+
try {
39+
Hook.runSync('project-start-complete', {
40+
arcli,
41+
params,
42+
props,
43+
message,
44+
success,
45+
});
46+
spinner.succeed(message);
47+
} catch (error) {
48+
return onError(error);
49+
}
50+
2251
return success;
2352
})
24-
.catch(error => {
25-
spinner.fail('error!');
26-
return error;
27-
});
53+
.catch(onError);
2854
};

commands/project/start/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const GENERATOR = require('./generator');
1515
/**
1616
* NAME String
1717
* @description Constant defined as the command name. Value passed to the commander.command() function.
18-
* @example $ arcli project <start>
18+
* @example $ arcli project start
1919
* @see https://www.npmjs.com/package/commander#command-specific-options
2020
* @since 2.0.0
2121
*/
@@ -102,7 +102,7 @@ const CONFORM = ({ input, props }) =>
102102
const HELP = () =>
103103
console.log(`
104104
Example:
105-
$ arcli project <start> -h
105+
$ arcli project start -h
106106
`);
107107

108108
/**
@@ -173,7 +173,7 @@ const SCHEMA = ({ props }) => {
173173
* @param props Object The CLI props passed from the calling class `orcli.js`.
174174
* @since 2.0.0
175175
*/
176-
const ACTION = ({ opt, props }) => {
176+
const ACTION = ({ arcli, opt, props }) => {
177177
const { cwd, prompt } = props;
178178
const schema = SCHEMA({ props });
179179
const ovr = FLAGS_TO_PARAMS({ opt });
@@ -200,7 +200,7 @@ const ACTION = ({ opt, props }) => {
200200
});
201201
})
202202
.then(() => CONFIRM({ props, params }))
203-
.then(() => GENERATOR({ params, props }))
203+
.then(() => GENERATOR({ arcli, params, props }))
204204
.then(() => prompt.stop())
205205
.then(results => {
206206
console.log('');
@@ -215,11 +215,11 @@ const ACTION = ({ opt, props }) => {
215215
* COMMAND Function
216216
* @description Function that executes program.command()
217217
*/
218-
const COMMAND = ({ program, props }) =>
218+
const COMMAND = ({ arcli, program, props }) =>
219219
program
220220
.command(NAME)
221221
.description(DESC)
222-
.action(opt => ACTION({ opt, props }))
222+
.action(opt => ACTION({ arcli, opt, props }))
223223
.option('-s, --sample [sample]', 'Sample parameter.')
224224
.option('-o, --overwrite [overwrite]', 'Overwrite existing file.')
225225
.on('--help', HELP);

0 commit comments

Comments
 (0)