gorig-cli 1.0.4 → 1.0.6
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 +18 -0
- package/commands/create.js +30 -0
- package/package.json +1 -1
- package/templates/config.go.ejs +3 -2
- package/templates/internal.go.ejs +5 -5
package/README.md
CHANGED
|
@@ -10,6 +10,12 @@ Gorig CLI 是一个基于 Node.js 的脚手架工具,用于快速创建基于
|
|
|
10
10
|
npm install -g gorig-cli
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
或者使用 npx 直接运行:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npx gorig-cli <command>
|
|
17
|
+
```
|
|
18
|
+
|
|
13
19
|
## 快速开始
|
|
14
20
|
|
|
15
21
|
### 初始化新项目
|
|
@@ -20,6 +26,12 @@ npm install -g gorig-cli
|
|
|
20
26
|
gorig-cli init my-new-project
|
|
21
27
|
```
|
|
22
28
|
|
|
29
|
+
或者使用 npx:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
npx gorig-cli init my-new-project
|
|
33
|
+
```
|
|
34
|
+
|
|
23
35
|
这将在当前目录下创建一个新项目,包含 `_cmd/main.go`、`domain/init.go`、`cron/cron.go` 等基本文件和目录。
|
|
24
36
|
|
|
25
37
|
### 创建新模块
|
|
@@ -30,6 +42,12 @@ gorig-cli init my-new-project
|
|
|
30
42
|
gorig-cli create user
|
|
31
43
|
```
|
|
32
44
|
|
|
45
|
+
或者使用 npx:
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npx gorig-cli create user
|
|
49
|
+
```
|
|
50
|
+
|
|
33
51
|
这将在项目中创建一个名为 `user` 的模块,包含 `api/`、`internal/`、`model/` 等文件夹和必要的代码。
|
|
34
52
|
|
|
35
53
|
### 运行项目
|
package/commands/create.js
CHANGED
|
@@ -120,6 +120,36 @@ const createModule = async (args) => {
|
|
|
120
120
|
await fs.writeFile(routerGoFilePath, routerGoContent);
|
|
121
121
|
console.log(chalk.green(`成功创建 ${chalk.bold('router.go')} 文件`));
|
|
122
122
|
|
|
123
|
+
// 检查并更新 domain/init.go 文件
|
|
124
|
+
const initFilePath = path.join(domainDir, 'init.go');
|
|
125
|
+
if (await fs.pathExists(initFilePath)) {
|
|
126
|
+
let initFileContent = await fs.readFile(initFilePath, 'utf-8');
|
|
127
|
+
|
|
128
|
+
const importStatement = `import _ "${projectName}/domain/${moduleName}/api"`;
|
|
129
|
+
|
|
130
|
+
if (!initFileContent.includes(importStatement)) {
|
|
131
|
+
const initFuncIndex = initFileContent.indexOf('func init()');
|
|
132
|
+
|
|
133
|
+
if (initFuncIndex !== -1) {
|
|
134
|
+
// 找到 init 函数,确保在 init 函数上方添加 import 语句
|
|
135
|
+
const insertPosition = initFuncIndex;
|
|
136
|
+
initFileContent =
|
|
137
|
+
initFileContent.slice(0, insertPosition) +
|
|
138
|
+
`${importStatement}\n\n` +
|
|
139
|
+
initFileContent.slice(insertPosition);
|
|
140
|
+
|
|
141
|
+
await fs.writeFile(initFilePath, initFileContent);
|
|
142
|
+
console.log(chalk.green(`成功更新 ${chalk.bold('init.go')} 文件,添加 import 语句`));
|
|
143
|
+
} else {
|
|
144
|
+
console.log(chalk.yellow(`未找到 init() 函数,跳过 import 语句添加`));
|
|
145
|
+
}
|
|
146
|
+
} else {
|
|
147
|
+
console.log(chalk.yellow(`init.go 文件中已存在相应的 import 语句,无需重复添加`));
|
|
148
|
+
}
|
|
149
|
+
} else {
|
|
150
|
+
console.log(chalk.yellow(`未找到 ${chalk.bold('init.go')} 文件,跳过 import 语句添加`));
|
|
151
|
+
}
|
|
152
|
+
|
|
123
153
|
console.log(chalk.blue(`\n模块 ${chalk.bold(moduleName)} 已成功创建在 ${chalk.bold(`domain/${moduleName}`)} 目录下`));
|
|
124
154
|
} catch (error) {
|
|
125
155
|
console.error(chalk.red('创建模块时出错:'), chalk.redBright(error.message));
|
package/package.json
CHANGED
package/templates/config.go.ejs
CHANGED
|
@@ -2,14 +2,14 @@ package internal
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"github.com/jom-io/gorig/domainx"
|
|
5
|
+
"github.com/jom-io/gorig/global/variable"
|
|
6
|
+
"<%= projectName %>/domain/<%= moduleName %>/api/req"
|
|
5
7
|
"<%= projectName %>/domain/<%= moduleName %>/model"
|
|
6
|
-
"<%= projectName %>/
|
|
7
|
-
"<%= projectName %>/global/constants"
|
|
8
|
-
"<%= projectName %>/global/varb"
|
|
8
|
+
"<%= projectName %>/global"
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
func <%= ModuleName %>() *<%= ModuleName %>M {
|
|
12
|
-
return &<%= ModuleName %>M{Complex: domainx.UseComplex[model.<%= ModuleName %>D](domainx.Mysql,
|
|
12
|
+
return &<%= ModuleName %>M{Complex: domainx.UseComplex[model.<%= ModuleName %>D](domainx.Mysql, global.DBDef, "<%= moduleName %>")}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
type <%= ModuleName %>M struct {
|
|
@@ -17,7 +17,7 @@ type <%= ModuleName %>M struct {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
func (u *<%= ModuleName %>M) TableName() string {
|
|
20
|
-
return
|
|
20
|
+
return variable.TBPrefix +"<%= moduleName %>"
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
func init() {
|