mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: loader: support profile
This commit is contained in:
9 files changed
+73
-68
No files matched your search
@@ -1,21 +1,11 @@
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import cac from 'cac';
|
||||
import fs from 'fs-extra';
|
||||
import { getAddons } from '../src/options';
|
||||
|
||||
const argv = cac().parse();
|
||||
|
||||
const hydroPath = path.resolve(os.homedir(), '.hydro');
|
||||
fs.ensureDirSync(hydroPath);
|
||||
const addonPath = path.resolve(hydroPath, 'addon.json');
|
||||
if (!fs.existsSync(addonPath)) fs.writeFileSync(addonPath, '[]');
|
||||
let addons = JSON.parse(fs.readFileSync(addonPath).toString());
|
||||
|
||||
addons = Array.from(new Set(addons));
|
||||
if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||
const hydro = require('../src/loader');
|
||||
for (const addon of addons) hydro.addon(addon);
|
||||
(argv.args[0] === 'cli' ? hydro.loadCli : hydro.load)().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
@@ -29,6 +19,7 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
||||
cli.help();
|
||||
cli.parse();
|
||||
if (!cli.matchedCommand) {
|
||||
const addons = getAddons();
|
||||
for (const i of addons) {
|
||||
try {
|
||||
require(`${i}/command.ts`).apply(cli);
|
||||
|
||||
Reference in new issue
Block a user