@modern-js/mwa-generator 3.0.4 → 3.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/dist/index.js +31 -19
- package/package.json +10 -10
- package/src/index.ts +271 -0
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) {
|
|
@@ -135394,7 +135414,7 @@ var require_constants6 = __commonJS({
|
|
|
135394
135414
|
exports.SERVER_DIR = "server";
|
|
135395
135415
|
exports.SHARED_DIR = "shared";
|
|
135396
135416
|
exports.CONFIG_CACHE_DIR = "./node_modules/.cache/node-bundle-require";
|
|
135397
|
-
exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".
|
|
135417
|
+
exports.CONFIG_FILE_EXTENSIONS = [".js", ".ts", ".mjs"];
|
|
135398
135418
|
exports.OUTPUT_CONFIG_FILE = "modern.config.json";
|
|
135399
135419
|
exports.DEFAULT_SERVER_CONFIG = "modern.server-runtime.config";
|
|
135400
135420
|
exports.ROUTE_MINIFEST_FILE = "routes-manifest.json";
|
|
@@ -135885,7 +135905,7 @@ var require_nodeEnv2 = __commonJS({
|
|
|
135885
135905
|
});
|
|
135886
135906
|
}
|
|
135887
135907
|
exports.canUseNpm = canUseNpm2;
|
|
135888
|
-
function
|
|
135908
|
+
function canUseYarn() {
|
|
135889
135909
|
return __async(this, null, function* () {
|
|
135890
135910
|
try {
|
|
135891
135911
|
yield (0, compiled_1.execa)("yarn", ["--version"], { env: process.env });
|
|
@@ -135895,7 +135915,7 @@ var require_nodeEnv2 = __commonJS({
|
|
|
135895
135915
|
}
|
|
135896
135916
|
});
|
|
135897
135917
|
}
|
|
135898
|
-
exports.canUseYarn =
|
|
135918
|
+
exports.canUseYarn = canUseYarn;
|
|
135899
135919
|
function canUsePnpm2() {
|
|
135900
135920
|
return __async(this, null, function* () {
|
|
135901
135921
|
try {
|
|
@@ -136974,6 +136994,7 @@ var require_dist3 = __commonJS({
|
|
|
136974
136994
|
};
|
|
136975
136995
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
136976
136996
|
__exportStar(require_compiled2(), exports);
|
|
136997
|
+
__exportStar(require_commands(), exports);
|
|
136977
136998
|
__exportStar(require_format2(), exports);
|
|
136978
136999
|
__exportStar(require_FileSizeReporter2(), exports);
|
|
136979
137000
|
__exportStar(require_printBuildError2(), exports);
|
|
@@ -137510,15 +137531,6 @@ function getPackageVersion(packageName, registry2) {
|
|
|
137510
137531
|
spinner.stop();
|
|
137511
137532
|
return stripAnsi2(result.stdout);
|
|
137512
137533
|
}
|
|
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
137534
|
if (yield (0, import_utils2.canUseNpm)()) {
|
|
137523
137535
|
const args = ["view", packageName, "version"];
|
|
137524
137536
|
if (registry2) {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "3.0.
|
|
14
|
+
"version": "3.0.5",
|
|
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/build": "2.
|
|
38
|
-
"@scripts/jest-config": "2.
|
|
30
|
+
"@modern-js/dependence-generator": "3.0.5",
|
|
31
|
+
"@modern-js/entry-generator": "3.0.5",
|
|
32
|
+
"@modern-js/generator-utils": "3.0.5",
|
|
33
|
+
"@modern-js/packages-generator": "3.0.5",
|
|
34
|
+
"@modern-js/plugin-i18n": "2.3.0",
|
|
35
|
+
"@modern-js/base-generator": "3.0.5",
|
|
36
|
+
"@modern-js/generator-common": "3.0.5",
|
|
37
|
+
"@scripts/build": "2.3.0",
|
|
38
|
+
"@scripts/jest-config": "2.3.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
|
+
};
|