1
1
import arg from 'arg' ;
2
2
import inquirer from 'inquirer' ;
3
3
import simpleGit from 'simple-git/promise' ;
4
- import builder from '../src/main'
4
+ import build from './parse' ;
5
+ import create from './create' ;
5
6
import fs from 'fs' ;
6
7
7
8
const localGit = 'Local directory' ;
@@ -28,6 +29,7 @@ function parseArgumentsIntoOptions(rawArgs) {
28
29
}
29
30
) ;
30
31
return {
32
+ command :args [ '_' ] [ 1 ] ,
31
33
git :args [ '--git' ] ,
32
34
dir :args [ '--dir' ] ,
33
35
codeBranch :args [ '--code' ] ,
@@ -45,11 +47,11 @@ async function promptForMissingOptions(options) {
45
47
if ( ! options . git && ! options . dir ) {
46
48
47
49
// check if the current dir is a valid repo
48
- const git = simpleGit ( __dirname ) ;
50
+ const git = simpleGit ( __dirname ) ;
49
51
const isRepo = await git . checkIsRepo ( ) ;
50
52
51
53
if ( ! isRepo ) {
52
-
54
+
53
55
questions . push ( {
54
56
type :'list' ,
55
57
name :'source' ,
@@ -127,22 +129,32 @@ async function promptForMissingOptions(options) {
127
129
128
130
export async function cli ( args ) {
129
131
let options = parseArgumentsIntoOptions ( args ) ;
130
-
132
+
131
133
// If help called just print the help text and exit
132
134
if ( options . help ) {
133
- console . log ( 'help message... ' ) ;
135
+ console . log ( 'Docs can be found at github: https://github.com/coderoad/builder-cli/ ' ) ;
134
136
}
135
137
else {
136
- // Otherwise, continue with the other options
137
- options = await promptForMissingOptions ( options ) ;
138
- console . log ( options ) ;
139
- config = await builder ( options ) ;
140
-
141
- if ( options . output ) {
142
- fs . writeFileSync ( options . output , config , 'utf8' ) ;
143
- }
144
- else {
145
- console . log ( JSON . stringify ( config ) )
138
+ switch ( options . command ) {
139
+ case 'build' :
140
+ // Otherwise, continue with the other options
141
+ options = await promptForMissingOptions ( options ) ;
142
+ console . log ( options ) ;
143
+ config = await build ( options ) ;
144
+
145
+ if ( config ) {
146
+ if ( options . output ) {
147
+ fs . writeFileSync ( options . output , config , 'utf8' ) ;
148
+ }
149
+ else {
150
+ console . log ( JSON . stringify ( config ) ) ;
151
+ }
152
+ }
153
+ break ;
154
+
155
+ case 'create' :
156
+ create ( __dirname ) ;
157
+ break ;
146
158
}
147
159
}
148
160
}