@nocobase/cli 0.14.0-alpha.2 → 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 +4 -0
- package/package.json +4 -4
- package/src/commands/build.js +1 -0
- package/src/commands/clean.js +1 -0
- package/src/commands/dev.js +3 -2
- package/src/commands/global.js +2 -2
- package/src/commands/start.js +1 -1
- package/src/commands/test.js +1 -1
- package/src/index.js +5 -0
- package/src/plugin-generator.js +2 -11
- package/src/util.js +36 -6
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',
|
|
@@ -20,6 +21,7 @@ const env = {
|
|
|
20
21
|
NODE_MODULES_PATH: resolve(process.cwd(), 'node_modules'),
|
|
21
22
|
PM2_HOME: resolve(process.cwd(), './storage/.pm2'),
|
|
22
23
|
PLUGIN_PACKAGE_PREFIX: '@nocobase/plugin-,@nocobase/plugin-sample-,@nocobase/preset-',
|
|
24
|
+
SERVER_TSCONFIG_PATH: './tsconfig.server.json',
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
if (!process.env.APP_ENV_PATH && process.argv[2] && process.argv[2] === 'test') {
|
|
@@ -28,6 +30,8 @@ if (!process.env.APP_ENV_PATH && process.argv[2] && process.argv[2] === 'test')
|
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
genTsConfigPaths();
|
|
34
|
+
|
|
31
35
|
dotenv.config({
|
|
32
36
|
path: resolve(process.cwd(), process.env.APP_ENV_PATH || '.env'),
|
|
33
37
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/cli",
|
|
3
|
-
"version": "0.14.0-alpha.
|
|
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.
|
|
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.
|
|
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": "
|
|
33
|
+
"gitHead": "e2aab7863bbdfd76afc7164272b275e868ac59c0"
|
|
34
34
|
}
|
package/src/commands/build.js
CHANGED
package/src/commands/clean.js
CHANGED
package/src/commands/dev.js
CHANGED
|
@@ -18,12 +18,13 @@ module.exports = (cli) => {
|
|
|
18
18
|
.allowUnknownOption()
|
|
19
19
|
.action(async (opts) => {
|
|
20
20
|
promptForTs();
|
|
21
|
+
const { SERVER_TSCONFIG_PATH } = process.env;
|
|
21
22
|
process.env.IS_DEV_CMD = true;
|
|
22
23
|
|
|
23
24
|
if (process.argv.includes('-h') || process.argv.includes('--help')) {
|
|
24
25
|
run('ts-node', [
|
|
25
26
|
'-P',
|
|
26
|
-
|
|
27
|
+
SERVER_TSCONFIG_PATH,
|
|
27
28
|
'-r',
|
|
28
29
|
'tsconfig-paths/register',
|
|
29
30
|
`${APP_PACKAGE_ROOT}/src/index.ts`,
|
|
@@ -62,7 +63,7 @@ module.exports = (cli) => {
|
|
|
62
63
|
'watch',
|
|
63
64
|
'--ignore=./storage/plugins/**',
|
|
64
65
|
'--tsconfig',
|
|
65
|
-
|
|
66
|
+
SERVER_TSCONFIG_PATH,
|
|
66
67
|
'-r',
|
|
67
68
|
'tsconfig-paths/register',
|
|
68
69
|
`${APP_PACKAGE_ROOT}/src/index.ts`,
|
package/src/commands/global.js
CHANGED
|
@@ -6,7 +6,7 @@ const { run, isDev, isProd, promptForTs } = require('../util');
|
|
|
6
6
|
* @param {Command} cli
|
|
7
7
|
*/
|
|
8
8
|
module.exports = (cli) => {
|
|
9
|
-
const { APP_PACKAGE_ROOT } = process.env;
|
|
9
|
+
const { APP_PACKAGE_ROOT, SERVER_TSCONFIG_PATH } = process.env;
|
|
10
10
|
cli
|
|
11
11
|
.allowUnknownOption()
|
|
12
12
|
.option('-h, --help')
|
|
@@ -16,7 +16,7 @@ module.exports = (cli) => {
|
|
|
16
16
|
promptForTs();
|
|
17
17
|
run('tsx', [
|
|
18
18
|
'--tsconfig',
|
|
19
|
-
|
|
19
|
+
SERVER_TSCONFIG_PATH,
|
|
20
20
|
'-r',
|
|
21
21
|
'tsconfig-paths/register',
|
|
22
22
|
`${APP_PACKAGE_ROOT}/src/index.ts`,
|
package/src/commands/start.js
CHANGED
package/src/commands/test.js
CHANGED
package/src/index.js
CHANGED
package/src/plugin-generator.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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 {
|
|
@@ -102,12 +103,12 @@ exports.postCheck = async (opts) => {
|
|
|
102
103
|
};
|
|
103
104
|
|
|
104
105
|
exports.runInstall = async () => {
|
|
105
|
-
const { APP_PACKAGE_ROOT } = process.env;
|
|
106
|
+
const { APP_PACKAGE_ROOT, SERVER_TSCONFIG_PATH } = process.env;
|
|
106
107
|
|
|
107
108
|
if (exports.isDev()) {
|
|
108
109
|
const argv = [
|
|
109
110
|
'--tsconfig',
|
|
110
|
-
|
|
111
|
+
SERVER_TSCONFIG_PATH,
|
|
111
112
|
'-r',
|
|
112
113
|
'tsconfig-paths/register',
|
|
113
114
|
`${APP_PACKAGE_ROOT}/src/index.ts`,
|
|
@@ -123,12 +124,12 @@ exports.runInstall = async () => {
|
|
|
123
124
|
};
|
|
124
125
|
|
|
125
126
|
exports.runAppCommand = async (command, args = []) => {
|
|
126
|
-
const { APP_PACKAGE_ROOT } = process.env;
|
|
127
|
+
const { APP_PACKAGE_ROOT, SERVER_TSCONFIG_PATH } = process.env;
|
|
127
128
|
|
|
128
129
|
if (exports.isDev()) {
|
|
129
130
|
const argv = [
|
|
130
131
|
'--tsconfig',
|
|
131
|
-
|
|
132
|
+
SERVER_TSCONFIG_PATH,
|
|
132
133
|
'-r',
|
|
133
134
|
'tsconfig-paths/register',
|
|
134
135
|
`${APP_PACKAGE_ROOT}/src/index.ts`,
|
|
@@ -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
|
+
};
|