1
1
import inquirer from 'inquirer' ;
2
2
import { StackConfig , LaravelWizard } from 'stacker-core' ;
3
3
4
+ import { getStackConfig , catchErrors } from '../utils' ;
5
+
4
6
5
7
async function getStackName ( ) {
6
8
const answers = await inquirer . prompt ( {
@@ -20,24 +22,25 @@ function getWizard(stack) {
20
22
if ( stack === 'laravel' ) return LaravelWizard ;
21
23
}
22
24
23
- async function getOptions ( wizard ) {
25
+ async function getOptions ( stack ) {
26
+ const wizard = getWizard ( stack ) ;
27
+
28
+ if ( ! wizard ) return { } ;
29
+
24
30
const questions = wizard . getQuestions ( ) ;
25
31
const answers = await inquirer . prompt ( questions ) ;
32
+
26
33
return wizard . makeOptions ( answers ) ;
27
34
}
28
35
29
36
async function handle ( args , options , logger ) {
30
- if ( await StackConfig . load ( process . cwd ( ) ) ) {
31
- logger . info ( 'This project is already initialized.' ) ;
32
- return ;
33
- }
37
+ if ( await getStackConfig ( ) ) throw new Error ( 'The project is already initialized' ) ;
34
38
35
39
const config = new StackConfig ( ) ;
36
40
const stack = options . stack || await getStackName ( ) ;
37
- const wizard = getWizard ( stack ) ;
38
41
39
42
config . stack = stack ;
40
- config . options = await getOptions ( wizard ) ;
43
+ config . options = options . defaults ? null : await getOptions ( stack ) ;
41
44
42
45
await config . save ( process . cwd ( ) ) ;
43
46
@@ -49,7 +52,7 @@ function register(program) {
49
52
. command ( 'init' , 'Init project' )
50
53
. argument ( '[stack]' , 'Stack type' , [ 'laravel' ] )
51
54
. option ( '-y, --defaults' , 'Use default options' , program . BOOL , false )
52
- . action ( handle ) ;
55
+ . action ( catchErrors ( handle ) ) ;
53
56
}
54
57
55
58
export default { register } ;
0 commit comments