mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
fix addon load
This commit is contained in:
1 parent
2e4c818c37
commit
92335d8529
9 files changed
+80
-38
No files matched your search
+5
-22
@@ -1,10 +1,9 @@
|
||||
/* eslint-disable no-eval */
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
import { argv } from 'yargs';
|
||||
import {
|
||||
lib, service, model, script,
|
||||
builtinLib, builtinScript, builtinModel,
|
||||
lib, service, model,
|
||||
builtinLib, builtinModel,
|
||||
} from './common';
|
||||
|
||||
const COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
@@ -45,10 +44,9 @@ async function cli() {
|
||||
return console.log(result);
|
||||
}
|
||||
|
||||
export async function load(call, args) {
|
||||
let pending = args;
|
||||
export async function load() {
|
||||
const pending = global.addons;
|
||||
const fail = [];
|
||||
const active = [];
|
||||
require('../lib/i18n');
|
||||
require('../utils');
|
||||
require('../error');
|
||||
@@ -68,21 +66,6 @@ export async function load(call, args) {
|
||||
await service(pending, fail);
|
||||
for (const i of builtinModel) require(`../model/${i}`);
|
||||
await model(pending, fail);
|
||||
for (const i in global.Hydro.service) {
|
||||
if (global.Hydro.service[i].postInit) {
|
||||
try {
|
||||
await global.Hydro.service[i].postInit();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const i of builtinScript) require(`../script/${i}`);
|
||||
await script(pending, fail, active);
|
||||
for (const postInit of global.Hydro.postInit) {
|
||||
await postInit();
|
||||
}
|
||||
pending = [];
|
||||
for (const postInit of global.Hydro.postInit) await postInit();
|
||||
await cli();
|
||||
return { active, fail };
|
||||
}
|
||||
+23
-1
@@ -1,8 +1,30 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { argv } from 'yargs';
|
||||
import { builtinModel } from './common';
|
||||
import { Entry } from '../loader';
|
||||
|
||||
export async function load(call) {
|
||||
const tmpdir = path.resolve(os.tmpdir(), 'hydro');
|
||||
const lockfile = path.resolve(tmpdir, 'lock.json');
|
||||
|
||||
export async function load(call: Entry) {
|
||||
if (fs.existsSync(lockfile) && !argv.ignorelock) {
|
||||
const file = require(lockfile);
|
||||
console.error(`Lockfile exists, pid=${file.pid}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const context = {
|
||||
addons: global.addons,
|
||||
pid: process.pid,
|
||||
ppid: process.ppid,
|
||||
};
|
||||
await fs.writeFile(lockfile, JSON.stringify(context));
|
||||
global.onDestory.push(() => {
|
||||
fs.emptyDirSync(tmpdir);
|
||||
});
|
||||
require('../lib/i18n');
|
||||
require('../utils');
|
||||
require('../error');
|
||||
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
builtinLib, builtinScript, builtinHandler, builtinModel,
|
||||
} from './common';
|
||||
|
||||
export async function load(call, args) {
|
||||
let pending = args;
|
||||
export async function load() {
|
||||
let pending = global.addons;
|
||||
const fail = [];
|
||||
const active = [];
|
||||
require('../lib/i18n');
|
||||
|
||||
Reference in new issue
Block a user