120 lines
4.9 KiB
JavaScript
120 lines
4.9 KiB
JavaScript
// Import only public navigation design assets. The standalone PCB build never
|
|
// imports the website's auth, publishing, workspace or other business scripts.
|
|
import { readFile, writeFile, mkdir, copyFile } from 'node:fs/promises';
|
|
import { resolve, dirname, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const designer = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const source = resolve(process.argv[2] || join(designer, '../../vibemake'));
|
|
const target = join(designer, 'src/assets/site-brand');
|
|
const [css, layout, users, fonts, cad] = await Promise.all([
|
|
readFile(join(source, 'css/style.css'), 'utf8'),
|
|
readFile(join(source, 'js/layout.js'), 'utf8'),
|
|
readFile(join(source, 'js/source.js'), 'utf8'),
|
|
readFile(join(source, 'css/fonts.css'), 'utf8'),
|
|
readFile(join(source, 'css/cad.css'), 'utf8'),
|
|
]);
|
|
function between(text, start, end) {
|
|
const from = text.indexOf(start);
|
|
const to = text.indexOf(end, from + start.length);
|
|
if (from < 0 || to < 0) throw new Error(`Website navigation source changed: ${start}`);
|
|
return text.slice(from, to).trim();
|
|
}
|
|
const tokens = between(css, ':root {', '\n}\n').replace(':root {', '');
|
|
const typography = between(css, 'body {', '\n}')
|
|
.split('\n')
|
|
.filter((line) => /font-family:|font-size:|line-height:|-webkit-font-smoothing:/.test(line))
|
|
.join('\n');
|
|
const mobile = between(
|
|
css,
|
|
'@media (max-width: 820px) {\n .container, .nav-inner',
|
|
'\n\n .hero',
|
|
).replace('.container, .nav-inner', '.nav-inner');
|
|
const navigation = `/* Generated from vibemake/css/style.css. Run pnpm sync:site-navigation. */
|
|
/* Scoped source rules keep the professional editor's own theme isolated. */
|
|
.vm-site-shell, .vm-cad-list {
|
|
${tokens}
|
|
${typography}
|
|
a { color: inherit; text-decoration: none; }
|
|
button { font: inherit; color: inherit; cursor: pointer; }
|
|
input { font: inherit; color: inherit; }
|
|
img { display: block; max-width: 100%; }
|
|
${between(css, 'h1, h2, h3, h4, h5, h6 {', '\n')}
|
|
.ic { flex: 0 0 auto; }
|
|
${between(css, '.btn {', '.chip {')}
|
|
${between(css, '.btn:disabled {', '\n')}
|
|
${between(css, '.avatar {', '/* ---------- 顶部导航')}
|
|
${between(css, '/* ---------- 顶部导航 ---------- */', '/* ⌘K 面板 */')}
|
|
${between(css, '.nav-user {', '.load-more {')}
|
|
${mobile}
|
|
}
|
|
&:lang(en) {
|
|
${mobile.replace('@media (max-width: 820px)', '@media (min-width: 821px) and (max-width: 1100px)').replace(' [data-desktop-only] { display: none !important; }\n', '')}
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
const nav = [
|
|
...between(layout, 'const NAV = [', '\n];').matchAll(
|
|
/\{ id: '([^']+)', label: '([^']+)', href: '([^']+)'([^}]*)\}/g,
|
|
),
|
|
].map((match) => ({
|
|
id: match[1],
|
|
label: match[2],
|
|
href: match[3],
|
|
desktopOnly: match[4].includes('desktopOnly: true'),
|
|
}));
|
|
if (nav.length !== 6) throw new Error('Check the website navigation before synchronizing.');
|
|
const icons = Object.fromEntries(
|
|
['search', 'upload', 'menu', 'cube', 'arrow', 'globe', 'plus', 'edit', 'trash', 'save'].map(
|
|
(key) => {
|
|
const match = layout.match(new RegExp(` ${key}: '([^']+)'`));
|
|
if (!match) throw new Error(`Missing website icon: ${key}`);
|
|
const shapes = [...match[1].matchAll(/<(path|circle) ([^>]+)\/>/g)].map((shape) => ({
|
|
tag: shape[1],
|
|
attributes: Object.fromEntries(
|
|
[...shape[2].matchAll(/(d|cx|cy|r)="([^"]*)"/g)].map((attribute) => [
|
|
attribute[1],
|
|
attribute[2],
|
|
]),
|
|
),
|
|
}));
|
|
if (!shapes.length) throw new Error(`Review the updated website icon: ${key}`);
|
|
return [key, shapes];
|
|
},
|
|
),
|
|
);
|
|
const palette = [...between(users, 'const PALETTE = [', '];').matchAll(/'(#[^']+)'/g)].map(
|
|
(m) => m[1],
|
|
);
|
|
await mkdir(join(target, 'css'), { recursive: true });
|
|
await mkdir(join(target, 'vendor/fonts'), { recursive: true });
|
|
await mkdir(join(designer, 'public/brand'), { recursive: true });
|
|
await Promise.all([
|
|
writeFile(join(target, 'css/navigation.css'), navigation),
|
|
writeFile(join(target, 'css/fonts.css'), fonts),
|
|
writeFile(
|
|
join(target, 'css/cad.css'),
|
|
`/* Generated from vibemake/css/cad.css. Keep CAD layout and metrics unchanged. */\n.vm-cad-design {\n${cad.replaceAll('.cad-page', '&')}\n}\n`,
|
|
),
|
|
writeFile(
|
|
join(target, 'navigation.ts'),
|
|
`// Generated public design data from VibeMake; no business code.\nexport const SITE_NAV = ${JSON.stringify(nav, null, 2)} as const;\nexport const SITE_ICONS = ${JSON.stringify(icons, null, 2)} as const;\nexport const AVATAR_PALETTE = ${JSON.stringify(palette)} as const;\n`,
|
|
),
|
|
...Array.from({ length: 12 }, (_, i) =>
|
|
copyFile(
|
|
join(source, `vendor/fonts/f${i + 1}.woff2`),
|
|
join(target, `vendor/fonts/f${i + 1}.woff2`),
|
|
),
|
|
),
|
|
...[256, 384, 512, 768].map((width) =>
|
|
copyFile(
|
|
join(source, `assets/brand/make-web-${width}.png`),
|
|
join(designer, `public/brand/make-web-${width}.png`),
|
|
),
|
|
),
|
|
]);
|
|
console.log(
|
|
'Synchronized VibeMake navigation CSS, local fonts, logo, links, icons and avatar palette.',
|
|
);
|