mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: load commands from external plugins
This commit is contained in:
1 parent
6e79c8995c
commit
b5bea63eed
3 files changed
+38
-23
No files matched your search
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable import/no-dynamic-require */
|
||||||
import child from 'child_process';
|
import child from 'child_process';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -46,9 +47,9 @@ if (!addons.includes('@hydrooj/ui-default')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addons = Array.from(new Set(addons));
|
||||||
if (!argv.args[0] || argv.args[0] === 'cli') {
|
if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||||
const hydro = require('../src/loader');
|
const hydro = require('../src/loader');
|
||||||
addons = Array.from(new Set(addons));
|
|
||||||
for (const addon of addons) hydro.addon(addon);
|
for (const addon of addons) hydro.addon(addon);
|
||||||
(argv.args[0] === 'cli' ? hydro.loadCli : hydro.load)().catch((e) => {
|
(argv.args[0] === 'cli' ? hydro.loadCli : hydro.load)().catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
@@ -194,8 +195,20 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
|||||||
});
|
});
|
||||||
cli.help();
|
cli.help();
|
||||||
cli.parse();
|
cli.parse();
|
||||||
|
if (!cli.matchedCommand) {
|
||||||
|
for (const i of addons) {
|
||||||
|
try {
|
||||||
|
require(`${i}/command.ts`).apply(cli);
|
||||||
|
} catch (e) {
|
||||||
|
try {
|
||||||
|
require(`${i}/command.js`).apply(cli);
|
||||||
|
} catch (err) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cli.parse();
|
||||||
if (!cli.matchedCommand) {
|
if (!cli.matchedCommand) {
|
||||||
console.log('Unknown command.');
|
console.log('Unknown command.');
|
||||||
cli.outputHelp();
|
cli.outputHelp();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import AdmZip from 'adm-zip';
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import moment from 'moment-timezone';
|
||||||
|
import Schema from 'schemastery';
|
||||||
|
import superagent from 'superagent';
|
||||||
|
import { Context } from './context';
|
||||||
|
export { ObjectID, ObjectId, FilterQuery } from 'mongodb';
|
||||||
|
export { WebSocket, WebSocketServer } from 'ws';
|
||||||
|
export * from './utils';
|
||||||
|
export * from './interface';
|
||||||
|
export * from './typeutils';
|
||||||
|
export {
|
||||||
|
Schema, yaml, fs, AdmZip, superagent, _, moment,
|
||||||
|
};
|
||||||
|
export const definePlugin = <T = never>(args: {
|
||||||
|
using?: keyof Context[];
|
||||||
|
apply: (ctx: Context, config: T) => Promise<void> | void;
|
||||||
|
schema?: Schema<T>;
|
||||||
|
name?: string;
|
||||||
|
}) => args;
|
||||||
@@ -1,20 +1,8 @@
|
|||||||
import AdmZip from 'adm-zip';
|
|
||||||
import fs from 'fs-extra';
|
|
||||||
import yaml from 'js-yaml';
|
|
||||||
import _ from 'lodash';
|
|
||||||
import moment from 'moment-timezone';
|
|
||||||
import Schema from 'schemastery';
|
|
||||||
import superagent from 'superagent';
|
|
||||||
import { Context } from './context';
|
|
||||||
import db from './service/db';
|
import db from './service/db';
|
||||||
export { ObjectID, ObjectId, FilterQuery } from 'mongodb';
|
|
||||||
export { WebSocket, WebSocketServer } from 'ws';
|
|
||||||
export * from './utils';
|
|
||||||
export * from './interface';
|
|
||||||
export * from './pipelineUtils';
|
export * from './pipelineUtils';
|
||||||
export * from './error';
|
export * from './error';
|
||||||
|
export * from './libs';
|
||||||
export * from './settings';
|
export * from './settings';
|
||||||
export * from './typeutils';
|
|
||||||
export * as SystemModel from './model/system';
|
export * as SystemModel from './model/system';
|
||||||
export * as TrainingModel from './model/training';
|
export * as TrainingModel from './model/training';
|
||||||
export * as OpcountModel from './model/opcount';
|
export * as OpcountModel from './model/opcount';
|
||||||
@@ -54,12 +42,4 @@ export {
|
|||||||
export { UiContextBase } from './service/layers/base';
|
export { UiContextBase } from './service/layers/base';
|
||||||
export * as StorageService from './service/storage';
|
export * as StorageService from './service/storage';
|
||||||
export { EventMap } from './service/bus';
|
export { EventMap } from './service/bus';
|
||||||
export {
|
export { db };
|
||||||
db, Schema, yaml, fs, AdmZip, superagent, _, moment,
|
|
||||||
};
|
|
||||||
export const definePlugin = <T = never>(args: {
|
|
||||||
using?: keyof Context[];
|
|
||||||
apply: (ctx: Context, config: T) => Promise<void> | void;
|
|
||||||
schema?: Schema<T>;
|
|
||||||
name?: string;
|
|
||||||
}) => args;
|
|
||||||
Reference in new issue
Block a user