@modern-js/main-doc 2.60.6 → 2.61.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +86 -33
  2. package/docs/en/components/init-app.mdx +0 -1
  3. package/docs/en/components/init-rspack-app.mdx +0 -1
  4. package/docs/en/guides/advanced-features/source-build.mdx +11 -4
  5. package/docs/en/guides/basic-features/deploy.mdx +104 -2
  6. package/docs/en/guides/concept/entries.mdx +58 -5
  7. package/docs/en/guides/get-started/introduction.mdx +1 -38
  8. package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +86 -33
  9. package/docs/zh/components/default-mwa-generate.mdx +0 -1
  10. package/docs/zh/components/init-app.mdx +0 -1
  11. package/docs/zh/components/init-rspack-app.mdx +0 -1
  12. package/docs/zh/guides/advanced-features/source-build.mdx +11 -4
  13. package/docs/zh/guides/basic-features/deploy.mdx +103 -5
  14. package/docs/zh/guides/concept/entries.mdx +52 -4
  15. package/docs/zh/guides/get-started/introduction.mdx +1 -36
  16. package/package.json +4 -4
  17. package/src/i18n/enUS.ts +0 -7
  18. package/src/i18n/zhCN.ts +0 -7
  19. package/src/pages/index.tsx +3 -32
  20. package/docs/en/guides/topic-detail/generator/_meta.json +0 -17
  21. package/docs/en/guides/topic-detail/generator/create/_meta.json +0 -1
  22. package/docs/en/guides/topic-detail/generator/create/config.mdx +0 -59
  23. package/docs/en/guides/topic-detail/generator/create/option.md +0 -146
  24. package/docs/en/guides/topic-detail/generator/create/use.mdx +0 -48
  25. package/docs/en/guides/topic-detail/generator/new/_meta.json +0 -1
  26. package/docs/en/guides/topic-detail/generator/new/config.md +0 -115
  27. package/docs/en/guides/topic-detail/generator/new/option.md +0 -67
  28. package/docs/en/guides/topic-detail/generator/new/use.md +0 -75
  29. package/docs/en/guides/topic-detail/generator/plugin/_meta.json +0 -11
  30. package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +0 -49
  31. package/docs/en/guides/topic-detail/generator/plugin/api/context.md +0 -184
  32. package/docs/en/guides/topic-detail/generator/plugin/api/input.md +0 -124
  33. package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +0 -310
  34. package/docs/en/guides/topic-detail/generator/plugin/category.md +0 -88
  35. package/docs/en/guides/topic-detail/generator/plugin/context.md +0 -104
  36. package/docs/en/guides/topic-detail/generator/plugin/structure.md +0 -106
  37. package/docs/en/guides/topic-detail/generator/plugin/use.md +0 -33
  38. package/docs/zh/guides/topic-detail/generator/_meta.json +0 -17
  39. package/docs/zh/guides/topic-detail/generator/create/_meta.json +0 -1
  40. package/docs/zh/guides/topic-detail/generator/create/config.mdx +0 -60
  41. package/docs/zh/guides/topic-detail/generator/create/option.md +0 -146
  42. package/docs/zh/guides/topic-detail/generator/create/use.mdx +0 -48
  43. package/docs/zh/guides/topic-detail/generator/new/_meta.json +0 -1
  44. package/docs/zh/guides/topic-detail/generator/new/config.md +0 -116
  45. package/docs/zh/guides/topic-detail/generator/new/option.md +0 -67
  46. package/docs/zh/guides/topic-detail/generator/new/use.md +0 -74
  47. package/docs/zh/guides/topic-detail/generator/plugin/_meta.json +0 -11
  48. package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +0 -50
  49. package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +0 -184
  50. package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +0 -124
  51. package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +0 -310
  52. package/docs/zh/guides/topic-detail/generator/plugin/category.md +0 -93
  53. package/docs/zh/guides/topic-detail/generator/plugin/context.md +0 -105
  54. package/docs/zh/guides/topic-detail/generator/plugin/structure.md +0 -106
  55. package/docs/zh/guides/topic-detail/generator/plugin/use.md +0 -33
