feat: 添加publish

This commit is contained in:
2024-12-05 17:31:32 +08:00
parent da6211299b
commit a117281b9e
7 changed files with 141 additions and 39 deletions

View File

@@ -6,6 +6,7 @@ import { fileIsExist } from '@/uitls/file.ts';
import { getConfig } from '@/module/get-config.ts';
import fs from 'fs';
import inquirer from 'inquirer';
import { checkPnpm } from '@/uitls/npm.ts';
const command = new Command('npm').description('npm command show publish and set .npmrc').action(async (options) => {});
const publish = new Command('publish')
@@ -165,5 +166,32 @@ const remove = new Command('remove').description('remove .npmrc').action(async (
});
command.addCommand(remove);
//
const install = new Command('install')
.option('-n, --noproxy', 'no proxy')
.description('npm install 使用 proxy代理去下载')
.action(async (options) => {
const cwd = process.cwd();
const config = getConfig();
let setEnv = {};
const proxyEnv = {
https_proxy: 'http://127.0.0.1:7890',
http_proxy: 'http://127.0.0.1:7890',
all_proxy: 'socks5://127.0.0.1:7890',
...config?.proxy,
};
setEnv = {
...proxyEnv,
};
if (options?.noproxy) {
setEnv = {};
}
if (checkPnpm()) {
spawn('pnpm', ['i'], { stdio: 'inherit', cwd: cwd, env: { ...process.env, ...setEnv } });
} else {
spawn('npm', ['i'], { stdio: 'inherit', cwd: cwd, env: { ...process.env, ...setEnv } });
}
});
command.addCommand(install);
// program 添加npm 的命令
program.addCommand(command);