@modern-js/main-doc 2.21.1 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -0
- package/docs/en/apis/app/commands.mdx +5 -5
- package/docs/en/apis/app/hooks/api/api.mdx +80 -0
- package/docs/en/apis/app/hooks/api/app.mdx +12 -0
- package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
- package/docs/en/apis/app/hooks/api/test.mdx +1 -1
- package/docs/en/apis/app/hooks/config/html.mdx +2 -2
- package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/public.mdx +10 -10
- package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
- package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
- package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
- package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
- package/docs/en/apis/app/hooks/server/test.mdx +5 -2
- package/docs/en/apis/app/hooks/shared.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +17 -27
- package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
- package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
- package/docs/en/apis/app/hooks/src/server.mdx +1 -1
- package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
- package/docs/en/apis/app/hooks/src/test.mdx +4 -3
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
- package/docs/en/components/init-app.mdx +3 -3
- package/docs/en/components/init-rspack-app.mdx +4 -4
- package/docs/en/components/language-config.mdx +9 -0
- package/docs/en/components/package-manager.mdx +11 -0
- package/docs/en/components/ua-polyfill.mdx +2 -2
- package/docs/en/configure/app/source/config-dir.mdx +1 -1
- package/docs/en/configure/app/source/design-system.mdx +67 -67
- package/docs/en/configure/app/source/disable-default-entries.mdx +6 -5
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +5 -5
- package/docs/en/configure/app/source/enable-async-entry.mdx +9 -9
- package/docs/en/configure/app/source/entries-dir.mdx +3 -3
- package/docs/en/configure/app/source/entries.mdx +21 -19
- package/docs/en/configure/app/tools/swc.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
- package/docs/en/guides/advanced-features/rspack-start.mdx +6 -6
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/testing.mdx +2 -2
- package/docs/en/guides/advanced-features/web-server.mdx +2 -2
- package/docs/en/guides/basic-features/css.mdx +2 -2
- package/docs/en/guides/basic-features/mock.mdx +1 -1
- package/docs/en/guides/basic-features/routes.mdx +11 -7
- package/docs/en/guides/concept/entries.mdx +3 -3
- package/docs/en/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/create/config.mdx +75 -0
- package/docs/en/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/en/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/en/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/new/config.md +155 -0
- package/docs/en/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/en/guides/topic-detail/generator/new/use.md +95 -0
- package/docs/en/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/en/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +49 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/en/guides/topic-detail/generator/plugin/category.md +88 -0
- package/docs/en/guides/topic-detail/generator/plugin/context.md +104 -0
- package/docs/en/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/en/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
- package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
- package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
- package/docs/zh/apis/app/commands.mdx +3 -3
- package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
- package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
- package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
- package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
- package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
- package/docs/zh/apis/app/hooks/shared.mdx +1 -1
- package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
- package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
- package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
- package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/zh/components/language-config.mdx +9 -0
- package/docs/zh/components/package-manager.mdx +11 -0
- package/docs/zh/components/ua-polyfill.mdx +1 -1
- package/docs/zh/configure/app/source/design-system.mdx +3 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +2 -5
- package/docs/zh/configure/app/source/entries.mdx +2 -2
- package/docs/zh/configure/app/tools/swc.mdx +2 -2
- package/docs/zh/guides/advanced-features/rspack-start.mdx +6 -6
- package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
- package/docs/zh/guides/advanced-features/testing.mdx +2 -2
- package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
- package/docs/zh/guides/basic-features/css.mdx +1 -1
- package/docs/zh/guides/basic-features/mock.mdx +1 -1
- package/docs/zh/guides/basic-features/routes.mdx +7 -4
- package/docs/zh/guides/concept/entries.mdx +3 -3
- package/docs/zh/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/create/config.mdx +76 -0
- package/docs/zh/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/zh/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/new/config.md +153 -0
- package/docs/zh/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/zh/guides/topic-detail/generator/new/use.md +94 -0
- package/docs/zh/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/zh/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +50 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/zh/guides/topic-detail/generator/plugin/category.md +93 -0
- package/docs/zh/guides/topic-detail/generator/plugin/context.md +105 -0
- package/docs/zh/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/zh/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
- package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
- package/package.json +5 -5
- package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
- package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
- package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/en/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/en/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/codesmith/api/git.mdx +0 -50
- package/docs/en/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -57
- package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -48
- package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/en/guides/topic-detail/generator/codesmith/introduce.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/en/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/en/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/en/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/en/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/en/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -58
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/en/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/en/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -31
- package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/en/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -90
- package/docs/en/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/en/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -18
- package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/en/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/en/guides/topic-detail/generator/project.mdx +0 -118
- package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/zh/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/zh/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/codesmith/api/git.mdx +0 -49
- package/docs/zh/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/zh/guides/topic-detail/generator/codesmith/introduce.mdx +0 -59
- package/docs/zh/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/zh/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/zh/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/zh/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/zh/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/zh/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -55
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -57
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -29
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/zh/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -92
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/zh/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/zh/guides/topic-detail/generator/project.mdx +0 -118
@@ -1,89 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 2
|
3
|
-
---
|
4
|
-
|
5
|
-
# The composition of the microgenerator
|
6
|
-
|
7
|
-
A microgenerator project is a module project or an Npm package that contains several basic parts:
|
8
|
-
|
9
|
-
## package.json
|
10
|
-
|
11
|
-
NPM package description information, including name, version, main and other fields.
|
12
|
-
|
13
|
-
## Entry file
|
14
|
-
|
15
|
-
The js file corresponding to the above main field. The file exports a generator function by default, and the function format is as follows:
|
16
|
-
|
17
|
-
```ts
|
18
|
-
export default async (
|
19
|
-
context: GeneratorContext,
|
20
|
-
generator: GeneratorCore,
|
21
|
-
) => {};
|
22
|
-
```
|
23
|
-
|
24
|
-
The function parameters are context and generator:
|
25
|
-
|
26
|
-
### context
|
27
|
-
|
28
|
-
Context provides context information maintained by the codesmith runtime. Its type is defined as:
|
29
|
-
|
30
|
-
```ts
|
31
|
-
interface GeneratorContext {
|
32
|
-
materials: Record<string, FsMaterial>;
|
33
|
-
config: Record<string, any>;
|
34
|
-
data?: Record<string, any>;
|
35
|
-
current: { material: FsMaterial } | null;
|
36
|
-
[key: string]: any;
|
37
|
-
}
|
38
|
-
```
|
39
|
-
|
40
|
-
Materials is an abstract file system for codesmith that maintains the mapping between generator names and actionable files.
|
41
|
-
|
42
|
-
Materials also maintains this default mapping relationship, which is used to maintain the resource information of the current generator execution directory, and can operate on the target project resources through this field.
|
43
|
-
|
44
|
-
For example, when you need to modify a field in the `package.json` of the current project:
|
45
|
-
|
46
|
-
```ts
|
47
|
-
const resource = context.materials.default.get(
|
48
|
-
path.join(appDir, 'package.json'),
|
49
|
-
);
|
50
|
-
```
|
51
|
-
|
52
|
-
Pass the acquired resources to the JSON API provided by codesmith to implement json operations.
|
53
|
-
|
54
|
-
The currently running generator file resource is maintained on the current field of `GeneratorContext`, and the current `FsMaterial` can be obtained through `current.material`.
|
55
|
-
|
56
|
-
The get method is provided in `FsMaterial` to get the resource file and pass the resource file to the API supported by the generator to process the template file.
|
57
|
-
|
58
|
-
For example:
|
59
|
-
|
60
|
-
```ts
|
61
|
-
const resourceMap = await material.find('templates/**/*');
|
62
|
-
```
|
63
|
-
|
64
|
-
All template files in the generator that match to the `templates /**/*` rules can be obtained in the above way, and the resource files can be operated by traversing the object.
|
65
|
-
|
66
|
-
### generator
|
67
|
-
|
68
|
-
Generator provides the function method of the codesmith runtime. Its type is defined as:
|
69
|
-
|
70
|
-
```ts
|
71
|
-
interface GeneratorCore {
|
72
|
-
logger: Logger;
|
73
|
-
outputPath: string;
|
74
|
-
output: {
|
75
|
-
fs: (file: string | number, data: any, options?: string | fs.WriteFileOptions | undefined) => Promise<void>
|
76
|
-
};
|
77
|
-
runSubGenerator: (subGenerator: string, relativePwdPath?: string | undefined, config?: Record<string, any> | undefined): Promise<void>
|
78
|
-
}
|
79
|
-
```
|
80
|
-
|
81
|
-
The outputPath and the `materials.default` in the context point to the same directory, the outputPath is used to directly calculate the target path and operate, and the `materials.default` is used to obtain resource files.
|
82
|
-
|
83
|
-
`runSubGenerator` provides a way to run other microgenerators in one microgenerator, which will automatically update and maintain new context information.
|
84
|
-
|
85
|
-
## Template File
|
86
|
-
|
87
|
-
Generator template file.
|
88
|
-
|
89
|
-
It is recommended to create a templates directory in the project root directory to maintain the template file of the microgenerator. During the execution of the microgenerator, you can only use your own template file. For template files that need to be shared, it is recommended to use a shared sub-generator implementation.
|
@@ -1,82 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 2
|
3
|
-
---
|
4
|
-
|
5
|
-
# Web App
|
6
|
-
|
7
|
-
## Project creation
|
8
|
-
|
9
|
-
When creating a project, the configuration used by `@modern-js/create` when using the `--config` parameter, and the configuration used when modifying and adding input in the generator plugin.
|
10
|
-
|
11
|
-
The application project creation parameters are [Generator Configuration](/guides/topic-detail/generator/config/common).
|
12
|
-
|
13
|
-
## New Command
|
14
|
-
|
15
|
-
The new command configuration in the application project can be used through the `--config` parameter configuration when executing the new command, or when creating elements and enabling functions in the generator plugin.
|
16
|
-
|
17
|
-
### actionType
|
18
|
-
|
19
|
-
The action type (actionType) of the New command , the type supports two types:
|
20
|
-
|
21
|
-
- element: reate engineering elements
|
22
|
-
|
23
|
-
- function: enable function
|
24
|
-
|
25
|
-
:::info
|
26
|
-
This parameter is not required when using the enable function and creating elements in the generator plugin, it is automatically added in the generator plugin.
|
27
|
-
|
28
|
-
:::
|
29
|
-
|
30
|
-
### element
|
31
|
-
|
32
|
-
Element name (element), supports two options:
|
33
|
-
|
34
|
-
- Create an application entry(entry)
|
35
|
-
|
36
|
-
- Create customized server dir(server)
|
37
|
-
|
38
|
-
The entry also need to be used in conjunction with the specific configuration, which is described as follows:
|
39
|
-
|
40
|
-
#### name
|
41
|
-
|
42
|
-
Entry name (name), character `string` type.
|
43
|
-
|
44
|
-
### function
|
45
|
-
|
46
|
-
Optional function name (function), supports the following options:
|
47
|
-
|
48
|
-
- Tailwind CSS(tailwindcss)
|
49
|
-
|
50
|
-
- BFF(bff)
|
51
|
-
|
52
|
-
- SSG(ssg)
|
53
|
-
|
54
|
-
- Micro Frontend(micro_frontend)
|
55
|
-
|
56
|
-
- Unit Test / Integration Test(test)
|
57
|
-
|
58
|
-
- Storybook(mwa_storybook)
|
59
|
-
|
60
|
-
- UA-based Polyfill Feature'(polyfill)
|
61
|
-
|
62
|
-
- Global Proxy(proxy)
|
63
|
-
|
64
|
-
`bff` also need to be used in conjunction with configuration, as described below:
|
65
|
-
|
66
|
-
#### BFF parameters
|
67
|
-
|
68
|
-
##### bffType
|
69
|
-
|
70
|
-
BFF type (bffType), supports two options:
|
71
|
-
|
72
|
-
- Function mode(function)
|
73
|
-
|
74
|
-
- Framework mode(framework)
|
75
|
-
|
76
|
-
##### framework
|
77
|
-
|
78
|
-
BFF runtime framework (framework), supports two options:
|
79
|
-
|
80
|
-
- Express(express)
|
81
|
-
|
82
|
-
- Koa(koa)
|
@@ -1,100 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 1
|
3
|
-
---
|
4
|
-
|
5
|
-
# Generator Configuration
|
6
|
-
|
7
|
-
### solution
|
8
|
-
|
9
|
-
Engineering solution type (solution), the options are as follows:
|
10
|
-
|
11
|
-
- Application(mwa)
|
12
|
-
|
13
|
-
- Module(module)
|
14
|
-
|
15
|
-
- Monorepo
|
16
|
-
|
17
|
-
:::info
|
18
|
-
Solution configuration can only be used in the `--config` parameter of `@modern-js/create`, not by setting the default value in the generator plugin.
|
19
|
-
|
20
|
-
:::
|
21
|
-
|
22
|
-
### scenes
|
23
|
-
|
24
|
-
Project scenarios (scenes), when using the generator plugin that creates the project scene type, this value is the key value of the corresponding generator plugin.
|
25
|
-
|
26
|
-
:::info
|
27
|
-
scenes configuration can only be used in the `--config` parameter of `@modern-js/create`, not by setting the default value in the generator plugin.
|
28
|
-
|
29
|
-
:::
|
30
|
-
|
31
|
-
### language
|
32
|
-
|
33
|
-
Development language (language), the options are as follows:
|
34
|
-
|
35
|
-
- TS(ts)
|
36
|
-
|
37
|
-
- ES6+(js)
|
38
|
-
|
39
|
-
### packageManager
|
40
|
-
|
41
|
-
Package management tool (packageManager), the options are as follows:
|
42
|
-
|
43
|
-
- pnpm(pnpm)
|
44
|
-
|
45
|
-
- Yarn(yarn)
|
46
|
-
|
47
|
-
:::info
|
48
|
-
In the custom type of the generator plugin to create a project scenario, only the `packageManager` configuration is provided by default.
|
49
|
-
|
50
|
-
:::
|
51
|
-
|
52
|
-
## Other configurations
|
53
|
-
|
54
|
-
### noNeedInstall
|
55
|
-
|
56
|
-
- **Type:** `boolean`
|
57
|
-
- **Default:** `false`
|
58
|
-
|
59
|
-
Whether to skip the dependency installation.
|
60
|
-
|
61
|
-
### noNeedGit
|
62
|
-
|
63
|
-
- **Type:** `boolean`
|
64
|
-
- **Default:** `false`
|
65
|
-
|
66
|
-
Whether to skip git initialization and commit initial commit.
|
67
|
-
|
68
|
-
### successInfo
|
69
|
-
|
70
|
-
- **Type:** `string`
|
71
|
-
- **Default:** Command operation prompts for different project schemes.
|
72
|
-
|
73
|
-
Customize prompt information to create project success.
|
74
|
-
|
75
|
-
### isMonorepoSubProject
|
76
|
-
|
77
|
-
- **Type:** `boolean`
|
78
|
-
- **Default:** `false`
|
79
|
-
|
80
|
-
Whether it is a Monorepo subproject.
|
81
|
-
|
82
|
-
### isTest
|
83
|
-
|
84
|
-
- **Type:** `boolean`
|
85
|
-
- **Default:** `false`
|
86
|
-
|
87
|
-
Works on an Application project to identify whether it is a test project.
|
88
|
-
|
89
|
-
- `true`: create project to `examples/`
|
90
|
-
- `false`: create project to `apps/`
|
91
|
-
|
92
|
-
### isPublic
|
93
|
-
|
94
|
-
- **Type:** `boolean`
|
95
|
-
- **Default:** `false`
|
96
|
-
|
97
|
-
Used in the Module project to identify whether it needs to be published to npm.
|
98
|
-
|
99
|
-
- `true`: create project to `packages/`
|
100
|
-
- `false`: create project to `features/`
|
@@ -1,42 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 3
|
3
|
-
---
|
4
|
-
|
5
|
-
# Module
|
6
|
-
|
7
|
-
## Project creation
|
8
|
-
|
9
|
-
When creating a project, the configuration used by `@modern-js/create` when using the `--config` parameter, and the configuration used when modifying and adding input in the generator plugin.
|
10
|
-
|
11
|
-
The application project creation parameters are [Generator Configuration](/guides/topic-detail/generator/config/common).
|
12
|
-
|
13
|
-
### packageName
|
14
|
-
|
15
|
-
Package name (packageName), character string type.
|
16
|
-
|
17
|
-
## New Command
|
18
|
-
|
19
|
-
The new command configuration in the module project can be used through the `--config` parameter configuration when executing the new command, or when enabling functions in the generator plugin.
|
20
|
-
|
21
|
-
### actionType
|
22
|
-
|
23
|
-
The action type (actionType) of the New command, he type supports one:
|
24
|
-
|
25
|
-
- function: enable function
|
26
|
-
|
27
|
-
:::info
|
28
|
-
This parameter is not required when using the enable function and creating elements in the generator plugin, it is automatically added in the generator plugin.
|
29
|
-
|
30
|
-
:::
|
31
|
-
|
32
|
-
### function
|
33
|
-
|
34
|
-
Optional function name (function), supports the following options:
|
35
|
-
|
36
|
-
- Tailwind CSS(tailwindcss)
|
37
|
-
|
38
|
-
- Storybook(mwa_storybook)
|
39
|
-
|
40
|
-
- Runtime API(runtimeApi)
|
41
|
-
|
42
|
-
- Test(test)
|
@@ -1,28 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 4
|
3
|
-
---
|
4
|
-
|
5
|
-
# Monorepo
|
6
|
-
|
7
|
-
Monorepo projects only need [PackageManager](/guides/topic-detail/generator/config/common#packagemanager).
|
8
|
-
|
9
|
-
## Create subproject
|
10
|
-
|
11
|
-
The Monorepo project supports the creation of sub-projects by using the new command. The sub-project type supports application, test application, module, internal module. In addition to the respective configuration of the application and module, some general sub-project configuration is required here.
|
12
|
-
|
13
|
-
### solution
|
14
|
-
|
15
|
-
Subproject type(solution), the different subproject type fields are:
|
16
|
-
|
17
|
-
- Application (mwa)
|
18
|
-
- Application (Test) (mwa_test)
|
19
|
-
- Module
|
20
|
-
- Modules (internal) (inner_module)
|
21
|
-
|
22
|
-
### packageName
|
23
|
-
|
24
|
-
Subproject name (packageName), character `string` type.
|
25
|
-
|
26
|
-
### packagePath
|
27
|
-
|
28
|
-
Subproject path (packagePath), character `string` type.
|
@@ -1,23 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 1
|
3
|
-
---
|
4
|
-
|
5
|
-
# Why do you need a generator plugin
|
6
|
-
|
7
|
-
Modern.js provides application, modules and Monorepo three engineering solutions, and by using the `@modern-js/create` tool can create the initial project template of the three engineering solutions, the initial project template will provide basic code development environment, simple sample code and configuration, etc.
|
8
|
-
|
9
|
-
Modern.js provides an initialization template that is versatile and can meet some general project development needs.
|
10
|
-
|
11
|
-
When you use Modern.js in depth, you will inevitably find that every time you create a project, you will make some similar changes specific to your own project, such as modifying the sample code, adding some configuration, enabling some functions, etc.
|
12
|
-
|
13
|
-
The generator plugin can help you precipitate these individual or team-specific changes. Simply bring the `--plugin` parameter when executing `npx @modern-js/create@latest` to avoid the need to repeatedly modify the project every time the project is created..
|
14
|
-
|
15
|
-
The generator plugin is based on the initialization template project provided by the Modern.js, providing methods to add, delete and modify templates, and modifying `package.json`, `modernConfig` configuration and opening functions in a fast way.
|
16
|
-
|
17
|
-
The generator plugin provides two ways of customization:
|
18
|
-
|
19
|
-
1. Extended engineering: directly customize the three major engineering provided by default.
|
20
|
-
|
21
|
-
2. Create engineering scenes: Create corresponding engineering scenes based on the default three major engineering.
|
22
|
-
|
23
|
-
The next step will introduce how to use and develop the generator plugin step by step.
|
@@ -1,52 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 4
|
3
|
-
---
|
4
|
-
|
5
|
-
# addFile
|
6
|
-
|
7
|
-
Add a single file. Use to add a single template file to the `templates` directory or add to a template file directly using templates.
|
8
|
-
|
9
|
-
This method can be used with any file type, for file types other than binary, Handlebars render is performed when files are added.
|
10
|
-
|
11
|
-
This method is available on the `onForged` time to live API parameter.
|
12
|
-
|
13
|
-
Its type is defined as:
|
14
|
-
|
15
|
-
```ts
|
16
|
-
export interface AddFileParams {
|
17
|
-
type: FileType;
|
18
|
-
file: string;
|
19
|
-
template?: string;
|
20
|
-
templateFile?: string;
|
21
|
-
force?: boolean;
|
22
|
-
data?: Record<string, string>;
|
23
|
-
}
|
24
|
-
export type ForgedAPI = {
|
25
|
-
addFile: (params: AddFileParams) => Promise<void>;
|
26
|
-
...
|
27
|
-
};
|
28
|
-
```
|
29
|
-
|
30
|
-
## type
|
31
|
-
|
32
|
-
File type, specific viewable[File type](/guides/topic-detail/generator/plugin/api/file/introduce).
|
33
|
-
|
34
|
-
## file
|
35
|
-
|
36
|
-
The path to the created target file.
|
37
|
-
|
38
|
-
## template
|
39
|
-
|
40
|
-
File template, configuration This field value can be used directly for template render files. The priority is lower than `templateFile`.
|
41
|
-
|
42
|
-
## templateFile
|
43
|
-
|
44
|
-
Template file, the template file path used for rendering, its value is the relative path of `templates`.
|
45
|
-
|
46
|
-
## force
|
47
|
-
|
48
|
-
Whether to force coverage, when the added file already exists, an error will be reported in conflict by default. When setting this value to true, coverage can be forced.
|
49
|
-
|
50
|
-
## data
|
51
|
-
|
52
|
-
Handlebars renders data.
|
@@ -1,26 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 2
|
3
|
-
---
|
4
|
-
|
5
|
-
# addHelper
|
6
|
-
|
7
|
-
For text files, add a customized Help function of Handlebars, the specific viewable document[Custom Helpers](https://handlebarsjs.com/guide/#custom-helpers).
|
8
|
-
|
9
|
-
This method is available on the `onForged` time to live API parameter.
|
10
|
-
|
11
|
-
Its type is defined as:
|
12
|
-
|
13
|
-
```ts
|
14
|
-
export type ForgedAPI = {
|
15
|
-
addHelper: (name: string, fn: Handlebars.HelperDelegate) => void;
|
16
|
-
...
|
17
|
-
};
|
18
|
-
```
|
19
|
-
|
20
|
-
## name
|
21
|
-
|
22
|
-
help function name.
|
23
|
-
|
24
|
-
## fn
|
25
|
-
|
26
|
-
help function.
|
@@ -1,58 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 5
|
3
|
-
---
|
4
|
-
|
5
|
-
# addManyFile
|
6
|
-
|
7
|
-
Import in batches file. Multiple files for adding the `templates` directory.
|
8
|
-
|
9
|
-
This method can be used with any file type, for file types other than binary, Handlebars render is performed when files are added.
|
10
|
-
|
11
|
-
This method is available on the `onForged` time to live API parameter.
|
12
|
-
|
13
|
-
Its type is defined as:
|
14
|
-
|
15
|
-
```ts
|
16
|
-
export interface AddManyFilesParams {
|
17
|
-
type: FileType;
|
18
|
-
destination: string;
|
19
|
-
templateFiles: string[] | (() => string[]);
|
20
|
-
templateBase?: string;
|
21
|
-
fileNameFunc?: (name: string) => string;
|
22
|
-
data?: Record<string, string>; // template data
|
23
|
-
}
|
24
|
-
export type ForgedAPI = {
|
25
|
-
addManyFiles: (params: AddManyFilesParams) => Promise<void>;
|
26
|
-
...
|
27
|
-
};
|
28
|
-
```
|
29
|
-
|
30
|
-
## type
|
31
|
-
|
32
|
-
File type, specific viewable[File type](/guides/topic-detail/generator/plugin/api/file/introduce).
|
33
|
-
|
34
|
-
## destination
|
35
|
-
|
36
|
-
Create the target folder path. Since it is an import in batches file, fill in the folder path that needs to be written here.
|
37
|
-
|
38
|
-
## templateFiles
|
39
|
-
|
40
|
-
List of template files.
|
41
|
-
|
42
|
-
This parameter supports the function parameter, as well as [globby](https://www.npmjs.com/package/globby).
|
43
|
-
|
44
|
-
## templateBase
|
45
|
-
|
46
|
-
Template base path.
|
47
|
-
|
48
|
-
The template path is usually the template file in the same directory. If the render result needs to remove the template file prefix directory, this field can be used.
|
49
|
-
|
50
|
-
Template render file content will be equal to `templateFiles - templateBase`
|
51
|
-
|
52
|
-
## fileNameFunc
|
53
|
-
|
54
|
-
Rename file function, where the file name of render is passed in once, and can be renamed in this function.
|
55
|
-
|
56
|
-
## data
|
57
|
-
|
58
|
-
Handlebars renders data.
|
@@ -1,26 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 3
|
3
|
-
---
|
4
|
-
|
5
|
-
# addPartial
|
6
|
-
|
7
|
-
For text files, add a customized Partial fragment of Handlebars, the specific viewable document [Partials](https://handlebarsjs.com/guide/#partials).
|
8
|
-
|
9
|
-
This method is available on the `onForged` time to live API parameter.
|
10
|
-
|
11
|
-
Its type is defined as:
|
12
|
-
|
13
|
-
```ts
|
14
|
-
export type ForgedAPI = {
|
15
|
-
addPartial: (name: string, str: Handlebars.Template) => void;
|
16
|
-
...
|
17
|
-
};
|
18
|
-
```
|
19
|
-
|
20
|
-
## name
|
21
|
-
|
22
|
-
partial name.
|
23
|
-
|
24
|
-
## str
|
25
|
-
|
26
|
-
partial template string.
|
@@ -1,39 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 1
|
3
|
-
---
|
4
|
-
|
5
|
-
# Introduction
|
6
|
-
|
7
|
-
The file operation API can be used in the `onForged` time to live function, which can add, delete and change the current project file.
|
8
|
-
|
9
|
-
File operation API related path to fill in the project relative path, generator plugin will automatically add the current project path prefix.
|
10
|
-
|
11
|
-
## File type
|
12
|
-
|
13
|
-
The generator plugin divides file types into the following categories:
|
14
|
-
|
15
|
-
- Text files: plain text content files, files that can be templated using handlebars.
|
16
|
-
|
17
|
-
- Binary files: pictures, audio, video and other files.
|
18
|
-
|
19
|
-
:::warning
|
20
|
-
The jsx or tsx file using the variable is a binary file, and its syntax conflicts with handlebars render, which will cause the template file failed to create.
|
21
|
-
|
22
|
-
:::
|
23
|
-
|
24
|
-
- JSON files: Files in JSON format, such as `package.json`, `tsconfig.json`.
|
25
|
-
|
26
|
-
- Text List File: A file consisting of lines of text, such as `.gitignore`, `.editorconfig`, `.npmrc`.
|
27
|
-
|
28
|
-
The file manipulation API for the generator plugin will operate on these four file types.
|
29
|
-
|
30
|
-
Its type is defined as:
|
31
|
-
|
32
|
-
```ts
|
33
|
-
export enum FileType {
|
34
|
-
Text = 'text',
|
35
|
-
Binary = 'binary',
|
36
|
-
Json = 'json',
|
37
|
-
TextRaw = 'textRaw',
|
38
|
-
}
|
39
|
-
```
|
@@ -1,24 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 10
|
3
|
-
---
|
4
|
-
|
5
|
-
# rmDir
|
6
|
-
|
7
|
-
Delete folder. This method deletes all files under the folder in recursion.
|
8
|
-
|
9
|
-
This method can be used for any file type.
|
10
|
-
|
11
|
-
This method is available on the `onForged` time to live API parameter.
|
12
|
-
|
13
|
-
Its type is defined as:
|
14
|
-
|
15
|
-
```ts
|
16
|
-
export type ForgedAPI = {
|
17
|
-
rmDir: (dirName: string) => Promise<void>;
|
18
|
-
...
|
19
|
-
};
|
20
|
-
```
|
21
|
-
|
22
|
-
## dirName
|
23
|
-
|
24
|
-
The folder name or folder path to delete.
|
@@ -1,24 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 9
|
3
|
-
---
|
4
|
-
|
5
|
-
# rmFile
|
6
|
-
|
7
|
-
Delete the file.
|
8
|
-
|
9
|
-
This method can be used for any file type.
|
10
|
-
|
11
|
-
This method is available on the `onForged` time to live API parameter.
|
12
|
-
|
13
|
-
Its type is defined as:
|
14
|
-
|
15
|
-
```ts
|
16
|
-
export type ForgedAPI = {
|
17
|
-
rmFile: (fileName: string) => Promise<void>;
|
18
|
-
...
|
19
|
-
};
|
20
|
-
```
|
21
|
-
|
22
|
-
## fileName
|
23
|
-
|
24
|
-
File name or file path to delete.
|
@@ -1,54 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 6
|
3
|
-
---
|
4
|
-
|
5
|
-
# updateJSONFile
|
6
|
-
|
7
|
-
Update the JSON file fields.
|
8
|
-
|
9
|
-
This method is suitable for JSON file types, and can batch update field values in JSON files.
|
10
|
-
|
11
|
-
This method is available on the `onForged` time to live API parameter.
|
12
|
-
|
13
|
-
Its type is defined as:
|
14
|
-
|
15
|
-
```ts
|
16
|
-
export type ForgedAPI = {
|
17
|
-
updateJSONFile: (
|
18
|
-
fileName: string,
|
19
|
-
updateInfo: Record<string, unknown>,
|
20
|
-
) => Promise<void>;
|
21
|
-
...
|
22
|
-
};
|
23
|
-
```
|
24
|
-
|
25
|
-
## fileName
|
26
|
-
|
27
|
-
The filename or file path of the JSON file.
|
28
|
-
|
29
|
-
## updateInfo
|
30
|
-
|
31
|
-
Field update information.
|
32
|
-
|
33
|
-
This information is represented in Record form.
|
34
|
-
|
35
|
-
For example, the name field needs to be updated:
|
36
|
-
|
37
|
-
```ts
|
38
|
-
api.updateJSONFile(file, {
|
39
|
-
name: 'new name',
|
40
|
-
});
|
41
|
-
```
|
42
|
-
|
43
|
-
Nested fields need to be updated:
|
44
|
-
|
45
|
-
```ts
|
46
|
-
api.updateJSONFile(file, {
|
47
|
-
'dependencies.name': 'new name',
|
48
|
-
});
|
49
|
-
```
|
50
|
-
|
51
|
-
:::warning
|
52
|
-
Pay attention to the field name when updating the nested field. If it is not a total volume update, the nested key should also be written into the field name.
|
53
|
-
|
54
|
-
:::
|