Skip to content

Commit 26402fb

Browse files
LinYuanBaoBaotaccisum
authored andcommitted
feat(scaffold): integrate egg-tx (#4)
1 parent 53083b9 commit 26402fb

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ node_modules/
77
run/
88
logs/
99
package-lock.json
10-
10+
.idea
1111
*.lcov
1212

1313
push.sh

generators/app/handler/package_json_th.js

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class PackageJsonTemplateHandler extends AbstractTemplateHandler {
3535
if (this.props.dependencies.swagger) {
3636
this._extendDependencies(pkgJson, 'egg-swagger-doc', '^2.3.1');
3737
}
38+
if (this.props.dependencies.tx) {
39+
this._extendDependencies(pkgJson, 'egg-tx', '^1.0.2');
40+
}
3841
switch (this.props.db) {
3942
case 'mongo': {
4043
this._extendDependencies(pkgJson, 'egg-mongoose', '^3.1.3');

generators/app/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const obj = {
2727
} else {
2828
return '名称不能为空';
2929
}
30-
} },
30+
}
31+
},
3132
option: { desc: '作者', type: String, default: '' }
3233
},
3334
router: {
@@ -126,7 +127,8 @@ module.exports = require('yo-power-generator').getGenerator(obj, {
126127
props.dependencies = {
127128
utils: true,
128129
eureka: true,
129-
swagger: true
130+
swagger: true,
131+
tx: (props.db !== 'none')
130132
}
131133
}
132134
});

generators/app/templates/config/config.default.tmpl.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = appInfo => {
7575
maxFileSize: 5 * 1024
7676
};
7777

78-
<%
78+
<%
7979
if (dependencies.eureka) {
8080
print(`
8181
config.eureka = {
@@ -131,6 +131,15 @@ module.exports = appInfo => {
131131
`);
132132
}
133133

134+
if (dependencies.tx) {
135+
print(`
136+
config.tx = {
137+
reqAction: ['POST','PUT','DELETE'],
138+
dbType: '${db}',
139+
};
140+
`);
141+
}
142+
134143
switch (db) {
135144
case 'mongo': {
136145
print(`
@@ -180,7 +189,7 @@ module.exports = appInfo => {
180189
break;
181190
}
182191
}
183-
%>
192+
%>
184193

185194
return {
186195
...config,

generators/app/templates/config/plugin.tmpl.js

+8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ module.exports = {
4040
swaggerdoc: {
4141
enable: true,
4242
package: 'egg-swagger-doc',
43+
},
44+
`);
45+
}
46+
if(dependencies.tx){
47+
print(`
48+
tx: {
49+
enable: true,
50+
package: 'egg-tx',
4351
},
4452
`);
4553
}

generators/test/app/index.test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,15 @@ describe('package.json content', () => {
141141

142142
it('should have dependencies', () => {
143143
assert(pkg.dependencies['egg-mongoose']);
144+
assert(pkg.dependencies['egg-tx']);
144145
})
145146

146147
it('should have config', () => {
147148
assert.fileContent([
148149
['config/config.default.js', /config.mongoose.*=/],
149-
['config/plugin.js', /mongoose.*:/]
150+
['config/plugin.js', /mongoose.*:/],
151+
['config/config.default.js', /config.tx.*=\s.*\s*.*\s*dbType:\s'mongo'/],
152+
['config/plugin.js', /tx.*:/]
150153
])
151154
})
152155
})
@@ -168,12 +171,15 @@ describe('package.json content', () => {
168171
it('should have dependencies', () => {
169172
assert(pkg.dependencies['egg-sequelize']);
170173
assert(pkg.dependencies['mysql2']);
174+
assert(pkg.dependencies['egg-tx']);
171175
})
172176

173177
it('should have config', () => {
174178
assert.fileContent([
175179
['config/config.default.js', /config.sequelize.*=/],
176-
['config/plugin.js', /sequelize.*:/]
180+
['config/plugin.js', /sequelize.*:/],
181+
['config/config.default.js', /config.tx.*=\s.*\s*.*\s*dbType:\s'mysql'/],
182+
['config/plugin.js', /tx.*:/]
177183
])
178184
})
179185
})
@@ -195,14 +201,17 @@ describe('package.json content', () => {
195201
it('should have not dependencies', () => {
196202
assert(!pkg.dependencies['egg-mongoose']);
197203
assert(!pkg.dependencies['egg-sequelize']);
204+
assert(!pkg.dependencies['egg-tx']);
198205
})
199206

200207
it('should have not config', () => {
201208
assert.noFileContent([
202209
['config/config.default.js', /config.mongoose.*=/],
203210
['config/plugin.js', /mongoose.*:/],
204211
['config/config.default.js', /config.sequelize.*=/],
205-
['config/plugin.js', /sequelize.*:/]
212+
['config/plugin.js', /sequelize.*:/],
213+
['config/config.default.js', /config.tx.*=/],
214+
['config/plugin.js', /tx.*:/]
206215
])
207216
})
208217
})

0 commit comments

Comments
 (0)