fix(cli): support upgrade to next (#5130)

This commit is contained in:
chenos 2024-08-26 15:51:12 +08:00 committed by GitHub
parent eaf23766c7
commit da966813ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ module.exports = (cli) => {
.command('upgrade')
.allowUnknownOption()
.option('--raw')
.option('--next')
.option('-S|--skip-code-update')
.action(async (options) => {
if (hasTsNode()) promptForTs();
@ -40,26 +41,32 @@ module.exports = (cli) => {
await runAppCommand('upgrade');
return;
}
// If ts-node is not installed, do not do the following
const appDevDir = resolve(process.cwd(), './storage/.app-dev');
if (existsSync(appDevDir)) {
rmSync(appDevDir, { recursive: true, force: true });
}
const rmAppDir = () => {
// If ts-node is not installed, do not do the following
const appDevDir = resolve(process.cwd(), './storage/.app-dev');
if (existsSync(appDevDir)) {
rmSync(appDevDir, { recursive: true, force: true });
}
};
const pkg = require('../../package.json');
// get latest version
const { stdout } = await run('npm', ['info', '@nocobase/cli', 'version'], { stdio: 'pipe' });
const { stdout } = await run('npm', ['info', options.next ? '@nocobase/cli@next' : '@nocobase/cli', 'version'], {
stdio: 'pipe',
});
if (pkg.version === stdout) {
await runAppCommand('upgrade');
rmAppDir();
return;
}
const currentY = 1 * pkg.version.split('.')[1];
const latestY = 1 * stdout.split('.')[1];
if (currentY > latestY) {
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', ['install']);
await runAppCommand('upgrade');
rmAppDir();
});
};