update
This commit is contained in:
@@ -16,8 +16,9 @@ const getRunFilePath = () => {
|
||||
if (isJs) {
|
||||
const dir = path.dirname(runFilePath); // /home/ubuntu/kevisual/cli/bin
|
||||
distDir = path.relative(dir, '../dist'); // /home/ubuntu/kevisual/cli
|
||||
} else {
|
||||
distDir = path.resolve(process.cwd(), 'dist');
|
||||
}
|
||||
distDir = path.resolve(process.cwd(), 'dist');
|
||||
|
||||
return distDir;
|
||||
}
|
||||
@@ -66,7 +67,12 @@ const downloadNewDistFiles = async (distDir: string) => {
|
||||
console.error('Error downloading files:', error);
|
||||
});
|
||||
}
|
||||
const getVersion = async () => {
|
||||
const getVersion = async (force?: boolean) => {
|
||||
const runFilePath = getRunFilePath();
|
||||
if (force) {
|
||||
await downloadNewDistFiles(runFilePath);
|
||||
return;
|
||||
}
|
||||
const baseURL = getConfig().baseURL || 'https://kevisual.cn';
|
||||
const file = 'package.json';
|
||||
const url = `${baseURL}/root/cli/${file}`;
|
||||
@@ -76,9 +82,8 @@ const getVersion = async () => {
|
||||
const latestVersion = json.version;
|
||||
const version = useContextKey('version');
|
||||
if (semver.lt(version, latestVersion)) {
|
||||
console.log('当前版本:', version);
|
||||
console.log('最新版本:', latestVersion);
|
||||
downloadNewDistFiles(getRunFilePath());
|
||||
console.log('当前版本:', version, '最新版本:', latestVersion, '正在更新...');
|
||||
downloadNewDistFiles(runFilePath);
|
||||
} else {
|
||||
console.log('已经是最新版本', version);
|
||||
}
|
||||
@@ -86,6 +91,7 @@ const getVersion = async () => {
|
||||
const update = new Command('update')
|
||||
.option('-g --global', 'update global')
|
||||
.option('-n --npm', 'use npm to update', false)
|
||||
.option('-f --force', 'force update', false)
|
||||
.description('update cli')
|
||||
.action((opts) => {
|
||||
try {
|
||||
@@ -93,7 +99,8 @@ const update = new Command('update')
|
||||
const cmd = opts.global ? 'npm install -g @kevisual/envision-cli' : 'npm install -D @kevisual/envision-cli';
|
||||
execSync(cmd, { stdio: 'inherit', encoding: 'utf-8' });
|
||||
} else {
|
||||
getVersion()
|
||||
const force = opts.force ? true : false;
|
||||
getVersion(force)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error updating CLI:', error);
|
||||
|
||||
Reference in New Issue
Block a user