mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
修复windows下路径的问题,添加设置项,完善翻译
This commit is contained in:
1 parent
5980080302
commit
6ad41dc2ae
29 files changed
+368
-278
No files matched your search
+30
-18
@@ -1,6 +1,5 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable no-eval */
|
||||
import os from 'os';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
@@ -30,20 +29,18 @@ export const builtinScript = [
|
||||
'blacklist', 'setSuperadmin', 'deleteUser',
|
||||
];
|
||||
|
||||
function getFiles(folder, base = '') {
|
||||
function getFiles(folder: string, base = ''): string[] {
|
||||
const files = [];
|
||||
const f = fs.readdirSync(folder);
|
||||
for (const i of f) {
|
||||
if (!i.startsWith('.')) {
|
||||
if (fs.statSync(path.join(folder, i)).isDirectory()) {
|
||||
files.push(...getFiles(path.join(folder, i), path.join(base, i)));
|
||||
} else files.push(path.join(base, i));
|
||||
}
|
||||
if (fs.statSync(path.join(folder, i)).isDirectory()) {
|
||||
files.push(...getFiles(path.join(folder, i), path.join(base, i)));
|
||||
} else files.push(path.join(base, i));
|
||||
}
|
||||
return files;
|
||||
return files.map((item) => item.replace(/\\/gmi, '/'));
|
||||
}
|
||||
|
||||
export async function handler(pending, fail) {
|
||||
export async function handler(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'handler.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -60,7 +57,7 @@ export async function handler(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function locale(pending, fail) {
|
||||
export async function locale(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
let p = path.resolve(i, 'locales');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'locale');
|
||||
@@ -82,7 +79,7 @@ export async function locale(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function setting(pending, fail, modelSetting: typeof import('../model/setting')) {
|
||||
export async function setting(pending: string[], fail: string[], modelSetting: typeof import('../model/setting')) {
|
||||
const map = {
|
||||
system: modelSetting.SystemSetting,
|
||||
account: modelSetting.AccountSetting,
|
||||
@@ -109,7 +106,7 @@ export async function setting(pending, fail, modelSetting: typeof import('../mod
|
||||
}
|
||||
}
|
||||
|
||||
export async function template(pending, fail) {
|
||||
export async function template(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
let p = path.resolve(i, 'templates');
|
||||
if (!fs.existsSync(p)) p = path.resolve(i, 'template');
|
||||
@@ -117,7 +114,9 @@ export async function template(pending, fail) {
|
||||
try {
|
||||
const files = getFiles(p);
|
||||
for (const file of files) {
|
||||
global.Hydro.template[file] = fs.readFileSync(path.resolve(p, file)).toString();
|
||||
global.Hydro.ui.template[file] = fs.readFileSync(
|
||||
path.resolve(p, file),
|
||||
).toString();
|
||||
}
|
||||
console.log(`Template init: ${i}`);
|
||||
} catch (e) {
|
||||
@@ -128,7 +127,20 @@ export async function template(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function model(pending, fail) {
|
||||
export async function uistatic(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'public', 'static-manifest.json');
|
||||
if (fs.existsSync(p) && fs.statSync(p).isFile() && !fail.includes(i)) {
|
||||
try {
|
||||
Object.assign(global.Hydro.ui.manifest, eval('require')(p));
|
||||
} catch (e) {
|
||||
fail.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function model(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'model.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -145,7 +157,7 @@ export async function model(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function lib(pending, fail) {
|
||||
export async function lib(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'lib.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -163,7 +175,7 @@ export async function lib(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function service(pending, fail) {
|
||||
export async function service(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'service.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -181,7 +193,7 @@ export async function service(pending, fail) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function script(pending, fail, active) {
|
||||
export async function script(pending: string[], fail: string[], active: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'script.js');
|
||||
if (fs.existsSync(p) && !fail.includes(i)) {
|
||||
@@ -199,7 +211,7 @@ export async function script(pending, fail, active) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function wiki(pending, fail) {
|
||||
export async function wiki(pending: string[], fail: string[]) {
|
||||
for (const i of pending) {
|
||||
const p = path.resolve(i, 'wiki');
|
||||
if (fs.existsSync(p) && fs.statSync(p).isDirectory() && !fail.includes(i)) {
|
||||
|
||||
+15
-5
@@ -4,7 +4,8 @@ import path from 'path';
|
||||
import AdmZip from 'adm-zip';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const moduleRoots = Array.from(new Set([
|
||||
const moduleRoots = [];
|
||||
const _moduleRoots = Array.from(new Set([
|
||||
path.resolve(process.cwd(), 'node_modules', '@hydrooj'),
|
||||
path.resolve(process.cwd(), 'modules'),
|
||||
path.resolve(process.cwd(), 'module'),
|
||||
@@ -16,17 +17,26 @@ const moduleRoots = Array.from(new Set([
|
||||
path.resolve(__dirname, '.build'),
|
||||
__dirname,
|
||||
path.resolve(os.homedir(), '.hydro', 'module'),
|
||||
// TODO add npm global path
|
||||
'/usr/local/share/.config/yarn/global/node_modules/@hydrooj',
|
||||
path.resolve(os.homedir(), 'AppData', 'Local', 'Yarn', 'Data', 'global', 'node_modules', '@hydrooj'),
|
||||
]));
|
||||
for (const moduleRoot of _moduleRoots) {
|
||||
if (fs.existsSync(moduleRoot)) moduleRoots.push(moduleRoot);
|
||||
}
|
||||
|
||||
if (process.env.debug) console.log('Module roots: ', moduleRoots);
|
||||
|
||||
const moduleTemp = path.resolve(os.tmpdir(), 'hydro', 'module');
|
||||
const publicTemp = path.resolve(os.tmpdir(), 'hydro', 'public');
|
||||
const tmp = path.resolve(os.tmpdir(), 'hydro', '__');
|
||||
|
||||
process.on('unhandledRejection', (e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
export async function load() {
|
||||
process.on('unhandledRejection', (e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
fs.ensureDirSync(moduleTemp);
|
||||
fs.ensureDirSync(publicTemp);
|
||||
for (const moduleRoot of moduleRoots) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
import {
|
||||
locale, template, lib, service, model, handler, script, setting,
|
||||
locale, template, lib, service, model, handler, script, setting, wiki, uistatic,
|
||||
builtinLib, builtinScript, builtinHandler, builtinModel,
|
||||
} from './common';
|
||||
|
||||
@@ -13,7 +13,12 @@ export async function load() {
|
||||
require('../utils');
|
||||
require('../error');
|
||||
require('../options');
|
||||
await Promise.all([locale(pending, fail), template(pending, fail)]);
|
||||
await Promise.all([
|
||||
locale(pending, fail),
|
||||
template(pending, fail),
|
||||
uistatic(pending, fail),
|
||||
wiki(pending, fail),
|
||||
]);
|
||||
const bus = require('../service/bus');
|
||||
await new Promise((resolve) => {
|
||||
const h = () => {
|
||||
@@ -51,6 +56,7 @@ export async function load() {
|
||||
}
|
||||
}
|
||||
for (const i of builtinScript) require(`../script/${i}`);
|
||||
await wiki(pending, fail);
|
||||
await script(pending, fail, active);
|
||||
for (const postInit of global.Hydro.postInit) {
|
||||
await postInit();
|
||||
|
||||
Reference in new issue
Block a user