feat: update ev cli
This commit is contained in:
@@ -7,11 +7,18 @@ import { getConfig } from '@/module/get-config.ts';
|
||||
import fs from 'fs';
|
||||
import inquirer from 'inquirer';
|
||||
import { checkPnpm } from '@/uitls/npm.ts';
|
||||
|
||||
const parseIfJson = (str: string) => {
|
||||
try {
|
||||
return JSON.parse(str);
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
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')
|
||||
.option('-t, --tag', 'tag')
|
||||
.description('publish npm')
|
||||
.action(async (registry, options) => {
|
||||
const answer = await inquirer.prompt([
|
||||
@@ -53,15 +60,12 @@ const publish = new Command('publish')
|
||||
switch (registry) {
|
||||
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)) {
|
||||
@@ -72,6 +76,20 @@ const publish = new Command('publish')
|
||||
[key]: config[key],
|
||||
};
|
||||
}, {});
|
||||
const pkg = fs.readFileSync(packageJson, 'utf-8');
|
||||
const pkgJson = parseIfJson(pkg);
|
||||
const version = pkgJson?.version as string;
|
||||
if (version && options?.tag) {
|
||||
let tag = String(version).split('-')[1] || '';
|
||||
if (tag) {
|
||||
if (tag.includes('.')) {
|
||||
tag = tag.split('.')[0];
|
||||
}
|
||||
cmd = `${cmd} --tag ${tag}`;
|
||||
}
|
||||
}
|
||||
console.log(chalk.green(cmd));
|
||||
|
||||
const child = spawn(cmd, {
|
||||
shell: true,
|
||||
cwd: execPath,
|
||||
|
||||
Reference in New Issue
Block a user