core: loader: support profile

This commit is contained in:
undefined committed 2024-06-07 06:08:43 +08:00
1 parent 1c8a6ee9ab
commit 8f0476e7cb
9 files changed
+73 -68

No files matched your search

+2 -11
View File
@@ -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);