fix(monaco): cross-platform postinstall via Node script
Replace Unix-only shell one-liner (mkdir -p / printf / cp -r) with a Node.js ESM script (scripts/copy-monaco.mjs) that works on Windows, macOS and Linux alike. The script still writes public/monaco/.gitignore to keep copied assets out of git.
This commit is contained in:
parent
64024207d8
commit
ac7d74b2b5
|
|
@ -20,7 +20,7 @@
|
||||||
"format:check": "prettier --check \"src/**/*.{ts,tsx,css}\"",
|
"format:check": "prettier --check \"src/**/*.{ts,tsx,css}\"",
|
||||||
"check": "npm run lint && npm run format:check",
|
"check": "npm run lint && npm run format:check",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"postinstall": "mkdir -p public/monaco && printf \"*\\n!.gitignore\\n\" > public/monaco/.gitignore && cp -r node_modules/monaco-editor/min/vs public/monaco/vs",
|
"postinstall": "node scripts/copy-monaco.mjs",
|
||||||
"test": "vitest run",
|
"test": "vitest run",
|
||||||
"test:watch": "vitest",
|
"test:watch": "vitest",
|
||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* Copies monaco-editor's min/vs assets into public/monaco/vs and writes a
|
||||||
|
* .gitignore so the generated files are never tracked in git.
|
||||||
|
* Cross-platform replacement for the Unix-only shell one-liner.
|
||||||
|
*/
|
||||||
|
import { cpSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
||||||
|
import { join, dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const root = join(__dirname, '..');
|
||||||
|
|
||||||
|
const src = join(root, 'node_modules', 'monaco-editor', 'min', 'vs');
|
||||||
|
const dest = join(root, 'public', 'monaco', 'vs');
|
||||||
|
const monacoDir = join(root, 'public', 'monaco');
|
||||||
|
|
||||||
|
if (!existsSync(src)) {
|
||||||
|
console.error('monaco-editor not found in node_modules — skipping copy.');
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdirSync(monacoDir, { recursive: true });
|
||||||
|
|
||||||
|
// Write a .gitignore that ignores everything inside public/monaco/
|
||||||
|
writeFileSync(join(monacoDir, '.gitignore'), '*\n!.gitignore\n');
|
||||||
|
|
||||||
|
cpSync(src, dest, { recursive: true });
|
||||||
|
|
||||||
|
console.log('monaco-editor assets copied to public/monaco/vs');
|
||||||
Loading…
Reference in New Issue