-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate
executable file
·30 lines (27 loc) · 1.01 KB
/
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env node
const fs = require("mz/fs");
const path = require("path");
const { generateCode } = require("./src/generator");
async function main() {
const filePath = process.argv[2];
if (!filePath) {
console.log("Please provide a file name.");
return;
}
const ast = JSON.parse((await fs.readFile(filePath)).toString());
const codeFilePath = filePath.replace(".ast", ".play");
const code = (await fs.readFile(codeFilePath)).toString();
const historyFilePath = filePath.replace(".ast", ".history");
const profileJsonPath = filePath.replace(".ast", ".profile.json");
const dir = path.dirname(filePath);
const outputFilePath = path.join(dir, path.basename(filePath, ".ast") + ".js");
const jsCode = generateCode(ast, {
historyFilePath,
profileJsonPath,
sourceFilePath: codeFilePath,
code
});
await fs.writeFile(outputFilePath, jsCode);
console.log(`Wrote ${outputFilePath}.`);
}
main().catch(err => console.log(err.stack));