1+ import * as Sentry from "@sentry/node" ;
12import chalk from "chalk" ;
23import commander from "commander" ;
3- import * as Sentry from "@sentry/node " ;
4+ import inquirer from "inquirer " ;
45
6+ /**
7+ * Initialize Sentry
8+ */
59Sentry . init ( {
610 dsn :
711 "https://55c913cc3d394f71ba669fda095698fd@o202486.ingest.sentry.io/5254191" ,
8- release : "0.3 .0" ,
12+ release : "0.4 .0" ,
913} ) ;
1014
1115import {
@@ -15,24 +19,43 @@ import {
1519 installDevDependencies ,
1620 createTSConfig ,
1721 displaySuccessMessage ,
22+ replaceTemplateValues ,
1823} from "./init" ;
1924import { handleIncorrectApplicationName } from "./program" ;
25+ import { cleanupError , validateApplicationName } from "./util" ;
2026
27+ /**
28+ * Main CLI Program
29+ */
2130const main = async ( ) : Promise < void > => {
31+ let applicationName ;
32+ let authorName = "YOUR NAME" ;
33+
2234 try {
23- let applicationName ;
35+ // * Used to set the directory, application name, and inserted into templates
2436 let language : "js" | "ts" ;
37+ // * Default language is JavaScript
2538 language = "js" ;
39+
40+ /**
41+ * The program that parses the initial user input
42+ */
2643 const program = new commander . Command ( "create-cli-application" )
27- . version ( "0.3 .0" )
44+ . version ( "0.4 .0" )
2845 . arguments ( "<application-name>" )
2946 . usage ( `${ chalk . yellowBright ( "<application-name>" ) } [options]` )
3047 . action ( ( name ) => {
3148 applicationName = name ;
3249 } )
3350 . option (
3451 "--typescript" ,
35- "use TypeScript as the cli application source language"
52+ "use TypeScript as the cli application source language" ,
53+ false
54+ )
55+ . option (
56+ "--interactive" ,
57+ "Have the bootstrapper walk you through the process" ,
58+ false
3659 )
3760 . on ( "--help" , ( ) => {
3861 console . log (
@@ -47,26 +70,71 @@ const main = async (): Promise<void> => {
4770 } )
4871 . parse ( process . argv ) ;
4972
50- // TODO - Catch names like "my.app.name" or "my app name"
51- if ( applicationName === "." || ! applicationName ) {
52- return handleIncorrectApplicationName ( program ) ;
73+ // * Application Name must exist, and not consist of illegal characters
74+ validateApplicationName ( applicationName ) ;
75+ if ( ! applicationName ) return ;
76+
77+ if ( program . interactive ) {
78+ // * Interactive walk-thru
79+
80+ // * Language
81+ const languageAnswer = await inquirer . prompt ( [
82+ {
83+ type : "list" ,
84+ name : "language" ,
85+ message : "Please select a source language:" ,
86+ choices : [
87+ { value : "js" , name : "JavaScript" } ,
88+ { value : "ts" , name : "TypeScript" } ,
89+ ] ,
90+ } ,
91+ ] ) ;
92+ const languageChoice : "js" | "ts" = languageAnswer . language ;
93+ language = languageChoice ;
94+
95+ // * Author Name
96+ const nameAnswer = await inquirer . prompt ( [
97+ {
98+ type : "input" ,
99+ name : "name" ,
100+ message :
101+ "Please input your name (used for the 'About' screen, but not required):" ,
102+ } ,
103+ ] ) ;
104+ const name : string = nameAnswer . name ;
105+ authorName = name ;
106+
107+ // TODO - Compiler Choice (Babel vs. other)
108+ // TODO - Add Prettier
109+ // TODO - Add ESLint / Other Linter
110+ // TODO - Menu Color Option
53111 }
54112
55- if ( program . typescript ) language = "ts" ;
113+ // * Set language to 'ts' if user passed --typescript flag
114+ if ( program . typescript && ! program . interactive ) language = "ts" ;
56115
116+ // * Creates a project directory and package.json
57117 await createProjectDirectory ( applicationName , language ) ;
58118
119+ // * Installs dependencies
59120 await installDependencies ( applicationName ) ;
60121
122+ // * Installs dev dependencies
61123 await installDevDependencies ( applicationName , language ) ;
62124
125+ // * Copies template files
63126 await copyTemplateFiles ( applicationName , language ) ;
64127
128+ // * Replaces template files placeholder values with real values for the application.
129+ await replaceTemplateValues ( applicationName , language , authorName ) ;
130+
131+ // * Creates a tsconfig.json file
65132 if ( language === "ts" ) await createTSConfig ( applicationName ) ;
66133
134+ // * Displays a success message to the user
67135 displaySuccessMessage ( applicationName ) ;
68136 } catch ( error ) {
69- // TODO - Cleanup
137+ await cleanupError ( applicationName ) ;
70138 console . error ( error ) ;
71139 throw new Error ( error ) ;
72140 }
0 commit comments