create-module-federation 0.0.0-next-20250305100230 → 0.0.0-next-20250306064243
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 +58 -19
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_child_process__ from "child_process";
|
|
4
5
|
import * as __WEBPACK_EXTERNAL_MODULE_url__ from "url";
|
|
5
6
|
import * as __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__ from "@clack/prompts";
|
|
6
7
|
import * as __WEBPACK_EXTERNAL_MODULE_minimist__ from "minimist";
|
|
@@ -94,6 +95,13 @@ class HandlebarsAPI {
|
|
|
94
95
|
const create_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
|
|
95
96
|
const create_dirname = __WEBPACK_EXTERNAL_MODULE_path__["default"].dirname(create_filename);
|
|
96
97
|
const packageDir = __WEBPACK_EXTERNAL_MODULE_path__["default"].resolve(create_dirname, '..');
|
|
98
|
+
const OTHER_TYPE = {
|
|
99
|
+
zephyr: {
|
|
100
|
+
label: 'zephyr',
|
|
101
|
+
command: 'npm create zephyr@latest',
|
|
102
|
+
hint: 'npm create zephyr@latest'
|
|
103
|
+
}
|
|
104
|
+
};
|
|
97
105
|
function upperFirst(str) {
|
|
98
106
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
99
107
|
}
|
|
@@ -106,6 +114,7 @@ function logHelpMessage(name, templates) {
|
|
|
106
114
|
-h, --help display help for command
|
|
107
115
|
-d, --dir create project in specified directory
|
|
108
116
|
-t, --template specify the template to use
|
|
117
|
+
-n, --name specify the mf name
|
|
109
118
|
--override override files in target directory
|
|
110
119
|
|
|
111
120
|
Templates:
|
|
@@ -237,16 +246,39 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
237
246
|
};
|
|
238
247
|
const templateDir = getTemplateDir(templateName);
|
|
239
248
|
let commonTemplateDir = '';
|
|
240
|
-
commonTemplateDir =
|
|
249
|
+
commonTemplateDir = "lib" === projectType ? 'templates/lib-common/' : `templates/${framework}-common/`;
|
|
241
250
|
await renderTemplate(commonTemplateDir);
|
|
242
251
|
await renderTemplate(templateDir);
|
|
243
252
|
}
|
|
253
|
+
async function getProjectType(template) {
|
|
254
|
+
if (!template) return checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
255
|
+
message: 'Please select the type of project you want to create:',
|
|
256
|
+
options: [
|
|
257
|
+
{
|
|
258
|
+
value: "app",
|
|
259
|
+
label: 'Application'
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
value: "lib",
|
|
263
|
+
label: 'Lib'
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
value: "other",
|
|
267
|
+
label: 'Other'
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
}));
|
|
271
|
+
if (template.startsWith('create-')) return "other";
|
|
272
|
+
if (template.includes('lib')) return "lib";
|
|
273
|
+
return "app";
|
|
274
|
+
}
|
|
244
275
|
async function create({ name, templates }) {
|
|
245
276
|
const argv = (0, __WEBPACK_EXTERNAL_MODULE_minimist__["default"])(process.argv.slice(2), {
|
|
246
277
|
alias: {
|
|
247
278
|
h: 'help',
|
|
248
279
|
d: 'dir',
|
|
249
|
-
t: 'template'
|
|
280
|
+
t: 'template',
|
|
281
|
+
n: 'name'
|
|
250
282
|
}
|
|
251
283
|
});
|
|
252
284
|
console.log('');
|
|
@@ -258,7 +290,8 @@ async function create({ name, templates }) {
|
|
|
258
290
|
const cwd = process.cwd();
|
|
259
291
|
const pkgInfo = pkgFromUserAgent(process.env['npm_config_user_agent']);
|
|
260
292
|
const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
|
|
261
|
-
const
|
|
293
|
+
const mfVersion = "0.10.0";
|
|
294
|
+
const mfName = argv.name || checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
|
|
262
295
|
message: 'Please input Module Federation name:',
|
|
263
296
|
placeholder: 'mf_project_name',
|
|
264
297
|
defaultValue: 'mf_project_name',
|
|
@@ -284,20 +317,25 @@ async function create({ name, templates }) {
|
|
|
284
317
|
}));
|
|
285
318
|
if ('no' === option) cancelAndExit();
|
|
286
319
|
}
|
|
287
|
-
const projectType =
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
320
|
+
const projectType = await getProjectType(argv.template);
|
|
321
|
+
if ("other" === projectType) {
|
|
322
|
+
const otherOptions = Object.keys(OTHER_TYPE).map((key)=>({
|
|
323
|
+
value: key,
|
|
324
|
+
label: OTHER_TYPE[key].label
|
|
325
|
+
}));
|
|
326
|
+
const otherProjectKey = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
|
|
327
|
+
message: 'Please select the type of template you want to create:',
|
|
328
|
+
options: otherOptions
|
|
329
|
+
}));
|
|
330
|
+
const { command } = OTHER_TYPE[otherProjectKey];
|
|
331
|
+
const commandWithManager = command.replace(/^npm create /, `${pkgManager} create `);
|
|
332
|
+
const realCommand = `${commandWithManager} -d ${distFolder} -n ${mfName}${argv.override ? ' --override' : ''}`;
|
|
333
|
+
const [cmd, ...cmdArgs] = realCommand.split(' ');
|
|
334
|
+
const { status } = (0, __WEBPACK_EXTERNAL_MODULE_child_process__.spawnSync)(cmd, cmdArgs, {
|
|
335
|
+
stdio: 'inherit'
|
|
336
|
+
});
|
|
337
|
+
process.exit(status ?? 0);
|
|
338
|
+
}
|
|
301
339
|
await forgeTemplate({
|
|
302
340
|
projectType,
|
|
303
341
|
argv,
|
|
@@ -310,7 +348,7 @@ async function create({ name, templates }) {
|
|
|
310
348
|
const nextSteps = [
|
|
311
349
|
`cd ${targetDir}`,
|
|
312
350
|
`${pkgManager} install`,
|
|
313
|
-
`${pkgManager} run ${
|
|
351
|
+
`${pkgManager} run ${"lib" === projectType ? 'mf-dev' : 'dev'}`
|
|
314
352
|
];
|
|
315
353
|
(0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(nextSteps.join('\n'), 'Next steps');
|
|
316
354
|
(0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.outro)('Done.');
|
|
@@ -321,7 +359,8 @@ const TEMPLATES = [
|
|
|
321
359
|
'provider-rsbuild',
|
|
322
360
|
'consumer-rsbuild',
|
|
323
361
|
'rslib',
|
|
324
|
-
'rslib-storybook'
|
|
362
|
+
'rslib-storybook',
|
|
363
|
+
'create-zephyr'
|
|
325
364
|
];
|
|
326
365
|
create({
|
|
327
366
|
name: 'Module Federation',
|
package/package.json
CHANGED