fix: update envision-cli tools for proxy and run app
This commit is contained in:
@@ -7,69 +7,12 @@ import { getConfig } from '@/module/get-config.ts';
|
||||
import fs from 'fs';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
const command = new Command('npm')
|
||||
.description('npm command show publish and set .npmrc')
|
||||
.option('-p --publish <publish>', 'publish')
|
||||
.action(async (options) => {
|
||||
const { publish } = options || {};
|
||||
const config = getConfig();
|
||||
let cmd = '';
|
||||
const execPath = process.cwd();
|
||||
if (publish) {
|
||||
const packageJson = path.resolve(execPath, 'package.json');
|
||||
switch (publish) {
|
||||
case 'me':
|
||||
cmd = 'npm publish --registry https://npm.xiongxiao.me';
|
||||
console.log(chalk.green(cmd));
|
||||
break;
|
||||
case 'npm':
|
||||
cmd = 'npm publish --registry https://registry.npmjs.org';
|
||||
console.log(chalk.green(cmd));
|
||||
break;
|
||||
default:
|
||||
cmd = 'npm publish --registry https://npm.xiongxiao.me';
|
||||
console.log(chalk.green(cmd));
|
||||
break;
|
||||
}
|
||||
if (fileIsExist(packageJson)) {
|
||||
const keys = Object.keys(config).filter((key) => key.includes('NPM_TOKEN'));
|
||||
const tokenEnv = keys.reduce((prev, key) => {
|
||||
return {
|
||||
...prev,
|
||||
[key]: config[key],
|
||||
};
|
||||
}, {});
|
||||
const child = spawn(cmd, {
|
||||
shell: true,
|
||||
cwd: execPath,
|
||||
env: {
|
||||
...process.env, // 保留当前环境变量
|
||||
...tokenEnv,
|
||||
},
|
||||
});
|
||||
child.stdout.on('data', (data) => {
|
||||
console.log(chalk.green(`${data}`));
|
||||
});
|
||||
child.stderr.on('data', (data) => {
|
||||
// 过滤掉 'npm notice' 或者其他信息
|
||||
if (data.toString().includes('npm notice')) {
|
||||
console.log(chalk.yellow(`notice: ${data}`));
|
||||
} else {
|
||||
console.error(`stderr: ${data}`);
|
||||
}
|
||||
});
|
||||
child.on('close', (code) => {
|
||||
// console.log(`child process exited with code ${code}`);
|
||||
});
|
||||
} else {
|
||||
console.error(chalk.red('package.json not found'));
|
||||
}
|
||||
}
|
||||
});
|
||||
const command = new Command('npm').description('npm command show publish and set .npmrc').action(async (options) => {});
|
||||
const publish = new Command('publish')
|
||||
.argument('[registry]')
|
||||
.option('-p --proxy', 'proxy')
|
||||
.description('publish npm')
|
||||
.action(async (registry) => {
|
||||
.action(async (registry, options) => {
|
||||
const answer = await inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
@@ -92,6 +35,18 @@ const publish = new Command('publish')
|
||||
const config = getConfig();
|
||||
let cmd = '';
|
||||
const execPath = process.cwd();
|
||||
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,
|
||||
};
|
||||
if (options?.proxy) {
|
||||
setEnv = {
|
||||
...proxyEnv,
|
||||
};
|
||||
}
|
||||
if (registry) {
|
||||
const packageJson = path.resolve(execPath, 'package.json');
|
||||
switch (registry) {
|
||||
@@ -122,6 +77,7 @@ const publish = new Command('publish')
|
||||
env: {
|
||||
...process.env, // 保留当前环境变量
|
||||
...tokenEnv,
|
||||
...setEnv,
|
||||
},
|
||||
});
|
||||
child.stdout.on('data', (data) => {
|
||||
@@ -187,7 +143,6 @@ const npmrc = new Command('set')
|
||||
writeFlag = true;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
writeFlag = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user