@modern-js/mwa-generator 3.0.4 → 3.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 +14 -18
- package/dist/index.js +52 -29
- package/package.json +11 -11
- package/src/index.ts +271 -0
package/README.md
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
1
|
<p align="center">
|
|
3
2
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
3
|
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
5
7
|
<p align="center">
|
|
6
|
-
|
|
7
|
-
<br/>
|
|
8
|
-
<a href="https://modernjs.dev" target="blank">
|
|
9
|
-
modernjs.dev
|
|
10
|
-
</a>
|
|
11
|
-
</p>
|
|
12
|
-
<p align="center">
|
|
13
|
-
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
14
9
|
</p>
|
|
15
10
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
11
|
+
## Getting Started
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
21
14
|
|
|
22
|
-
##
|
|
15
|
+
## Documentation
|
|
23
16
|
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [API References](https://modernjs.dev/docs/apis)
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
27
19
|
|
|
28
20
|
## Contributing
|
|
29
21
|
|
|
30
|
-
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -35762,7 +35762,7 @@ var require_nodeEnv = __commonJS({
|
|
|
35762
35762
|
});
|
|
35763
35763
|
}
|
|
35764
35764
|
exports.canUseNpm = canUseNpm2;
|
|
35765
|
-
function
|
|
35765
|
+
function canUseYarn() {
|
|
35766
35766
|
return __async(this, null, function* () {
|
|
35767
35767
|
try {
|
|
35768
35768
|
yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
|
|
@@ -35772,7 +35772,7 @@ var require_nodeEnv = __commonJS({
|
|
|
35772
35772
|
}
|
|
35773
35773
|
});
|
|
35774
35774
|
}
|
|
35775
|
-
exports.canUseYarn =
|
|
35775
|
+
exports.canUseYarn = canUseYarn;
|
|
35776
35776
|
function canUsePnpm2() {
|
|
35777
35777
|
return __async(this, null, function* () {
|
|
35778
35778
|
try {
|
|
@@ -44410,7 +44410,7 @@ var require_env = __commonJS({
|
|
|
44410
44410
|
exports.canUseNpm = canUseNpm2;
|
|
44411
44411
|
exports.canUseNvm = canUseNvm;
|
|
44412
44412
|
exports.canUsePnpm = canUsePnpm2;
|
|
44413
|
-
exports.canUseYarn =
|
|
44413
|
+
exports.canUseYarn = canUseYarn;
|
|
44414
44414
|
var _utils = require_dist();
|
|
44415
44415
|
function canUseNvm() {
|
|
44416
44416
|
return __async(this, null, function* () {
|
|
@@ -44437,7 +44437,7 @@ var require_env = __commonJS({
|
|
|
44437
44437
|
}
|
|
44438
44438
|
});
|
|
44439
44439
|
}
|
|
44440
|
-
function
|
|
44440
|
+
function canUseYarn() {
|
|
44441
44441
|
return __async(this, null, function* () {
|
|
44442
44442
|
try {
|
|
44443
44443
|
yield (0, _utils.execa)("yarn", ["--version"], {
|
|
@@ -45473,14 +45473,14 @@ var require_packageManager = __commonJS({
|
|
|
45473
45473
|
value: true
|
|
45474
45474
|
});
|
|
45475
45475
|
exports.canUsePnpm = canUsePnpm2;
|
|
45476
|
-
exports.canUseYarn =
|
|
45476
|
+
exports.canUseYarn = canUseYarn;
|
|
45477
45477
|
exports.runInstall = runInstall;
|
|
45478
45478
|
var _path = _interopRequireDefault(require("path"));
|
|
45479
45479
|
var _utils = require_dist();
|
|
45480
45480
|
function _interopRequireDefault(obj) {
|
|
45481
45481
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
45482
45482
|
}
|
|
45483
|
-
function
|
|
45483
|
+
function canUseYarn() {
|
|
45484
45484
|
return __async(this, null, function* () {
|
|
45485
45485
|
try {
|
|
45486
45486
|
yield (0, _utils.execa)("yarn", ["--version"], {
|
|
@@ -45527,7 +45527,7 @@ var require_packageManager = __commonJS({
|
|
|
45527
45527
|
params.push(`--registry=${registryUrl}`);
|
|
45528
45528
|
}
|
|
45529
45529
|
yield (0, _utils.execa)("pnpm", params, options);
|
|
45530
|
-
} else if (yield
|
|
45530
|
+
} else if (yield canUseYarn()) {
|
|
45531
45531
|
const params = ["install", "--production", "--silent", "--ignore-scripts"];
|
|
45532
45532
|
if (registryUrl) {
|
|
45533
45533
|
params.push(`--registry=${registryUrl}`);
|
|
@@ -134820,6 +134820,26 @@ var require_compiled2 = __commonJS({
|
|
|
134820
134820
|
}
|
|
134821
134821
|
});
|
|
134822
134822
|
|
|
134823
|
+
// ../../../toolkit/utils/dist/commands.js
|
|
134824
|
+
var require_commands = __commonJS({
|
|
134825
|
+
"../../../toolkit/utils/dist/commands.js"(exports) {
|
|
134826
|
+
"use strict";
|
|
134827
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
134828
|
+
exports.isDevCommand = exports.getCommand = void 0;
|
|
134829
|
+
var getCommand = () => {
|
|
134830
|
+
const args = process.argv.slice(2);
|
|
134831
|
+
const command = args[0];
|
|
134832
|
+
return command;
|
|
134833
|
+
};
|
|
134834
|
+
exports.getCommand = getCommand;
|
|
134835
|
+
var isDevCommand = () => {
|
|
134836
|
+
const command = (0, exports.getCommand)();
|
|
134837
|
+
return command === "dev" || command === "start";
|
|
134838
|
+
};
|
|
134839
|
+
exports.isDevCommand = isDevCommand;
|
|
134840
|
+
}
|
|
134841
|
+
});
|
|
134842
|
+
|
|
134823
134843
|
// ../../../toolkit/utils/dist/format.js
|
|
134824
134844
|
var require_format2 = __commonJS({
|
|
134825
134845
|
"../../../toolkit/utils/dist/format.js"(exports) {
|
|
@@ -135195,12 +135215,14 @@ var require_node_env2 = __commonJS({
|
|
|
135195
135215
|
"../../../toolkit/utils/dist/is/node-env.js"(exports) {
|
|
135196
135216
|
"use strict";
|
|
135197
135217
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
135198
|
-
exports.isProdProfile = exports.isTest = exports.isProd = exports.isDev = void 0;
|
|
135199
|
-
var
|
|
135218
|
+
exports.isProdProfile = exports.isTest = exports.isProd = exports.isDev = exports.getNodeEnv = void 0;
|
|
135219
|
+
var getNodeEnv = () => process.env.NODE_ENV || "development";
|
|
135220
|
+
exports.getNodeEnv = getNodeEnv;
|
|
135221
|
+
var isDev = () => (0, exports.getNodeEnv)() === "development";
|
|
135200
135222
|
exports.isDev = isDev;
|
|
135201
|
-
var isProd = () =>
|
|
135223
|
+
var isProd = () => (0, exports.getNodeEnv)() === "production";
|
|
135202
135224
|
exports.isProd = isProd;
|
|
135203
|
-
var isTest = () =>
|
|
135225
|
+
var isTest = () => (0, exports.getNodeEnv)() === "test";
|
|
135204
135226
|
exports.isTest = isTest;
|
|
135205
135227
|
var isProdProfile = () => (0, exports.isProd)() && process.argv.includes("--profile");
|
|
135206
135228
|
exports.isProdProfile = isProdProfile;
|
|
@@ -135343,10 +135365,10 @@ var require_is2 = __commonJS({
|
|
|
135343
135365
|
|
|
135344
135366
|
// ../../../toolkit/utils/dist/compatRequire.js
|
|
135345
135367
|
var require_compatRequire2 = __commonJS({
|
|
135346
|
-
"../../../toolkit/utils/dist/compatRequire.js"(exports) {
|
|
135368
|
+
"../../../toolkit/utils/dist/compatRequire.js"(exports, module2) {
|
|
135347
135369
|
"use strict";
|
|
135348
135370
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
135349
|
-
exports.cleanRequireCache = exports.requireExistModule = exports.dynamicImport = exports.compatRequire = void 0;
|
|
135371
|
+
exports.deleteRequireCache = exports.cleanRequireCache = exports.requireExistModule = exports.dynamicImport = exports.compatRequire = void 0;
|
|
135350
135372
|
var findExists_1 = require_findExists2();
|
|
135351
135373
|
var compatRequire = (filePath, interop = true) => {
|
|
135352
135374
|
const mod = require(filePath);
|
|
@@ -135373,6 +135395,15 @@ var require_compatRequire2 = __commonJS({
|
|
|
135373
135395
|
});
|
|
135374
135396
|
};
|
|
135375
135397
|
exports.cleanRequireCache = cleanRequireCache;
|
|
135398
|
+
function deleteRequireCache(path3) {
|
|
135399
|
+
if (require.cache[path3]) {
|
|
135400
|
+
delete require.cache[path3];
|
|
135401
|
+
}
|
|
135402
|
+
if (module2.children) {
|
|
135403
|
+
module2.children = module2.children.filter((item) => item.filename !== path3);
|
|
135404
|
+
}
|
|
135405
|
+
}
|
|
135406
|
+
exports.deleteRequireCache = deleteRequireCache;
|
|
135376
135407
|
}
|
|
135377
135408
|
});
|
|
135378
135409
|
|
|
@@ -135394,7 +135425,7 @@ var require_constants6 = __commonJS({
|
|
|
135394
135425
|
exports.SERVER_DIR = "server";
|
|
135395
135426
|
exports.SHARED_DIR = "shared";
|
|
135396
135427
|
exports.CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
|
|
135397
|
-
exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".
|
|
135428
|
+
exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
|
|
135398
135429
|
exports.OUTPUT_CONFIG_FILE = "modern.config.json";
|
|
135399
135430
|
exports.DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
|
|
135400
135431
|
exports.ROUTE_MINIFEST_FILE = "routes-manifest.json";
|
|
@@ -135885,7 +135916,7 @@ var require_nodeEnv2 = __commonJS({
|
|
|
135885
135916
|
});
|
|
135886
135917
|
}
|
|
135887
135918
|
exports.canUseNpm = canUseNpm2;
|
|
135888
|
-
function
|
|
135919
|
+
function canUseYarn() {
|
|
135889
135920
|
return __async(this, null, function* () {
|
|
135890
135921
|
try {
|
|
135891
135922
|
yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
|
|
@@ -135895,7 +135926,7 @@ var require_nodeEnv2 = __commonJS({
|
|
|
135895
135926
|
}
|
|
135896
135927
|
});
|
|
135897
135928
|
}
|
|
135898
|
-
exports.canUseYarn =
|
|
135929
|
+
exports.canUseYarn = canUseYarn;
|
|
135899
135930
|
function canUsePnpm2() {
|
|
135900
135931
|
return __async(this, null, function* () {
|
|
135901
135932
|
try {
|
|
@@ -136974,6 +137005,7 @@ var require_dist3 = __commonJS({
|
|
|
136974
137005
|
};
|
|
136975
137006
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
136976
137007
|
__exportStar(require_compiled2(), exports);
|
|
137008
|
+
__exportStar(require_commands(), exports);
|
|
136977
137009
|
__exportStar(require_format2(), exports);
|
|
136978
137010
|
__exportStar(require_FileSizeReporter2(), exports);
|
|
136979
137011
|
__exportStar(require_printBuildError2(), exports);
|
|
@@ -137193,7 +137225,7 @@ var ZH_LOCALE = {
|
|
|
137193
137225
|
var EN_LOCALE = {
|
|
137194
137226
|
solution: {
|
|
137195
137227
|
self: "Please select the solution you want to create",
|
|
137196
|
-
mwa: "
|
|
137228
|
+
mwa: "Web App Solution",
|
|
137197
137229
|
module: "Module Solution",
|
|
137198
137230
|
monorepo: "Monorepo Solution",
|
|
137199
137231
|
custom: "Custom Solution",
|
|
@@ -137204,10 +137236,10 @@ var EN_LOCALE = {
|
|
|
137204
137236
|
},
|
|
137205
137237
|
sub_solution: {
|
|
137206
137238
|
self: "Please select the solution you want to create",
|
|
137207
|
-
mwa: "
|
|
137208
|
-
mwa_test: "
|
|
137239
|
+
mwa: "Web App Solution",
|
|
137240
|
+
mwa_test: "Web App Solution (Test)",
|
|
137209
137241
|
module: "Module Solution",
|
|
137210
|
-
inner_module: "Module Solution(Inner)",
|
|
137242
|
+
inner_module: "Module Solution (Inner)",
|
|
137211
137243
|
monorepo: "Monorepo Solution"
|
|
137212
137244
|
},
|
|
137213
137245
|
action: {
|
|
@@ -137510,15 +137542,6 @@ function getPackageVersion(packageName, registry2) {
|
|
|
137510
137542
|
spinner.stop();
|
|
137511
137543
|
return stripAnsi2(result.stdout);
|
|
137512
137544
|
}
|
|
137513
|
-
if (yield (0, import_utils2.canUseYarn)()) {
|
|
137514
|
-
const args = ["info", packageName, "version", "--silent"];
|
|
137515
|
-
if (registry2) {
|
|
137516
|
-
args.push(`--registry=${registry2}`);
|
|
137517
|
-
}
|
|
137518
|
-
const result = yield (0, import_utils2.execa)("yarn", args);
|
|
137519
|
-
spinner.stop();
|
|
137520
|
-
return stripAnsi2(result.stdout);
|
|
137521
|
-
}
|
|
137522
137545
|
if (yield (0, import_utils2.canUseNpm)()) {
|
|
137523
137546
|
const args = ["view", packageName, "version"];
|
|
137524
137547
|
if (registry2) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/mwa-generator",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/modern-js-dev/modern.js/issues",
|
|
6
6
|
"repository": "modern-js-dev/modern.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "3.0.
|
|
14
|
+
"version": "3.0.6",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"main": "./dist/index.js",
|
|
17
17
|
"files": [
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"@types/node": "^14",
|
|
28
28
|
"jest": "^27",
|
|
29
29
|
"typescript": "^4",
|
|
30
|
-
"@modern-js/
|
|
31
|
-
"@modern-js/generator
|
|
32
|
-
"@modern-js/
|
|
33
|
-
"@modern-js/packages-generator": "3.0.
|
|
34
|
-
"@modern-js/plugin-i18n": "2.
|
|
35
|
-
"@modern-js/generator
|
|
36
|
-
"@modern-js/
|
|
37
|
-
"@scripts/
|
|
38
|
-
"@scripts/
|
|
30
|
+
"@modern-js/base-generator": "3.0.6",
|
|
31
|
+
"@modern-js/entry-generator": "3.0.6",
|
|
32
|
+
"@modern-js/generator-utils": "3.0.6",
|
|
33
|
+
"@modern-js/packages-generator": "3.0.6",
|
|
34
|
+
"@modern-js/plugin-i18n": "2.4.0",
|
|
35
|
+
"@modern-js/dependence-generator": "3.0.6",
|
|
36
|
+
"@modern-js/generator-common": "3.0.6",
|
|
37
|
+
"@scripts/jest-config": "2.4.0",
|
|
38
|
+
"@scripts/build": "2.4.0"
|
|
39
39
|
},
|
|
40
40
|
"sideEffects": false,
|
|
41
41
|
"publishConfig": {
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
|
|
3
|
+
import { AppAPI } from '@modern-js/codesmith-api-app';
|
|
4
|
+
import { JsonAPI } from '@modern-js/codesmith-api-json';
|
|
5
|
+
import {
|
|
6
|
+
i18n as commonI18n,
|
|
7
|
+
BaseGenerator,
|
|
8
|
+
Solution,
|
|
9
|
+
getMWASchema,
|
|
10
|
+
Language,
|
|
11
|
+
EntryGenerator,
|
|
12
|
+
PackagesGenerator,
|
|
13
|
+
} from '@modern-js/generator-common';
|
|
14
|
+
import {
|
|
15
|
+
getMWAProjectPath,
|
|
16
|
+
getAllPackages,
|
|
17
|
+
i18n as utilsI18n,
|
|
18
|
+
validatePackageName,
|
|
19
|
+
validatePackagePath,
|
|
20
|
+
getPackageManagerText,
|
|
21
|
+
getModernVersion,
|
|
22
|
+
} from '@modern-js/generator-utils';
|
|
23
|
+
import { i18n, localeKeys } from './locale';
|
|
24
|
+
|
|
25
|
+
const getGeneratorPath = (generator: string, distTag: string) => {
|
|
26
|
+
if (process.env.CODESMITH_ENV === 'development') {
|
|
27
|
+
return path.dirname(require.resolve(generator));
|
|
28
|
+
} else if (distTag) {
|
|
29
|
+
return `${generator}@${distTag}`;
|
|
30
|
+
}
|
|
31
|
+
return generator;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const handleTemplateFile = async (
|
|
35
|
+
context: GeneratorContext,
|
|
36
|
+
generator: GeneratorCore,
|
|
37
|
+
appApi: AppAPI,
|
|
38
|
+
) => {
|
|
39
|
+
const jsonAPI = new JsonAPI(generator);
|
|
40
|
+
|
|
41
|
+
const { isMonorepoSubProject, isTest, projectDir = '' } = context.config;
|
|
42
|
+
|
|
43
|
+
const { outputPath } = generator;
|
|
44
|
+
|
|
45
|
+
let packages: string[] = [];
|
|
46
|
+
|
|
47
|
+
if (isMonorepoSubProject) {
|
|
48
|
+
try {
|
|
49
|
+
packages = getAllPackages(outputPath);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
generator.logger.debug('get all packages error', e);
|
|
52
|
+
generator.logger.warn(i18n.t(localeKeys.get_packages_error));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
context.config = {
|
|
57
|
+
...context.config,
|
|
58
|
+
isMwa: true,
|
|
59
|
+
isEmptySrc: true,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const { hasPlugin, generatorPlugin, ...extra } = context.config;
|
|
63
|
+
|
|
64
|
+
let ans: Record<string, unknown> = {};
|
|
65
|
+
|
|
66
|
+
if (hasPlugin) {
|
|
67
|
+
await generatorPlugin.installPlugins(Solution.MWA, extra);
|
|
68
|
+
const schema = generatorPlugin.getInputSchema();
|
|
69
|
+
const inputValue = generatorPlugin.getInputValue();
|
|
70
|
+
context.config.gitCommitMessage =
|
|
71
|
+
generatorPlugin.getGitMessage() || context.config.gitCommitMessage;
|
|
72
|
+
ans = await appApi.getInputBySchema(
|
|
73
|
+
schema,
|
|
74
|
+
'formily',
|
|
75
|
+
{ ...context.config, ...inputValue },
|
|
76
|
+
{
|
|
77
|
+
packageName: input =>
|
|
78
|
+
validatePackageName(input as string, packages, {
|
|
79
|
+
isMonorepoSubProject,
|
|
80
|
+
}),
|
|
81
|
+
packagePath: input =>
|
|
82
|
+
validatePackagePath(
|
|
83
|
+
input as string,
|
|
84
|
+
path.join(process.cwd(), projectDir),
|
|
85
|
+
{
|
|
86
|
+
isTest,
|
|
87
|
+
isMwa: true,
|
|
88
|
+
},
|
|
89
|
+
),
|
|
90
|
+
},
|
|
91
|
+
{},
|
|
92
|
+
);
|
|
93
|
+
} else {
|
|
94
|
+
ans = await appApi.getInputBySchemaFunc(
|
|
95
|
+
getMWASchema,
|
|
96
|
+
{ ...context.config },
|
|
97
|
+
{
|
|
98
|
+
packageName: input =>
|
|
99
|
+
validatePackageName(input as string, packages, {
|
|
100
|
+
isMonorepoSubProject,
|
|
101
|
+
}),
|
|
102
|
+
packagePath: input =>
|
|
103
|
+
validatePackagePath(
|
|
104
|
+
input as string,
|
|
105
|
+
path.join(process.cwd(), projectDir),
|
|
106
|
+
{ isTest, isMwa: true },
|
|
107
|
+
),
|
|
108
|
+
},
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const modernVersion = await getModernVersion(
|
|
113
|
+
Solution.MWA,
|
|
114
|
+
context.config.registry,
|
|
115
|
+
context.config.distTag,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
generator.logger.debug(`inputData=${JSON.stringify(ans)}`, ans);
|
|
119
|
+
|
|
120
|
+
const { packageName, packagePath, language } = ans;
|
|
121
|
+
|
|
122
|
+
const projectPath = getMWAProjectPath(
|
|
123
|
+
packagePath as string,
|
|
124
|
+
isMonorepoSubProject,
|
|
125
|
+
isTest,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const dirname = path.basename(generator.outputPath);
|
|
129
|
+
|
|
130
|
+
await appApi.runSubGenerator(
|
|
131
|
+
getGeneratorPath(BaseGenerator, context.config.distTag),
|
|
132
|
+
undefined,
|
|
133
|
+
{ ...context.config, hasPlugin: false },
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
await appApi.forgeTemplate(
|
|
137
|
+
'templates/base-template/**/*',
|
|
138
|
+
undefined,
|
|
139
|
+
resourceKey =>
|
|
140
|
+
resourceKey
|
|
141
|
+
.replace('templates/base-template/', projectPath)
|
|
142
|
+
.replace('.handlebars', ''),
|
|
143
|
+
{
|
|
144
|
+
name: packageName || dirname,
|
|
145
|
+
isMonorepoSubProject,
|
|
146
|
+
modernVersion,
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (language === Language.TS) {
|
|
151
|
+
await jsonAPI.update(
|
|
152
|
+
context.materials.default.get(path.join(projectPath, 'package.json')),
|
|
153
|
+
{
|
|
154
|
+
query: {},
|
|
155
|
+
update: {
|
|
156
|
+
$set: {
|
|
157
|
+
'devDependencies.typescript': '~4.9.4',
|
|
158
|
+
'devDependencies.@types/jest': '~29.2.4',
|
|
159
|
+
'devDependencies.@types/node': '~16.11.7',
|
|
160
|
+
'devDependencies.@types/react': '~18.0.26',
|
|
161
|
+
'devDependencies.@types/react-dom': '~18.0.10',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
await appApi.forgeTemplate(
|
|
168
|
+
'templates/ts-template/**/*',
|
|
169
|
+
undefined,
|
|
170
|
+
resourceKey =>
|
|
171
|
+
resourceKey
|
|
172
|
+
.replace('templates/ts-template/', projectPath)
|
|
173
|
+
.replace('.handlebars', ''),
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
await appApi.forgeTemplate(
|
|
177
|
+
'templates/js-template/**/*',
|
|
178
|
+
undefined,
|
|
179
|
+
resourceKey =>
|
|
180
|
+
resourceKey
|
|
181
|
+
.replace('templates/js-template/', projectPath)
|
|
182
|
+
.replace('.handlebars', ''),
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
await appApi.runSubGenerator(
|
|
187
|
+
getGeneratorPath(EntryGenerator, context.config.distTag),
|
|
188
|
+
`./${projectPath}`,
|
|
189
|
+
{
|
|
190
|
+
...context.config,
|
|
191
|
+
isSubGenerator: true,
|
|
192
|
+
},
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
if (isMonorepoSubProject) {
|
|
196
|
+
await appApi.updateWorkspace({
|
|
197
|
+
name: packagePath as string,
|
|
198
|
+
path: projectPath,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
const { packagesInfo } = context.config;
|
|
203
|
+
if (packagesInfo && Object.keys(packagesInfo).length > 0) {
|
|
204
|
+
await appApi.runSubGenerator(
|
|
205
|
+
getGeneratorPath(PackagesGenerator, context.config.distTag),
|
|
206
|
+
undefined,
|
|
207
|
+
context.config,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return { projectPath };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
215
|
+
const appApi = new AppAPI(context, generator);
|
|
216
|
+
|
|
217
|
+
const { locale, successInfo } = context.config;
|
|
218
|
+
commonI18n.changeLanguage({ locale });
|
|
219
|
+
utilsI18n.changeLanguage({ locale });
|
|
220
|
+
appApi.i18n.changeLanguage({ locale });
|
|
221
|
+
i18n.changeLanguage({ locale });
|
|
222
|
+
|
|
223
|
+
if (!(await appApi.checkEnvironment())) {
|
|
224
|
+
// eslint-disable-next-line no-process-exit
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
generator.logger.debug(`start run @modern-js/mwa-generator`);
|
|
229
|
+
generator.logger.debug(`context=${JSON.stringify(context)}`);
|
|
230
|
+
generator.logger.debug(`context.data=${JSON.stringify(context.data)}`);
|
|
231
|
+
|
|
232
|
+
let projectPath = '';
|
|
233
|
+
try {
|
|
234
|
+
({ projectPath } = await handleTemplateFile(context, generator, appApi));
|
|
235
|
+
} catch (e) {
|
|
236
|
+
generator.logger.error(e);
|
|
237
|
+
// eslint-disable-next-line no-process-exit
|
|
238
|
+
process.exit(1);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (context.handleForged) {
|
|
242
|
+
await context.handleForged(
|
|
243
|
+
Solution.MWA,
|
|
244
|
+
context,
|
|
245
|
+
context.config.hasPlugin,
|
|
246
|
+
projectPath,
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
try {
|
|
251
|
+
await appApi.runGitAndInstall(context.config.gitCommitMessage);
|
|
252
|
+
} catch (e) {
|
|
253
|
+
generator.logger.error(e);
|
|
254
|
+
// eslint-disable-next-line no-process-exit
|
|
255
|
+
process.exit(1);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const { packageManager } = context.config;
|
|
259
|
+
|
|
260
|
+
if (successInfo) {
|
|
261
|
+
appApi.showSuccessInfo(successInfo);
|
|
262
|
+
} else {
|
|
263
|
+
appApi.showSuccessInfo(
|
|
264
|
+
i18n.t(localeKeys.success, {
|
|
265
|
+
packageManager: getPackageManagerText(packageManager),
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
generator.logger.debug(`forge @modern-js/mwa-generator succeed `);
|
|
271
|
+
};
|