1- const arg = require ( "arg" ) ;
2- const inquirer = require ( "inquirer" ) ;
3- const schema = require ( "./main" ) ;
4-
5- // export var schemaDetails = {};
6- function parseArgumentsIntoOptions ( rawArgs ) {
1+ import arg from "arg" ;
2+ import inquirer from "inquirer" ;
3+ import createSchema from "./main" ;
4+
5+ function parseArgumentsIntoOptions (
6+ rawArgs : any [ ]
7+ ) : {
8+ language : boolean ;
9+ filePath : string ;
10+ } {
711 const args = arg (
812 {
913 "--typescript" : Boolean ,
@@ -17,24 +21,39 @@ function parseArgumentsIntoOptions(rawArgs) {
1721 }
1822 ) ;
1923 return {
20- language : args [ "--typescript" ] || undefined ,
24+ language : args [ "--typescript" ] || false ,
2125 filePath : args [ "--filepath" ] || "/" ,
2226 } ;
2327}
2428
25- async function promptForMissingOptions ( options ) {
29+ type optionsType = {
30+ language : boolean ;
31+ filePath ?: string ;
32+ schemaKeys ?: number | 0 ;
33+ } ;
34+
35+ type questionType = {
36+ type : string ;
37+ name : string ;
38+ message : string ;
39+ default : string | boolean | number ;
40+ choices ?: string [ ] | number [ ] ;
41+ } ;
42+
43+ async function promptForMissingOptions (
44+ options : optionsType
45+ ) : Promise < {
46+ language : any ;
47+ schema : any ;
48+ filePath ?: string | undefined ;
49+ schemaKeys ?: number | undefined ;
50+ } > {
2651 const defaultOptions = {
2752 language : "Javascript" ,
2853 schema : "default" ,
2954 } ;
30- // if (options.skipPrompts) {
31- // return {
32- // ...options,
33- // template: options.template || defaultLanguage,
34- // };
35- // }
3655
37- const questions = [ ] ;
56+ const questions : questionType [ ] = [ ] ;
3857 //@TODO : Temporary Disabled, Uncomment after adding Typescript Schema
3958 // if (!options.language) {
4059 // questions.push({
@@ -57,20 +76,18 @@ async function promptForMissingOptions(options) {
5776 return {
5877 ...options ,
5978 language : options . language || answers . language ,
60- mongoose : options . mongoose || answers . mongoose ,
6179 schema : answers . schema ,
6280 } ;
6381}
6482
6583async function promptForSchemaObject ( ) {
66- console . log ( ) ;
6784 const defaultOptions = {
6885 name : "default" ,
6986 type : "String" ,
7087 required : true ,
7188 default : "" ,
7289 } ;
73- const questions = [ ] ;
90+ const questions : questionType [ ] = [ ] ;
7491
7592 questions . push ( {
7693 type : "input" ,
@@ -101,18 +118,23 @@ async function promptForSchemaObject() {
101118 default : defaultOptions . default ,
102119 } ) ;
103120
104- const answers = await inquirer . prompt ( questions ) ;
121+ const answers : {
122+ name : string ;
123+ type : string ;
124+ required : boolean ;
125+ default : string ;
126+ } = await inquirer . prompt ( questions ) ;
105127
106128 return {
107- schemaName : answers . name ,
129+ name : answers . name ,
108130 type : answers . type ,
109131 isRequired : answers . required ,
110132 defaultValue : answers . default ,
111133 } ;
112134}
113135
114- async function cli ( args ) {
115- var options = parseArgumentsIntoOptions ( args ) ;
136+ async function cli ( args : string [ ] ) {
137+ var options : optionsType = parseArgumentsIntoOptions ( args ) ;
116138 options = await promptForMissingOptions ( options ) ;
117139
118140 const { schemaKeys } = await inquirer . prompt ( {
@@ -122,19 +144,20 @@ async function cli(args) {
122144 default : 0 ,
123145 } ) ;
124146
125- // Get Schema Keys' Input
126- const schemaKeyValues = [ ] ;
147+ const schemaKeyValues : {
148+ name : string ;
149+ type : string ;
150+ isRequired : boolean ;
151+ defaultValue : string ;
152+ } [ ] = [ ] ;
127153 for ( let i = 0 ; i < schemaKeys ; i ++ ) {
128154 const objectValues = await promptForSchemaObject ( ) ;
129155 schemaKeyValues . push ( objectValues ) ;
130156 }
131157
132- options = {
133- ...options ,
134- schemaKeys,
135- } ;
158+ var schema = { ...schemaKeys } ;
136159
137- await schema ( options , schemaKeyValues ) ;
160+ await createSchema ( schema , schemaKeyValues ) ;
138161}
139162
140- module . exports = cli ;
163+ export default cli ;
0 commit comments