Skip to content

Commit

Permalink
feat: more Handlers for extension (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese authored Feb 9, 2024
1 parent dffd04a commit 38796ec
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
29 changes: 28 additions & 1 deletion src/handlers/extension.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import IO from '../base/io.js';
import { resolve } from 'path';
import Others from './others.js';
import NpmHandler from './npm.js';
import LogoHandler from './logo.js';
import GulpHandler from './gulp.js';
import DelayHanlder from './delay.js';
import ConfigRender from './config.js';
import MirrorHandler from './mirror.js';
import NetWork from '../base/network.js';
import ModuleResolver from './module.js';
import InfoHandler from './information.js';
import VerionsHandler from './versions.js';
import ManifestHandler from './manifest.js';
import DelayHanlderWithInfo from './delayInfo.js';
import { done, error, start } from '../base/console.js';

class ExtensionClass {
Expand Down Expand Up @@ -43,6 +54,7 @@ class ExtensionClass {
async load(program) {
if (this.extList.length) {
start('Load extensions...');

try {
for (const packageName of this.extList) {
(
Expand All @@ -54,11 +66,26 @@ class ExtensionClass {
'index.js'
)
)
).cli(program, InfoHandler, IO);
)(program, {
Others,
NpmHandler,
LogoHandler,
GulpHandler,
DelayHanlder,
ConfigRender,
MirrorHandler,
NetWork,
ModuleResolver,
InfoHandler,
VerionsHandler,
ManifestHandler,
DelayHanlderWithInfo
});
}
} catch (e) {
console.log(error('Failed to load extension!'), e);
}

done('Load extensions.');
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/handlers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class NpmClass extends DelayHanlderWithInfo {
async update() {
this.pnpm = checkPnpm();
this.platform = process.platform;
this.android_suffix =
this.platform === 'android' ? '--no-bin-links' : '';
this.mirror = await MirrorHandler.getFastestMirror();
if (existsSync('package.json')) {
this.package = IO.readJSON('package.json');
Expand Down Expand Up @@ -126,8 +128,6 @@ class NpmClass extends DelayHanlderWithInfo {

async install() {
await this.check();
const android_suffix =
this.platform === 'android' ? '--no-bin-links' : '';
if (this.pnpm) {
if (this.platform === 'android')
IO.writeText('.npmrc', 'node-linker=hoisted');
Expand All @@ -138,14 +138,15 @@ class NpmClass extends DelayHanlderWithInfo {
);
IO.exec(`pnpm install --registry=${this.mirror}`);
} else
IO.exec(`npm install --registry=${this.mirror} ${android_suffix}`);
IO.exec(
`npm install --registry=${this.mirror} ${this.android_suffix}`
);
}

async add(packageName) {
await this.check();
const android_suffix =
this.platform === 'android' ? '--no-bin-links' : '';
start(`Install extension "${packageName}"...`);

if (this.pnpm) {
if (this.platform === 'android')
IO.writeText('.npmrc', 'node-linker=hoisted');
Expand All @@ -154,11 +155,12 @@ class NpmClass extends DelayHanlderWithInfo {
'Detects that you have pnpm and will automatically enable the pnpm installation dependency.'
)
);
IO.exec(`pnpm install ${packageName} --registry=${this.mirror}`);
IO.exec(`pnpm install ${packageName} --registry=${this.mirror} --save-dev`);
} else
IO.exec(
`npm install ${packageName} --registry=${this.mirror} ${android_suffix}`
`npm install ${packageName} --registry=${this.mirror} ${this.android_suffix} --save-dev`
);

done(`Install extension "${packageName}".`);
}

Expand Down

0 comments on commit 38796ec

Please sign in to comment.