create-nocobase-app 1.7.0-beta.8 → 1.7.0
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/lib/cli.js +1 -1
- package/lib/generator.js +15 -54
- package/package.json +4 -3
- package/src/cli.js +2 -1
- package/src/generator.js +18 -57
- package/templates/app/{package.json.tpl → package.json} +10 -9
package/lib/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ const { AppGenerator } = require("./generator");
|
|
|
14
14
|
const { concat } = require("./util");
|
|
15
15
|
const packageJson = require("../package.json");
|
|
16
16
|
const cli = new Command("create-nocobase");
|
|
17
|
-
cli.arguments("<name>", "directory of new NocoBase app").option("--quickstart", "quickstart app creation").option("-a, --all-db-dialect", "install all database dialect dependencies").option("-d, --db-dialect
|
|
17
|
+
cli.arguments("<name>", "directory of new NocoBase app").option("--quickstart", "quickstart app creation").option("--skip-dev-dependencies").option("-a, --all-db-dialect", "install all database dialect dependencies").option("-d, --db-dialect [dbDialect]", "database dialect, current support postgres, mysql, mariadb, kingbase").option("-e, --env <env>", "environment variables write into .env file", concat, []).description("create a new application").action(async (name, options) => {
|
|
18
18
|
if (options.quickstart) {
|
|
19
19
|
console.log(`\u26A0\uFE0F ${chalk.yellow("quickstart option is deprecated")}`);
|
|
20
20
|
}
|
package/lib/generator.js
CHANGED
|
@@ -11,7 +11,8 @@ var __defProp = Object.defineProperty;
|
|
|
11
11
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
12
|
const chalk = require("chalk");
|
|
13
13
|
const crypto = require("crypto");
|
|
14
|
-
const { existsSync } = require("fs");
|
|
14
|
+
const { existsSync, promises } = require("fs");
|
|
15
|
+
const fs = require("fs-extra");
|
|
15
16
|
const { join, resolve } = require("path");
|
|
16
17
|
const { Generator } = require("@umijs/utils");
|
|
17
18
|
const { downloadPackageFromNpm, updateJsonFile } = require("./util");
|
|
@@ -35,61 +36,19 @@ const _AppGenerator = class _AppGenerator extends Generator {
|
|
|
35
36
|
}
|
|
36
37
|
return items;
|
|
37
38
|
}
|
|
38
|
-
checkDbEnv() {
|
|
39
|
-
const dialect = this.args.dbDialect;
|
|
40
|
-
const env = this.env;
|
|
41
|
-
if (dialect === "sqlite") {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
if (!env.DB_DATABASE || !env.DB_USER || !env.DB_PASSWORD) {
|
|
45
|
-
console.log(
|
|
46
|
-
chalk.red(
|
|
47
|
-
`Please set DB_HOST, DB_PORT, DB_DATABASE, DB_USER, DB_PASSWORD in .env file to complete database settings`
|
|
48
|
-
)
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
39
|
checkProjectPath() {
|
|
53
40
|
if (existsSync(this.cwd)) {
|
|
54
41
|
console.log(chalk.red("Project directory already exists"));
|
|
55
42
|
process.exit(1);
|
|
56
43
|
}
|
|
57
44
|
}
|
|
58
|
-
checkDialect() {
|
|
59
|
-
const dialect = this.args.dbDialect;
|
|
60
|
-
const supportDialects = ["mysql", "mariadb", "sqlite", "postgres"];
|
|
61
|
-
if (!supportDialects.includes(dialect)) {
|
|
62
|
-
console.log(
|
|
63
|
-
`dialect ${chalk.red(dialect)} is not supported, currently supported dialects are ${chalk.green(
|
|
64
|
-
supportDialects.join(",")
|
|
65
|
-
)}.`
|
|
66
|
-
);
|
|
67
|
-
process.exit(1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
45
|
getContext() {
|
|
71
46
|
const env = this.env;
|
|
72
47
|
const envs = [];
|
|
73
48
|
const dependencies = [];
|
|
74
|
-
const { dbDialect
|
|
75
|
-
if (allDbDialect) {
|
|
76
|
-
dependencies.push(`"mysql2": "^3.11.0"`);
|
|
77
|
-
dependencies.push(`"mariadb": "^2.5.6"`);
|
|
78
|
-
dependencies.push(`"pg": "^8.7.3"`);
|
|
79
|
-
dependencies.push(`"pg-hstore": "^2.3.4"`);
|
|
80
|
-
dependencies.push(`"sqlite3": "^5.0.8"`);
|
|
81
|
-
}
|
|
49
|
+
const { dbDialect } = this.args;
|
|
82
50
|
switch (dbDialect) {
|
|
83
|
-
case "sqlite":
|
|
84
|
-
if (!allDbDialect) {
|
|
85
|
-
dependencies.push(`"sqlite3": "^5.0.8"`);
|
|
86
|
-
}
|
|
87
|
-
envs.push(`DB_STORAGE=${env.DB_STORAGE || "storage/db/nocobase.sqlite"}`);
|
|
88
|
-
break;
|
|
89
51
|
case "mysql":
|
|
90
|
-
if (!allDbDialect) {
|
|
91
|
-
dependencies.push(`"mysql2": "^3.11.0"`);
|
|
92
|
-
}
|
|
93
52
|
envs.push(`DB_HOST=${env.DB_HOST || "localhost"}`);
|
|
94
53
|
envs.push(`DB_PORT=${env.DB_PORT || 3306}`);
|
|
95
54
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ""}`);
|
|
@@ -97,9 +56,6 @@ const _AppGenerator = class _AppGenerator extends Generator {
|
|
|
97
56
|
envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ""}`);
|
|
98
57
|
break;
|
|
99
58
|
case "mariadb":
|
|
100
|
-
if (!allDbDialect) {
|
|
101
|
-
dependencies.push(`"mariadb": "^2.5.6"`);
|
|
102
|
-
}
|
|
103
59
|
envs.push(`DB_HOST=${env.DB_HOST || "localhost"}`);
|
|
104
60
|
envs.push(`DB_PORT=${env.DB_PORT || 3306}`);
|
|
105
61
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ""}`);
|
|
@@ -108,10 +64,6 @@ const _AppGenerator = class _AppGenerator extends Generator {
|
|
|
108
64
|
break;
|
|
109
65
|
case "kingbase":
|
|
110
66
|
case "postgres":
|
|
111
|
-
if (!allDbDialect) {
|
|
112
|
-
dependencies.push(`"pg": "^8.7.3"`);
|
|
113
|
-
dependencies.push(`"pg-hstore": "^2.3.4"`);
|
|
114
|
-
}
|
|
115
67
|
envs.push(`DB_HOST=${env.DB_HOST || "localhost"}`);
|
|
116
68
|
envs.push(`DB_PORT=${env.DB_PORT || 5432}`);
|
|
117
69
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ""}`);
|
|
@@ -166,16 +118,25 @@ const _AppGenerator = class _AppGenerator extends Generator {
|
|
|
166
118
|
}
|
|
167
119
|
async writing() {
|
|
168
120
|
this.checkProjectPath();
|
|
169
|
-
this.checkDialect();
|
|
170
121
|
const { name } = this.context;
|
|
171
122
|
console.log(`Creating a new NocoBase application at ${chalk.green(name)}`);
|
|
172
123
|
console.log("Creating files");
|
|
124
|
+
const context = this.getContext();
|
|
173
125
|
this.copyDirectory({
|
|
174
|
-
context
|
|
126
|
+
context,
|
|
175
127
|
path: join(__dirname, "../templates/app"),
|
|
176
128
|
target: this.cwd
|
|
177
129
|
});
|
|
178
|
-
|
|
130
|
+
const json = {
|
|
131
|
+
name: context.name,
|
|
132
|
+
...await fs.readJSON(join(this.cwd, "package.json"), "utf8")
|
|
133
|
+
};
|
|
134
|
+
json["dependencies"]["@nocobase/cli"] = context.version;
|
|
135
|
+
if (!this.args.skipDevDependencies) {
|
|
136
|
+
json["devDependencies"] = json["devDependencies"] || {};
|
|
137
|
+
json["devDependencies"]["@nocobase/devtools"] = context.version;
|
|
138
|
+
}
|
|
139
|
+
await fs.writeJSON(join(this.cwd, "package.json"), json, { encoding: "utf8", spaces: 2 });
|
|
179
140
|
console.log("");
|
|
180
141
|
console.log(chalk.green(`$ cd ${name}`));
|
|
181
142
|
console.log(chalk.green(`$ yarn install`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-nocobase-app",
|
|
3
|
-
"version": "1.7.0
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"main": "src/index.js",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"dependencies": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"axios": "^1.7.0",
|
|
9
9
|
"chalk": "^4.1.1",
|
|
10
10
|
"commander": "^9.2.0",
|
|
11
|
-
"
|
|
11
|
+
"fs-extra": "^11.3.0",
|
|
12
|
+
"tar": "^7.4.3"
|
|
12
13
|
},
|
|
13
14
|
"bin": {
|
|
14
15
|
"create-nocobase-app": "./bin/index.js"
|
|
@@ -18,5 +19,5 @@
|
|
|
18
19
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
19
20
|
"directory": "packages/core/create-nocobase-app"
|
|
20
21
|
},
|
|
21
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "767ae089e404a104d718962272289c0bec01803a"
|
|
22
23
|
}
|
package/src/cli.js
CHANGED
|
@@ -19,8 +19,9 @@ const cli = new Command('create-nocobase');
|
|
|
19
19
|
cli
|
|
20
20
|
.arguments('<name>', 'directory of new NocoBase app')
|
|
21
21
|
.option('--quickstart', 'quickstart app creation')
|
|
22
|
+
.option('--skip-dev-dependencies')
|
|
22
23
|
.option('-a, --all-db-dialect', 'install all database dialect dependencies')
|
|
23
|
-
.option('-d, --db-dialect
|
|
24
|
+
.option('-d, --db-dialect [dbDialect]', 'database dialect, current support postgres, mysql, mariadb, kingbase')
|
|
24
25
|
.option('-e, --env <env>', 'environment variables write into .env file', concat, [])
|
|
25
26
|
.description('create a new application')
|
|
26
27
|
.action(async (name, options) => {
|
package/src/generator.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
const chalk = require('chalk');
|
|
11
11
|
const crypto = require('crypto');
|
|
12
|
-
const { existsSync } = require('fs');
|
|
12
|
+
const { existsSync, promises } = require('fs');
|
|
13
|
+
const fs = require('fs-extra');
|
|
13
14
|
const { join, resolve } = require('path');
|
|
14
15
|
const { Generator } = require('@umijs/utils');
|
|
15
16
|
const { downloadPackageFromNpm, updateJsonFile } = require('./util');
|
|
@@ -36,21 +37,6 @@ class AppGenerator extends Generator {
|
|
|
36
37
|
return items;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
checkDbEnv() {
|
|
40
|
-
const dialect = this.args.dbDialect;
|
|
41
|
-
const env = this.env;
|
|
42
|
-
if (dialect === 'sqlite') {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (!env.DB_DATABASE || !env.DB_USER || !env.DB_PASSWORD) {
|
|
46
|
-
console.log(
|
|
47
|
-
chalk.red(
|
|
48
|
-
`Please set DB_HOST, DB_PORT, DB_DATABASE, DB_USER, DB_PASSWORD in .env file to complete database settings`,
|
|
49
|
-
),
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
40
|
checkProjectPath() {
|
|
55
41
|
if (existsSync(this.cwd)) {
|
|
56
42
|
console.log(chalk.red('Project directory already exists'));
|
|
@@ -58,44 +44,14 @@ class AppGenerator extends Generator {
|
|
|
58
44
|
}
|
|
59
45
|
}
|
|
60
46
|
|
|
61
|
-
checkDialect() {
|
|
62
|
-
const dialect = this.args.dbDialect;
|
|
63
|
-
const supportDialects = ['mysql', 'mariadb', 'sqlite', 'postgres'];
|
|
64
|
-
if (!supportDialects.includes(dialect)) {
|
|
65
|
-
console.log(
|
|
66
|
-
`dialect ${chalk.red(dialect)} is not supported, currently supported dialects are ${chalk.green(
|
|
67
|
-
supportDialects.join(','),
|
|
68
|
-
)}.`,
|
|
69
|
-
);
|
|
70
|
-
process.exit(1);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
47
|
getContext() {
|
|
75
48
|
const env = this.env;
|
|
76
49
|
const envs = [];
|
|
77
50
|
const dependencies = [];
|
|
78
|
-
const { dbDialect
|
|
79
|
-
|
|
80
|
-
if (allDbDialect) {
|
|
81
|
-
dependencies.push(`"mysql2": "^3.11.0"`);
|
|
82
|
-
dependencies.push(`"mariadb": "^2.5.6"`);
|
|
83
|
-
dependencies.push(`"pg": "^8.7.3"`);
|
|
84
|
-
dependencies.push(`"pg-hstore": "^2.3.4"`);
|
|
85
|
-
dependencies.push(`"sqlite3": "^5.0.8"`);
|
|
86
|
-
}
|
|
51
|
+
const { dbDialect } = this.args;
|
|
87
52
|
|
|
88
53
|
switch (dbDialect) {
|
|
89
|
-
case 'sqlite':
|
|
90
|
-
if (!allDbDialect) {
|
|
91
|
-
dependencies.push(`"sqlite3": "^5.0.8"`);
|
|
92
|
-
}
|
|
93
|
-
envs.push(`DB_STORAGE=${env.DB_STORAGE || 'storage/db/nocobase.sqlite'}`);
|
|
94
|
-
break;
|
|
95
54
|
case 'mysql':
|
|
96
|
-
if (!allDbDialect) {
|
|
97
|
-
dependencies.push(`"mysql2": "^3.11.0"`);
|
|
98
|
-
}
|
|
99
55
|
envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
|
|
100
56
|
envs.push(`DB_PORT=${env.DB_PORT || 3306}`);
|
|
101
57
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
|
|
@@ -103,9 +59,6 @@ class AppGenerator extends Generator {
|
|
|
103
59
|
envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`);
|
|
104
60
|
break;
|
|
105
61
|
case 'mariadb':
|
|
106
|
-
if (!allDbDialect) {
|
|
107
|
-
dependencies.push(`"mariadb": "^2.5.6"`);
|
|
108
|
-
}
|
|
109
62
|
envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
|
|
110
63
|
envs.push(`DB_PORT=${env.DB_PORT || 3306}`);
|
|
111
64
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
|
|
@@ -114,10 +67,6 @@ class AppGenerator extends Generator {
|
|
|
114
67
|
break;
|
|
115
68
|
case 'kingbase':
|
|
116
69
|
case 'postgres':
|
|
117
|
-
if (!allDbDialect) {
|
|
118
|
-
dependencies.push(`"pg": "^8.7.3"`);
|
|
119
|
-
dependencies.push(`"pg-hstore": "^2.3.4"`);
|
|
120
|
-
}
|
|
121
70
|
envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
|
|
122
71
|
envs.push(`DB_PORT=${env.DB_PORT || 5432}`);
|
|
123
72
|
envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
|
|
@@ -176,21 +125,33 @@ class AppGenerator extends Generator {
|
|
|
176
125
|
|
|
177
126
|
async writing() {
|
|
178
127
|
this.checkProjectPath();
|
|
179
|
-
this.checkDialect();
|
|
180
128
|
|
|
181
129
|
const { name } = this.context;
|
|
182
130
|
|
|
183
131
|
console.log(`Creating a new NocoBase application at ${chalk.green(name)}`);
|
|
184
132
|
console.log('Creating files');
|
|
185
133
|
|
|
134
|
+
const context = this.getContext();
|
|
135
|
+
|
|
186
136
|
this.copyDirectory({
|
|
187
|
-
context
|
|
137
|
+
context,
|
|
188
138
|
path: join(__dirname, '../templates/app'),
|
|
189
139
|
target: this.cwd,
|
|
190
140
|
});
|
|
191
141
|
|
|
192
|
-
|
|
142
|
+
const json = {
|
|
143
|
+
name: context.name,
|
|
144
|
+
...(await fs.readJSON(join(this.cwd, 'package.json'), 'utf8')),
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
json['dependencies']['@nocobase/cli'] = context.version;
|
|
148
|
+
|
|
149
|
+
if (!this.args.skipDevDependencies) {
|
|
150
|
+
json['devDependencies'] = json['devDependencies'] || {};
|
|
151
|
+
json['devDependencies']['@nocobase/devtools'] = context.version;
|
|
152
|
+
}
|
|
193
153
|
|
|
154
|
+
await fs.writeJSON(join(this.cwd, 'package.json'), json, { encoding: 'utf8', spaces: 2 });
|
|
194
155
|
console.log('');
|
|
195
156
|
console.log(chalk.green(`$ cd ${name}`));
|
|
196
157
|
console.log(chalk.green(`$ yarn install`));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "{{{name}}}",
|
|
3
2
|
"private": true,
|
|
4
3
|
"workspaces": [
|
|
5
4
|
"packages/*/*",
|
|
@@ -28,14 +27,16 @@
|
|
|
28
27
|
"@types/react-dom": "^18.0.0",
|
|
29
28
|
"react-router-dom": "6.28.1",
|
|
30
29
|
"react-router": "6.28.1",
|
|
31
|
-
"antd": "5.
|
|
32
|
-
"
|
|
30
|
+
"antd": "5.24.2",
|
|
31
|
+
"async": "^3.2.6",
|
|
32
|
+
"rollup": "4.24.0",
|
|
33
|
+
"semver": "^7.7.1"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
36
|
+
"pm2": "^6.0.5",
|
|
37
|
+
"mysql2": "^3.14.0",
|
|
38
|
+
"mariadb": "^2.5.6",
|
|
39
|
+
"pg": "^8.14.1",
|
|
40
|
+
"pg-hstore": "^2.3.4"
|
|
40
41
|
}
|
|
41
|
-
}
|
|
42
|
+
}
|