Skip to content

Commit 0c9bb65

Browse files
Add command to generate JS code from .astx files and import necessary functions
1 parent 7291b3c commit 0c9bb65

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/index.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { compile, loadFromFile, run, saveToFile } from "@astx/lib";
19+
import {
20+
compile,
21+
generateJSCode,
22+
loadFromFile,
23+
run,
24+
saveToFile,
25+
} from "@astx/lib";
2026
import { program } from "commander";
21-
import { readFileSync } from "fs";
27+
import { readFileSync, writeFileSync } from "fs";
2228

2329
program
2430
.version("1.0.0")
@@ -55,6 +61,23 @@ program
5561
run(program);
5662
});
5763

64+
program
65+
.description(
66+
"Generate .js code from .astx files (For debugging - code is not optimized or human readable)"
67+
)
68+
.command("gen <input> <output>")
69+
.action((input, output) => {
70+
console.log("Loading .astx file...");
71+
72+
const program = loadFromFile(input);
73+
74+
console.log("Generating JS Code...");
75+
const code = generateJSCode(program);
76+
77+
console.log("Saving to file...");
78+
writeFileSync(output, code);
79+
});
80+
5881
program.showHelpAfterError();
5982

6083
program.parse(process.argv);

0 commit comments

Comments
 (0)