diff --git a/index.js b/index.js index 79deff1..ed1257c 100755 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ import ExtensionHandler from './src/handlers/extension.js'; if (['rescue', 'r'].includes(process.argv[2])) await rescue(); else { - ExtensionHandler.init(); - ExtensionHandler.load(process); + await ExtensionHandler.init(); + await ExtensionHandler.load(program); program.parse(process.argv); } diff --git a/src/executer/cli.js b/src/executer/cli.js index 480b8bd..132c2eb 100644 --- a/src/executer/cli.js +++ b/src/executer/cli.js @@ -67,13 +67,13 @@ program .command('install ') .alias('ins') .description('install an extension for serein') - .action((...packageName) => install(packageName)); + .action((packageName) => install(packageName)); program .command('uninstall ') .alias('unins') .description('uninstall an extension') - .action((...packageName) => uninstall(packageName)); + .action((packageName) => uninstall(packageName)); program .command('rescue') diff --git a/src/handlers/extension.js b/src/handlers/extension.js index a0b773d..d7b5fd9 100644 --- a/src/handlers/extension.js +++ b/src/handlers/extension.js @@ -1,7 +1,8 @@ -import { done, error, start } from '../base/console.js'; import IO from '../base/io.js'; +import { resolve } from 'path'; import NpmHandler from './npm.js'; import InfoHandler from './information.js'; +import { done, error, start } from '../base/console.js'; class ExtensionClass { constructor() { @@ -12,27 +13,27 @@ class ExtensionClass { init() { if (IO.exists('.serein.json')) { this.context = IO.readJSON('.serein.json'); - if (!this.context['extensions']) this.context['extension'] = []; + if (!this.context['extension']) this.context['extension'] = []; else this.extList = this.context['extension']; } } - async install(packageNames) { + async install(packageName) { start('Install extensions...'); - await NpmHandler.add(packageNames.join(' ')); - this.context.extension.push(...packageNames); + await NpmHandler.add(packageName); + this.context.extension.push(packageName); IO.writeJSON('.serein.json', this.context); done('Intstall extension.'); } - async uninstall(packageNames) { + async uninstall(packageName) { start('Uninstall extensions...'); - await NpmHandler.del(packageNames.join(' ')); + await NpmHandler.del(packageName); this.context.extension = this.context.extension.filter( - (v) => !packageNames.includes(v) + (v) => v !== packageName ); IO.writeJSON('.serein.json', this.context); @@ -43,8 +44,18 @@ class ExtensionClass { if (this.extList.length) { start('Load extensions...'); try { - for (const packageName in this.extList) - (await import(packageName)).cli((program, InfoHandler)); + for (const packageName of this.extList) { + ( + await import( + resolve( + process.cwd(), + 'node_modules', + packageName, + 'index.js' + ) + ) + ).cli(program, InfoHandler, IO); + } } catch (e) { console.log(error('Failed to load extension!'), e); } diff --git a/src/handlers/npm.js b/src/handlers/npm.js index 496ce4a..ed7ef8b 100644 --- a/src/handlers/npm.js +++ b/src/handlers/npm.js @@ -145,8 +145,18 @@ class NpmClass extends DelayHanlderWithInfo { await this.check(); start(`Install extension "${packageName}"...`); if (this.pnpm) { - IO.exec(`pnpm install ${packageName}`); - } else IO.exec(`npm install ${packageName}`); + if (this.platform === 'android') + IO.writeText('.npmrc', 'node-linker=hoisted'); + console.log( + accept( + 'Detects that you have pnpm and will automatically enable the pnpm installation dependency.' + ) + ); + IO.exec(`pnpm install ${packageName} --registry=${this.mirror}`); + } else + IO.exec( + `npm install ${packageName} --registry=${this.mirror} ${android_suffix}` + ); done(`Install extension "${packageName}".`); }