@@ -3,6 +3,7 @@ const fs = require("fs");
33const { promisify } = require ( "util" ) ;
44const Listr = require ( "listr" ) ;
55const schema = require ( "../template" ) ;
6+ const chalk = require ( "chalk" ) ;
67
78const writeFile = promisify ( fs . writeFile ) ;
89const appendFile = promisify ( fs . appendFile ) ;
@@ -11,50 +12,27 @@ export async function createSchema(options, schemaKeyValues) {
1112 const schemaOptions = {
1213 ...options ,
1314 dirPath : path . resolve ( __dirname , "../template" ) ,
14- outPath : path . resolve ( __dirname , "../out" , `./${ options . schema } .js` ) ,
15+ outPath : path . resolve ( process . cwd ( ) , `./${ options . schema } .js` ) ,
1516 } ;
1617
1718 console . log ( ) ;
1819
19- // initializeSchema(schemaOptions.outPath);
20- // await createObjects(schemaOptions.outPath, schemaKeyValues);
21- // exportSchema(schemaOptions.outPath, schema.schemaBottom());
22-
2320 const tasks = new Listr ( [
2421 {
25- title : "Creating File and Adding Imports" ,
26- task : ( ) => initializeSchema ( schemaOptions . outPath ) ,
27- } ,
28- {
29- title : "Adding Schema Keys" ,
22+ title : "Creating Schema" ,
3023 task : async ( ) =>
3124 await createObjects ( schemaOptions . outPath , schemaKeyValues ) ,
3225 } ,
33- {
34- title : "Making Schema Exportable" ,
35- task : ( ) => exportSchema ( schemaOptions . outPath , schema . schemaBottom ( ) ) ,
36- } ,
3726 ] ) ;
3827
3928 await tasks . run ( ) ;
40-
41- // Append Objects to the Schema
42-
43- // Close the Schema and Add Export
44-
45- // await appendFile(schemaOptions.out, schema.schemaBottom(true));
46- }
47-
48- async function initializeSchema ( outPath ) {
49- await writeFile ( outPath , schema . schemaTop ( ) ) ;
29+ console . log ( chalk . green ( "DONE!" ) , "Schema Generated" ) ;
5030}
5131
5232async function createObjects ( outPath , schemaKeyValues ) {
33+ await writeFile ( outPath , schema . schemaTop ( ) ) ;
5334 for ( let i = 0 ; i < schemaKeyValues . length ; i ++ ) {
5435 await appendFile ( outPath , schema . createSchemaObject ( schemaKeyValues [ i ] ) ) ;
5536 }
56- }
57-
58- async function exportSchema ( outPath ) {
5937 await appendFile ( outPath , schema . schemaBottom ( ) ) ;
6038}
0 commit comments