|
| 1 | +#!/usr/bin/env node |
| 2 | +// Stage vim's runtime tree into the gitignored `share/vim/vim92/` so |
| 3 | +// `agentos-toolchain build` ships it in dist/package and the manifest's |
| 4 | +// `provides.files` can overlay it read-only at /usr/local/share/vim/vim92 |
| 5 | +// (VIMRUNTIME points straight at it, bypassing vim's version-dir search, so a |
| 6 | +// 9.0/9.1 host runtime sources cleanly under the 9.2 binary). |
| 7 | +// |
| 8 | +// Sources, in order: $VIM_RUNTIME_SRC, then the host vim runtimes. Bulky, |
| 9 | +// non-load-bearing subtrees (docs, tutor, spell dictionaries, translations) |
| 10 | +// are trimmed — the runtime here exists so `vim` starts clean (defaults.vim, |
| 11 | +// syntax, ftplugin, indent, autoload, colors), not to ship a manual. |
| 12 | +// Missing source → skip with a notice (the package stays a valid placeholder, |
| 13 | +// same contract as a missing command binary). |
| 14 | +import { cpSync, existsSync, mkdirSync, rmSync } from "node:fs"; |
| 15 | +import { dirname, join, resolve } from "node:path"; |
| 16 | +import { fileURLToPath } from "node:url"; |
| 17 | + |
| 18 | +const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); |
| 19 | +const target = join(packageRoot, "share", "vim", "vim92"); |
| 20 | + |
| 21 | +const TRIM = new Set(["doc", "tutor", "spell", "lang", "print", "keymap"]); |
| 22 | + |
| 23 | +const candidates = [ |
| 24 | + process.env.VIM_RUNTIME_SRC, |
| 25 | + "/usr/share/vim/vim92", |
| 26 | + "/usr/share/vim/vim91", |
| 27 | + "/usr/share/vim/vim90", |
| 28 | + "/usr/local/share/vim/vim92", |
| 29 | +].filter(Boolean); |
| 30 | + |
| 31 | +const source = candidates.find((dir) => existsSync(join(dir, "defaults.vim"))); |
| 32 | +if (!source) { |
| 33 | + console.log( |
| 34 | + "stage-runtime: no vim runtime found (set VIM_RUNTIME_SRC or install vim) — skipping; package ships without the runtime tree", |
| 35 | + ); |
| 36 | + process.exit(0); |
| 37 | +} |
| 38 | + |
| 39 | +rmSync(join(packageRoot, "share"), { recursive: true, force: true }); |
| 40 | +mkdirSync(target, { recursive: true }); |
| 41 | +cpSync(source, target, { |
| 42 | + recursive: true, |
| 43 | + filter: (src) => { |
| 44 | + const rel = src.slice(source.length).split("/").filter(Boolean); |
| 45 | + return rel.length === 0 || !TRIM.has(rel[0]); |
| 46 | + }, |
| 47 | +}); |
| 48 | +console.log(`stage-runtime: ${source} -> share/vim/vim92 (trimmed: ${[...TRIM].join(", ")})`); |
0 commit comments