mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: use cordis to manage app lifecycle
This commit is contained in:
1 parent
d7ec26b772
commit
5b7067d77d
19 files changed
+307
-375
No files matched your search
@@ -2,8 +2,6 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
import cac from 'cac';
|
||||
import { ObjectID } from 'mongodb';
|
||||
import { validate } from '../lib/validator';
|
||||
import options from '../options';
|
||||
import db from '../service/db';
|
||||
import {
|
||||
lib, model, script, service,
|
||||
@@ -24,12 +22,7 @@ function parseParameters(fn: Function) {
|
||||
async function runScript(name: string, arg: any) {
|
||||
const s = global.Hydro.script[name];
|
||||
if (!s) return console.error('Script %s not found.', name);
|
||||
if (typeof s.validate === 'function') {
|
||||
arg = s.validate(arg);
|
||||
} else {
|
||||
console.warn('You are using the legacy script validation API, which will be dropped in the future.');
|
||||
validate(s.validate, arg);
|
||||
}
|
||||
if (typeof s.validate === 'function') arg = s.validate(arg);
|
||||
return await s.run(arg, console.info);
|
||||
}
|
||||
|
||||
@@ -84,26 +77,24 @@ async function cli() {
|
||||
return console.log(result);
|
||||
}
|
||||
|
||||
export async function load() {
|
||||
export async function load(ctx) {
|
||||
const pending = global.addons;
|
||||
const fail = [];
|
||||
require('../lib/i18n');
|
||||
require('../utils');
|
||||
require('../error');
|
||||
require('../options');
|
||||
const opts = options();
|
||||
await db.start(opts);
|
||||
await db.start();
|
||||
await require('../settings').loadConfig();
|
||||
const storage = require('../service/storage');
|
||||
await storage.loadStorageService();
|
||||
require('../lib/index');
|
||||
await lib(pending, fail);
|
||||
await lib(pending, fail, ctx);
|
||||
const systemModel = require('../model/system');
|
||||
await systemModel.runConfig();
|
||||
await service(pending, fail);
|
||||
await service(pending, fail, ctx);
|
||||
require('../model/index');
|
||||
await model(pending, fail);
|
||||
await model(pending, fail, ctx);
|
||||
require('../script/index');
|
||||
await script(pending, fail);
|
||||
await script(pending, fail, ctx);
|
||||
await cli();
|
||||
}
|
||||
Reference in new issue
Block a user