@nocobase/cli 1.6.0-alpha.1 → 1.6.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "1.6.0-alpha.1",
3
+ "version": "1.6.0-alpha.10",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./src/index.js",
@@ -8,7 +8,7 @@
8
8
  "nocobase": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/app": "1.6.0-alpha.1",
11
+ "@nocobase/app": "1.6.0-alpha.10",
12
12
  "@types/fs-extra": "^11.0.1",
13
13
  "@umijs/utils": "3.5.20",
14
14
  "chalk": "^4.1.1",
@@ -25,12 +25,12 @@
25
25
  "tsx": "^4.19.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@nocobase/devtools": "1.6.0-alpha.1"
28
+ "@nocobase/devtools": "1.6.0-alpha.10"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
32
32
  "url": "git+https://github.com/nocobase/nocobase.git",
33
33
  "directory": "packages/core/cli"
34
34
  },
35
- "gitHead": "a4c91015e34ec0c9a427451b5fbdfb5fedc4f3d7"
35
+ "gitHead": "8ba8204282be7bf6674ef427fdbe31caa65977d5"
36
36
  }
@@ -30,10 +30,10 @@ module.exports = (cli) => {
30
30
  cli
31
31
  .command('dev')
32
32
  .option('-p, --port [port]')
33
- .option('--client')
34
- .option('--server')
33
+ .option('-c, --client')
34
+ .option('-s, --server')
35
35
  .option('--db-sync')
36
- .option('--inspect [port]')
36
+ .option('-i, --inspect [port]')
37
37
  .allowUnknownOption()
38
38
  .action(async (opts) => {
39
39
  let subprocess;
@@ -89,16 +89,13 @@ module.exports = (cli) => {
89
89
 
90
90
  watcher
91
91
  .on('ready', () => {
92
- console.log('Initial scan complete.');
93
92
  isReady = true;
94
93
  })
95
94
  .on('addDir', async (pathname) => {
96
- console.log('addDir....', isReady);
97
95
  if (!isReady) return;
98
96
  restartClient();
99
97
  })
100
98
  .on('unlinkDir', async (pathname) => {
101
- console.log('unlinkDir....', isReady);
102
99
  if (!isReady) return;
103
100
  restartClient();
104
101
  });
@@ -58,14 +58,16 @@ class Package {
58
58
  return [version, this.data.versions[version].dist.tarball];
59
59
  }
60
60
 
61
- if (version.includes('beta')) {
62
- version = version.split('beta')[0] + 'beta';
63
- } else if (version.includes('alpha')) {
64
- const prefix = (version = version.split('alpha')[0]);
65
- version = Object.keys(this.data.versions)
66
- .filter((ver) => ver.startsWith(`${prefix}alpha`))
67
- .sort()
68
- .pop();
61
+ const keys = version.split('.');
62
+ const length = keys.length;
63
+
64
+ if (version.includes('rc')) {
65
+ version = version.split('-').shift();
66
+ }
67
+
68
+ if (length === 5) {
69
+ keys.pop();
70
+ version = keys.join('.');
69
71
  }
70
72
 
71
73
  if (version === 'latest') {
@@ -93,11 +95,25 @@ class Package {
93
95
  return false;
94
96
  }
95
97
 
98
+ async isDownloaded(version) {
99
+ const packageFile = path.resolve(process.env.PLUGIN_STORAGE_PATH, this.packageName, 'package.json');
100
+ if (await fs.exists(packageFile)) {
101
+ const json = await fs.readJson(packageFile);
102
+ if (json.version === version) {
103
+ return true;
104
+ }
105
+ }
106
+ return false;
107
+ }
108
+
96
109
  async download(options = {}) {
97
110
  if (await this.isDevPackage()) {
98
111
  console.log(chalk.yellowBright(`Skipped: ${this.packageName} is dev package`));
99
112
  return;
100
113
  }
114
+ if (await this.isDownloaded(options.version)) {
115
+ return;
116
+ }
101
117
  await this.getInfo();
102
118
  if (!this.data) {
103
119
  console.log(chalk.redBright(`Download failed: ${this.packageName} package does not exist`));
@@ -105,6 +121,9 @@ class Package {
105
121
  }
106
122
  try {
107
123
  const [version, url] = this.getTarball(options.version);
124
+ if (await this.isDownloaded(version)) {
125
+ return;
126
+ }
108
127
  const response = await axios({
109
128
  url,
110
129
  responseType: 'stream',
@@ -121,7 +140,7 @@ class Package {
121
140
  .on('finish', resolve)
122
141
  .on('error', reject);
123
142
  });
124
- console.log(chalk.greenBright(`Download success: ${this.packageName}@${version}`));
143
+ console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`));
125
144
  } catch (error) {
126
145
  console.log(chalk.redBright(`Download failed: ${this.packageName}`));
127
146
  }
@@ -170,21 +189,45 @@ class PackageManager {
170
189
  },
171
190
  responseType: 'json',
172
191
  });
173
- return res.data.data;
192
+ return {
193
+ licensed_plugins: res.data?.data || [],
194
+ commercial_plugins: res.data?.meta?.commercial_plugins || [],
195
+ };
174
196
  }
175
197
 
176
198
  async getPackages() {
177
199
  const pkgs = await this.getProPackages();
200
+
201
+ if (Array.isArray(pkgs)) {
202
+ return {
203
+ commercial_plugins: pkgs,
204
+ licensed_plugins: pkgs,
205
+ };
206
+ }
178
207
  return pkgs;
179
208
  }
180
209
 
210
+ async removePackage(packageName) {
211
+ const dir = path.resolve(process.env.PLUGIN_STORAGE_PATH, packageName);
212
+ const r = await fs.exists(dir);
213
+ if (r) {
214
+ console.log(chalk.yellowBright(`Removed: ${packageName}`));
215
+ await fs.rm(dir, { force: true, recursive: true });
216
+ }
217
+ }
218
+
181
219
  async download(options = {}) {
182
220
  const { version } = options;
183
221
  if (!this.token) {
184
222
  return;
185
223
  }
186
- const pkgs = await this.getPackages();
187
- for (const pkg of pkgs) {
224
+ const { commercial_plugins, licensed_plugins } = await this.getPackages();
225
+ for (const pkg of commercial_plugins) {
226
+ if (!licensed_plugins.includes(pkg)) {
227
+ await this.removePackage(pkg);
228
+ }
229
+ }
230
+ for (const pkg of licensed_plugins) {
188
231
  await this.getPackage(pkg).download({ version });
189
232
  }
190
233
  }
@@ -200,8 +243,12 @@ module.exports = (cli) => {
200
243
  .command('download-pro')
201
244
  .option('-V, --version [version]')
202
245
  .action(async () => {
203
- const { NOCOBASE_PKG_URL, NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
204
- if (!(NOCOBASE_PKG_URL && NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
246
+ const {
247
+ NOCOBASE_PKG_URL = 'https://pkg.nocobase.com/',
248
+ NOCOBASE_PKG_USERNAME,
249
+ NOCOBASE_PKG_PASSWORD,
250
+ } = process.env;
251
+ if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
205
252
  return;
206
253
  }
207
254
  const credentials = { username: NOCOBASE_PKG_USERNAME, password: NOCOBASE_PKG_PASSWORD };
@@ -58,16 +58,13 @@ module.exports = (cli) => {
58
58
 
59
59
  watcher
60
60
  .on('ready', () => {
61
- console.log('Initial scan complete.');
62
61
  isReady = true;
63
62
  })
64
63
  .on('addDir', async (pathname) => {
65
- console.log('addDir....', isReady);
66
64
  if (!isReady) return;
67
65
  restart();
68
66
  })
69
67
  .on('unlinkDir', async (pathname) => {
70
- console.log('unlinkDir....', isReady);
71
68
  if (!isReady) return;
72
69
  restart();
73
70
  });
package/src/util.js CHANGED
@@ -164,6 +164,10 @@ exports.promptForTs = () => {
164
164
  };
165
165
 
166
166
  exports.downloadPro = async () => {
167
+ const { NOCOBASE_PKG_USERNAME, NOCOBASE_PKG_PASSWORD } = process.env;
168
+ if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD)) {
169
+ return;
170
+ }
167
171
  await exports.run('yarn', ['nocobase', 'pkg', 'download-pro']);
168
172
  };
169
173
 
@@ -337,6 +341,7 @@ exports.initEnv = function initEnv() {
337
341
  LOCAL_STORAGE_DEST: 'storage/uploads',
338
342
  PLUGIN_STORAGE_PATH: resolve(process.cwd(), 'storage/plugins'),
339
343
  MFSU_AD: 'none',
344
+ MAKO_AD: 'none',
340
345
  WS_PATH: '/ws',
341
346
  SOCKET_PATH: 'storage/gateway.sock',
342
347
  NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),