-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
27 lines (21 loc) · 836 Bytes
/
index.ts
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
import * as babelCore from "@babel/core";
import { getVisitor } from "./ast/ast";
import { parseArgumentsIntoOptions, getPaths, handlePaths } from "./files/files";
(async function main(): Promise<void> {
const { path, transform } = parseArgumentsIntoOptions(process.argv.slice(2));
if (path == null || transform == null) {
throw new Error("Path or transform is not defined");
}
try {
const { paths, transformPaths } = await getPaths(path, transform);
const getVisitorFunction = await getVisitor(transformPaths[0]);
const visitor = getVisitorFunction(babelCore.types);
handlePaths(paths, visitor);
} catch (error: unknown) {
let message = 'Error while running the program';
if (error instanceof Error) {
message += `: ${error.message}`;
}
throw new Error(message);
}
})();