-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
55 lines (48 loc) · 1.47 KB
/
index.ts
File metadata and controls
55 lines (48 loc) · 1.47 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
transform,
} from "./src/transform/transform";
import { parseJSTQL } from "./src/langium/langiumRunner";
import { parseArgs } from "util";
const { values: argVals, tokens: positional } = parseArgs({
options: {
o: {
type: "string",
},
},
tokens: true,
allowPositionals: true,
});
const main = async () => {
//transform(selfHostedTransformExampleMultiStmt, codeFromFile);
console.log(positional);
console.log(argVals);
if (!positional) {
throw new Error("Something is wrong with args");
}
if (
!positional[0] &&
positional[0].kind === "positional" &&
!positional[0].value.endsWith(".jstql")
) {
throw new Error("First positional argument is current JSTQL file");
}
if (!positional[1] || !positional[1].value.endsWith(".js")) {
throw new Error(
"Second positional argument is JS code to be transformed"
);
}
const jstql_file = positional[0].value;
const code_file = positional[1].value;
let jstqlString = await Bun.file(jstql_file).text();
let codeString = await Bun.file(code_file).text();
let parsedJSTQL = await parseJSTQL(jstqlString);
for (let proposal of parsedJSTQL) {
let [resultString, matches] = transform(proposal.cases, codeString);
let path = "./out.js";
if (argVals["o"]) {
path = argVals["o"];
}
await Bun.write(path, resultString);
}
};
main();