diff --git a/packages/core/cli/src/commands/upgrade.js b/packages/core/cli/src/commands/upgrade.js index 4dc501b846..a36c0ef1fe 100644 --- a/packages/core/cli/src/commands/upgrade.js +++ b/packages/core/cli/src/commands/upgrade.js @@ -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(); }); };