@@ -22,31 +22,39 @@ import { readFileSync } from "fs";
2222
2323program
2424 . version ( "1.0.0" )
25- . description ( "Compile and run your .astx files" )
26- . option ( "compile <input> <output>" , "Compile a .js file to a .astx file" )
27- . option ( "run <input>" , "Run a .astx file" )
28- . action ( ( options ) => {
29- if ( options . compile ) {
30- console . log ( "Compiling..." ) ;
31-
32- const start = performance . now ( ) ;
33- const fileContent = readFileSync ( options . compile [ 0 ] , "utf-8" ) ;
34-
35- if ( ! fileContent ) {
36- console . error ( "File not found" ) ;
37- process . exit ( 1 ) ;
38- }
39-
40- const compiled = compile ( fileContent ) ;
41-
42- saveToFile ( compiled , options . compile [ 1 ] ) ;
43- console . log ( `Compiled in ${ performance . now ( ) - start } ms` ) ;
44- } else if ( options . run ) {
45- console . log ( "Running..." ) ;
46-
47- const program = loadFromFile ( options . run [ 0 ] ) ;
48- run ( program ) ;
25+ . description ( "Compile .js to .astx" )
26+ . command ( "compile <input> <output>" )
27+ . action ( ( input , output ) => {
28+ console . log ( "Compiling..." ) ;
29+
30+ const start = performance . now ( ) ;
31+ const fileContent = readFileSync ( input , "utf-8" ) ;
32+
33+ if ( ! fileContent ) {
34+ console . error ( "File not found" ) ;
35+ process . exit ( 1 ) ;
36+ }
37+
38+ const compiled = compile ( fileContent ) ;
39+
40+ if ( ! output . endsWith ( ".astx" ) ) {
41+ output += ".astx" ;
4942 }
43+
44+ saveToFile ( compiled , output ) ;
45+ console . log ( `Compiled in ${ performance . now ( ) - start } ms` ) ;
5046 } ) ;
5147
48+ program
49+ . description ( "Run .astx files" )
50+ . command ( "run <input>" )
51+ . action ( ( input ) => {
52+ console . log ( "Running..." ) ;
53+
54+ const program = loadFromFile ( input ) ;
55+ run ( program ) ;
56+ } ) ;
57+
58+ program . showHelpAfterError ( ) ;
59+
5260program . parse ( process . argv ) ;
0 commit comments