gorig-cli 1.0.3 → 1.0.5

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 CHANGED
@@ -24,7 +24,7 @@ gorig-cli init my-new-project
24
24
 
25
25
  ### 创建新模块
26
26
 
27
- 使用 `create` 命令创建一个新模块:
27
+ 在项目根目录下使用 `create` 命令创建一个新模块:
28
28
 
29
29
  ```sh
30
30
  gorig-cli create user
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gorig-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "type": "module",
5
5
  "description": "gorig构建工具",
6
6
  "main": "bin/cli.js",
@@ -5,9 +5,10 @@ import (
5
5
  )
6
6
 
7
7
  var (
8
- SysName = ""
8
+ DBDef = "def"
9
+ SysName = ""
9
10
  )
10
11
 
11
12
  func init() {
12
- SysName = configure.GetString("sys.name", "<%= projectNameUpper %>")
13
+ SysName = configure.GetString("sys.name", "TEST")
13
14
  }
@@ -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 %>/domain/<%= moduleName %>/api/req"
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, constants.Main, "<%= moduleName %>")}
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 varb.GetApp().TableName("<%= moduleName %>")
20
+ return variable.TBPrefix +"<%= moduleName %>"
21
21
  }
22
22
 
23
23
  func init() {