11import arg from 'arg' ;
22import inquirer from 'inquirer' ;
33import simpleGit from 'simple-git/promise' ;
4- import builder from '../src/main'
4+ import build from './parse' ;
5+ import create from './create' ;
56import fs from 'fs' ;
67
78const localGit = 'Local directory' ;
@@ -28,6 +29,7 @@ function parseArgumentsIntoOptions(rawArgs) {
2829 }
2930 ) ;
3031 return {
32+ command : args [ '_' ] [ 1 ] ,
3133 git : args [ '--git' ] ,
3234 dir : args [ '--dir' ] ,
3335 codeBranch : args [ '--code' ] ,
@@ -45,11 +47,11 @@ async function promptForMissingOptions(options) {
4547 if ( ! options . git && ! options . dir ) {
4648
4749 // check if the current dir is a valid repo
48- const git = simpleGit ( __dirname ) ;
50+ const git = simpleGit ( __dirname ) ;
4951 const isRepo = await git . checkIsRepo ( ) ;
5052
5153 if ( ! isRepo ) {
52-
54+
5355 questions . push ( {
5456 type : 'list' ,
5557 name : 'source' ,
@@ -127,22 +129,32 @@ async function promptForMissingOptions(options) {
127129
128130export async function cli ( args ) {
129131 let options = parseArgumentsIntoOptions ( args ) ;
130-
132+
131133 // If help called just print the help text and exit
132134 if ( options . help ) {
133- console . log ( 'help message... ' ) ;
135+ console . log ( 'Docs can be found at github: https://github.com/coderoad/builder-cli/ ' ) ;
134136 }
135137 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 ;
146158 }
147159 }
148160}
0 commit comments