-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbuild-wasm.ts
More file actions
52 lines (44 loc) · 1.98 KB
/
Copy pathbuild-wasm.ts
File metadata and controls
52 lines (44 loc) · 1.98 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
#!/usr/bin/env node
/**
* Build WASM grammar files from tree-sitter grammar packages.
*
* Usage: node scripts/build-wasm.js
*
* Requires devDependencies: tree-sitter-cli + grammar packages.
* Outputs .wasm files into grammars/ (committed to repo).
*/
import { execFileSync } from 'child_process';
import { mkdirSync, existsSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(__dirname, '..');
const grammarsDir = resolve(root, 'grammars');
if (!existsSync(grammarsDir)) mkdirSync(grammarsDir);
const grammars = [
{ name: 'tree-sitter-javascript', pkg: 'tree-sitter-javascript', sub: null },
{ name: 'tree-sitter-typescript', pkg: 'tree-sitter-typescript', sub: 'typescript' },
{ name: 'tree-sitter-tsx', pkg: 'tree-sitter-typescript', sub: 'tsx' },
{ name: 'tree-sitter-python', pkg: 'tree-sitter-python', sub: null },
{ name: 'tree-sitter-hcl', pkg: '@tree-sitter-grammars/tree-sitter-hcl', sub: null },
{ name: 'tree-sitter-go', pkg: 'tree-sitter-go', sub: null },
{ name: 'tree-sitter-rust', pkg: 'tree-sitter-rust', sub: null },
{ name: 'tree-sitter-java', pkg: 'tree-sitter-java', sub: null },
{ name: 'tree-sitter-c-sharp', pkg: 'tree-sitter-c-sharp', sub: null },
{ name: 'tree-sitter-ruby', pkg: 'tree-sitter-ruby', sub: null },
{ name: 'tree-sitter-php', pkg: 'tree-sitter-php', sub: 'php' },
];
for (const g of grammars) {
const pkgDir = dirname(require.resolve(`${g.pkg}/package.json`));
const grammarDir = g.sub ? resolve(pkgDir, g.sub) : pkgDir;
console.log(`Building ${g.name}.wasm from ${grammarDir}...`);
execFileSync('npx', ['tree-sitter', 'build', '--wasm', grammarDir], {
cwd: grammarsDir,
stdio: 'inherit',
shell: true,
});
console.log(` Done: ${g.name}.wasm`);
}
console.log('\nAll grammars built successfully into grammars/');