create-module-federation 0.0.0-next-20250305095557 → 0.0.0-next-20250306063156

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 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,12 @@ 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'
102
+ }
103
+ };
97
104
  function upperFirst(str) {
98
105
  return str.charAt(0).toUpperCase() + str.slice(1);
99
106
  }
@@ -106,6 +113,7 @@ function logHelpMessage(name, templates) {
106
113
  -h, --help display help for command
107
114
  -d, --dir create project in specified directory
108
115
  -t, --template specify the template to use
116
+ -n, --name specify the mf name
109
117
  --override override files in target directory
110
118
 
111
119
  Templates:
@@ -237,16 +245,39 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
237
245
  };
238
246
  const templateDir = getTemplateDir(templateName);
239
247
  let commonTemplateDir = '';
240
- commonTemplateDir = 'lib' === projectType ? 'templates/lib-common/' : `templates/${framework}-common/`;
248
+ commonTemplateDir = "lib" === projectType ? 'templates/lib-common/' : `templates/${framework}-common/`;
241
249
  await renderTemplate(commonTemplateDir);
242
250
  await renderTemplate(templateDir);
243
251
  }
252
+ async function getProjectType(template) {
253
+ if (!template) return checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
254
+ message: 'Please select the type of project you want to create:',
255
+ options: [
256
+ {
257
+ value: "app",
258
+ label: 'Application'
259
+ },
260
+ {
261
+ value: "lib",
262
+ label: 'Lib'
263
+ },
264
+ {
265
+ value: "other",
266
+ label: 'Other'
267
+ }
268
+ ]
269
+ }));
270
+ if (template.startsWith('create-')) return "other";
271
+ if (template.includes('lib')) return "lib";
272
+ return "app";
273
+ }
244
274
  async function create({ name, templates }) {
245
275
  const argv = (0, __WEBPACK_EXTERNAL_MODULE_minimist__["default"])(process.argv.slice(2), {
246
276
  alias: {
247
277
  h: 'help',
248
278
  d: 'dir',
249
- t: 'template'
279
+ t: 'template',
280
+ n: 'name'
250
281
  }
251
282
  });
252
283
  console.log('');
@@ -258,7 +289,8 @@ async function create({ name, templates }) {
258
289
  const cwd = process.cwd();
259
290
  const pkgInfo = pkgFromUserAgent(process.env['npm_config_user_agent']);
260
291
  const pkgManager = pkgInfo ? pkgInfo.name : 'npm';
261
- const mfName = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
292
+ const mfVersion = "0.10.0";
293
+ const mfName = argv.name || checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.text)({
262
294
  message: 'Please input Module Federation name:',
263
295
  placeholder: 'mf_project_name',
264
296
  defaultValue: 'mf_project_name',
@@ -284,20 +316,25 @@ async function create({ name, templates }) {
284
316
  }));
285
317
  if ('no' === option) cancelAndExit();
286
318
  }
287
- const projectType = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
288
- message: 'Please select the type of project you want to create:',
289
- options: [
290
- {
291
- value: 'app',
292
- label: 'Application'
293
- },
294
- {
295
- value: 'lib',
296
- label: 'Lib'
297
- }
298
- ]
299
- }));
300
- const mfVersion = "0.10.0";
319
+ const projectType = await getProjectType(argv.template);
320
+ if ("other" === projectType) {
321
+ const otherOptions = Object.keys(OTHER_TYPE).map((key)=>({
322
+ value: key,
323
+ label: OTHER_TYPE[key].label
324
+ }));
325
+ const otherProjectKey = checkCancel(await (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.select)({
326
+ message: 'Please select the type of template you want to create:',
327
+ options: otherOptions
328
+ }));
329
+ const { command } = OTHER_TYPE[otherProjectKey];
330
+ const commandWithManager = command.replace(/^npm create /, `${pkgManager} create `);
331
+ const realCommand = `${commandWithManager} -d ${distFolder} -n ${mfName}${argv.override ? ' --override' : ''}`;
332
+ const [cmd, ...cmdArgs] = realCommand.split(' ');
333
+ const { status } = (0, __WEBPACK_EXTERNAL_MODULE_child_process__.spawnSync)(cmd, cmdArgs, {
334
+ stdio: 'inherit'
335
+ });
336
+ process.exit(status ?? 0);
337
+ }
301
338
  await forgeTemplate({
302
339
  projectType,
303
340
  argv,
@@ -310,7 +347,7 @@ async function create({ name, templates }) {
310
347
  const nextSteps = [
311
348
  `cd ${targetDir}`,
312
349
  `${pkgManager} install`,
313
- `${pkgManager} run ${'lib' === projectType ? 'mf-dev' : 'dev'}`
350
+ `${pkgManager} run ${"lib" === projectType ? 'mf-dev' : 'dev'}`
314
351
  ];
315
352
  (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.note)(nextSteps.join('\n'), 'Next steps');
316
353
  (0, __WEBPACK_EXTERNAL_MODULE__clack_prompts_3cae1695__.outro)('Done.');
@@ -321,7 +358,8 @@ const TEMPLATES = [
321
358
  'provider-rsbuild',
322
359
  'consumer-rsbuild',
323
360
  'rslib',
324
- 'rslib-storybook'
361
+ 'rslib-storybook',
362
+ 'create-zephyr'
325
363
  ];
326
364
  create({
327
365
  name: 'Module Federation',
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Create a new Module Federation project",
4
4
  "public": true,
5
5
  "sideEffects": false,
6
- "version": "0.0.0-next-20250305095557",
6
+ "version": "0.0.0-next-20250306063156",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
@@ -39,6 +39,7 @@
39
39
  "storybook-addon-rslib": "^0.1.7",
40
40
  "storybook-react-rsbuild": "^0.1.7",
41
41
  "typescript": "^5.7.3",
42
+ "@types/node": "^22.13.9",
42
43
  "@module-federation/rsbuild-plugin":"^{{mfVersion}}",
43
44
  "@module-federation/storybook-addon":"^4.0.1"
44
45
  },