refactor: rewrite scripts in typescript
This commit is contained in:
parent
31ceb99603
commit
169d7ad57f
5 changed files with 70 additions and 53 deletions
46
lib/binding_web/script/check-artifacts-fresh.ts
Executable file
46
lib/binding_web/script/check-artifacts-fresh.ts
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const inputFiles = [
|
||||
'../lib/tree-sitter.c',
|
||||
'../src/constants.ts',
|
||||
'../src/index.ts',
|
||||
'../src/language.ts',
|
||||
'../src/lookahead_iterator.ts',
|
||||
'../src/marshal.ts',
|
||||
'../src/node.ts',
|
||||
'../src/parser.ts',
|
||||
'../src/query.ts',
|
||||
'../src/tree.ts',
|
||||
'../src/tree_cursor.ts',
|
||||
'../dist/tree-sitter.js',
|
||||
'../wasm/exports.txt',
|
||||
'../wasm/imports.js',
|
||||
'../wasm/prefix.js',
|
||||
...listFiles('../../include/tree_sitter'),
|
||||
...listFiles('../../src'),
|
||||
];
|
||||
|
||||
const outputFiles = ['../tree-sitter.js', '../tree-sitter.wasm'];
|
||||
const outputMtime = Math.min(...outputFiles.map(getMtime));
|
||||
|
||||
for (const inputFile of inputFiles) {
|
||||
if (getMtime(inputFile) > outputMtime) {
|
||||
console.log(`File '${inputFile}' has changed. Re-run 'npm run build:wasm'.`);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
function listFiles(dir: string): string[] {
|
||||
return fs
|
||||
.readdirSync(path.resolve(scriptDir, dir))
|
||||
.filter(p => !p.startsWith('.'))
|
||||
.map(p => path.join(dir, p));
|
||||
}
|
||||
|
||||
function getMtime(p: string): number {
|
||||
return fs.statSync(path.resolve(scriptDir, p)).mtime.getTime();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue