diff --git a/packages/core/cli/src/commands/pkg.js b/packages/core/cli/src/commands/pkg.js index 8ef7fa2b21..3b70946815 100644 --- a/packages/core/cli/src/commands/pkg.js +++ b/packages/core/cli/src/commands/pkg.js @@ -140,7 +140,7 @@ class Package { .on('finish', resolve) .on('error', reject); }); - console.log(chalk.greenBright(`Download success: ${this.packageName}@${version}`)); + console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`)); } catch (error) { console.log(chalk.redBright(`Download failed: ${this.packageName}`)); } @@ -194,16 +194,37 @@ class PackageManager { async getPackages() { const pkgs = await this.getProPackages(); + + if (Array.isArray(pkgs)) { + return { + commercial_plugins: pkgs, + licensed_plugins: pkgs, + }; + } return pkgs; } + async removePackage(packageName) { + const dir = path.resolve(process.env.PLUGIN_STORAGE_PATH, packageName); + const r = await fs.exists(dir); + if (r) { + console.log(chalk.yellowBright(`Removed: ${packageName}`)); + await fs.rm(dir, { force: true, recursive: true }); + } + } + async download(options = {}) { const { version } = options; if (!this.token) { return; } - const pkgs = await this.getPackages(); - for (const pkg of pkgs) { + const { commercial_plugins, licensed_plugins } = await this.getPackages(); + for (const pkg of commercial_plugins) { + if (!licensed_plugins.includes(pkg)) { + await this.removePackage(pkg); + } + } + for (const pkg of licensed_plugins) { await this.getPackage(pkg).download({ version }); } } diff --git a/packages/core/cli/src/util.js b/packages/core/cli/src/util.js index 4c0f3c41ef..1f2884e00a 100644 --- a/packages/core/cli/src/util.js +++ b/packages/core/cli/src/util.js @@ -164,6 +164,10 @@ exports.promptForTs = () => { }; exports.downloadPro = async () => { + const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env; + if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) { + return; + } await exports.run('yarn', ['nocobase', 'pkg', 'download-pro']); };