@modern-js/bff-generator 1.2.1 → 1.2.2
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/dist/js/node/index.js +209 -0
- package/dist/js/node/main.js +287 -246
- package/package.json +2 -2
- package/templates/function/app/ts/nest.ts.handlebars +3 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.handleTemplateFile = exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _generatorUtils = require("@modern-js/generator-utils");
|
|
11
|
+
|
|
12
|
+
var _codesmithApiApp = require("@modern-js/codesmith-api-app");
|
|
13
|
+
|
|
14
|
+
var _codesmithApiJson = require("@modern-js/codesmith-api-json");
|
|
15
|
+
|
|
16
|
+
var _generatorCommon = require("@modern-js/generator-common");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
+
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
|
|
24
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
+
|
|
26
|
+
function isEmptyApiDir(apiDir) {
|
|
27
|
+
const files = _generatorUtils.fs.readdirSync(apiDir);
|
|
28
|
+
|
|
29
|
+
if (files.length === 0) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return files.every(file => {
|
|
34
|
+
if (_generatorUtils.fs.statSync(_path.default.join(apiDir, file)).isDirectory()) {
|
|
35
|
+
const childFiles = _generatorUtils.fs.readdirSync(_path.default.join(apiDir, file));
|
|
36
|
+
|
|
37
|
+
return childFiles.length === 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return false;
|
|
41
|
+
});
|
|
42
|
+
} // eslint-disable-next-line max-statements
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const handleTemplateFile = async (context, generator, appApi) => {
|
|
46
|
+
const jsonAPI = new _codesmithApiJson.JsonAPI(generator);
|
|
47
|
+
const ans = await appApi.getInputBySchema(_generatorCommon.BFFSchema, context.config);
|
|
48
|
+
const appDir = context.materials.default.basePath;
|
|
49
|
+
|
|
50
|
+
const apiDir = _path.default.join(appDir, 'api');
|
|
51
|
+
|
|
52
|
+
if (_generatorUtils.fs.existsSync(apiDir) && !isEmptyApiDir(apiDir)) {
|
|
53
|
+
const files = _generatorUtils.fs.readdirSync(apiDir);
|
|
54
|
+
|
|
55
|
+
if (files.length > 0) {
|
|
56
|
+
generator.logger.warn("'api' is already exist");
|
|
57
|
+
throw Error("'api' is already exist");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const {
|
|
62
|
+
bffType,
|
|
63
|
+
framework
|
|
64
|
+
} = ans;
|
|
65
|
+
const language = (0, _generatorUtils.isTsProject)(appDir) ? _generatorCommon.Language.TS : _generatorCommon.Language.JS;
|
|
66
|
+
|
|
67
|
+
if (language === _generatorCommon.Language.JS && framework === _generatorCommon.Framework.Nest) {
|
|
68
|
+
generator.logger.warn('nest not support js project');
|
|
69
|
+
throw Error('nest not support js project');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let updateInfo = {};
|
|
73
|
+
|
|
74
|
+
if (framework === _generatorCommon.Framework.Express || framework === _generatorCommon.Framework.Koa) {
|
|
75
|
+
updateInfo = {
|
|
76
|
+
[`devDependencies.@types/${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(`@types/${framework}`)}`
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (framework === _generatorCommon.Framework.Nest) {
|
|
81
|
+
updateInfo = {
|
|
82
|
+
'dependencies.@nestjs/core': `^${await (0, _generatorUtils.getPackageVersion)('@nestjs/core')}`,
|
|
83
|
+
'dependencies.@nestjs/common': `^${await (0, _generatorUtils.getPackageVersion)('@nestjs/common')}`
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (bffType === _generatorCommon.BFFType.Func) {
|
|
87
|
+
updateInfo['dependencies.express'] = `^${await (0, _generatorUtils.getPackageVersion)('express')}`;
|
|
88
|
+
updateInfo['devDependencies.@types/express'] = `^${await (0, _generatorUtils.getPackageVersion)('@types/express')}`;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
updateInfo = _objectSpread(_objectSpread({}, updateInfo), {}, {
|
|
92
|
+
[`dependencies.${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(framework)}`
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'package.json')), {
|
|
97
|
+
query: {},
|
|
98
|
+
update: {
|
|
99
|
+
$set: _objectSpread({
|
|
100
|
+
'dependencies.@modern-js/plugin-bff': `^${await (0, _generatorUtils.getPackageVersion)('@modern-js/plugin-bff')}`,
|
|
101
|
+
[`dependencies.@modern-js/plugin-${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(`@modern-js/plugin-${framework}`)}`
|
|
102
|
+
}, updateInfo)
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (language === _generatorCommon.Language.TS) {
|
|
107
|
+
const tsconfigJSON = (0, _generatorUtils.readTsConfigByFile)(_path.default.join(appDir, 'tsconfig.json'));
|
|
108
|
+
|
|
109
|
+
if (!(tsconfigJSON.include || []).includes('api')) {
|
|
110
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
111
|
+
query: {},
|
|
112
|
+
update: {
|
|
113
|
+
$set: {
|
|
114
|
+
include: [...(tsconfigJSON.include || []), 'api']
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
await appApi.forgeTemplate('templates/js-template/**/*', undefined, resourceKey => resourceKey.replace('templates/js-template/', 'api/').replace('.handlebars', `.${language}`));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (bffType === _generatorCommon.BFFType.Func) {
|
|
124
|
+
if (language === _generatorCommon.Language.TS) {
|
|
125
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
126
|
+
query: {},
|
|
127
|
+
update: {
|
|
128
|
+
$set: {
|
|
129
|
+
'compilerOptions.paths.@api/*': ['./api/*']
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await appApi.forgeTemplate('templates/function/base/*', undefined, resourceKey => resourceKey.replace('templates/function/base/', 'api/').replace('.handlebars', `.${language}`));
|
|
136
|
+
await appApi.forgeTemplate(`templates/function/info/*`, resourceKey => resourceKey.includes(language), resourceKey => resourceKey.replace('templates/function/info/', 'api/info/').replace('.handlebars', ``));
|
|
137
|
+
await appApi.forgeTemplate(`templates/function/app/${language}/${framework}.${language}.handlebars`, undefined, resourceKey => resourceKey.replace(`templates/function/app/${language}/${framework}.${language}.handlebars`, `api/_app.${language}`));
|
|
138
|
+
} else {
|
|
139
|
+
if (language === _generatorCommon.Language.TS) {
|
|
140
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
141
|
+
query: {},
|
|
142
|
+
update: {
|
|
143
|
+
$set: {
|
|
144
|
+
'compilerOptions.paths.@api/*': ['./api/lambda/*']
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
await appApi.forgeTemplate(`templates/framework/lambda/*`, undefined, resourceKey => resourceKey.replace(`templates/framework/`, 'api/').replace('.handlebars', `.${language}`));
|
|
151
|
+
await appApi.forgeTemplate(`templates/framework/app/${framework}/**/*`, resourceKey => framework === _generatorCommon.Framework.Egg || framework === _generatorCommon.Framework.Koa ? resourceKey.includes(language) : true, resourceKey => resourceKey.replace(`templates/framework/app/${framework}/`, 'api/').replace('.handlebars', framework === _generatorCommon.Framework.Express ? `.${language}` : ''));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const appendTypeContent = _generatorCommon.FrameworkAppendTypeContent[framework];
|
|
155
|
+
|
|
156
|
+
if (appendTypeContent) {
|
|
157
|
+
const typePath = _path.default.join(appDir, 'src', 'modern-app-env.d.ts');
|
|
158
|
+
|
|
159
|
+
if (_generatorUtils.fs.existsSync(typePath)) {
|
|
160
|
+
const npmrc = _generatorUtils.fs.readFileSync(typePath, 'utf-8');
|
|
161
|
+
|
|
162
|
+
if (!npmrc.includes(appendTypeContent)) {
|
|
163
|
+
_generatorUtils.fs.writeFileSync(typePath, `${npmrc}${appendTypeContent}\n`, 'utf-8');
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
_generatorUtils.fs.ensureFileSync(typePath);
|
|
167
|
+
|
|
168
|
+
_generatorUtils.fs.writeFileSync(typePath, appendTypeContent, 'utf-8');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
exports.handleTemplateFile = handleTemplateFile;
|
|
174
|
+
|
|
175
|
+
var _default = async (context, generator) => {
|
|
176
|
+
const appApi = new _codesmithApiApp.AppAPI(context, generator);
|
|
177
|
+
const {
|
|
178
|
+
locale
|
|
179
|
+
} = context.config;
|
|
180
|
+
|
|
181
|
+
_generatorCommon.i18n.changeLanguage({
|
|
182
|
+
locale
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
appApi.i18n.changeLanguage({
|
|
186
|
+
locale
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
if (!(await appApi.checkEnvironment())) {
|
|
190
|
+
// eslint-disable-next-line no-process-exit
|
|
191
|
+
process.exit(1);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
generator.logger.debug(`start run @modern-js/bff-generator`);
|
|
195
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
196
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
await handleTemplateFile(context, generator, appApi);
|
|
200
|
+
} catch (e) {
|
|
201
|
+
// eslint-disable-next-line no-process-exit
|
|
202
|
+
process.exit(1);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
await appApi.runInstall();
|
|
206
|
+
generator.logger.debug(`forge @modern-js/bff-generator succeed `);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
exports.default = _default;
|
package/dist/js/node/main.js
CHANGED
|
@@ -466,7 +466,7 @@ Object.defineProperty(exports, "I18n", ({
|
|
|
466
466
|
}));
|
|
467
467
|
exports.localeKeys = exports.i18n = void 0;
|
|
468
468
|
|
|
469
|
-
var _pluginI18n = __webpack_require__(
|
|
469
|
+
var _pluginI18n = __webpack_require__(54207);
|
|
470
470
|
|
|
471
471
|
var _zh = __webpack_require__(57724);
|
|
472
472
|
|
|
@@ -5689,7 +5689,7 @@ exports.pointer = pointer;
|
|
|
5689
5689
|
|
|
5690
5690
|
/***/ }),
|
|
5691
5691
|
|
|
5692
|
-
/***/
|
|
5692
|
+
/***/ 54207:
|
|
5693
5693
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
5694
5694
|
|
|
5695
5695
|
"use strict";
|
|
@@ -5702,7 +5702,7 @@ exports.I18n = void 0;
|
|
|
5702
5702
|
|
|
5703
5703
|
var _get2 = _interopRequireDefault(__webpack_require__(71189));
|
|
5704
5704
|
|
|
5705
|
-
var _utils = __webpack_require__(
|
|
5705
|
+
var _utils = __webpack_require__(41083);
|
|
5706
5706
|
|
|
5707
5707
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
5708
5708
|
|
|
@@ -5771,7 +5771,7 @@ exports.I18n = I18n;
|
|
|
5771
5771
|
|
|
5772
5772
|
/***/ }),
|
|
5773
5773
|
|
|
5774
|
-
/***/
|
|
5774
|
+
/***/ 41083:
|
|
5775
5775
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
5776
5776
|
|
|
5777
5777
|
"use strict";
|
|
@@ -269421,7 +269421,7 @@ const SubSolutionSchema = {
|
|
|
269421
269421
|
}));
|
|
269422
269422
|
|
|
269423
269423
|
if (data.solution && data.solution !== 'custom') {
|
|
269424
|
-
items.
|
|
269424
|
+
items.unshift({
|
|
269425
269425
|
key: data.solution,
|
|
269426
269426
|
label: `${SubSolutionText[data.solution]()}(${_locale.i18n.t(_locale.localeKeys.solution.default)})`
|
|
269427
269427
|
});
|
|
@@ -269870,7 +269870,7 @@ const ZH_LOCALE = {
|
|
|
269870
269870
|
runtime_api: '启用「Rumtime API」',
|
|
269871
269871
|
mwa_storybook: '启用「Visual Testing (Storybook)」模式',
|
|
269872
269872
|
ssg: '启用「SSG」功能',
|
|
269873
|
-
polyfill: '
|
|
269873
|
+
polyfill: '启用「基于 UA 的 Polyfill」功能',
|
|
269874
269874
|
deploy: '启用「部署」功能'
|
|
269875
269875
|
},
|
|
269876
269876
|
element: {
|
|
@@ -270965,7 +270965,7 @@ const MWAActionFunctionsDependencies = {
|
|
|
270965
270965
|
[_common.ActionFunction.Less]: '@modern-js/plugin-less',
|
|
270966
270966
|
[_common.ActionFunction.Sass]: '@modern-js/plugin-sass',
|
|
270967
270967
|
[_common.ActionFunction.BFF]: '@modern-js/plugin-bff',
|
|
270968
|
-
[_common.ActionFunction.MicroFrontend]: '@modern-js/plugin-
|
|
270968
|
+
[_common.ActionFunction.MicroFrontend]: '@modern-js/plugin-garfish',
|
|
270969
270969
|
[_common.ActionFunction.I18n]: '@modern-js/plugin-i18n',
|
|
270970
270970
|
[_common.ActionFunction.SSG]: '@modern-js/plugin-ssg',
|
|
270971
270971
|
[_common.ActionFunction.Polyfill]: '@modern-js/plugin-polyfill'
|
|
@@ -270973,7 +270973,7 @@ const MWAActionFunctionsDependencies = {
|
|
|
270973
270973
|
exports.MWAActionFunctionsDependencies = MWAActionFunctionsDependencies;
|
|
270974
270974
|
const MWAActionFunctionsAppendTypeContent = {
|
|
270975
270975
|
[_common.ActionFunction.Test]: `/// <reference types='@modern-js/plugin-testing/type' />`,
|
|
270976
|
-
[_common.ActionFunction.MicroFrontend]: `/// <reference types='@modern-js/plugin-
|
|
270976
|
+
[_common.ActionFunction.MicroFrontend]: `/// <reference types='@modern-js/plugin-garfish/type' />`
|
|
270977
270977
|
};
|
|
270978
270978
|
exports.MWAActionFunctionsAppendTypeContent = MWAActionFunctionsAppendTypeContent;
|
|
270979
270979
|
const MWANewActionGenerators = {
|
|
@@ -271371,6 +271371,222 @@ function stripAnsi(string) {
|
|
|
271371
271371
|
|
|
271372
271372
|
/***/ }),
|
|
271373
271373
|
|
|
271374
|
+
/***/ 34701:
|
|
271375
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
271376
|
+
|
|
271377
|
+
"use strict";
|
|
271378
|
+
|
|
271379
|
+
|
|
271380
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
271381
|
+
value: true
|
|
271382
|
+
}));
|
|
271383
|
+
exports.handleTemplateFile = exports["default"] = void 0;
|
|
271384
|
+
|
|
271385
|
+
var _path = _interopRequireDefault(__webpack_require__(71017));
|
|
271386
|
+
|
|
271387
|
+
var _generatorUtils = __webpack_require__(89489);
|
|
271388
|
+
|
|
271389
|
+
var _codesmithApiApp = __webpack_require__(83028);
|
|
271390
|
+
|
|
271391
|
+
var _codesmithApiJson = __webpack_require__(54517);
|
|
271392
|
+
|
|
271393
|
+
var _generatorCommon = __webpack_require__(50828);
|
|
271394
|
+
|
|
271395
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
271396
|
+
|
|
271397
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
271398
|
+
|
|
271399
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
271400
|
+
|
|
271401
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
271402
|
+
|
|
271403
|
+
function isEmptyApiDir(apiDir) {
|
|
271404
|
+
const files = _generatorUtils.fs.readdirSync(apiDir);
|
|
271405
|
+
|
|
271406
|
+
if (files.length === 0) {
|
|
271407
|
+
return true;
|
|
271408
|
+
}
|
|
271409
|
+
|
|
271410
|
+
return files.every(file => {
|
|
271411
|
+
if (_generatorUtils.fs.statSync(_path.default.join(apiDir, file)).isDirectory()) {
|
|
271412
|
+
const childFiles = _generatorUtils.fs.readdirSync(_path.default.join(apiDir, file));
|
|
271413
|
+
|
|
271414
|
+
return childFiles.length === 0;
|
|
271415
|
+
}
|
|
271416
|
+
|
|
271417
|
+
return false;
|
|
271418
|
+
});
|
|
271419
|
+
} // eslint-disable-next-line max-statements
|
|
271420
|
+
|
|
271421
|
+
|
|
271422
|
+
const handleTemplateFile = async (context, generator, appApi) => {
|
|
271423
|
+
const jsonAPI = new _codesmithApiJson.JsonAPI(generator);
|
|
271424
|
+
const ans = await appApi.getInputBySchema(_generatorCommon.BFFSchema, context.config);
|
|
271425
|
+
const appDir = context.materials.default.basePath;
|
|
271426
|
+
|
|
271427
|
+
const apiDir = _path.default.join(appDir, 'api');
|
|
271428
|
+
|
|
271429
|
+
if (_generatorUtils.fs.existsSync(apiDir) && !isEmptyApiDir(apiDir)) {
|
|
271430
|
+
const files = _generatorUtils.fs.readdirSync(apiDir);
|
|
271431
|
+
|
|
271432
|
+
if (files.length > 0) {
|
|
271433
|
+
generator.logger.warn("'api' is already exist");
|
|
271434
|
+
throw Error("'api' is already exist");
|
|
271435
|
+
}
|
|
271436
|
+
}
|
|
271437
|
+
|
|
271438
|
+
const {
|
|
271439
|
+
bffType,
|
|
271440
|
+
framework
|
|
271441
|
+
} = ans;
|
|
271442
|
+
const language = (0, _generatorUtils.isTsProject)(appDir) ? _generatorCommon.Language.TS : _generatorCommon.Language.JS;
|
|
271443
|
+
|
|
271444
|
+
if (language === _generatorCommon.Language.JS && framework === _generatorCommon.Framework.Nest) {
|
|
271445
|
+
generator.logger.warn('nest not support js project');
|
|
271446
|
+
throw Error('nest not support js project');
|
|
271447
|
+
}
|
|
271448
|
+
|
|
271449
|
+
let updateInfo = {};
|
|
271450
|
+
|
|
271451
|
+
if (framework === _generatorCommon.Framework.Express || framework === _generatorCommon.Framework.Koa) {
|
|
271452
|
+
updateInfo = {
|
|
271453
|
+
[`devDependencies.@types/${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(`@types/${framework}`)}`
|
|
271454
|
+
};
|
|
271455
|
+
}
|
|
271456
|
+
|
|
271457
|
+
if (framework === _generatorCommon.Framework.Nest) {
|
|
271458
|
+
updateInfo = {
|
|
271459
|
+
'dependencies.@nestjs/core': `^${await (0, _generatorUtils.getPackageVersion)('@nestjs/core')}`,
|
|
271460
|
+
'dependencies.@nestjs/common': `^${await (0, _generatorUtils.getPackageVersion)('@nestjs/common')}`
|
|
271461
|
+
};
|
|
271462
|
+
|
|
271463
|
+
if (bffType === _generatorCommon.BFFType.Func) {
|
|
271464
|
+
updateInfo['dependencies.express'] = `^${await (0, _generatorUtils.getPackageVersion)('express')}`;
|
|
271465
|
+
updateInfo['devDependencies.@types/express'] = `^${await (0, _generatorUtils.getPackageVersion)('@types/express')}`;
|
|
271466
|
+
}
|
|
271467
|
+
} else {
|
|
271468
|
+
updateInfo = _objectSpread(_objectSpread({}, updateInfo), {}, {
|
|
271469
|
+
[`dependencies.${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(framework)}`
|
|
271470
|
+
});
|
|
271471
|
+
}
|
|
271472
|
+
|
|
271473
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'package.json')), {
|
|
271474
|
+
query: {},
|
|
271475
|
+
update: {
|
|
271476
|
+
$set: _objectSpread({
|
|
271477
|
+
'dependencies.@modern-js/plugin-bff': `^${await (0, _generatorUtils.getPackageVersion)('@modern-js/plugin-bff')}`,
|
|
271478
|
+
[`dependencies.@modern-js/plugin-${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(`@modern-js/plugin-${framework}`)}`
|
|
271479
|
+
}, updateInfo)
|
|
271480
|
+
}
|
|
271481
|
+
});
|
|
271482
|
+
|
|
271483
|
+
if (language === _generatorCommon.Language.TS) {
|
|
271484
|
+
const tsconfigJSON = (0, _generatorUtils.readTsConfigByFile)(_path.default.join(appDir, 'tsconfig.json'));
|
|
271485
|
+
|
|
271486
|
+
if (!(tsconfigJSON.include || []).includes('api')) {
|
|
271487
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
271488
|
+
query: {},
|
|
271489
|
+
update: {
|
|
271490
|
+
$set: {
|
|
271491
|
+
include: [...(tsconfigJSON.include || []), 'api']
|
|
271492
|
+
}
|
|
271493
|
+
}
|
|
271494
|
+
});
|
|
271495
|
+
}
|
|
271496
|
+
} else {
|
|
271497
|
+
await appApi.forgeTemplate('templates/js-template/**/*', undefined, resourceKey => resourceKey.replace('templates/js-template/', 'api/').replace('.handlebars', `.${language}`));
|
|
271498
|
+
}
|
|
271499
|
+
|
|
271500
|
+
if (bffType === _generatorCommon.BFFType.Func) {
|
|
271501
|
+
if (language === _generatorCommon.Language.TS) {
|
|
271502
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
271503
|
+
query: {},
|
|
271504
|
+
update: {
|
|
271505
|
+
$set: {
|
|
271506
|
+
'compilerOptions.paths.@api/*': ['./api/*']
|
|
271507
|
+
}
|
|
271508
|
+
}
|
|
271509
|
+
});
|
|
271510
|
+
}
|
|
271511
|
+
|
|
271512
|
+
await appApi.forgeTemplate('templates/function/base/*', undefined, resourceKey => resourceKey.replace('templates/function/base/', 'api/').replace('.handlebars', `.${language}`));
|
|
271513
|
+
await appApi.forgeTemplate(`templates/function/info/*`, resourceKey => resourceKey.includes(language), resourceKey => resourceKey.replace('templates/function/info/', 'api/info/').replace('.handlebars', ``));
|
|
271514
|
+
await appApi.forgeTemplate(`templates/function/app/${language}/${framework}.${language}.handlebars`, undefined, resourceKey => resourceKey.replace(`templates/function/app/${language}/${framework}.${language}.handlebars`, `api/_app.${language}`));
|
|
271515
|
+
} else {
|
|
271516
|
+
if (language === _generatorCommon.Language.TS) {
|
|
271517
|
+
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
271518
|
+
query: {},
|
|
271519
|
+
update: {
|
|
271520
|
+
$set: {
|
|
271521
|
+
'compilerOptions.paths.@api/*': ['./api/lambda/*']
|
|
271522
|
+
}
|
|
271523
|
+
}
|
|
271524
|
+
});
|
|
271525
|
+
}
|
|
271526
|
+
|
|
271527
|
+
await appApi.forgeTemplate(`templates/framework/lambda/*`, undefined, resourceKey => resourceKey.replace(`templates/framework/`, 'api/').replace('.handlebars', `.${language}`));
|
|
271528
|
+
await appApi.forgeTemplate(`templates/framework/app/${framework}/**/*`, resourceKey => framework === _generatorCommon.Framework.Egg || framework === _generatorCommon.Framework.Koa ? resourceKey.includes(language) : true, resourceKey => resourceKey.replace(`templates/framework/app/${framework}/`, 'api/').replace('.handlebars', framework === _generatorCommon.Framework.Express ? `.${language}` : ''));
|
|
271529
|
+
}
|
|
271530
|
+
|
|
271531
|
+
const appendTypeContent = _generatorCommon.FrameworkAppendTypeContent[framework];
|
|
271532
|
+
|
|
271533
|
+
if (appendTypeContent) {
|
|
271534
|
+
const typePath = _path.default.join(appDir, 'src', 'modern-app-env.d.ts');
|
|
271535
|
+
|
|
271536
|
+
if (_generatorUtils.fs.existsSync(typePath)) {
|
|
271537
|
+
const npmrc = _generatorUtils.fs.readFileSync(typePath, 'utf-8');
|
|
271538
|
+
|
|
271539
|
+
if (!npmrc.includes(appendTypeContent)) {
|
|
271540
|
+
_generatorUtils.fs.writeFileSync(typePath, `${npmrc}${appendTypeContent}\n`, 'utf-8');
|
|
271541
|
+
}
|
|
271542
|
+
} else {
|
|
271543
|
+
_generatorUtils.fs.ensureFileSync(typePath);
|
|
271544
|
+
|
|
271545
|
+
_generatorUtils.fs.writeFileSync(typePath, appendTypeContent, 'utf-8');
|
|
271546
|
+
}
|
|
271547
|
+
}
|
|
271548
|
+
};
|
|
271549
|
+
|
|
271550
|
+
exports.handleTemplateFile = handleTemplateFile;
|
|
271551
|
+
|
|
271552
|
+
var _default = async (context, generator) => {
|
|
271553
|
+
const appApi = new _codesmithApiApp.AppAPI(context, generator);
|
|
271554
|
+
const {
|
|
271555
|
+
locale
|
|
271556
|
+
} = context.config;
|
|
271557
|
+
|
|
271558
|
+
_generatorCommon.i18n.changeLanguage({
|
|
271559
|
+
locale
|
|
271560
|
+
});
|
|
271561
|
+
|
|
271562
|
+
appApi.i18n.changeLanguage({
|
|
271563
|
+
locale
|
|
271564
|
+
});
|
|
271565
|
+
|
|
271566
|
+
if (!(await appApi.checkEnvironment())) {
|
|
271567
|
+
// eslint-disable-next-line no-process-exit
|
|
271568
|
+
process.exit(1);
|
|
271569
|
+
}
|
|
271570
|
+
|
|
271571
|
+
generator.logger.debug(`start run @modern-js/bff-generator`);
|
|
271572
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
271573
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
271574
|
+
|
|
271575
|
+
try {
|
|
271576
|
+
await handleTemplateFile(context, generator, appApi);
|
|
271577
|
+
} catch (e) {
|
|
271578
|
+
// eslint-disable-next-line no-process-exit
|
|
271579
|
+
process.exit(1);
|
|
271580
|
+
}
|
|
271581
|
+
|
|
271582
|
+
await appApi.runInstall();
|
|
271583
|
+
generator.logger.debug(`forge @modern-js/bff-generator succeed `);
|
|
271584
|
+
};
|
|
271585
|
+
|
|
271586
|
+
exports["default"] = _default;
|
|
271587
|
+
|
|
271588
|
+
/***/ }),
|
|
271589
|
+
|
|
271374
271590
|
/***/ 13076:
|
|
271375
271591
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
271376
271592
|
|
|
@@ -271735,7 +271951,7 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
271735
271951
|
exports.clearConsole = void 0;
|
|
271736
271952
|
|
|
271737
271953
|
const clearConsole = () => {
|
|
271738
|
-
if (process.stdout.isTTY) {
|
|
271954
|
+
if (process.stdout.isTTY && !process.env.DEBUG) {
|
|
271739
271955
|
process.stdout.write('\x1B[H\x1B[2J');
|
|
271740
271956
|
}
|
|
271741
271957
|
};
|
|
@@ -271745,7 +271961,7 @@ exports.clearConsole = clearConsole;
|
|
|
271745
271961
|
/***/ }),
|
|
271746
271962
|
|
|
271747
271963
|
/***/ 4002:
|
|
271748
|
-
/***/ ((
|
|
271964
|
+
/***/ ((module, exports, __webpack_require__) => {
|
|
271749
271965
|
|
|
271750
271966
|
"use strict";
|
|
271751
271967
|
|
|
@@ -271753,7 +271969,7 @@ exports.clearConsole = clearConsole;
|
|
|
271753
271969
|
Object.defineProperty(exports, "__esModule", ({
|
|
271754
271970
|
value: true
|
|
271755
271971
|
}));
|
|
271756
|
-
exports.requireExistModule = exports.compatRequire = void 0;
|
|
271972
|
+
exports.requireExistModule = exports.compatRequire = exports.cleanRequireCache = void 0;
|
|
271757
271973
|
|
|
271758
271974
|
var _findExists = __webpack_require__(3664);
|
|
271759
271975
|
|
|
@@ -271782,6 +271998,14 @@ const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
|
|
|
271782
271998
|
|
|
271783
271999
|
exports.requireExistModule = requireExistModule;
|
|
271784
272000
|
|
|
272001
|
+
const cleanRequireCache = filelist => {
|
|
272002
|
+
filelist.forEach(filepath => {
|
|
272003
|
+
delete __webpack_require__.c[filepath];
|
|
272004
|
+
});
|
|
272005
|
+
};
|
|
272006
|
+
|
|
272007
|
+
exports.cleanRequireCache = cleanRequireCache;
|
|
272008
|
+
|
|
271785
272009
|
/***/ }),
|
|
271786
272010
|
|
|
271787
272011
|
/***/ 36762:
|
|
@@ -271793,23 +272017,11 @@ exports.requireExistModule = requireExistModule;
|
|
|
271793
272017
|
Object.defineProperty(exports, "__esModule", ({
|
|
271794
272018
|
value: true
|
|
271795
272019
|
}));
|
|
271796
|
-
exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.
|
|
272020
|
+
exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_PLUGINS = exports.HMR_SOCK_PATH = exports.ENTRY_NAME_PATTERN = exports.API_DIR = void 0;
|
|
271797
272021
|
|
|
271798
|
-
/**
|
|
271799
|
-
* alias to src directory
|
|
271800
|
-
*/
|
|
271801
|
-
const INTERNAL_SRC_ALIAS = '@_modern_js_src';
|
|
271802
|
-
/**
|
|
271803
|
-
* alias to node_modules/.modern-js
|
|
271804
|
-
*/
|
|
271805
|
-
|
|
271806
|
-
exports.INTERNAL_SRC_ALIAS = INTERNAL_SRC_ALIAS;
|
|
271807
|
-
const INTERNAL_DIR_ALAIS = '@_modern_js_internal';
|
|
271808
272022
|
/**
|
|
271809
272023
|
* hmr socket connect path
|
|
271810
272024
|
*/
|
|
271811
|
-
|
|
271812
|
-
exports.INTERNAL_DIR_ALAIS = INTERNAL_DIR_ALAIS;
|
|
271813
272025
|
const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
|
271814
272026
|
/**
|
|
271815
272027
|
* route specification file
|
|
@@ -271853,17 +272065,11 @@ const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
|
271853
272065
|
|
|
271854
272066
|
exports.SERVER_RENDER_FUNCTION_NAME = SERVER_RENDER_FUNCTION_NAME;
|
|
271855
272067
|
const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
|
271856
|
-
/**
|
|
271857
|
-
* real entry generate by modern.js
|
|
271858
|
-
*/
|
|
271859
|
-
|
|
271860
|
-
exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
|
|
271861
|
-
const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
|
271862
272068
|
/**
|
|
271863
272069
|
* internal specified folder
|
|
271864
272070
|
*/
|
|
271865
272071
|
|
|
271866
|
-
exports.
|
|
272072
|
+
exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
|
|
271867
272073
|
const API_DIR = 'api';
|
|
271868
272074
|
exports.API_DIR = API_DIR;
|
|
271869
272075
|
const SERVER_DIR = 'server';
|
|
@@ -271944,8 +272150,8 @@ const INTERNAL_PLUGINS = {
|
|
|
271944
272150
|
cli: '@modern-js/plugin-server/cli',
|
|
271945
272151
|
server: '@modern-js/plugin-server/server'
|
|
271946
272152
|
},
|
|
271947
|
-
'@modern-js/plugin-
|
|
271948
|
-
cli: '@modern-js/plugin-
|
|
272153
|
+
'@modern-js/plugin-garfish': {
|
|
272154
|
+
cli: '@modern-js/plugin-garfish/cli'
|
|
271949
272155
|
},
|
|
271950
272156
|
'@modern-js/plugin-jarvis': {
|
|
271951
272157
|
cli: '@modern-js/plugin-jarvis/cli'
|
|
@@ -272113,7 +272319,7 @@ const PLUGIN_SCHEMAS = {
|
|
|
272113
272319
|
typeof: ['object', 'function']
|
|
272114
272320
|
}
|
|
272115
272321
|
}],
|
|
272116
|
-
'@modern-js/plugin-
|
|
272322
|
+
'@modern-js/plugin-garfish': [{
|
|
272117
272323
|
target: 'runtime.masterApp',
|
|
272118
272324
|
schema: {
|
|
272119
272325
|
type: ['object']
|
|
@@ -273093,6 +273299,20 @@ Object.keys(_nodeEnv).forEach(function (key) {
|
|
|
273093
273299
|
});
|
|
273094
273300
|
});
|
|
273095
273301
|
|
|
273302
|
+
var _wait = __webpack_require__(96649);
|
|
273303
|
+
|
|
273304
|
+
Object.keys(_wait).forEach(function (key) {
|
|
273305
|
+
if (key === "default" || key === "__esModule") return;
|
|
273306
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
273307
|
+
if (key in exports && exports[key] === _wait[key]) return;
|
|
273308
|
+
Object.defineProperty(exports, key, {
|
|
273309
|
+
enumerable: true,
|
|
273310
|
+
get: function () {
|
|
273311
|
+
return _wait[key];
|
|
273312
|
+
}
|
|
273313
|
+
});
|
|
273314
|
+
});
|
|
273315
|
+
|
|
273096
273316
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
273097
273317
|
|
|
273098
273318
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -273835,13 +274055,14 @@ const prettyInstructions = (appContext, config) => {
|
|
|
273835
274055
|
const {
|
|
273836
274056
|
entrypoints,
|
|
273837
274057
|
serverRoutes,
|
|
273838
|
-
port
|
|
274058
|
+
port,
|
|
274059
|
+
existSrc
|
|
273839
274060
|
} = appContext;
|
|
273840
274061
|
const urls = getAddressUrls(config.dev.https && (0, _is.isDev)() ? 'https' : 'http', port);
|
|
273841
|
-
const routes = serverRoutes.filter(route => route.entryName);
|
|
274062
|
+
const routes = existSrc ? serverRoutes.filter(route => route.entryName) : serverRoutes;
|
|
273842
274063
|
let message = 'App running at:\n\n';
|
|
273843
274064
|
|
|
273844
|
-
if (isSingleEntry(entrypoints)) {
|
|
274065
|
+
if (isSingleEntry(entrypoints) || !existSrc) {
|
|
273845
274066
|
message += urls.map(({
|
|
273846
274067
|
type,
|
|
273847
274068
|
url
|
|
@@ -274065,6 +274286,25 @@ exports.createRuntimeExportsUtils = createRuntimeExportsUtils;
|
|
|
274065
274286
|
|
|
274066
274287
|
/***/ }),
|
|
274067
274288
|
|
|
274289
|
+
/***/ 96649:
|
|
274290
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
274291
|
+
|
|
274292
|
+
"use strict";
|
|
274293
|
+
|
|
274294
|
+
|
|
274295
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
274296
|
+
value: true
|
|
274297
|
+
}));
|
|
274298
|
+
exports.wait = void 0;
|
|
274299
|
+
|
|
274300
|
+
const wait = (time = 0) => new Promise(resolve => {
|
|
274301
|
+
setTimeout(resolve, time);
|
|
274302
|
+
});
|
|
274303
|
+
|
|
274304
|
+
exports.wait = wait;
|
|
274305
|
+
|
|
274306
|
+
/***/ }),
|
|
274307
|
+
|
|
274068
274308
|
/***/ 31116:
|
|
274069
274309
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
274070
274310
|
|
|
@@ -281096,6 +281336,9 @@ module.exports = JSON.parse('{"v0.8":{"start":"2012-06-25","end":"2014-07-31"},"
|
|
|
281096
281336
|
/******/ return module.exports;
|
|
281097
281337
|
/******/ }
|
|
281098
281338
|
/******/
|
|
281339
|
+
/******/ // expose the module cache
|
|
281340
|
+
/******/ __webpack_require__.c = __webpack_module_cache__;
|
|
281341
|
+
/******/
|
|
281099
281342
|
/************************************************************************/
|
|
281100
281343
|
/******/ /* webpack/runtime/define property getters */
|
|
281101
281344
|
/******/ (() => {
|
|
@@ -281135,214 +281378,12 @@ module.exports = JSON.parse('{"v0.8":{"start":"2012-06-25","end":"2014-07-31"},"
|
|
|
281135
281378
|
/******/ })();
|
|
281136
281379
|
/******/
|
|
281137
281380
|
/************************************************************************/
|
|
281138
|
-
|
|
281139
|
-
//
|
|
281140
|
-
|
|
281141
|
-
|
|
281142
|
-
var
|
|
281143
|
-
|
|
281144
|
-
|
|
281145
|
-
Object.defineProperty(exports, "__esModule", ({
|
|
281146
|
-
value: true
|
|
281147
|
-
}));
|
|
281148
|
-
exports["default"] = void 0;
|
|
281149
|
-
|
|
281150
|
-
var _path = _interopRequireDefault(__webpack_require__(71017));
|
|
281151
|
-
|
|
281152
|
-
var _generatorUtils = __webpack_require__(89489);
|
|
281153
|
-
|
|
281154
|
-
var _codesmithApiApp = __webpack_require__(83028);
|
|
281155
|
-
|
|
281156
|
-
var _codesmithApiJson = __webpack_require__(54517);
|
|
281157
|
-
|
|
281158
|
-
var _generatorCommon = __webpack_require__(50828);
|
|
281159
|
-
|
|
281160
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
281161
|
-
|
|
281162
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
281163
|
-
|
|
281164
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
281165
|
-
|
|
281166
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
281167
|
-
|
|
281168
|
-
function isEmptyApiDir(apiDir) {
|
|
281169
|
-
const files = _generatorUtils.fs.readdirSync(apiDir);
|
|
281170
|
-
|
|
281171
|
-
if (files.length === 0) {
|
|
281172
|
-
return true;
|
|
281173
|
-
}
|
|
281174
|
-
|
|
281175
|
-
return files.every(file => {
|
|
281176
|
-
if (_generatorUtils.fs.statSync(_path.default.join(apiDir, file)).isDirectory()) {
|
|
281177
|
-
const childFiles = _generatorUtils.fs.readdirSync(_path.default.join(apiDir, file));
|
|
281178
|
-
|
|
281179
|
-
return childFiles.length === 0;
|
|
281180
|
-
}
|
|
281181
|
-
|
|
281182
|
-
return false;
|
|
281183
|
-
});
|
|
281184
|
-
} // eslint-disable-next-line max-statements
|
|
281185
|
-
|
|
281186
|
-
|
|
281187
|
-
const handleTemplateFile = async (context, generator, appApi) => {
|
|
281188
|
-
const jsonAPI = new _codesmithApiJson.JsonAPI(generator);
|
|
281189
|
-
const ans = await appApi.getInputBySchema(_generatorCommon.BFFSchema, context.config);
|
|
281190
|
-
const appDir = context.materials.default.basePath;
|
|
281191
|
-
|
|
281192
|
-
const apiDir = _path.default.join(appDir, 'api');
|
|
281193
|
-
|
|
281194
|
-
if (_generatorUtils.fs.existsSync(apiDir) && !isEmptyApiDir(apiDir)) {
|
|
281195
|
-
const files = _generatorUtils.fs.readdirSync('api');
|
|
281196
|
-
|
|
281197
|
-
if (files.length > 0) {
|
|
281198
|
-
generator.logger.warn("'api' is already exist"); // eslint-disable-next-line no-process-exit
|
|
281199
|
-
|
|
281200
|
-
process.exit(1);
|
|
281201
|
-
}
|
|
281202
|
-
}
|
|
281203
|
-
|
|
281204
|
-
const {
|
|
281205
|
-
bffType,
|
|
281206
|
-
framework
|
|
281207
|
-
} = ans;
|
|
281208
|
-
const language = (0, _generatorUtils.isTsProject)(appDir) ? _generatorCommon.Language.TS : _generatorCommon.Language.JS;
|
|
281209
|
-
|
|
281210
|
-
if (language === _generatorCommon.Language.JS && framework === _generatorCommon.Framework.Nest) {
|
|
281211
|
-
generator.logger.warn('nest not support js project'); // eslint-disable-next-line no-process-exit
|
|
281212
|
-
|
|
281213
|
-
process.exit(1);
|
|
281214
|
-
}
|
|
281215
|
-
|
|
281216
|
-
let updateInfo = {};
|
|
281217
|
-
|
|
281218
|
-
if (framework === _generatorCommon.Framework.Express || framework === _generatorCommon.Framework.Koa) {
|
|
281219
|
-
updateInfo = {
|
|
281220
|
-
[`devDependencies.@types/${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(`@types/${framework}`)}`
|
|
281221
|
-
};
|
|
281222
|
-
}
|
|
281223
|
-
|
|
281224
|
-
if (framework === _generatorCommon.Framework.Nest) {
|
|
281225
|
-
updateInfo = {
|
|
281226
|
-
'dependencies.@nestjs/core': `^${await (0, _generatorUtils.getPackageVersion)('@nestjs/core')}`,
|
|
281227
|
-
'dependencies.@nestjs/common': `^${await (0, _generatorUtils.getPackageVersion)('@nestjs/common')}`
|
|
281228
|
-
};
|
|
281229
|
-
|
|
281230
|
-
if (bffType === _generatorCommon.BFFType.Func) {
|
|
281231
|
-
updateInfo['dependencies.express'] = `^${await (0, _generatorUtils.getPackageVersion)('express')}`;
|
|
281232
|
-
}
|
|
281233
|
-
} else {
|
|
281234
|
-
updateInfo = _objectSpread(_objectSpread({}, updateInfo), {}, {
|
|
281235
|
-
[`dependencies.${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(framework)}`
|
|
281236
|
-
});
|
|
281237
|
-
}
|
|
281238
|
-
|
|
281239
|
-
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'package.json')), {
|
|
281240
|
-
query: {},
|
|
281241
|
-
update: {
|
|
281242
|
-
$set: _objectSpread({
|
|
281243
|
-
'dependencies.@modern-js/plugin-bff': `^${await (0, _generatorUtils.getPackageVersion)('@modern-js/plugin-bff')}`,
|
|
281244
|
-
[`dependencies.@modern-js/plugin-${framework}`]: `^${await (0, _generatorUtils.getPackageVersion)(`@modern-js/plugin-${framework}`)}`
|
|
281245
|
-
}, updateInfo)
|
|
281246
|
-
}
|
|
281247
|
-
});
|
|
281248
|
-
|
|
281249
|
-
if (language === _generatorCommon.Language.TS) {
|
|
281250
|
-
const tsconfigJSON = (0, _generatorUtils.readTsConfigByFile)(_path.default.join(appDir, 'tsconfig.json'));
|
|
281251
|
-
|
|
281252
|
-
if (!(tsconfigJSON.include || []).includes('api')) {
|
|
281253
|
-
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
281254
|
-
query: {},
|
|
281255
|
-
update: {
|
|
281256
|
-
$set: {
|
|
281257
|
-
include: [...(tsconfigJSON.include || []), 'api']
|
|
281258
|
-
}
|
|
281259
|
-
}
|
|
281260
|
-
});
|
|
281261
|
-
}
|
|
281262
|
-
} else {
|
|
281263
|
-
await appApi.forgeTemplate('templates/js-template/**/*', undefined, resourceKey => resourceKey.replace('templates/js-template/', 'api/').replace('.handlebars', `.${language}`));
|
|
281264
|
-
}
|
|
281265
|
-
|
|
281266
|
-
if (bffType === _generatorCommon.BFFType.Func) {
|
|
281267
|
-
if (language === _generatorCommon.Language.TS) {
|
|
281268
|
-
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
281269
|
-
query: {},
|
|
281270
|
-
update: {
|
|
281271
|
-
$set: {
|
|
281272
|
-
'compilerOptions.paths.@api/*': ['./api/*']
|
|
281273
|
-
}
|
|
281274
|
-
}
|
|
281275
|
-
});
|
|
281276
|
-
}
|
|
281277
|
-
|
|
281278
|
-
await appApi.forgeTemplate('templates/function/base/*', undefined, resourceKey => resourceKey.replace('templates/function/base/', 'api/').replace('.handlebars', `.${language}`));
|
|
281279
|
-
await appApi.forgeTemplate(`templates/function/info/*`, resourceKey => resourceKey.includes(language), resourceKey => resourceKey.replace('templates/function/info/', 'api/info/').replace('.handlebars', ``));
|
|
281280
|
-
await appApi.forgeTemplate(`templates/function/app/${language}/${framework}.${language}.handlebars`, undefined, resourceKey => resourceKey.replace(`templates/function/app/${language}/${framework}.${language}.handlebars`, `api/_app.${language}`));
|
|
281281
|
-
} else {
|
|
281282
|
-
if (language === _generatorCommon.Language.TS) {
|
|
281283
|
-
await jsonAPI.update(context.materials.default.get(_path.default.join(appDir, 'tsconfig.json')), {
|
|
281284
|
-
query: {},
|
|
281285
|
-
update: {
|
|
281286
|
-
$set: {
|
|
281287
|
-
'compilerOptions.paths.@api/*': ['./api/lambda/*']
|
|
281288
|
-
}
|
|
281289
|
-
}
|
|
281290
|
-
});
|
|
281291
|
-
}
|
|
281292
|
-
|
|
281293
|
-
await appApi.forgeTemplate(`templates/framework/lambda/*`, undefined, resourceKey => resourceKey.replace(`templates/framework/`, 'api/').replace('.handlebars', `.${language}`));
|
|
281294
|
-
await appApi.forgeTemplate(`templates/framework/app/${framework}/**/*`, resourceKey => framework === _generatorCommon.Framework.Egg || framework === _generatorCommon.Framework.Koa ? resourceKey.includes(language) : true, resourceKey => resourceKey.replace(`templates/framework/app/${framework}/`, 'api/').replace('.handlebars', framework === _generatorCommon.Framework.Express ? `.${language}` : ''));
|
|
281295
|
-
}
|
|
281296
|
-
|
|
281297
|
-
const appendTypeContent = _generatorCommon.FrameworkAppendTypeContent[framework];
|
|
281298
|
-
|
|
281299
|
-
if (appendTypeContent) {
|
|
281300
|
-
const typePath = _path.default.join(appDir, 'src', 'modern-app-env.d.ts');
|
|
281301
|
-
|
|
281302
|
-
if (_generatorUtils.fs.existsSync(typePath)) {
|
|
281303
|
-
const npmrc = _generatorUtils.fs.readFileSync(typePath, 'utf-8');
|
|
281304
|
-
|
|
281305
|
-
if (!npmrc.includes(appendTypeContent)) {
|
|
281306
|
-
_generatorUtils.fs.writeFileSync(typePath, `${npmrc}${appendTypeContent}\n`, 'utf-8');
|
|
281307
|
-
}
|
|
281308
|
-
} else {
|
|
281309
|
-
_generatorUtils.fs.ensureFileSync(typePath);
|
|
281310
|
-
|
|
281311
|
-
_generatorUtils.fs.writeFileSync(typePath, appendTypeContent, 'utf-8');
|
|
281312
|
-
}
|
|
281313
|
-
}
|
|
281314
|
-
};
|
|
281315
|
-
|
|
281316
|
-
var _default = async (context, generator) => {
|
|
281317
|
-
const appApi = new _codesmithApiApp.AppAPI(context, generator);
|
|
281318
|
-
const {
|
|
281319
|
-
locale
|
|
281320
|
-
} = context.config;
|
|
281321
|
-
|
|
281322
|
-
_generatorCommon.i18n.changeLanguage({
|
|
281323
|
-
locale
|
|
281324
|
-
});
|
|
281325
|
-
|
|
281326
|
-
appApi.i18n.changeLanguage({
|
|
281327
|
-
locale
|
|
281328
|
-
});
|
|
281329
|
-
|
|
281330
|
-
if (!(await appApi.checkEnvironment())) {
|
|
281331
|
-
// eslint-disable-next-line no-process-exit
|
|
281332
|
-
process.exit(1);
|
|
281333
|
-
}
|
|
281334
|
-
|
|
281335
|
-
generator.logger.debug(`start run @modern-js/bff-generator`);
|
|
281336
|
-
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
281337
|
-
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
281338
|
-
await handleTemplateFile(context, generator, appApi);
|
|
281339
|
-
await appApi.runInstall();
|
|
281340
|
-
generator.logger.debug(`forge @modern-js/bff-generator succeed `);
|
|
281341
|
-
};
|
|
281342
|
-
|
|
281343
|
-
exports["default"] = _default;
|
|
281344
|
-
})();
|
|
281345
|
-
|
|
281346
|
-
module.exports = __webpack_exports__;
|
|
281381
|
+
/******/
|
|
281382
|
+
/******/ // module cache are used so entry inlining is disabled
|
|
281383
|
+
/******/ // startup
|
|
281384
|
+
/******/ // Load entry module and return exports
|
|
281385
|
+
/******/ var __webpack_exports__ = __webpack_require__(34701);
|
|
281386
|
+
/******/ module.exports = __webpack_exports__;
|
|
281387
|
+
/******/
|
|
281347
281388
|
/******/ })()
|
|
281348
281389
|
;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./src/index.ts",
|
|
17
17
|
"main": "./dist/js/node/main.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@modern-js/codesmith-api-app": "^1.0.7",
|
|
26
26
|
"@modern-js/codesmith-api-json": "^1.0.7",
|
|
27
27
|
"@modern-js/codesmith-tools": "^1.0.9",
|
|
28
|
-
"@modern-js/generator-common": "^1.
|
|
28
|
+
"@modern-js/generator-common": "^1.4.0",
|
|
29
29
|
"@modern-js/generator-utils": "^1.2.1",
|
|
30
30
|
"@types/jest": "^26",
|
|
31
31
|
"@types/lodash": "^4.14.168",
|