create-module-federation 0.0.0-next-20250701093604 → 0.0.0-next-20250701105507
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 +45 -45
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
2
|
+
import external_path_default from "path";
|
|
3
|
+
import external_fs_default from "fs";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { cancel, isCancel, multiselect, note, outro, select as prompts_select, text as prompts_text } from "@clack/prompts";
|
|
7
|
+
import external_minimist_default from "minimist";
|
|
8
|
+
import { logger } from "rslog";
|
|
9
|
+
import external_glob_default from "glob";
|
|
10
|
+
import external_fs_extra_default from "fs-extra";
|
|
11
|
+
import external_handlebars_default from "handlebars";
|
|
12
12
|
const IMAGE_EXT_LIST = [
|
|
13
13
|
'.jpg',
|
|
14
14
|
'.jpeg',
|
|
@@ -29,49 +29,49 @@ class FsResource {
|
|
|
29
29
|
this.resourceKey = resourceKey;
|
|
30
30
|
}
|
|
31
31
|
async value() {
|
|
32
|
-
const resourceFileExt =
|
|
32
|
+
const resourceFileExt = external_path_default.extname(this.filePath);
|
|
33
33
|
if (IMAGE_EXT_LIST.includes(resourceFileExt)) {
|
|
34
|
-
const buffer = await
|
|
34
|
+
const buffer = await external_fs_extra_default.readFile(external_path_default.resolve(this.filePath));
|
|
35
35
|
return {
|
|
36
36
|
content: buffer
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
-
const text = await
|
|
39
|
+
const text = await external_fs_extra_default.readFile(external_path_default.resolve(this.filePath), 'utf8');
|
|
40
40
|
return {
|
|
41
41
|
content: text
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
const promisifyGlob = (pattern, options)=>new Promise((resolve, reject)=>{
|
|
46
|
-
(
|
|
46
|
+
external_glob_default(pattern, options, (err, files)=>null === err ? resolve(files) : reject(err));
|
|
47
47
|
});
|
|
48
48
|
class FsMaterial {
|
|
49
49
|
constructor(basePath){
|
|
50
50
|
this.basePath = basePath;
|
|
51
51
|
}
|
|
52
52
|
get(resourceKey) {
|
|
53
|
-
return new FsResource(
|
|
53
|
+
return new FsResource(external_path_default.resolve(this.basePath, resourceKey), resourceKey);
|
|
54
54
|
}
|
|
55
55
|
async find(globStr, options) {
|
|
56
56
|
const matches = await promisifyGlob(globStr, {
|
|
57
|
-
cwd:
|
|
57
|
+
cwd: external_path_default.resolve(this.basePath),
|
|
58
58
|
nodir: options?.nodir,
|
|
59
59
|
dot: options?.dot,
|
|
60
60
|
ignore: options?.ignore
|
|
61
61
|
});
|
|
62
62
|
return matches.reduce((pre, cur)=>{
|
|
63
|
-
pre[cur] = new FsResource(
|
|
63
|
+
pre[cur] = new FsResource(external_path_default.resolve(this.basePath, cur), cur);
|
|
64
64
|
return pre;
|
|
65
65
|
}, {});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
function renderString(template, fullData) {
|
|
69
|
-
return
|
|
69
|
+
return external_handlebars_default.compile(template)(fullData) || '';
|
|
70
70
|
}
|
|
71
71
|
async function outputFs(file, content, outputPath, options) {
|
|
72
|
-
const filePath =
|
|
73
|
-
await
|
|
74
|
-
await
|
|
72
|
+
const filePath = external_path_default.resolve(outputPath, file.toString());
|
|
73
|
+
await external_fs_extra_default.mkdirp(external_path_default.dirname(filePath));
|
|
74
|
+
await external_fs_extra_default.writeFile(filePath, content, options);
|
|
75
75
|
}
|
|
76
76
|
class HandlebarsAPI {
|
|
77
77
|
async renderTemplate(templateResource, target, outputFilePath, parameters = {}) {
|
|
@@ -92,9 +92,9 @@ class HandlebarsAPI {
|
|
|
92
92
|
}));
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
const create_filename =
|
|
96
|
-
const create_dirname =
|
|
97
|
-
const packageDir =
|
|
95
|
+
const create_filename = fileURLToPath(import.meta.url);
|
|
96
|
+
const create_dirname = external_path_default.dirname(create_filename);
|
|
97
|
+
const packageDir = external_path_default.resolve(create_dirname, '..');
|
|
98
98
|
const OTHER_TYPE = {
|
|
99
99
|
zephyr: {
|
|
100
100
|
label: 'zephyr',
|
|
@@ -106,7 +106,7 @@ function upperFirst(str) {
|
|
|
106
106
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
107
107
|
}
|
|
108
108
|
function logHelpMessage(name, templates) {
|
|
109
|
-
|
|
109
|
+
logger.log(`
|
|
110
110
|
Usage: create-${name} [options]
|
|
111
111
|
|
|
112
112
|
Options:
|
|
@@ -132,11 +132,11 @@ function pkgFromUserAgent(userAgent) {
|
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
function cancelAndExit() {
|
|
135
|
-
|
|
135
|
+
cancel('Operation cancelled.');
|
|
136
136
|
process.exit(0);
|
|
137
137
|
}
|
|
138
138
|
function checkCancel(value) {
|
|
139
|
-
if (
|
|
139
|
+
if (isCancel(value)) cancelAndExit();
|
|
140
140
|
return value;
|
|
141
141
|
}
|
|
142
142
|
function formatProjectName(input) {
|
|
@@ -147,7 +147,7 @@ function formatProjectName(input) {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
function isEmptyDir(path) {
|
|
150
|
-
const files =
|
|
150
|
+
const files = external_fs_default.readdirSync(path);
|
|
151
151
|
return 0 === files.length || 1 === files.length && '.git' === files[0];
|
|
152
152
|
}
|
|
153
153
|
async function getAppTemplateName({ roleType, framework }, { template }) {
|
|
@@ -156,7 +156,7 @@ async function getAppTemplateName({ roleType, framework }, { template }) {
|
|
|
156
156
|
}
|
|
157
157
|
async function getLibTemplateName({ template, role }) {
|
|
158
158
|
if (template) return `${template}-ts`;
|
|
159
|
-
const templateName = checkCancel(await (
|
|
159
|
+
const templateName = checkCancel(await prompts_select({
|
|
160
160
|
message: 'Select template',
|
|
161
161
|
options: [
|
|
162
162
|
{
|
|
@@ -165,7 +165,7 @@ async function getLibTemplateName({ template, role }) {
|
|
|
165
165
|
}
|
|
166
166
|
]
|
|
167
167
|
}));
|
|
168
|
-
const tools = checkCancel(await
|
|
168
|
+
const tools = checkCancel(await multiselect({
|
|
169
169
|
message: 'Select development tools (Use <space> to select, <enter> to continue)',
|
|
170
170
|
required: false,
|
|
171
171
|
options: [
|
|
@@ -190,7 +190,7 @@ function getTemplateDir(templateName) {
|
|
|
190
190
|
return `templates/${templateName}/`;
|
|
191
191
|
}
|
|
192
192
|
async function getProjectType(template) {
|
|
193
|
-
if (!template) return checkCancel(await (
|
|
193
|
+
if (!template) return checkCancel(await prompts_select({
|
|
194
194
|
message: 'Please select the type of project you want to create:',
|
|
195
195
|
options: [
|
|
196
196
|
{
|
|
@@ -214,7 +214,7 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
214
214
|
let framework = 'modern';
|
|
215
215
|
let roleType = "provider";
|
|
216
216
|
if (!argv?.template && 'app' === projectType) {
|
|
217
|
-
framework = checkCancel(await (
|
|
217
|
+
framework = checkCancel(await prompts_select({
|
|
218
218
|
message: 'Select template',
|
|
219
219
|
options: [
|
|
220
220
|
{
|
|
@@ -227,7 +227,7 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
227
227
|
}
|
|
228
228
|
]
|
|
229
229
|
}));
|
|
230
|
-
roleType = argv.role || checkCancel(await (
|
|
230
|
+
roleType = argv.role || checkCancel(await prompts_select({
|
|
231
231
|
message: 'Please select the role of project you want to create:',
|
|
232
232
|
initialValue: 'provider',
|
|
233
233
|
options: [
|
|
@@ -273,7 +273,7 @@ async function forgeTemplate({ projectType, argv, templateParameters, distFolder
|
|
|
273
273
|
await renderTemplate(templateDir);
|
|
274
274
|
}
|
|
275
275
|
async function create({ name, templates }) {
|
|
276
|
-
const argv = (
|
|
276
|
+
const argv = external_minimist_default(process.argv.slice(2), {
|
|
277
277
|
alias: {
|
|
278
278
|
h: 'help',
|
|
279
279
|
d: 'dir',
|
|
@@ -283,7 +283,7 @@ async function create({ name, templates }) {
|
|
|
283
283
|
}
|
|
284
284
|
});
|
|
285
285
|
console.log('');
|
|
286
|
-
|
|
286
|
+
logger.greet(`\u{25C6} Create ${upperFirst(name)} Project`);
|
|
287
287
|
if (argv.help) return void logHelpMessage(name, templates);
|
|
288
288
|
const cwd = process.cwd();
|
|
289
289
|
const pkgInfo = pkgFromUserAgent(process.env['npm_config_user_agent']);
|
|
@@ -294,18 +294,18 @@ async function create({ name, templates }) {
|
|
|
294
294
|
if ("zephyr" === projectType) {
|
|
295
295
|
const zephyrPackage = OTHER_TYPE['zephyr'].packageName;
|
|
296
296
|
const zephyrCommand = `${pkgManager} create ${zephyrPackage}`;
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
note(`Running: ${zephyrCommand}`, 'Launching Zephyr setup');
|
|
298
|
+
spawnSync(pkgManager, [
|
|
299
299
|
'create',
|
|
300
300
|
zephyrPackage
|
|
301
301
|
], {
|
|
302
302
|
stdio: 'inherit',
|
|
303
303
|
shell: true
|
|
304
304
|
});
|
|
305
|
-
|
|
305
|
+
outro('Done.');
|
|
306
306
|
return;
|
|
307
307
|
}
|
|
308
|
-
const mfName = argv.name || checkCancel(await (
|
|
308
|
+
const mfName = argv.name || checkCancel(await prompts_text({
|
|
309
309
|
message: 'Please input Module Federation name:',
|
|
310
310
|
placeholder: 'mf_project_name',
|
|
311
311
|
defaultValue: 'mf_project_name',
|
|
@@ -313,10 +313,10 @@ async function create({ name, templates }) {
|
|
|
313
313
|
if (0 === value.length) return 'Name is required';
|
|
314
314
|
}
|
|
315
315
|
}));
|
|
316
|
-
const { targetDir } = formatProjectName(
|
|
317
|
-
const distFolder =
|
|
318
|
-
if (!argv.override &&
|
|
319
|
-
const option = checkCancel(await (
|
|
316
|
+
const { targetDir } = formatProjectName(external_path_default.join(argv.dir || mfName));
|
|
317
|
+
const distFolder = external_path_default.isAbsolute(targetDir) ? targetDir : external_path_default.join(cwd, targetDir);
|
|
318
|
+
if (!argv.override && external_fs_default.existsSync(distFolder) && !isEmptyDir(distFolder)) {
|
|
319
|
+
const option = checkCancel(await prompts_select({
|
|
320
320
|
message: `"${targetDir}" is not empty, please choose:`,
|
|
321
321
|
options: [
|
|
322
322
|
{
|
|
@@ -345,8 +345,8 @@ async function create({ name, templates }) {
|
|
|
345
345
|
`${pkgManager} install`,
|
|
346
346
|
`${pkgManager} run ${"lib" === projectType ? 'mf-dev' : 'dev'}`
|
|
347
347
|
];
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
note(nextSteps.join('\n'), 'Next steps');
|
|
349
|
+
outro('Done.');
|
|
350
350
|
}
|
|
351
351
|
const TEMPLATES = [
|
|
352
352
|
'provider-modern',
|
package/package.json
CHANGED