@nocobase/cli 0.14.0-alpha.3 → 0.14.0-alpha.4

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/bin/index.js CHANGED
@@ -4,6 +4,7 @@ const dotenv = require('dotenv');
4
4
  const { resolve } = require('path');
5
5
  const { existsSync } = require('fs');
6
6
  const chalk = require('chalk');
7
+ const { genTsConfigPaths } = require('../src/util');
7
8
 
8
9
  const env = {
9
10
  APP_ENV: 'development',
@@ -29,6 +30,8 @@ if (!process.env.APP_ENV_PATH && process.argv[2] && process.argv[2] === 'test')
29
30
  }
30
31
  }
31
32
 
33
+ genTsConfigPaths();
34
+
32
35
  dotenv.config({
33
36
  path: resolve(process.cwd(), process.env.APP_ENV_PATH || '.env'),
34
37
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "0.14.0-alpha.3",
3
+ "version": "0.14.0-alpha.4",
4
4
  "description": "",
5
5
  "license": "Apache-2.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": "0.14.0-alpha.3",
11
+ "@nocobase/app": "0.14.0-alpha.4",
12
12
  "@types/fs-extra": "^11.0.1",
13
13
  "@umijs/utils": "3.5.20",
14
14
  "chalk": "^4.1.1",
@@ -23,12 +23,12 @@
23
23
  "tsx": "^3.12.7"
24
24
  },
25
25
  "devDependencies": {
26
- "@nocobase/devtools": "0.14.0-alpha.3"
26
+ "@nocobase/devtools": "0.14.0-alpha.4"
27
27
  },
28
28
  "repository": {
29
29
  "type": "git",
30
30
  "url": "git+https://github.com/nocobase/nocobase.git",
31
31
  "directory": "packages/core/cli"
32
32
  },
33
- "gitHead": "535a8c83d37e488a52bd1ad3c75726101081177c"
33
+ "gitHead": "e2aab7863bbdfd76afc7164272b275e868ac59c0"
34
34
  }
@@ -24,6 +24,7 @@ module.exports = (cli) => {
24
24
  });
25
25
  if (options.watch) return;
26
26
  }
27
+
27
28
  await run('nocobase-build', [
28
29
  ...pkgs,
29
30
  options.version ? '--version' : '',
@@ -16,5 +16,6 @@ module.exports = (cli) => {
16
16
  }
17
17
  run('rimraf', ['-rf', './storage/app-dev']);
18
18
  run('rimraf', ['-rf', 'packages/*/*/{lib,esm,es,dist,node_modules}']);
19
+ run('rimraf', ['-rf', 'packages/*/@*/*/{lib,esm,es,dist,node_modules}']);
19
20
  });
20
21
  };
@@ -1,5 +1,5 @@
1
1
  const { Command } = require('commander');
2
- const { nodeCheck, runAppCommand, promptForTs } = require('../util');
2
+ const { nodeCheck, runAppCommand, promptForTs, genTsConfigPaths } = require('../util');
3
3
 
4
4
  /**
5
5
  *
package/src/index.js CHANGED
@@ -0,0 +1,5 @@
1
+ const util = require('./util');
2
+
3
+ module.exports = {
4
+ ...util,
5
+ };
@@ -3,6 +3,7 @@ const { existsSync } = require('fs');
3
3
  const { join, resolve } = require('path');
4
4
  const { Generator } = require('@umijs/utils');
5
5
  const { readFile, writeFile } = require('fs').promises;
6
+ const { genTsConfigPaths } = require('./util');
6
7
 
7
8
  const execa = require('execa');
8
9
 
@@ -46,16 +47,6 @@ class PluginGenerator extends Generator {
46
47
  };
47
48
  }
48
49
 
49
- async addTsConfigPaths() {
50
- const { name } = this.context;
51
- if (name.startsWith('@') && name.split('/')[0] !== '@nocobase') {
52
- const target = resolve(process.cwd(), 'tsconfig.json');
53
- const content = require(target);
54
- content.compilerOptions.paths[name] = [`packages/plugins/${name}/src`];
55
- await writeFile(target, JSON.stringify(content, null, 2), 'utf-8');
56
- }
57
- }
58
-
59
50
  async writing() {
60
51
  const { name } = this.context;
61
52
  const target = resolve(process.cwd(), 'packages/plugins/', name);
@@ -70,7 +61,7 @@ class PluginGenerator extends Generator {
70
61
  path: join(__dirname, '../templates/plugin'),
71
62
  });
72
63
  console.log('');
73
- await this.addTsConfigPaths();
64
+ genTsConfigPaths();
74
65
  execa.sync('yarn', ['install'], { shell: true, stdio: 'inherit' });
75
66
  // execa.sync('yarn', ['build', `plugins/${name}`], { shell: true, stdio: 'inherit' });
76
67
  console.log(`The plugin folder is in ${chalk.green(`packages/plugins/${name}`)}`);
package/src/util.js CHANGED
@@ -1,9 +1,10 @@
1
1
  const net = require('net');
2
2
  const chalk = require('chalk');
3
3
  const execa = require('execa');
4
- const { dirname, resolve } = require('path');
4
+ const fg = require('fast-glob');
5
+ const { dirname, join, resolve } = require('path');
5
6
  const { readFile, writeFile } = require('fs').promises;
6
- const { existsSync, mkdirSync, cpSync } = require('fs');
7
+ const { existsSync, mkdirSync, cpSync, writeFileSync } = require('fs');
7
8
 
8
9
  exports.isPackageValid = (package) => {
9
10
  try {
@@ -174,3 +175,32 @@ exports.generateAppDir = function generateAppDir() {
174
175
  process.env.APP_PACKAGE_ROOT = appPkgPath;
175
176
  }
176
177
  };
178
+
179
+ exports.genTsConfigPaths = function genTsConfigPaths() {
180
+ const cwd = process.cwd();
181
+ const cwdLength = cwd.length;
182
+ const paths = {
183
+ '@@/*': ['.dumi/tmp/*'],
184
+ };
185
+ const packages = fg.sync(['packages/*/*/package.json', 'packages/*/*/*/package.json'], {
186
+ absolute: true,
187
+ onlyFiles: true,
188
+ });
189
+ packages.forEach((packageFile) => {
190
+ const packageJsonName = require(packageFile).name;
191
+ const packageDir = dirname(packageFile);
192
+ const relativePath = packageDir.slice(cwdLength + 1).replace(/\\/, '/');
193
+ const hasClient = fg.sync(['client', 'client.ts', 'client.tsx', 'client.js', 'client.jsx'], {
194
+ cwd: join(packageDir, 'src'),
195
+ }).length;
196
+ if (hasClient) {
197
+ paths[`${packageJsonName}/client`] = [`${relativePath}/src/client`];
198
+ }
199
+ paths[packageJsonName] = [`${relativePath}/src`];
200
+ });
201
+
202
+ const tsConfigJsonPath = join(cwd, './tsconfig.paths.json');
203
+ const content = { compilerOptions: { paths } };
204
+ writeFileSync(tsConfigJsonPath, JSON.stringify(content, null, 2), 'utf-8');
205
+ return content;
206
+ };