-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-admin.js
More file actions
40 lines (33 loc) · 1.49 KB
/
Copy pathbuild-admin.js
File metadata and controls
40 lines (33 loc) · 1.49 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
36
37
38
39
40
import { execSync } from 'child_process';
import { rmSync, mkdirSync, readdirSync, statSync, copyFileSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
const src = 'admin-dashboard/dist';
const dest = 'public/admin';
// Install admin dependencies and build
console.log('Installing admin dependencies...');
execSync('npm install', { cwd: 'admin-dashboard', stdio: 'inherit' });
console.log('Building admin dashboard...');
execSync('npm run build', { cwd: 'admin-dashboard', stdio: 'inherit' });
// Copy dist to public/admin
console.log('Copying to public/admin...');
rmSync(dest, { recursive: true, force: true });
function copyDir(s, d) {
mkdirSync(d, { recursive: true });
for (const f of readdirSync(s)) {
const sp = join(s, f);
const dp = join(d, f);
statSync(sp).isDirectory() ? copyDir(sp, dp) : copyFileSync(sp, dp);
}
}
copyDir(src, dest);
// Fix Vite's /admin/ absolute base paths to relative paths for embedding
const indexFile = join(dest, 'index.html');
let html = readFileSync(indexFile, 'utf-8');
html = html.replace(/src="\/admin\/assets\//g, 'src="./assets/');
html = html.replace(/href="\/admin\/assets\//g, 'href="./assets/');
html = html.replace(/href="\/admin\/favicon\.svg"/g, 'href="../favicon.svg"');
html = html.replace(/href="\/favicon\.svg"/g, 'href="../favicon.svg"');
html = html.replace(/href="\/admin\/"/g, 'href="./"');
html = html.replace(/ crossorigin/g, '');
writeFileSync(indexFile, html);
console.log('Admin dashboard ready at public/admin/');