Repository navigation
Expand file tree
/
Copy pathdev.js
More file actions
35 lines (30 loc) · 1.37 KB
/
Copy pathdev.js
File metadata and controls
35 lines (30 loc) · 1.37 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
// Start the vite-plugin-monkey dev server for ONE script, with hot reload.
// Usage: node dev.js <slug> (e.g. node dev.js masonry-image-gallery)
//
// On first run, open the printed Install URL in the browser once to install a
// tiny proxy userscript. After that, every edit to src/ live-updates in the
// browser — no rebuild, no re-paste.
import { createServer } from 'vite';
import { readdirSync, existsSync, lstatSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
const root = dirname(fileURLToPath(import.meta.url));
const scriptsDir = join(root, 'scripts');
const slug = process.argv.slice(2).find((a) => !a.startsWith('--'));
if (!slug) {
const available = existsSync(scriptsDir)
? readdirSync(scriptsDir).filter((d) => lstatSync(join(scriptsDir, d)).isDirectory())
: [];
console.error('Usage: npm run dev <slug>');
console.error('Available scripts:', available.join(', ') || '(none)');
process.exit(1);
}
const configFile = join(scriptsDir, slug, 'vite.config.js');
if (!existsSync(configFile)) {
console.error(`No vite.config.js for "${slug}" at scripts/${slug}/`);
process.exit(1);
}
const server = await createServer({ configFile });
await server.listen();
server.printUrls();
console.log(`\nDev server for "${slug}" running. Open the Install URL above once, then edit src/ — changes hot-reload.`);