2023-09-07 16:56:17 +09:00
|
|
|
/*
|
2023-09-07 17:57:17 +09:00
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey, cherrypick contributors
|
2023-09-07 16:56:17 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as fs from 'node:fs/promises';
|
|
|
|
import * as path from 'node:path';
|
|
|
|
import cssnano from 'cssnano';
|
|
|
|
import postcss from 'postcss';
|
|
|
|
import * as terser from 'terser';
|
|
|
|
|
2023-11-27 17:50:01 +09:00
|
|
|
import { build as buildLocales } from '../locales/index.js';
|
2023-09-10 19:31:01 +09:00
|
|
|
import generateDTS from '../locales/generateDTS.js';
|
2023-09-07 16:56:17 +09:00
|
|
|
import meta from '../package.json' assert { type: "json" };
|
|
|
|
|
2023-11-27 17:50:01 +09:00
|
|
|
let locales = buildLocales();
|
|
|
|
|
2023-09-07 16:56:17 +09:00
|
|
|
async function copyFrontendFonts() {
|
|
|
|
await fs.cp('./packages/frontend/node_modules/three/examples/fonts', './built/_frontend_dist_/fonts', { dereference: true, recursive: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function copyFrontendTablerIcons() {
|
2023-12-30 00:18:03 +09:00
|
|
|
await fs.cp('./packages/frontend/node_modules/@tabler/icons-webfont', `./built/_frontend_dist_/tabler-icons.${meta.version}`, { dereference: true, recursive: true });
|
2023-09-07 16:56:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
async function copyFrontendLocales() {
|
2023-09-10 19:31:01 +09:00
|
|
|
generateDTS();
|
|
|
|
|
2023-09-07 16:56:17 +09:00
|
|
|
await fs.mkdir('./built/_frontend_dist_/locales', { recursive: true });
|
|
|
|
|
|
|
|
const v = { '_version_': meta.version };
|
|
|
|
|
|
|
|
for (const [lang, locale] of Object.entries(locales)) {
|
|
|
|
await fs.writeFile(`./built/_frontend_dist_/locales/${lang}.${meta.version}.json`, JSON.stringify({ ...locale, ...v }), 'utf-8');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 14:12:40 +09:00
|
|
|
async function copyFrontendShikiAssets() {
|
2023-12-30 00:18:03 +09:00
|
|
|
await fs.cp('./packages/frontend/node_modules/shiki/dist', `./built/_frontend_dist_/shiki.${meta.version}/dist`, { dereference: true, recursive: true });
|
|
|
|
await fs.cp('./packages/frontend/node_modules/shiki/languages', `./built/_frontend_dist_/shiki.${meta.version}/languages`, { dereference: true, recursive: true });
|
|
|
|
await fs.cp('./packages/frontend/node_modules/aiscript-vscode/aiscript/syntaxes', `./built/_frontend_dist_/shiki.${meta.version}/languages`, { dereference: true, recursive: true });
|
|
|
|
await fs.cp('./packages/frontend/node_modules/shiki/themes', `./built/_frontend_dist_/shiki.${meta.version}/themes`, { dereference: true, recursive: true });
|
2023-10-29 14:12:40 +09:00
|
|
|
}
|
|
|
|
|
2023-09-07 16:56:17 +09:00
|
|
|
async function copyBackendViews() {
|
|
|
|
await fs.cp('./packages/backend/src/server/web/views', './packages/backend/built/server/web/views', { recursive: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function buildBackendScript() {
|
|
|
|
await fs.mkdir('./packages/backend/built/server/web', { recursive: true });
|
|
|
|
|
|
|
|
for (const file of [
|
|
|
|
'./packages/backend/src/server/web/boot.js',
|
|
|
|
'./packages/backend/src/server/web/bios.js',
|
|
|
|
'./packages/backend/src/server/web/cli.js'
|
|
|
|
]) {
|
|
|
|
let source = await fs.readFile(file, { encoding: 'utf-8' });
|
|
|
|
source = source.replaceAll('LANGS', JSON.stringify(Object.keys(locales)));
|
|
|
|
const { code } = await terser.minify(source, { toplevel: true });
|
|
|
|
await fs.writeFile(`./packages/backend/built/server/web/${path.basename(file)}`, code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function buildBackendStyle() {
|
|
|
|
await fs.mkdir('./packages/backend/built/server/web', { recursive: true });
|
|
|
|
|
|
|
|
for (const file of [
|
|
|
|
'./packages/backend/src/server/web/style.css',
|
|
|
|
'./packages/backend/src/server/web/bios.css',
|
|
|
|
'./packages/backend/src/server/web/cli.css',
|
|
|
|
'./packages/backend/src/server/web/error.css'
|
|
|
|
]) {
|
|
|
|
const source = await fs.readFile(file, { encoding: 'utf-8' });
|
|
|
|
const { css } = await postcss([cssnano({ zindex: false })]).process(source, { from: undefined });
|
|
|
|
await fs.writeFile(`./packages/backend/built/server/web/${path.basename(file)}`, css);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function build() {
|
|
|
|
await Promise.all([
|
|
|
|
copyFrontendFonts(),
|
|
|
|
copyFrontendTablerIcons(),
|
|
|
|
copyFrontendLocales(),
|
2023-10-29 14:12:40 +09:00
|
|
|
copyFrontendShikiAssets(),
|
2023-09-07 16:56:17 +09:00
|
|
|
copyBackendViews(),
|
|
|
|
buildBackendScript(),
|
|
|
|
buildBackendStyle(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
await build();
|
|
|
|
|
|
|
|
if (process.argv.includes("--watch")) {
|
2023-11-30 14:48:02 +09:00
|
|
|
const watcher = fs.watch('./locales');
|
2023-11-27 19:41:39 +09:00
|
|
|
for await (const event of watcher) {
|
2023-11-27 19:43:13 +09:00
|
|
|
const filename = event.filename?.replaceAll('\\', '/');
|
2023-11-30 14:48:02 +09:00
|
|
|
if (/^[a-z]+-[A-Z]+\.yml/.test(filename)) {
|
2023-12-14 20:16:02 +09:00
|
|
|
console.log(`update ${filename} ...`)
|
2023-11-27 17:50:01 +09:00
|
|
|
locales = buildLocales();
|
|
|
|
await copyFrontendLocales()
|
|
|
|
}
|
|
|
|
}
|
2023-09-07 16:56:17 +09:00
|
|
|
}
|