()
| 26 | }; |
| 27 | |
| 28 | async function main() { |
| 29 | const requested = process.argv.slice(2); |
| 30 | const targets = requested.length > 0 ? requested : Object.keys(PACKAGES); |
| 31 | |
| 32 | await fs.mkdir(GRAMMARS_DIR, { recursive: true }); |
| 33 | |
| 34 | console.log(`Installing Tree-sitter grammars for: ${targets.join(', ')}`); |
| 35 | console.log(`(This requires 'tree-sitter-cli' to be globally available or installed locally.)`); |
| 36 | console.log(''); |
| 37 | console.log('If this fails, you can manually download pre-built WASM files from:'); |
| 38 | console.log(' https://github.com/tree-sitter/<lang>/releases'); |
| 39 | console.log(' https://github.com/emscripten-core/tree-sitter'); |
| 40 | console.log(''); |
| 41 | console.log('Or skip this step — QodeX still works without edit_symbol (falls back to edit_text).'); |
| 42 | console.log(''); |
| 43 | |
| 44 | for (const lang of targets) { |
| 45 | const spec = PACKAGES[lang]; |
| 46 | if (!spec) { |
| 47 | console.warn(`Unknown language: ${lang}, skipping.`); |
| 48 | continue; |
| 49 | } |
| 50 | const outPath = path.join(GRAMMARS_DIR, `tree-sitter-${lang}.wasm`); |
| 51 | try { |
| 52 | await fs.access(outPath); |
| 53 | console.log(`✓ ${lang} already installed`); |
| 54 | continue; |
| 55 | } catch {} |
| 56 | |
| 57 | try { |
| 58 | console.log(`→ Installing ${lang}...`); |
| 59 | execSync(`npm install --no-save ${spec.pkg}`, { stdio: 'inherit' }); |
| 60 | const candidates = [ |
| 61 | path.join('node_modules', spec.pkg, spec.wasmIn), |
| 62 | path.join('node_modules', spec.pkg, 'src', spec.wasmIn), |
| 63 | ]; |
| 64 | let found = null; |
| 65 | for (const c of candidates) { |
| 66 | try { |
| 67 | await fs.access(c); |
| 68 | found = c; |
| 69 | break; |
| 70 | } catch {} |
| 71 | } |
| 72 | if (!found) { |
| 73 | console.warn(`✗ Could not find ${spec.wasmIn} in ${spec.pkg}. You may need to build it with tree-sitter-cli.`); |
| 74 | continue; |
| 75 | } |
| 76 | await fs.copyFile(found, outPath); |
| 77 | console.log(`✓ ${lang} → ${outPath}`); |
| 78 | } catch (e) { |
| 79 | console.warn(`✗ Failed to install ${lang}: ${e.message}`); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | console.log('\nDone. Restart QodeX to use AST-aware editing.'); |
| 84 | } |
| 85 |
no test coverage detected