@@ -1,115 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # Configuration Parameters
6
-
7
- The `new` command provides the [--config](/guides/topic-detail/generator/new/option.html#-c,---config-<config>) parameter, which is used to specify the answers to interactive questions in advance during the execution process.
8
-
9
- Here, we will introduce the fields and field values that can be configured in the `config` under different scenario.
10
-
11
- ## General Configuration
12
-
13
- ### actionType
14
-
15
- Question: Please select the operation you wants.
16
-
17
- Options:
18
-
19
- - Create project element -- element
20
-
21
- - Enable features -- function
22
-
23
- - Automatic refactors -- refactor
24
-
25
- ## Web App
26
-
27
- ### element
28
-
29
- Question: Please select the type of element to create.
30
-
31
- Options:
32
-
33
- - New "entry" -- entry
34
-
35
- - New "Custom Web Server" source code directory -- server
36
-
37
- ### name
38
-
39
- Question: Please fill in the entry name.
40
-
41
- :::info
42
- This configuration is required when creating a new application entry, and the configuration value is a string.
43
- :::
44
-
45
- ### function
46
-
47
- Question: Please select the feature name.
48
-
49
- Options:
50
-
51
- - Enable Rspack Build -- rspack
52
-
53
- - Enable Tailwind CSS -- tailwindcss
54
-
55
- - Enable BFF -- bff
56
-
57
- - Enable SSG -- ssg
58
-
59
- - Enable SWC Compile -- swc
60
-
61
- - Enable Micro Frontend -- micro_frontend
62
-
63
- - Enable UA-based Polyfill Feature -- polyfill
64
-
65
- - Enable Global Proxy -- proxy
66
-
67
- ### bffType
68
-
69
- Question: Please select the BFF type
70
-
71
- Options:
72
-
73
- - Function -- func
74
-
75
- - Framework -- framework
76
-
77
- :::info
78
- This configuration is required when enabling the BFF function.
79
- :::
80
-
81
- ### framework
82
-
83
- Question: Please select the framework.
84
-
85
- Options:
86
-
87
- - Express -- express
88
-
89
- - Koa -- koa
90
-
91
- :::info
92
- This configuration is required when enabling the BFF function.
93
- :::
94
-
95
- ### refactor
96
-
97
- Question: Please select the type of refactoring.
98
-
99
- Options:
100
-
101
- - Use React Router v5 -- react_router_5
102
-
103
- ## Npm Module
104
-
105
- ### function
106
-
107
- Question: Please select the feature name.
108
-
109
- Options:
110
-
111
- - Enable Tailwind CSS -- tailwindcss
112
-
113
- - Enable Storybook -- storybook
114
-
115
- - Enable Runtime API -- runtime_api
@@ -1,67 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # CLI Parameters
6
-
7
- The `new` command provides many configuration parameters to configure its behavior during execution, which can be viewed using the `--help` parameter:
8
-
9
- ```bash
10
- npm run new --help
11
-
12
- Usage: modern new [options]
13
-
14
- enable optional features or add a new entry
15
-
16
- Options:
17
- --lang <lang> set new command language(en or zh)
18
- -c, --config <config> set default generator config(json string)
19
- -d, --debug using debug mode to log something (default: false)
20
- --dist-tag <tag> use specified tag version for it's generator
21
- --registry <registry> set npm registry url to run npm command
22
- -h, --help display help for command
23
- ```
24
-
25
- The following will provide a detailed introduction to these parameters:
26
-
27
- ## --lang \<lang>
28
-
29
- The language used for execution, supports `zh` and `en`.
30
-
31
- By default, the `new` command will automatically recognize the user's system language and choose to use Chinese or English. If recognition fails or does not meet usage habits, this parameter can be used to manually specify it.
32
-
33
- ## -c, --config \<config>
34
-
35
- Specify the default configuration for the project.
36
-
37
- By default, the `new` command will prompt interactive questions during the execution process for selecting operation types, enabling features, etc. When it is necessary to specify these configuration contents in advance, they can be passed in through this field.
38
-
39
- This field is a JSON string. For example, to specify the BFF framework:
40
-
41
- ```bash
42
- npm run new --config '{"framework": "express"}'
43
- ```
44
-
45
- The parameters supported by `config` can be viewed in [Configuration Parameters](/guides/topic-detail/generator/new/config.html)。
46
-
47
- ## -d,--debug
48
-
49
- Displays debug logs.
50
-
51
- When encountering problems during use, this parameter can be used to display debug logs, which is convenient for quickly locating the problem location and troubleshooting the problem.
52
-
53
- ## --registry \<registry>
54
-
55
- Specify the sub-generator to execute and the npm registry to fetch project dependencies version.
56
-
57
- ## --dist-tag \<distTag>
58
-
59
- Specify the generator version.
60
-
61
- During the execution process of the `new` command, smaller micro-generator will be executed by default, and the latest micro-generator version will be used by default. This parameter can be used to specify the version number of the micro-generator to be executed.
62
-
63
- For example, using the `next` version:
64
-
65
- ```bash
66
- npm run new --dist-tag next
67
- ```
@@ -1,75 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # Usage
6
-
7
- In Web App, Npm Module projects, we provide the `new` command to create project elements, enable features and create sub-project.
8
-
9
- ## Web App
10
-
11
- Web App projects use the `new` command provided by `@modern-js/app-tools`.
12
-
13
-
14
- The `new` command provides three types of operations:
15
-
16
- - Create project elements
17
-
18
- - Enable optional features
19
-
20
- - Automatic refactoring
21
-
22
- Each type of operation provides a corresponding list of supported options, which can be selected based on the project situation.
23
-
24
- For example:
25
-
26
- Create a new application entry:
27
-
28
- ```bash
29
- npm run new
30
- ? Please select the operation you want: Create Element
31
- ? Please select the type of element to create: New "entry"
32
- ? Please fill in the entry name: entry
33
- ```
34
-
35
- After running, a new folder with the corresponding name of the entry will be created in the `src` directory of the project, along with the default entry file. The previous entry files under the `src` directory will be sorted into the folder corresponding to the `name` field in `package.json`.
36
-
37
- Enable BFF function:
38
-
39
- ```bash
40
- npm run new
41
- ? Please select the operation you want: Enable Features
42
- ? Please select the feature name: Enable BFF
43
- ? Please select the BFF type: Function
44
- ? Please select the framework: Express
45
- ```
46
-
47
- After running, BFF-related dependencies will be installed in the project, and an `api` directory will be created for BFF module development, along with prompt information for registering BFF plugins.
48
-
49
- :::info
50
- We did not automatically register the plugin for the user here because the `modern.config.[tj]s` may change during the project lifecycle, and there may be problems with mutual references between modules, so allowing the user to manually register can ensure the correctness of modifying the configuration.
51
-
52
- In subsequent customized development, if there are similar needs, you can also provide users with operational guidance through prompts, allowing users to manually operate on files.
53
- :::
54
-
55
- :::warning
56
- When running the `new` command, it may be necessary to enable a feature that is not in the list. Check whether the corresponding plugin for the feature has been installed in the `package.json` file of the project. If you still need to use the `new` command to enable it, you need to manually remove the plugin dependency first.
57
- :::
58
-
59
- ## Npm Module
60
-
61
- Npm Module projects use the `new` command provided by `@modern-js/module-tools`.
62
-
63
- The `new` command provides the ability to enable optional features.
64
-
65
- For example:
66
-
67
- Enable Storybook capability:
68
-
69
- ```bash
70
- npm run new
71
- ? Please select the operation you want: Enable Features
72
- ? Please select the feature name: Enable Storybook
73
- ```
74
-
75
- After running, Storybook plugin dependencies will be installed in the project, and the `storybook` command will be added. A `stories` directory will be created for Storybook module development, along with prompt information for registering Storybook plugins.
@@ -1,11 +0,0 @@
1
- [
2
- "structure",
3
- "category",
4
- "use",
5
- "context",
6
- {
7
- "type": "dir",
8
- "name": "api",
9
- "label": "API"
10
- }
11
- ]
@@ -1,49 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # afterForged
6
-
7
- `afterForged` is a lifecycle function used for other step operations after file operations in generator plugin.
8
-
9
- ## Types
10
-
11
- ```ts
12
- export type AfterForgedAPI = {
13
- isInGitRepo: () => Promise<boolean>;
14
- initGitRepo: () => Promise<void>;
15
- gitAddAndCommit: (commitMessage: string) => Promise<void>;
16
- install: () => Promise<void>;
17
- };
18
-
19
- export type PluginAfterForgedFunc = (api: AfterForgedAPI, inputData: Record<string, unknown>) => Promise<void>;
20
-
21
- export interface IPluginContext {
22
- afterForged: (func: PluginAfterForgedFunc) => void;
23
- ...
24
- }
25
- ```
26
-
27
- ## API
28
-
29
- The APIs provided by the `api` parameter will be introduced below.
30
-
31
- ### isInGitRepo
32
-
33
- Checks whether the current project is a git repository.
34
-
35
- ### initGitRepo
36
-
37
- Initializes the current project as a git repository.
38
-
39
- ### gitAddAndCommit
40
-
41
- Commits changes to the current repository.
42
-
43
- Parameters:
44
-
45
- - `commitMessage`: commit message.
46
-
47
- ### install
48
-
49
- Installs dependencies in the root directory of the project. The `install` function will use the corresponding package manager according to the value of `packageManager` to install dependencies.
@@ -1,184 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # context
6
-
7
- The generator plugin exports a function by default in the `main` file, and the function parameter is `context`. All APIs provided by the generator plugin are provided by this `context`.
8
-
9
- ## Types
10
-
11
- Let's first understand the type definition of `context`:
12
-
13
- ```ts
14
- export interface IPluginContext {
15
- locale?: string;
16
- addInputBefore: (key: string, input: Schema) => void;
17
- addInputAfter: (key: string, input: Schema) => void;
18
- setInput: (key: string, field: string, value: unknown) => void;
19
- setInputValue: (value: Record<string, unknown>) => void;
20
- setDefaultConfig: (value: Record<string, unknown>) => void;
21
- isFileExist: (fileName: string) => Promise<boolean>;
22
- readDir: (dir: string) => Promise<string[]>;
23
- setGitMessage: (gitMessage: string) => void;
24
- onForged: (func: PluginForgedFunc) => void;
25
- afterForged: (func: PluginAfterForgedFunc) => void;
26
- }
27
- ```
28
-
29
- The contents provided by `context` can be mainly divided into three categories:
30
-
31
- - Get the information of the current generator execution environment.
32
-
33
- - Operate input.
34
-
35
- - Generator plugin lifecycle function.
36
-
37
-
38
- The generator plugin APIs will be introduced from these three categories below.
39
-
40
- ### Get Information
41
-
42
- #### locale
43
-
44
- Gets the language of the generator plugin execution environment. `@modern-js/create` provides two languages, `zh` and `en`, which correspond to these two values.
45
-
46
- #### isFileExist
47
-
48
- Checks whether a file exists. We often need to confirm whether the target project file exists before defining the operation. This API can be used directly for this purpose.
49
-
50
- For example, we need to find out if the `package.json` file exists and then do someing:
51
-
52
- ```ts
53
- const isExist = await context.isFileExist('package.json');
54
- if (isExist) {
55
- ...
56
- }
57
- ```
58
-
59
- #### readDir
60
-
61
- Gets the file list in a folder. We often need to get the file list under the target project folder before defining the operation. This API can be used directly for this purpose.
62
-
63
- For example, we need to get all files under the `src` folder and then do someing:
64
-
65
- ```ts
66
- const files = await context.readDir('src');
67
-
68
- files.map(name => {
69
- ...
70
- });
71
- ```
72
-
73
- ### Input Operations
74
-
75
- The `key` parameter used in input operations can refer to [Configuration Parameters](/guides/topic-detail/generator/create/config.html) and use the key under the solution’s scheme, that is, it does not support `solution` and `scenes`.
76
-
77
- The input parameter in input operations corresponds to the schema type described in [Input](/guides/topic-detail/generator/plugin/api/input.html).
78
-
79
- #### addInputBefore
80
-
81
- Adds a question before the specified input `key`.
82
-
83
- For example:
84
-
85
- ```ts
86
- context.addInputBefore('packageManager', {
87
- type: 'object',
88
- properties: {
89
- language: {
90
- type: 'string',
91
- title: 'Please select the programming language:',
92
- enum: [
93
- { label: 'TS', value: 'ts' },
94
- { label: 'ES6+', value: 'js' },
95
- ],
96
- },
97
- },
98
- });
99
- ```
100
-
101
- #### addInputAfter
102
-
103
- Adds a question after the specified input `key`.
104
-
105
- For example:
106
-
107
- ```ts
108
- context.addInputAfter('packageManager', {
109
- type: 'object',
110
- properties: {
111
- language: {
112
- type: 'string',
113
- title: 'Please select the programming language:',
114
- enum: [
115
- { label: 'TS', value: 'ts' },
116
- { label: 'ES6+', value: 'js' },
117
- ],
118
- },
119
- },
120
- });
121
- ```
122
-
123
- :::info
124
- 1. The `key` for adding a question cannot be the same as the `key` of the question provided by Modern.js solution scheme itself.
125
- 2. The priority of adding a question with `addInputAfter` is higher than that of `addInputBefore`. When adding an After question to a key and adding a Before question to the next key, the After question will be before the Before question.
126
- 3. When adding multiple questions before or after the same `key`, this method can be called multiple times, and the order of the questions will be arranged according to the calling sequence.
127
-
128
- :::
129
-
130
- #### setInput
131
-
132
- Sets the attributes of the specified input `key`.
133
-
134
- For example, set the `title` attribute of `packageName`:
135
-
136
- ```ts
137
- context.setInput('packageName', 'title', "Name");
138
- ```
139
-
140
- :::info
141
- For input options provided by Modern.js solution schemes, only deletion is supported, and adding will cause logical judgment problems in the code.
142
- :::
143
-
144
-
145
- #### setInputValue
146
-
147
- Sets the default value of the specified input `key`.
148
-
149
- For example, set the default value of `packageManager`:
150
-
151
- ```ts
152
- context.setInputValue({
153
- packageManager: 'npm',
154
- });
155
- ```
156
-
157
- :::info
158
- After setting, the question still needs to be interactive, but the default value configured by the generator plugin will be used.
159
- :::
160
-
161
- #### setDefaultConfig
162
-
163
- Sets the default value of the specified input `key`.
164
-
165
- For example, set the default value of `packageManager`:
166
-
167
- ```ts
168
- context.setDefaultConfig({
169
- packageManager: 'npm',
170
- });
171
- ```
172
-
173
- :::info
174
- After setting, the corresponding question will no longer be displayed, which is consistent with the `--config` behavior specified by `@modern-js/create`. Does not support setting `vertical` and `projectOrg`.
175
- :::
176
-
177
- #### setGitMessage
178
-
179
- Sets the initial git commit message. Modern.js defaults to the git initialization commit message as `feat: init`, which can be modified by this function.
180
-
181
-
182
- ### Lifecycle Functions
183
-
184
- The lifecycle functions are relatively complex and will be introduced separately in the following two sections, [`onForged`](/guides/topic-detail/generator/plugin/api/onForged.html) and [`afterForged`](/guides/topic-detail/generator/plugin/api/afterForged.html).
@@ -1,124 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # Input
6
-
7
- Generator plugin provides a way to interact with users through Input, which is defined using JSON Schema:
8
-
9
- For example:
10
-
11
- ```js
12
- const schema = {
13
- type: 'object',
14
- properties: {
15
- language: {
16
- type: 'string',
17
- title: 'Please select the programming language:',
18
- enum: [
19
- { label: 'TS', value: 'ts' },
20
- { label: 'ES6+', value: 'js' },
21
- ],
22
- },
23
- },
24
- };
25
- ```
26
-
27
- JSON Schema format is based on the open source [Formily](https://formilyjs.org/) Schema format. The following are the supported fields:
28
-
29
- ## type
30
-
31
- Defines the type of the current schema. Currently supported types are `string`, `number`, and `object`. `string` type is used for string inputs and dropdown options. `object` type is used for nesting schemas and needs to be used with the `properties` attribute.
32
-
33
- ## title
34
-
35
- Defines the display name of the current schema.
36
-
37
- ## default
38
-
39
- Defines the default value of the current schema.
40
-
41
- ## enum
42
-
43
- Defines the options when the current schema is a dropdown selection.
44
-
45
- The sub-items support `string` or `{ label: string; value: string}` types. When the value and display value are the same in the dropdown options, `string` can be used directly to define the options.
46
-
47
- When representing multiple selection options, set the `default` field to `[]`.
48
-
49
- ## x-validator
50
-
51
- Defines the validation rules for the current schema. When the schema is an input type, validation will be automatically performed after input completion.
52
-
53
- The validation rules supported here are provided by [Formily](https://formilyjs.org/zh-CN/guide/advanced/validate), for example, the maximum value is 5:
54
-
55
- ```js
56
- const schema = {
57
- type: 'object',
58
- properties: {
59
- max_5: {
60
- type: 'number',
61
- title: 'Maximum value (>5 will cause an error)',
62
- 'x-validator': {
63
- maximum: 5,
64
- },
65
- },
66
- },
67
- };
68
- ```
69
-
70
- It also supports using validation functions directly:
71
-
72
- ```js
73
- const schema = {
74
- type: 'object',
75
- properties: {
76
- path: {
77
- type: 'string',
78
- title: 'Can only contain numbers and letters',
79
- 'x-validator': value => {
80
- if (!/^[0-9a-zA-Z]*$/g.test(value)) {
81
- return 'Incorrect format';
82
- }
83
- return '';
84
- },
85
- },
86
- },
87
- };
88
- ```
89
-
90
- ## x-reactions
91
-
92
- Use linkage between schemas. This is exactly the same as [Formily linkage rules](https://formilyjs.org/zh-CN/guide/advanced/linkages).
93
-
94
- For example:
95
-
96
- ```js
97
- const schema = {
98
- type: 'object',
99
- properties: {
100
- name: {
101
- type: 'string',
102
- title: 'Name',
103
- },
104
- path: {
105
- type: 'string',
106
- title: 'Path',
107
- 'x-reactions': [
108
- {
109
- dependencies: ['name'],
110
- fulfill: {
111
- state: {
112
- value: '{{$deps[0]}}',
113
- },
114
- },
115
- },
116
- ],
117
- },
118
- },
119
- };
120
- ```
121
-
122
- ## properties
123
-
124
- Organize the structure of the current schema and define sub-forms. `properties` is an object, where the `key` is the schema keyword and the `value` is a schema object as described above.