Skip to content

Commit 1f97a7b

Browse files
Added flag to disable type map generation
1 parent bda9c37 commit 1f97a7b

File tree

10 files changed

+43
-3557
lines changed

10 files changed

+43
-3557
lines changed

bin/astgen.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ async function main(argvs) {
2828
type: "boolean",
2929
description: "Recurse mode suitable for mono-repos",
3030
})
31+
.option("tsTypes", {
32+
default: true,
33+
type: "boolean",
34+
description: "Generate type mappings using the Typescript Compiler API",
35+
})
3136
.version()
3237
.help("h").argv;
3338

index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ const createJSAst = async (options) => {
223223
try {
224224
const promiseMap = await getAllSrcJSAndTSFiles(options.src);
225225
const srcFiles = promiseMap.flatMap((d) => d);
226-
const ts = createTsc(srcFiles);
226+
let ts;
227+
if (options.tsTypes) {
228+
ts = createTsc(srcFiles);
229+
}
227230

228231
for (const file of srcFiles) {
229232
try {
@@ -305,17 +308,18 @@ const writeAstFile = (file, ast, options) => {
305308
outAstFile,
306309
JSON.stringify(data, getCircularReplacer(), " ")
307310
);
308-
console.log("Converted", relativePath, "to", outAstFile);
311+
console.log("Converted AST for", relativePath, "to", outAstFile);
309312
};
310313

311314
const writeTypesFile = (file, seenTypes, options) => {
312315
const relativePath = file.replace(new RegExp("^" + options.src + "/"), "");
313-
const outAstFile = path.join(options.output, relativePath + ".typemap");
314-
fs.mkdirSync(path.dirname(outAstFile), { recursive: true });
316+
const outTypeFile = path.join(options.output, relativePath + ".typemap");
317+
fs.mkdirSync(path.dirname(outTypeFile), { recursive: true });
315318
fs.writeFileSync(
316-
outAstFile,
319+
outTypeFile,
317320
JSON.stringify(mapToObj(seenTypes))
318321
);
322+
console.log("Converted types for", relativePath, "to", outTypeFile);
319323
};
320324

321325

jest.config.js

Lines changed: 0 additions & 181 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@joernio/astgen",
3-
"version": "2.0.4",
4-
"description": "Generate AST in json format for a number of languages by invoking appropriate tool",
3+
"version": "0.1.0",
4+
"description": "Generate JS/TS AST in json format with Babel",
55
"exports": "./index.js",
66
"keywords": [
77
"AST",
@@ -10,17 +10,15 @@
1010
"bin": {
1111
"astgen": "./bin/astgen.js"
1212
},
13-
"repository": "https://github.com/joernio/astgen",
14-
"author": "Team joernio",
13+
"repository": "https://github.com/max-leuthaeuser/astgen",
14+
"author": "Max Leuthaeuser",
1515
"license": "Apache-2.0",
1616
"dependencies": {
1717
"@babel/parser": "^7.17.9",
1818
"typescript": "^4.9.4",
1919
"yargs": "^17.4.1"
2020
},
2121
"scripts": {
22-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
23-
"watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch",
2422
"postinstall": "pkg . --no-bytecode --no-native-build --public --compress GZip"
2523
},
2624
"engines": {
@@ -32,7 +30,6 @@
3230
],
3331
"devDependencies": {
3432
"cross-env": "^7.0.3",
35-
"jest": "^26.6.3",
3633
"pkg": "^5.8.0"
3734
}
3835
}

test/App.svelte

Lines changed: 0 additions & 57 deletions
This file was deleted.

test/App.vue

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)