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 +1 -1
- 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
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() {
|