ui: remove gulp

This commit is contained in:
undefined committed 2024-08-29 22:10:06 +08:00
1 parent c303849d4d
commit 50f1ac9278
12 files changed
+87 -233

No files matched your search

+26 -30
View File
@@ -2,15 +2,13 @@
import { size } from '@hydrooj/utils/lib/utils';
import cac from 'cac';
import chalk from 'chalk';
import log from 'fancy-log';
import fs from 'fs-extra';
import { globbySync } from 'globby';
import gulp from 'gulp';
import path from 'path';
import svgtofont from 'svgtofont';
import webpack, { Stats } from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import pkg from '../package.json';
import gulpConfig from './config/gulp';
import webpackConfig from './config/webpack';
import root from './utils/root';
@@ -66,14 +64,15 @@ async function runWebpack({
const data = await fs.stat(path.join(root('public'), file.name));
const key = file.name
.replace(/\.[a-f0-9]{6}\.chunk\./, '.chunk.')
.replace(/\.[a-f0-9]{6}\.worker\./, '.worker.');
.replace(/\.[a-f0-9]{6}\.worker\./, '.worker.')
.replace(/\.[a-f0-9]{6}\.e\.js/, '.e.js');
stats[key] = data.size;
}
const statsPath = root('__bundleInfo');
let oldTotal = 0;
let newTotal = 0;
if (fs.existsSync(statsPath)) {
log('Compare to last production bundle:');
console.log('Compare to last production bundle:');
const oldStats = JSON.parse(await fs.readFile(statsPath, 'utf-8')) as Record<string, number>;
for (const key in stats) oldStats[key] ||= 0;
const entries: [filename: string, orig: number, curr: number][] = [];
@@ -89,40 +88,37 @@ async function runWebpack({
const diff = 100 * (curr - orig) / orig;
if (Math.abs(diff) < 0.01 && name !== 'Total') continue;
const color = orig > curr ? chalk.green : chalk.red;
log(color(`${name.padStart(35)} ${size(orig).padStart(10)} -> ${size(curr).padEnd(10)} (${diff.toPrecision(5)}%)`), chalk.reset());
console.log(color(`${name.padStart(35)} ${size(orig).padStart(10)} -> ${size(curr).padEnd(10)} (${diff.toPrecision(5)}%)`), chalk.reset());
}
}
await fs.writeFile(statsPath, JSON.stringify(stats));
}
}
async function runGulp() {
function errorHandler(err) {
log(chalk.red('Error: %s'), chalk.reset(err.toString() + err.stack));
process.exit(1);
}
const gulpTasks = gulpConfig({ errorHandler });
return new Promise((resolve) => {
const taskList = {};
gulp.on('start', ({ uid, name }) => {
log(chalk.blue('Starting task: %s'), chalk.reset(name));
taskList[uid] = true;
});
gulp.on('stop', ({ uid, name }) => {
log(chalk.green('Finished: %s'), chalk.reset(name));
taskList[uid] = false;
if (Object.values(taskList).filter((b) => b).length === 0) resolve(null);
});
gulpTasks.default();
});
}
async function main() {
const dir = process.cwd();
process.chdir(root());
if (argv.options.gulp) await runGulp();
else {
if (argv.options.iconfont) {
await svgtofont({
src: root('misc/icons'),
dist: root('misc/.iconfont'),
styleTemplates: root('misc/icons/template'),
classNamePrefix: 'icon',
fontName: 'hydro-icons',
css: true,
startUnicode: 0xea01,
svg2ttf: {
timestamp: 1577836800, // 2020-1-1
},
svgicons2svgfont: {
fontHeight: 1000,
descent: 6.25 / 100 * 1000,
normalize: true,
},
});
const file = fs.readFileSync(root('misc/.iconfont/webicon.inc.styl'), 'utf-8');
fs.writeFileSync(root('misc/.iconfont/webicon.inc.styl'), file.replace(/:/g, ' ='));
} else {
await runWebpack(argv.options as any);
if (fs.existsSync('public/theme.css')) {
fs.copyFileSync('public/theme.css', `public/theme-${pkg.version}.css`);