core: serve static files without copy

This commit is contained in:
undefined committed 2021-09-15 12:29:18 +08:00
1 parent eef64ff2e0
commit b7348e4be3
5 files changed
+7 -20

No files matched your search

+2 -6
View File
@@ -4,7 +4,6 @@
import 'reflect-metadata';
import './init';
import './interface';
import os from 'os';
import path from 'path';
import fs from 'fs-extra';
import './utils';
@@ -24,8 +23,6 @@ logger.debug('%o', argv);
process.on('unhandledRejection', logger.error);
process.on('uncaughtException', logger.error);
const publicTemp = path.resolve(os.tmpdir(), 'hydro', 'public');
export function addon(addonPath: string, prepend = false) {
if (!(fs.existsSync(addonPath) && fs.statSync(addonPath).isFile())) {
try {
@@ -33,9 +30,8 @@ export function addon(addonPath: string, prepend = false) {
const packagejson = require.resolve(`${addonPath}/package.json`);
const modulePath = path.dirname(packagejson);
const publicPath = path.resolve(modulePath, 'public');
if (fs.existsSync(publicPath)) fs.copySync(publicPath, publicTemp);
if (prepend) global.addons.unshift(modulePath);
else global.addons.push(modulePath);
if (fs.existsSync(publicPath)) global.publicDirs[prepend ? 'push' : 'unshift'](publicPath);
global.addons[prepend ? 'unshift' : 'push'](modulePath);
} catch (e) {
logger.error(`Addon not found: ${addonPath}`);
}