fix(cli): improve internal logic of nocobase upgrade command (#6280)

This commit is contained in:
chenos 2025-02-24 21:35:06 +08:00 committed by GitHub
parent 235fd81e6b
commit 7e2f2303e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,8 +52,14 @@ module.exports = (cli) => {
}
};
const pkg = require('../../package.json');
let distTag = 'latest';
if (pkg.version.includes('alpha')) {
distTag = 'alpha';
} else if (pkg.version.includes('beta')) {
distTag = 'beta';
}
// get latest version
const { stdout } = await run('npm', ['info', options.next ? '@nocobase/cli@next' : '@nocobase/cli', 'version'], {
const { stdout } = await run('npm', ['info', `@nocobase/cli@${distTag}`, 'version'], {
stdio: 'pipe',
});
if (pkg.version === stdout) {
@ -62,13 +68,7 @@ module.exports = (cli) => {
await rmAppDir();
return;
}
const currentY = 1 * pkg.version.split('.')[1];
const latestY = 1 * stdout.split('.')[1];
if (options.next || currentY > latestY) {
await run('yarn', ['add', '@nocobase/cli@next', '@nocobase/devtools@next', '-W']);
} else {
await run('yarn', ['add', '@nocobase/cli', '@nocobase/devtools', '-W']);
}
await run('yarn', ['add', `@nocobase/cli@${distTag}`, `@nocobase/devtools@${distTag}`, '-W']);
await run('yarn', ['install']);
await downloadPro();
await runAppCommand('upgrade');