zero-ai 0.3.34 → 0.3.36
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/README.md +16 -1
- package/package.json +1 -1
- package/src/_template/APP/.placeholder +0 -0
- package/src/_template/MODULE/.placeholder +0 -0
- package/src/_template/MODULE/database/MYSQL.properties +4 -0
- package/src/_template/MODULE/database/MYSQL.yml +2 -0
- package/src/_template/MODULE/database/database-reinit.sh +3 -0
- package/src/_template/MODULE/source-domain/ExtensionGeneration.ejs +7 -0
- package/src/_template/MODULE/source-domain/configuration.yml.ejs +3 -0
- package/src/_template/MODULE/source-provider/ExtensionSource.ejs +14 -0
- package/src/_template/SPRING/.placeholder +0 -0
- package/src/_template/SPRING/database/database-account.sql.ejs +3 -0
- package/src/_template/SPRING/database/database-reinit.sql.ejs +5 -0
- package/src/_template/SPRING/database/init-db.sh +4 -0
- package/src/_template/SPRING/mvn-build.sh +3 -0
- package/src/_template/SPRING/mvn-env.sh.ejs +7 -0
- package/src/_template/SPRING/pom.xml.ejs +29 -0
- package/src/_template/SPRING/source-api/AppDev.java.ejs +13 -0
- package/src/_template/SPRING/source-api/Application.java.ejs +12 -0
- package/src/_template/SPRING/source-api/application.yml.ejs +64 -0
- package/src/_template/SPRING/source-api/env.properties.ejs +7 -0
- package/src/_template/SPRING/source-api/pom.xml.ejs +64 -0
- package/src/_template/SPRING/source-domain/ActOperationCommon.ejs +17 -0
- package/src/_template/SPRING/source-domain/GenConfigApp.ejs +22 -0
- package/src/_template/SPRING/source-domain/pom.xml.ejs +20 -0
- package/src/_template/SPRING/source-provider/GenAppModule.ejs +12 -0
- package/src/_template/SPRING/source-provider/pom.xml.ejs +21 -0
- package/src/_template/SPRING/source-test/pom.xml.ejs +28 -0
- package/src/_template/ZERO/.placeholder +0 -0
- package/src/_template/ZERO/app.env.ejs +96 -0
- package/src/_template/ZERO/database/database-account.sql.ejs +3 -0
- package/src/_template/ZERO/database/database-reinit-history.sql.ejs +5 -0
- package/src/_template/ZERO/database/database-reinit-workflow.sql.ejs +5 -0
- package/src/_template/ZERO/database/database-reinit.sql.ejs +5 -0
- package/src/_template/ZERO/database/init-db.sh +49 -0
- package/src/_template/ZERO/mvn-build.sh +3 -0
- package/src/_template/ZERO/pom.xml.ejs +24 -0
- package/src/_template/ZERO/source-api/AppDev.java.ejs +13 -0
- package/src/_template/ZERO/source-api/Application.java.ejs +11 -0
- package/src/_template/ZERO/source-api/env.properties.ejs +18 -0
- package/src/_template/ZERO/source-api/flyway.conf +6 -0
- package/src/_template/ZERO/source-api/pom.xml.ejs +24 -0
- package/src/_template/ZERO/source-api/vertx.yml.ejs +70 -0
- package/src/_template/ZERO/source-domain/ModuleGeneration.java.ejs +8 -0
- package/src/_template/ZERO/source-domain/pom.xml.ejs +20 -0
- package/src/_template/ZERO/source-provider/ModuleSource.java.ejs +14 -0
- package/src/_template/ZERO/source-provider/pom.xml.ejs +21 -0
- package/src/_template/ZERO/source-test/pom.xml.ejs +28 -0
- package/src/_template/version +5 -0
- package/src/{commander → cab/removed}/app.json +8 -2
- package/src/commander/spring.json +24 -0
- package/src/commander/zero.json +24 -0
- package/src/commander-ai/fn.source.app.js +8 -3
- package/src/commander-ai/fn.source.mod.js +1 -1
- package/src/commander-ai/fn.source.spring.js +24 -0
- package/src/commander-ai/fn.source.zero.js +24 -0
- package/src/commander-ai/index.js +7 -4
- package/src/commander-shared/ai.fn.initialize.__.io.util.js +166 -0
- package/src/commander-shared/ai.fn.initialize.__.module.directory.js +63 -0
- package/src/commander-shared/ai.fn.initialize.__.module.file.js +81 -0
- package/src/commander-shared/ai.fn.initialize.__.spring.directory.js +73 -0
- package/src/commander-shared/ai.fn.initialize.__.spring.file.js +111 -0
- package/src/commander-shared/ai.fn.initialize.__.zero.directory.js +75 -0
- package/src/commander-shared/ai.fn.initialize.__.zero.file.js +117 -0
- package/src/commander-shared/ai.fn.initialize.app.js +26 -0
- package/src/commander-shared/ai.fn.initialize.module.js +35 -28
- package/src/commander-shared/ai.fn.initialize.spring.js +73 -0
- package/src/commander-shared/ai.fn.initialize.zero.js +84 -0
- package/src/commander-shared/ai.fn.parse.argument.js +9 -1
- package/src/commander-shared/index.js +23 -1
- package/src/_template/SERVICE/database/database-reinit.sh +0 -3
- package/src/commander-shared/ai.fn.initialize.io.js +0 -86
- /package/src/_template/{SERVICE → MODULE}/database/database-reinit.sql +0 -0
- /package/src/_template/{SERVICE → MODULE}/database/init-db.sh +0 -0
- /package/src/_template/{SERVICE → MODULE}/pom.xml.ejs +0 -0
- /package/src/_template/{SERVICE → MODULE}/source-api/pom.xml.ejs +0 -0
- /package/src/_template/{SERVICE → MODULE}/source-domain/pom.xml.ejs +0 -0
- /package/src/_template/{SERVICE → MODULE}/source-provider/pom.xml.ejs +0 -0
- /package/src/{commander → cab/removed}/mod.json +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package <%= packageName %>;
|
|
2
|
+
|
|
3
|
+
import io.zerows.boot.VertxApplication;
|
|
4
|
+
import io.zerows.epoch.annotations.Up;
|
|
5
|
+
import io.zerows.platform.annotations.PropertySource;
|
|
6
|
+
|
|
7
|
+
@Up
|
|
8
|
+
@PropertySource("env.properties")
|
|
9
|
+
public class <%= name %>Dev {
|
|
10
|
+
public static void main(final String[] args) {
|
|
11
|
+
VertxApplication.run(<%= name %>Dev.class);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# ------- 端口信息
|
|
2
|
+
Z_API_PORT=7085
|
|
3
|
+
# ------- 应用程序专用环境
|
|
4
|
+
Z_APP=<%= appName %>
|
|
5
|
+
Z_APP_ID=<%= appId %>
|
|
6
|
+
Z_SIGMA=<%= appSigma %>
|
|
7
|
+
Z_TENANT=<%= appTenant %>
|
|
8
|
+
#
|
|
9
|
+
# ------- 数据库连接信息
|
|
10
|
+
Z_DB_TYPE="<%= dbType %>"
|
|
11
|
+
Z_DBS_INSTANCE="<%= dbName %>_APP"
|
|
12
|
+
Z_DBW_INSTANCE="<%= dbName %>_WF"
|
|
13
|
+
Z_DB_HOST="<%= dbHost %>"
|
|
14
|
+
Z_DB_PORT=<%= dbPort %>
|
|
15
|
+
Z_DB_USERNAME="root"
|
|
16
|
+
Z_DB_PASSWORD=""
|
|
17
|
+
Z_DB_APP_USER="<%= dbUser %>"
|
|
18
|
+
Z_DB_APP_PASS="<%= dbPassword %>"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# src/main/resources/flyway.conf
|
|
2
|
+
# 注意:这里使用的是 Maven 格式的变量
|
|
3
|
+
flyway.url=jdbc:mysql://${env.Z_DB_HOST}:${env.Z_DB_PORT}/${env.Z_DBS_INSTANCE}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&useSSL=false&allowPublicKeyRetrieval=true
|
|
4
|
+
flyway.user=${env.Z_DB_APP_USER}
|
|
5
|
+
flyway.password=${env.Z_DB_APP_PASS}
|
|
6
|
+
flyway.baselineOnMigrate=true
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
3
|
+
xmlns="http://maven.apache.org/POM/4.0.0"
|
|
4
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
5
|
+
<modelVersion>4.0.0</modelVersion>
|
|
6
|
+
<parent>
|
|
7
|
+
<groupId><%= group %></groupId>
|
|
8
|
+
<artifactId><%= id %></artifactId>
|
|
9
|
+
<version>${revision}</version>
|
|
10
|
+
</parent>
|
|
11
|
+
|
|
12
|
+
<artifactId><%= id %>-api</artifactId>
|
|
13
|
+
<name>App::<%= name %>::Api</name>
|
|
14
|
+
<properties>
|
|
15
|
+
<maven.main.class><%= packageName %>.<%= name %>App</maven.main.class>
|
|
16
|
+
</properties>
|
|
17
|
+
<dependencies>
|
|
18
|
+
<dependency>
|
|
19
|
+
<groupId><%= group %></groupId>
|
|
20
|
+
<artifactId><%= id %>-provider</artifactId>
|
|
21
|
+
<version>${project.version}</version>
|
|
22
|
+
</dependency>
|
|
23
|
+
</dependencies>
|
|
24
|
+
</project>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
server:
|
|
2
|
+
port: ${Z_API_PORT:7185}
|
|
3
|
+
address: ${Z_API_HOST:0.0.0.0}
|
|
4
|
+
vertx:
|
|
5
|
+
application:
|
|
6
|
+
name: ${Z_APP:r2mo-app-momo} # ---> 💻️ 微服务名称
|
|
7
|
+
config:
|
|
8
|
+
instance:
|
|
9
|
+
- name: <%= appName %>-001
|
|
10
|
+
options:
|
|
11
|
+
maxEventLoopExecuteTime: 1200_000_000_000
|
|
12
|
+
maxWorkerExecuteTime: 1200_000_000_000
|
|
13
|
+
|
|
14
|
+
# 🚀【核心优化 1】EventLoop 线程池
|
|
15
|
+
# 公式:CPU核数(12) * 2 = 24
|
|
16
|
+
# 原来的 128 太大,导致 CPU 频繁切换上下文,降低性能
|
|
17
|
+
eventLoopPoolSize: 24
|
|
18
|
+
|
|
19
|
+
# 🚀【核心优化 2】Worker 线程池 (阻塞任务池)
|
|
20
|
+
# 如果你的业务主要是查数据库,这个值可以大一点 (64 - 128 之间)
|
|
21
|
+
# 如果太小,高并发查库时会由排队现象;太大则浪费内存。
|
|
22
|
+
# 建议先降到 64 或 128,原 256 略显激进
|
|
23
|
+
workerPoolSize: 128
|
|
24
|
+
|
|
25
|
+
# 内部阻塞池,通常不需要太大,32-64 即可
|
|
26
|
+
internalBlockingPoolSize: 32
|
|
27
|
+
delivery:
|
|
28
|
+
timeout: 180_000
|
|
29
|
+
deployment:
|
|
30
|
+
worker:
|
|
31
|
+
# 🚀【核心优化 3】Worker Verticle 实例数
|
|
32
|
+
# 不需要太多,Vert.x 会复用 Worker 线程池
|
|
33
|
+
# 设置为 CPU 核数 x 2 或 x 4 即可
|
|
34
|
+
instances: 32
|
|
35
|
+
# 这里的 workerPoolSize 是覆盖上面全局配置的,保持一致或按需调整
|
|
36
|
+
workerPoolSize: 128
|
|
37
|
+
agent:
|
|
38
|
+
# 🚀【核心优化 4】Agent (Http Server) 实例数
|
|
39
|
+
# 必须严格等于 eventLoopPoolSize,实现 1:1 绑定
|
|
40
|
+
# 这样每个 CPU 核心只负责 2 个 Server 实例,效率最高
|
|
41
|
+
instances: 24
|
|
42
|
+
mvc:
|
|
43
|
+
cors:
|
|
44
|
+
allow-credentials: true
|
|
45
|
+
allowed-origins:
|
|
46
|
+
- "*"
|
|
47
|
+
datasource:
|
|
48
|
+
dynamic:
|
|
49
|
+
primary: master
|
|
50
|
+
strict: false
|
|
51
|
+
datasource:
|
|
52
|
+
# master 库同 datasource,其他两库可分离,不开启动态的模式下直接使用 datasource 配置
|
|
53
|
+
master:
|
|
54
|
+
url: ${Z_DBS_URL:jdbc:mysql://ox.engine.cn:3306/DB_HOTEL_004?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true}
|
|
55
|
+
instance: ${Z_DBS_INSTANCE:DB_HOTEL_004}
|
|
56
|
+
hostname: ${vertx.datasource.hostname}
|
|
57
|
+
port: ${vertx.datasource.port}
|
|
58
|
+
username: ${vertx.datasource.username}
|
|
59
|
+
password: ${vertx.datasource.password}
|
|
60
|
+
hostname: ${Z_DB_HOST:ox.engine.cn}
|
|
61
|
+
port: ${Z_DB_PORT:3306}
|
|
62
|
+
username: ${Z_DB_APP_USER:r2mo}
|
|
63
|
+
password: ${Z_DB_APP_PASS:r2mo}
|
|
64
|
+
driver-class-name: "com.mysql.cj.jdbc.Driver"
|
|
65
|
+
# ------------------- 业务环境综述
|
|
66
|
+
# 📌 应用管理
|
|
67
|
+
app:
|
|
68
|
+
id: "<%= appId %>"
|
|
69
|
+
ns: "<%= appNs %>"
|
|
70
|
+
tenant: "<%= appTenant %>"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
3
|
+
xmlns="http://maven.apache.org/POM/4.0.0"
|
|
4
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
5
|
+
<modelVersion>4.0.0</modelVersion>
|
|
6
|
+
<parent>
|
|
7
|
+
<groupId><%= group %></groupId>
|
|
8
|
+
<artifactId><%= id %></artifactId>
|
|
9
|
+
<version>${revision}</version>
|
|
10
|
+
</parent>
|
|
11
|
+
|
|
12
|
+
<artifactId><%= id %>-domain</artifactId>
|
|
13
|
+
<name>App::<%= name %>::Domain</name>
|
|
14
|
+
<dependencies>
|
|
15
|
+
<dependency>
|
|
16
|
+
<groupId>io.zerows</groupId>
|
|
17
|
+
<artifactId>zero-extension-skeleton</artifactId>
|
|
18
|
+
</dependency>
|
|
19
|
+
</dependencies>
|
|
20
|
+
</project>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package <%= packageName %>;
|
|
2
|
+
|
|
3
|
+
import io.zerows.extension.skeleton.boot.ExtensionLauncher;
|
|
4
|
+
import io.zerows.platform.ENV;
|
|
5
|
+
|
|
6
|
+
public class Module<%= name %>Source {
|
|
7
|
+
|
|
8
|
+
public static void main(final String[] args) {
|
|
9
|
+
final ExtensionLauncher launcher = ExtensionLauncher.create(Module<%= name %>Source.class, args);
|
|
10
|
+
final Module<%= name %>Generation configuration = new Module<%= name %>Generation();
|
|
11
|
+
configuration.resolver(ENV::parseVariable);
|
|
12
|
+
launcher.startGenerate(configuration);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
3
|
+
xmlns="http://maven.apache.org/POM/4.0.0"
|
|
4
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
5
|
+
<modelVersion>4.0.0</modelVersion>
|
|
6
|
+
<parent>
|
|
7
|
+
<groupId><%= group %></groupId>
|
|
8
|
+
<artifactId><%= id %></artifactId>
|
|
9
|
+
<version>${revision}</version>
|
|
10
|
+
</parent>
|
|
11
|
+
|
|
12
|
+
<artifactId><%= id %>-provider</artifactId>
|
|
13
|
+
<name>App::<%= name %>::Provider</name>
|
|
14
|
+
<dependencies>
|
|
15
|
+
<dependency>
|
|
16
|
+
<groupId><%= group %></groupId>
|
|
17
|
+
<artifactId><%= id %>-domain</artifactId>
|
|
18
|
+
<version>${project.version}</version>
|
|
19
|
+
</dependency>
|
|
20
|
+
</dependencies>
|
|
21
|
+
</project>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
3
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
4
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
5
|
+
<modelVersion>4.0.0</modelVersion>
|
|
6
|
+
<parent>
|
|
7
|
+
<groupId><%= group %></groupId>
|
|
8
|
+
<artifactId><%= id %></artifactId>
|
|
9
|
+
<version>1.0</version>
|
|
10
|
+
</parent>
|
|
11
|
+
|
|
12
|
+
<artifactId><%= id %>-test</artifactId>
|
|
13
|
+
<name>APP::<%= name %>::Test</name>
|
|
14
|
+
<dependencies>
|
|
15
|
+
<dependency>
|
|
16
|
+
<groupId>io.zerows</groupId>
|
|
17
|
+
<artifactId>r2mo-spring-junit5</artifactId>
|
|
18
|
+
<version>${r2mo.version}</version>
|
|
19
|
+
<scope>test</scope>
|
|
20
|
+
</dependency>
|
|
21
|
+
<dependency>
|
|
22
|
+
<groupId><%= group %></groupId>
|
|
23
|
+
<artifactId><%= id %>-api</artifactId>
|
|
24
|
+
<version>${project.version}</version>
|
|
25
|
+
</dependency>
|
|
26
|
+
</dependencies>
|
|
27
|
+
|
|
28
|
+
</project>
|
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
"description": "创建应用的名称!"
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
|
-
"name": "
|
|
13
|
-
"alias": "
|
|
12
|
+
"name": "config",
|
|
13
|
+
"alias": "c",
|
|
14
|
+
"description": "配置文件路径,默认读取 app.json 文件!",
|
|
15
|
+
"default": "app.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "output",
|
|
19
|
+
"alias": "o",
|
|
14
20
|
"description": "默认应用的输出路径,若不制定为当前路径!",
|
|
15
21
|
"default": "."
|
|
16
22
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"executor": "executeSpring",
|
|
3
|
+
"description": "(后端)创建一个新的 Spring 脚手架!",
|
|
4
|
+
"command": "spring",
|
|
5
|
+
"options": [
|
|
6
|
+
{
|
|
7
|
+
"name": "name",
|
|
8
|
+
"alias": "n",
|
|
9
|
+
"description": "创建应用的名称!"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "config",
|
|
13
|
+
"alias": "c",
|
|
14
|
+
"description": "配置文件路径,默认读取 app.json 文件!",
|
|
15
|
+
"default": "app.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "output",
|
|
19
|
+
"alias": "o",
|
|
20
|
+
"description": "默认应用的输出路径,若不制定为当前路径!",
|
|
21
|
+
"default": "."
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"executor": "executeZero",
|
|
3
|
+
"description": "(后端)创建一个新的 Zero 脚手架!",
|
|
4
|
+
"command": "zero",
|
|
5
|
+
"options": [
|
|
6
|
+
{
|
|
7
|
+
"name": "name",
|
|
8
|
+
"alias": "n",
|
|
9
|
+
"description": "创建应用的名称!"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "config",
|
|
13
|
+
"alias": "c",
|
|
14
|
+
"description": "配置文件路径,默认读取 app.json 文件!",
|
|
15
|
+
"default": "app.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"name": "output",
|
|
19
|
+
"alias": "o",
|
|
20
|
+
"description": "默认应用的输出路径,若不制定为当前路径!",
|
|
21
|
+
"default": "."
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -9,7 +9,12 @@ module.exports = (options) => {
|
|
|
9
9
|
/*
|
|
10
10
|
* 基本信息验证
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
if (!Ut.nameValid(parsed.name)) {
|
|
13
|
+
Ec.error("应用名称只能包含字母、数字、点(.)和短横线(-),且不能以数字、点(.)或短横线(-)开头!");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const configuration = Ut.initAppConfiguration(parsed);
|
|
17
|
+
Ec.info(`准备生成 Zero App 应用:${configuration.artifactId}`);
|
|
18
|
+
configuration.srcType = Symbol("APP");
|
|
19
|
+
Ut.initApp(configuration).then(() => Ec.info(`应用生成完成!`));
|
|
15
20
|
}
|
|
@@ -9,7 +9,7 @@ module.exports = (options) => {
|
|
|
9
9
|
/*
|
|
10
10
|
* 基本信息验证
|
|
11
11
|
*/
|
|
12
|
-
const configuration = Ut.
|
|
12
|
+
const configuration = Ut.initModuleConfiguration(parsed);
|
|
13
13
|
Ec.info(`准备生成 Zero Extension 扩展模块:${configuration.artifactId}`);
|
|
14
14
|
Ut.initMod(configuration).then(() => Ec.info(`模块生成完成!`));
|
|
15
15
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const Ec = require("../epic");
|
|
2
|
+
const Ut = require("../commander-shared");
|
|
3
|
+
const request = require("superagent");
|
|
4
|
+
|
|
5
|
+
module.exports = async (options) => {
|
|
6
|
+
/*
|
|
7
|
+
* 参数解析,解析完成后直接加载基础版本,由于 parseArgument 的通用性,版本解析
|
|
8
|
+
* 只会在 ai spring 等项目初始化命令中完成,所以这里需要单独调用 parseVersion 方法
|
|
9
|
+
* 进行版本解析。
|
|
10
|
+
*/
|
|
11
|
+
let parsed = Ut.parseArgument(options);
|
|
12
|
+
parsed = await Ut.parseVersion(parsed);
|
|
13
|
+
/*
|
|
14
|
+
* 基本信息验证
|
|
15
|
+
*/
|
|
16
|
+
if (!Ut.nameValid(parsed.name)) {
|
|
17
|
+
Ec.error("应用名称只能包含字母、数字、点(.)和短横线(-),且不能以数字、点(.)或短横线(-)开头!");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const configuration = await Ut.initSpringConfiguration(parsed);
|
|
21
|
+
Ec.execute(`准备生成 Rapid Spring App 应用:${configuration.artifactId}`);
|
|
22
|
+
await Ut.initSpring(configuration);
|
|
23
|
+
Ec.info(`应用生成完成!`);
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const Ec = require("../epic");
|
|
2
|
+
const Ut = require("../commander-shared");
|
|
3
|
+
const request = require("superagent");
|
|
4
|
+
|
|
5
|
+
module.exports = async (options) => {
|
|
6
|
+
/*
|
|
7
|
+
* 参数解析,解析完成后直接加载基础版本,由于 parseArgument 的通用性,版本解析
|
|
8
|
+
* 只会在 ai zero 等项目初始化命令中完成,所以这里需要单独调用 parseVersion 方法
|
|
9
|
+
* 进行版本解析。
|
|
10
|
+
*/
|
|
11
|
+
let parsed = Ut.parseArgument(options);
|
|
12
|
+
parsed = await Ut.parseVersion(parsed);
|
|
13
|
+
/*
|
|
14
|
+
* 基本信息验证
|
|
15
|
+
*/
|
|
16
|
+
if (!Ut.nameValid(parsed.name)) {
|
|
17
|
+
Ec.error("应用名称只能包含字母、数字、点(.)和短横线(-),且不能以数字、点(.)或短横线(-)开头!");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const configuration = await Ut.initZeroConfiguration(parsed);
|
|
21
|
+
Ec.execute(`准备生成 Zero App 应用:${configuration.artifactId}`);
|
|
22
|
+
await Ut.initZero(configuration);
|
|
23
|
+
Ec.info(`应用生成完成!`);
|
|
24
|
+
}
|
|
@@ -2,19 +2,22 @@ const executeUuid = require('./fn.random.uuid');
|
|
|
2
2
|
const executeString = require('./fn.random.string');
|
|
3
3
|
const executeMD5 = require('./fn.random.md5');
|
|
4
4
|
const executeFrontendSync = require('./fn.source.sync');
|
|
5
|
-
const executeApp = require('./fn.source.app');
|
|
6
|
-
const executeMod = require('./fn.source.mod');
|
|
7
5
|
const executeHelp = require('./fn.help.metadata');
|
|
8
6
|
const executeWeb = require('./fn.source.front');
|
|
7
|
+
|
|
8
|
+
const executeSpring = require('./fn.source.spring');
|
|
9
|
+
const executeZero = require('./fn.source.zero');
|
|
9
10
|
const exported = {
|
|
10
11
|
executeUuid, // ai uuid
|
|
11
12
|
executeString, // ai str
|
|
12
13
|
executeMD5, // ai md5
|
|
13
14
|
executeFrontendSync, // ai sync
|
|
14
|
-
executeApp, // ai app
|
|
15
|
-
executeMod, // ai mod
|
|
16
15
|
executeHelp, // ai help
|
|
17
16
|
executeWeb, // ai web
|
|
17
|
+
// Spring 脚手架
|
|
18
|
+
executeSpring, // ai spring
|
|
19
|
+
// Zero 基础脚手架
|
|
20
|
+
executeZero, // ai zero
|
|
18
21
|
};
|
|
19
22
|
module.exports = exported;
|
|
20
23
|
/**
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
const Ec = require("../epic");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const fsAsync = require("fs").promises;
|
|
4
|
+
const ejs = require("ejs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const ioEJS = async (source, configuration = {}) => new Promise((resolve, reject) => {
|
|
8
|
+
Ec.execute(`读取 EJS 模版:${source.blue}`)
|
|
9
|
+
fs.readFile(source, "utf8", (err, data) => {
|
|
10
|
+
if (err) {
|
|
11
|
+
reject(err);
|
|
12
|
+
}
|
|
13
|
+
// 渲染模板
|
|
14
|
+
const renderContent = ejs.render(data, configuration);
|
|
15
|
+
resolve(renderContent);
|
|
16
|
+
});
|
|
17
|
+
})
|
|
18
|
+
const withDomain = (configuration = {}, path) => {
|
|
19
|
+
return `${configuration.srcOut}/${configuration.artifactId}/${configuration.artifactId}-domain/${path}`;
|
|
20
|
+
}
|
|
21
|
+
const withProvider = (configuration = {}, path) => {
|
|
22
|
+
return `${configuration.srcOut}/${configuration.artifactId}/${configuration.artifactId}-provider/${path}`;
|
|
23
|
+
}
|
|
24
|
+
const withApi = (configuration = {}, path) => {
|
|
25
|
+
return `${configuration.srcOut}/${configuration.artifactId}/${configuration.artifactId}-api/${path}`;
|
|
26
|
+
}
|
|
27
|
+
const withTest = (configuration = {}, path) => {
|
|
28
|
+
return `${configuration.srcOut}/${configuration.artifactId}/${configuration.artifactId}-test/${path}`;
|
|
29
|
+
}
|
|
30
|
+
const withDPA = (configuration = {}, path) => {
|
|
31
|
+
return `${configuration.srcOut}/${configuration.artifactId}/${path}`;
|
|
32
|
+
}
|
|
33
|
+
const ioConfiguration = (parsed = {}, name) => {
|
|
34
|
+
const configMap = {};
|
|
35
|
+
configMap.groupId = "io.zerows";
|
|
36
|
+
configMap.artifactId = name;
|
|
37
|
+
configMap.srcPackage = `io.zerows.extension.${name}`;
|
|
38
|
+
|
|
39
|
+
let output = parsed.output;
|
|
40
|
+
if ('.' === output) {
|
|
41
|
+
output = process.cwd();
|
|
42
|
+
}
|
|
43
|
+
configMap.srcId = name;
|
|
44
|
+
configMap.srcOut = output;
|
|
45
|
+
configMap.srcConfig = parsed.config;
|
|
46
|
+
configMap.dbType = "MYSQL";
|
|
47
|
+
|
|
48
|
+
return configMap;
|
|
49
|
+
}
|
|
50
|
+
const ioApp = async (configuration = {}) => {
|
|
51
|
+
let configFile = process.cwd() + `\`/${configuration.srcConfig}`;
|
|
52
|
+
const configDefault = process.cwd() + `/app.json`;
|
|
53
|
+
if (!fs.existsSync(configFile)) {
|
|
54
|
+
Ec.warn(`配置文件不存在,使用默认配置!路径 = ` + configDefault.blue);
|
|
55
|
+
configFile = configDefault;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 加载配置文件
|
|
59
|
+
if (fs.existsSync(configFile)) {
|
|
60
|
+
// 配置加载
|
|
61
|
+
const configData = Ec.ioJObject(configFile);
|
|
62
|
+
[
|
|
63
|
+
"framework", // 框架版本
|
|
64
|
+
"dbHost", // 数据库主机
|
|
65
|
+
"dbPort", // 数据库端口
|
|
66
|
+
"dbUser", // 数据库用户
|
|
67
|
+
"dbPassword", // 数据库密码
|
|
68
|
+
"dbName", // 数据库名称
|
|
69
|
+
"groupId", // Maven Group ID
|
|
70
|
+
"artifactId", // Maven Artifact ID
|
|
71
|
+
"srcPackage" // Java 包名称
|
|
72
|
+
].forEach(field => {
|
|
73
|
+
if (configData.hasOwnProperty(field)) {
|
|
74
|
+
configuration[field] = configData[field];
|
|
75
|
+
Ec.execute("\t配置项覆盖:" + field + " = " + configData[field]);
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
/*
|
|
80
|
+
* - group / Maven 对应的 groupId
|
|
81
|
+
* - id / Maven 对应的 artifactId
|
|
82
|
+
* - name / 模块名称,大写形式
|
|
83
|
+
* - packageName / Java 包名称
|
|
84
|
+
*/
|
|
85
|
+
configuration.id = configuration?.artifactId;
|
|
86
|
+
configuration.name = configuration?.srcId.toUpperCase();
|
|
87
|
+
configuration.packageName = configuration?.srcPackage;
|
|
88
|
+
configuration.group = configuration?.groupId;
|
|
89
|
+
return configuration;
|
|
90
|
+
}
|
|
91
|
+
const ioAppName = (name) => {
|
|
92
|
+
let appName;
|
|
93
|
+
if (0 < name.indexOf("-")) {
|
|
94
|
+
appName = name.substring(name.lastIndexOf("-") + 1);
|
|
95
|
+
} else if (0 < name.indexOf(".")) {
|
|
96
|
+
appName = name.substring(name.lastIndexOf(".") + 1);
|
|
97
|
+
} else {
|
|
98
|
+
appName = name;
|
|
99
|
+
}
|
|
100
|
+
return appName;
|
|
101
|
+
}
|
|
102
|
+
const ioChmod = async (directory) => {
|
|
103
|
+
try {
|
|
104
|
+
// Ec.execute(`正在扫描目录:${directory}`);
|
|
105
|
+
// 1. 目录读取
|
|
106
|
+
const files = await fsAsync.readdir(directory, {withFileTypes: true});
|
|
107
|
+
// 2. 筛选所有的 .sh 文件
|
|
108
|
+
const chmodPromise = [];
|
|
109
|
+
for (const file of files) {
|
|
110
|
+
const fullPath = path.join(directory, file.name);
|
|
111
|
+
if (file.isDirectory()) {
|
|
112
|
+
// 递归处理子目录
|
|
113
|
+
const subPromises = await ioChmod(fullPath);
|
|
114
|
+
chmodPromise.push(...subPromises);
|
|
115
|
+
} else if (file.isFile() && path.extname(file.name) === '.sh') {
|
|
116
|
+
// 处理 .sh 文件
|
|
117
|
+
const chmodPromiseItem = fsAsync.stat(fullPath)
|
|
118
|
+
.then(stat => {
|
|
119
|
+
const currentMode = stat.mode;
|
|
120
|
+
const newMode = currentMode
|
|
121
|
+
| fsAsync.constants.S_IXUSR
|
|
122
|
+
| fsAsync.constants.S_IXGRP
|
|
123
|
+
| fsAsync.constants.S_IXOTH;
|
|
124
|
+
return fsAsync.chmod(fullPath, newMode);
|
|
125
|
+
})
|
|
126
|
+
.then(() => {
|
|
127
|
+
Ec.execute(`${fullPath} 的执行权限已添加。`);
|
|
128
|
+
})
|
|
129
|
+
.catch(chmodErr => {
|
|
130
|
+
Ec.error(`修改 ${fullPath} 权限时发生错误: ${chmodErr.message}`);
|
|
131
|
+
});
|
|
132
|
+
chmodPromise.push(chmodPromiseItem);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 等待所有 chmod 操作完成
|
|
137
|
+
await Promise.all(chmodPromise);
|
|
138
|
+
|
|
139
|
+
return chmodPromise;
|
|
140
|
+
|
|
141
|
+
} catch (error) {
|
|
142
|
+
Ec.error(`处理目录发生错误:${directory}`);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const ioPackage = async (suffix, configuration, baseFn) => {
|
|
147
|
+
const packageName = !!suffix ? configuration.srcPackage + `.${suffix}` : configuration.srcPackage;
|
|
148
|
+
const pathPackage = packageName.replace(/\./g, "/");
|
|
149
|
+
let dirPackage = baseFn(configuration, `src/main/java/${pathPackage}`);
|
|
150
|
+
await fsAsync.mkdir(dirPackage, {recursive: true});
|
|
151
|
+
await fsAsync.access(dirPackage, fsAsync.constants.F_OK);
|
|
152
|
+
return pathPackage;
|
|
153
|
+
}
|
|
154
|
+
module.exports = {
|
|
155
|
+
ioPackage,
|
|
156
|
+
ioChmod,
|
|
157
|
+
ioConfiguration,
|
|
158
|
+
ioEJS,
|
|
159
|
+
ioAppName,
|
|
160
|
+
ioApp,
|
|
161
|
+
withTest,
|
|
162
|
+
withDomain,
|
|
163
|
+
withProvider,
|
|
164
|
+
withApi,
|
|
165
|
+
withDPA,
|
|
166
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const fs = require("fs").promises;
|
|
2
|
+
const Ec = require('../epic');
|
|
3
|
+
const IoZero = require('./ai.fn.initialize.__.module.file');
|
|
4
|
+
const IoUt = require('./ai.fn.initialize.__.io.util');
|
|
5
|
+
const ioDPAStructure = async (baseDir, configuration) => {
|
|
6
|
+
const name = configuration.artifactId;
|
|
7
|
+
const folders = [
|
|
8
|
+
`${baseDir}/${name}`,
|
|
9
|
+
`${baseDir}/${name}/${name}-domain/database`,
|
|
10
|
+
`${baseDir}/${name}/${name}-domain/src/main/java`,
|
|
11
|
+
`${baseDir}/${name}/${name}-domain/src/main/resources/plugins/${name}`,
|
|
12
|
+
`${baseDir}/${name}/${name}-domain/src/main/resources/plugins/${name}/database/${configuration.dbType}/`,
|
|
13
|
+
`${baseDir}/${name}/${name}-domain/src/test/java`,
|
|
14
|
+
`${baseDir}/${name}/${name}-domain/src/test/resources`,
|
|
15
|
+
`${baseDir}/${name}/${name}-api/src/main/java`,
|
|
16
|
+
`${baseDir}/${name}/${name}-api/src/main/resources`,
|
|
17
|
+
`${baseDir}/${name}/${name}-api/src/test/java`,
|
|
18
|
+
`${baseDir}/${name}/${name}-api/src/test/resources`,
|
|
19
|
+
`${baseDir}/${name}/${name}-provider/src/main/java`,
|
|
20
|
+
`${baseDir}/${name}/${name}-provider/src/main/resources`,
|
|
21
|
+
`${baseDir}/${name}/${name}-provider/src/test/java`,
|
|
22
|
+
`${baseDir}/${name}/${name}-provider/src/test/resources`,
|
|
23
|
+
];
|
|
24
|
+
const results = [];
|
|
25
|
+
folders.map(async (folder) => {
|
|
26
|
+
Ec.execute("创建目录:" + folder);
|
|
27
|
+
await fs.mkdir(folder, {recursive: true});
|
|
28
|
+
results.push(true);
|
|
29
|
+
})
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const ioDPAPom = async (source, configuration = {}) => {
|
|
34
|
+
let fileSrc = `${source}/pom.xml.ejs`;
|
|
35
|
+
let fileContent = await IoUt.ioEJS(fileSrc, configuration);
|
|
36
|
+
let fileDest = IoUt.withDPA(configuration, `pom.xml`);
|
|
37
|
+
await fs.writeFile(fileDest, fileContent.toString(), null);
|
|
38
|
+
Ec.execute("生成文件:" + fileDest.green);
|
|
39
|
+
|
|
40
|
+
fileSrc = `${source}/source-api/pom.xml.ejs`;
|
|
41
|
+
fileContent = await IoUt.ioEJS(fileSrc, configuration);
|
|
42
|
+
fileDest = IoUt.withApi(configuration, `pom.xml`);
|
|
43
|
+
await fs.writeFile(fileDest, fileContent.toString(), null);
|
|
44
|
+
Ec.execute("生成文件:" + fileDest.green);
|
|
45
|
+
|
|
46
|
+
fileSrc = `${source}/source-provider/pom.xml.ejs`;
|
|
47
|
+
fileContent = await IoUt.ioEJS(fileSrc, configuration);
|
|
48
|
+
fileDest = IoUt.withProvider(configuration, `pom.xml`);
|
|
49
|
+
await fs.writeFile(fileDest, fileContent.toString(), null);
|
|
50
|
+
Ec.execute("生成文件:" + fileDest.green);
|
|
51
|
+
|
|
52
|
+
fileSrc = `${source}/source-domain/pom.xml.ejs`;
|
|
53
|
+
fileContent = await IoUt.ioEJS(fileSrc, configuration);
|
|
54
|
+
fileDest = IoUt.withDomain(configuration, `pom.xml`);
|
|
55
|
+
await fs.writeFile(fileDest, fileContent.toString(), null);
|
|
56
|
+
Ec.execute("生成文件:" + fileDest.green);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
module.exports = {
|
|
60
|
+
ioDPAStructure,
|
|
61
|
+
ioDPAPom,
|
|
62
|
+
...IoZero,
|
|
63
|
+
}
|