22import chalk from "chalk" ;
33import clear from "clear" ;
44import figlet from "figlet" ;
5- import path from "path" ;
5+ // import path from "path";
66import { program } from "commander" ;
77import * as fs from "fs" ;
88import { WriteMermaidErDiagramsToSqlFiles } from "./Library" ;
9+ import { MarkdownContentResponseI , MarkdownInputSettingsI } from "./types" ;
910clear ( ) ;
1011console . log (
1112 chalk . red (
@@ -21,7 +22,7 @@ program
2122 . option ( "-r, --raw" , "src is raw content rather than file" )
2223 . option (
2324 "-o, --output <string>" ,
24- "Output file e.g. result becomes result-1.sql"
25+ "Output file format e.g. result becomes result-1.sql"
2526 )
2627 . option (
2728 "-d, --database <string>" ,
@@ -32,38 +33,37 @@ program
3233const options = program . opts ( ) ;
3334
3435console . log ( "current options:" ) ;
35- if ( options . src ) console . log ( " - src" ) ;
36+ if ( options . src ) console . log ( ` - src ${ options . src } ` ) ;
3637// else {
3738// console.log(`error: required option '-s, --src <string>' not specified`);
3839// process.exit(1);
3940// }
40- if ( options . database ) console . log ( " - database" ) ;
41+ if ( options . database ) console . log ( ` - database ${ options . database } ` ) ;
42+
43+ if ( options . raw ) console . log ( " - raw true" ) ;
4144
4245const database : string =
4346 undefined === options . database ? "postgres" : options . database || "no" ;
4447
4548const output : string =
46- undefined === options . database ? "result " : options . database || "result" ;
49+ undefined === options . output ? "output " : options . output || "result" ;
4750
4851const src : string = options . src ;
4952
5053const isRaw = options . raw ? true : false ;
5154// required params, input only
5255
53- console . log ( " - %s database" , database ) ;
56+ // console.log(" - %s database", database);
5457
5558if ( ! process . argv . slice ( 2 ) . length ) {
5659 program . outputHelp ( ) ;
5760}
5861
59- interface MarkdownInputSettingsI {
60- src: string ;
61- isRaw: boolean ;
62- }
63-
6462const markdownFileSettings : MarkdownInputSettingsI = {
6563 src,
6664 isRaw,
65+ outputName : output ,
66+ database
6767} ;
6868
6969/**
@@ -72,7 +72,7 @@ const markdownFileSettings: MarkdownInputSettingsI = {
7272 */
7373async function LoadMarkDownFile (
7474 inputInformation : MarkdownInputSettingsI
75- ) : Promise < string > {
75+ ) : Promise < MarkdownContentResponseI > {
7676 let fileContents : string | null = null ;
7777 if ( inputInformation . isRaw ) {
7878 fileContents = inputInformation . src ;
@@ -83,13 +83,16 @@ async function LoadMarkDownFile(
8383 }
8484 fileContents = await fs . readFileSync ( inputInformation . src , "utf8" ) ;
8585 }
86- return fileContents ;
86+ return {
87+ settings : inputInformation ,
88+ content : fileContents
89+ } ;
8790}
8891
8992LoadMarkDownFile ( markdownFileSettings )
90- . then ( async ( contents ) => {
93+ . then ( async ( response ) => {
9194 console . log ( "done loading file" ) ;
92- await WriteMermaidErDiagramsToSqlFiles ( contents , options . database ) . then ( ( result ) => {
95+ await WriteMermaidErDiagramsToSqlFiles ( response ) . then ( ( result ) => {
9396 console . log ( result ) ;
9497 console . log ( "done generating sql" ) ;
9598 } ) ;
0 commit comments