@modern-js/main-doc 2.60.5 → 2.61.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +86 -33
  2. package/docs/en/components/bff-upload.mdx +95 -0
  3. package/docs/en/components/init-app.mdx +0 -1
  4. package/docs/en/components/init-rspack-app.mdx +0 -1
  5. package/docs/en/configure/app/dev/https.mdx +3 -0
  6. package/docs/en/configure/app/tools/html-plugin.mdx +13 -0
  7. package/docs/en/configure/app/tools/terser.mdx +1 -1
  8. package/docs/en/configure/app/tools/ts-loader.mdx +6 -3
  9. package/docs/en/configure/app/tools/webpack-chain.mdx +3 -3
  10. package/docs/en/guides/advanced-features/bff/_meta.json +1 -1
  11. package/docs/en/guides/advanced-features/bff/upload.mdx +5 -0
  12. package/docs/en/guides/advanced-features/source-build.mdx +11 -4
  13. package/docs/en/guides/basic-features/deploy.mdx +104 -2
  14. package/docs/en/guides/concept/entries.mdx +58 -5
  15. package/docs/en/guides/get-started/introduction.mdx +1 -38
  16. package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +86 -33
  17. package/docs/zh/components/bff-upload.mdx +97 -0
  18. package/docs/zh/components/default-mwa-generate.mdx +0 -1
  19. package/docs/zh/components/init-app.mdx +0 -1
  20. package/docs/zh/components/init-rspack-app.mdx +0 -1
  21. package/docs/zh/configure/app/dev/https.mdx +3 -0
  22. package/docs/zh/configure/app/tools/html-plugin.mdx +13 -0
  23. package/docs/zh/configure/app/tools/terser.mdx +1 -1
  24. package/docs/zh/configure/app/tools/ts-loader.mdx +6 -3
  25. package/docs/zh/configure/app/tools/webpack-chain.mdx +3 -3
  26. package/docs/zh/guides/advanced-features/bff/_meta.json +1 -1
  27. package/docs/zh/guides/advanced-features/bff/upload.mdx +5 -0
  28. package/docs/zh/guides/advanced-features/source-build.mdx +11 -4
  29. package/docs/zh/guides/basic-features/deploy.mdx +103 -5
  30. package/docs/zh/guides/concept/entries.mdx +52 -4
  31. package/docs/zh/guides/get-started/introduction.mdx +1 -36
  32. package/package.json +4 -4
  33. package/src/i18n/enUS.ts +0 -7
  34. package/src/i18n/zhCN.ts +0 -7
  35. package/src/pages/index.tsx +3 -32
  36. package/docs/en/guides/topic-detail/generator/_meta.json +0 -17
  37. package/docs/en/guides/topic-detail/generator/create/_meta.json +0 -1
  38. package/docs/en/guides/topic-detail/generator/create/config.mdx +0 -59
  39. package/docs/en/guides/topic-detail/generator/create/option.md +0 -146
  40. package/docs/en/guides/topic-detail/generator/create/use.mdx +0 -48
  41. package/docs/en/guides/topic-detail/generator/new/_meta.json +0 -1
  42. package/docs/en/guides/topic-detail/generator/new/config.md +0 -115
  43. package/docs/en/guides/topic-detail/generator/new/option.md +0 -67
  44. package/docs/en/guides/topic-detail/generator/new/use.md +0 -75
  45. package/docs/en/guides/topic-detail/generator/plugin/_meta.json +0 -11
  46. package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +0 -49
  47. package/docs/en/guides/topic-detail/generator/plugin/api/context.md +0 -184
  48. package/docs/en/guides/topic-detail/generator/plugin/api/input.md +0 -124
  49. package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +0 -310
  50. package/docs/en/guides/topic-detail/generator/plugin/category.md +0 -88
  51. package/docs/en/guides/topic-detail/generator/plugin/context.md +0 -104
  52. package/docs/en/guides/topic-detail/generator/plugin/structure.md +0 -106
  53. package/docs/en/guides/topic-detail/generator/plugin/use.md +0 -33
  54. package/docs/zh/guides/topic-detail/generator/_meta.json +0 -17
  55. package/docs/zh/guides/topic-detail/generator/create/_meta.json +0 -1
  56. package/docs/zh/guides/topic-detail/generator/create/config.mdx +0 -60
  57. package/docs/zh/guides/topic-detail/generator/create/option.md +0 -146
  58. package/docs/zh/guides/topic-detail/generator/create/use.mdx +0 -48
  59. package/docs/zh/guides/topic-detail/generator/new/_meta.json +0 -1
  60. package/docs/zh/guides/topic-detail/generator/new/config.md +0 -116
  61. package/docs/zh/guides/topic-detail/generator/new/option.md +0 -67
  62. package/docs/zh/guides/topic-detail/generator/new/use.md +0 -74
  63. package/docs/zh/guides/topic-detail/generator/plugin/_meta.json +0 -11
  64. package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +0 -50
  65. package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +0 -184
  66. package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +0 -124
  67. package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +0 -310
  68. package/docs/zh/guides/topic-detail/generator/plugin/category.md +0 -93
  69. package/docs/zh/guides/topic-detail/generator/plugin/context.md +0 -105
  70. package/docs/zh/guides/topic-detail/generator/plugin/structure.md +0 -106
  71. package/docs/zh/guides/topic-detail/generator/plugin/use.md +0 -33
@@ -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.
@@ -1,310 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # onForged
6
-
7
- `onForged` is a lifecycle function used for file operations in generator plugin.
8
-
9
- ## Types
10
-
11
- ```ts
12
- export type ForgedAPI = {
13
- addFile: (params: AddFileParams) => Promise<void>;
14
- addManyFiles: (params: AddManyFilesParams) => Promise<void>;
15
- updateJSONFile: (fileName: string, updateInfo: Record<string, unknown>) => Promise<void>;
16
- updateTextRawFile: (fileName: string, update: (content: string[]) => string[]) => Promise<void>;
17
- updateModernConfig: (updateInfo: Record<string, any>) => Promise<void>;
18
- rmFile: (fileName: string) => Promise<void>;
19
- rmDir: (dirName: string) => Promise<void>;
20
- addHelper: (name: string, fn: Handlebars.HelperDelegate) => void;
21
- addPartial: (name: string, str: Handlebars.Template) => void;
22
- createElement: (element: ActionElement, params: Record<string, unknown>) => Promise<void>;
23
- enableFunc: (func: ActionFunction, params?: Record<string, unknown> | undefined) => Promise<void>;
24
- };
25
-
26
- export type PluginForgedFunc = (
27
- api: ForgedAPI,
28
- inputData: Record<string, unknown>,
29
- ) => void | Promise<void>;
30
-
31
- export interface IPluginContext {
32
- onForged: (func: PluginForgedFunc) => void;
33
- ...
34
- }
35
- ```
36
-
37
- The `onForged` parameter is a callback function with `api` and `input` as parameters, which are used to provide the APIs and current input information provided by the lifecycle function.
38
-
39
- ## Concepts
40
-
41
- ### File Types
42
-
43
- The generator plugin classifies files into four categories:
44
-
45
- - Text files
46
-
47
- Files with pure text content that can be processed using [Handlebars](https://handlebarsjs.com/) or [EJS](https://ejs.co/) templates.
48
-
49
- - Binary files
50
-
51
- Files such as images, audio, and video.
52
-
53
- - JSON files
54
-
55
- Files in JSON format.
56
-
57
- - Text list files
58
-
59
- Files composed of lines of text, such as `.gitignore`, `.editorconfig`, and `.npmrc`.
60
-
61
- The type definitions for the four types of files are:
62
-
63
- ```ts
64
- export enum FileType {
65
- Text = 'text',
66
- Binary = 'binary',
67
- Json = 'json',
68
- TextRaw = 'textRaw',
69
- }
70
- ```
71
-
72
- ## API
73
-
74
- The APIs provided by the `api` parameter will be introduced below.
75
-
76
- ### addFile
77
-
78
- Adds a single file.
79
-
80
- Parameter types:
81
-
82
- ```ts
83
- export interface AddFileParams {
84
- type: FileType;
85
- file: string;
86
- template?: string;
87
- templateFile?: string;
88
- force?: boolean;
89
- data?: Record<string, string>;
90
- }
91
- ```
92
-
93
- - `type`: File type.
94
- - `file`: Target file path, relative to the target project directory.
95
- - `template`: Template content, the value of this field can be directly used to render the file. Lower priority than `templateFile`.
96
- - `templateFile`: Template file path, relative to the templates directory.
97
- - `force`: Whether to force overwrite when the target file exists, default is false.
98
- - `data`: Template rendering data.
99
-
100
- :::info
101
- Text files are processed using Handlebars by default. If the template file ends with `.ejs`, [EJS](https://ejs.co/) will be used for template rendering.
102
- :::
103
-
104
- For example, add the template file `App.tsx.hanlebars` to `src/App.tsx`:
105
-
106
- ```ts
107
- context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
108
- await api.addFile({
109
- type: FileType.Text,
110
- file: `src/App.tsx`,
111
- templateFile: `App.tsx.handlebars`,
112
- });
113
- })
114
- ```
115
-
116
- ### addManyFiles
117
-
118
- Adds multiple files, usually used to add multiple files to the same target directory.
119
-
120
- Parameter types:
121
-
122
- ```ts
123
- export interface AddManyFilesParams {
124
- type: FileType;
125
- destination: string;
126
- templateFiles: string[] | (() => string[]);
127
- templateBase?: string;
128
- fileNameFunc?: (name: string) => string;
129
- data?: Record<string, string>;
130
- }
131
- ```
132
-
133
- - `type`: File type.
134
- - `destination`: Target folder, relative path to the target project directory.
135
- - `templateFiles`: Template file list, supporting regular expressions from [globby](https://www.npmjs.com/package/globby).
136
- - `templateBase`: Common path of template files. When using this parameter, the target file will automatically delete this path.
137
- - `fileNameFunc`: Function to rename files. During the file addition process, the file name will be passed to this function in turn, and the renaming can be performed as needed.
138
- - `data`: Template rendering data.
139
-
140
- For example, render all files in the `src-ts` directory of the template file to the `src` directory:
141
-
142
- ```ts
143
- context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
144
- await api.addManyFiles({
145
- type: FileType.Text,
146
- destination: 'src',
147
- templateFiles: ['src-ts/**/*'],
148
- templateBase: 'src-ts',
149
- fileNameFunc: name => name.replace('.handlebars', ''),
150
- });
151
- })
152
- ```
153
-
154
- ### updateJSONFile
155
-
156
- Update fields in a JSON file.
157
-
158
- Parameter types:
159
-
160
- ```ts
161
- fileName: strings
162
- updateInfo: Record<string, unknown>
163
- ```
164
-
165
- - `fileName`: JSON file path, relative to the target project path.
166
- - `updateInfo`: Update information. Nested field updates need to be flattened, otherwise the entire update will cause content loss.
167
-
168
- For example, update the `name` field of `package.json`:
169
-
170
- ```ts
171
- context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
172
- await api.updateJSONFile('package.json', { name: 'new_name' });
173
- })
174
- ```
175
-
176
- For example, update the version of `react-dom` in `dependencies`:
177
-
178
- ```ts
179
- context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
180
- await api.updateJSONFile('package.json', {
181
- 'dependencies.react-dom': '^18',
182
- });
183
- })
184
- ```
185
-
186
- ### updateTextRawFile
187
-
188
- Update the contents of a text list file.
189
-
190
- Parameter types:
191
-
192
- ```ts
193
- fileName: string
194
- update: (content: string[]) => string[]
195
- ```
196
-
197
- - `fileName`: Text list file path, relative to the target project path.
198
- - `update`: Update function. The parameter is an array divided by `\n` of the current file content, and the return value is also the modified array after modification. `@modern-js/create` will automatically merge it with `\n` and write it to the source file.
199
-
200
- For example, add the `dist` directory to the `.gitinore` file:
201
-
202
- ```ts
203
- context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
204
- await api.updateTextRawFile('.gitinore', (content) => [...content, 'dist']);
205
- })
206
- ```
207
-
208
- ### updateModernConfig (not recommended)
209
-
210
- In addition to configuring in `modern.config.[tj]s`, Modern.js configuration also supports configuring `modernConfig` in `package.json`. This function is used to update this field.
211
-
212
- Parameter types:
213
-
214
- ```ts
215
- updateInfo: Record<string, any>
216
- ```
217
-
218
- - `updateInfo`: Update content information. `updateModernConfig` is a package based on `updateJSONFile`, which will automatically update under the `modernConfig` field. Only the configuration fields under `modernConfig` need to be filled in `updateInfo`.
219
-
220
- For example, enable SSR:
221
-
222
- ```ts
223
- context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
224
- await api.updateModernConfig({ 'server.ssr': true });
225
- })
226
- ```
227
-
228
- ### rmFile
229
-
230
- Delete files.
231
-
232
- Parameter types:
233
-
234
- ```ts
235
- fileName: string
236
- ```
237
-
238
- - `fileName`: The path of the file to be deleted, relative to the target project path.
239
-
240
- ### rmDir
241
-
242
- Delete a folder.
243
-
244
- Parameter types:
245
-
246
- ```ts
247
- dirName: string
248
- ```
249
-
250
- - `dirName`: The path of the folder to be deleted, relative to the target project path.
251
-
252
- ### addHelper
253
-
254
- Add a [custom helper](https://handlebarsjs.com/guide/#custom-helpers) rendered by handlebrs.
255
-
256
- Parameter types:
257
-
258
- ```ts
259
- name: string
260
- fn: Handlebars.HelperDelegate
261
- ```
262
-
263
- - `name`: Helper function name.
264
- - `fn`: Helper function implementation.
265
-
266
- ### addPartial
267
-
268
- Add a [Partial](https://handlebarsjs.com/guide/partials.html#basic-partials) rendered by Handlebars.
269
-
270
- Parameter types:
271
-
272
- ```ts
273
- name: string
274
- str: Handlebars.Template
275
- ```
276
-
277
- - `name`: Partial name.
278
- - `str`: Template string of the Partial.
279
-
280
- ### createElement
281
-
282
- Automatically run the `new` command to create project elements.
283
-
284
- Parameter types:
285
-
286
- ```ts
287
- element: ActionElement
288
- params: Record<string, unknown>
289
- ```
290
-
291
- - `element`: Type of project element, new entry or new custom Web Server source directory.
292
- - `params`: Other parameters corresponding to creating project elements.
293
-
294
- ### enableFunc
295
-
296
- Automatically run the `new` command to enable optional features.
297
-
298
- Parameter types:
299
-
300
- ```ts
301
- func: ActionFunction
302
- params?: Record<string, unknown>
303
- ```
304
-
305
- - `func`: Name of the feature to enable.
306
- - `params`: Other parameters corresponding to enabling the feature.
307
-
308
- :::info
309
- Refer to [Configuration Parameters](/guides/topic-detail/generator/new/config.html) for creating project elements and enabling feature configurations.
310
- :::
@@ -1,88 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # Introduction
6
-
7
- There are two types of generator plugin:
8
-
9
- - Extension: Web App(Npm Module) = Web App(Npm Module) + Generator Plugin
10
-
11
- - Custom: New Application(Npm Module) = Web App(Npm Module) + Generator Plugin
12
-
13
-
14
- In simpler terms, extension means using the original project name of Modern.js, while custom means creating a new name.
15
-
16
- ## Identifier
17
-
18
- The type of generator plugin is provided through the `meta` field in `package.json`:
19
-
20
- ### Extension
21
-
22
- ```json title="package.json"
23
- {
24
- "meta": {
25
- "extend": "mwa" // module
26
- }
27
- }
28
- ```
29
-
30
- ### Custom
31
-
32
- ```json title="package.json"
33
- {
34
- "meta": {
35
- "key": "new_app",
36
- "name": "new App",
37
- "type": "mwa" // module and custom
38
- }
39
- }
40
- ```
41
-
42
- :::info
43
- For custom type, the `type` field supports the `custom` value, which utilizes some best practice templates for project development provided by Modern.js, such as `.gitignore`, `.editorConfig`, etc. Other business-related code templates need to be manually provided through generator plugin.
44
- :::
45
-
46
- # Creating Initial Project
47
-
48
- ### Extension
49
-
50
- ```bash
51
- npx @modern-js/create@latest plugin --plugin @modern-js/generator-plugin-plugin
52
- ? Please select the type of project you want to create: Npm Module
53
- ? Please select the project scenario: Generator Plugin
54
- ? Please fill in the package name of the generator plugin: plugin
55
- ? Please select the programming language: TS
56
- ? Please select the package manager: pnpm
57
- ? Please select the type of plugin: extend
58
- ? Please select the base type of the plugin: Web App
59
- ```
60
-
61
- ### Custom
62
-
63
- ```bash
64
- npx @modern-js/create@latest plugin --plugin @modern-js/generator-plugin-plugin
65
- ? Please select the type of project you want to create: Npm Module
66
- ? Please select the project scenario: Generator Plugin
67
- ? Please fill in the package name of the generator plugin: plugin
68
- ? Please select the programming language: TS
69
- ? Please select the package manager: pnpm
70
- ? Please select the type of plugin: custom
71
- ? Please fill in the plugin keyword: new_app
72
- ? Please fill in the display name of the plugin: new App
73
- ? Please select the base type of the plugin: Web App
74
- ```
75
-
76
- ## Execution Order
77
-
78
- Generator plugins support using multiple plugins at the same time, which means that multiple `--plugin` parameters are supported when executing `@modern-js/create`.
79
-
80
- ### Extension
81
-
82
- For extension generator plugins, when executing with the declared generator plugin parameters, the corresponding lifecycle functions of the project scheme that is extended will be executed in order.
83
-
84
- For example, if there are two generator plugins A and B, both of which extend the Modern.js application scheme. A plugin declares to add the `a.ts` file, and B plugin declares to add the `b.ts` file. When executing `npx @modern-js/create@latest --plugin A --plugin B`, and selecting the Web APP scheme, the default project files of the Web APP will be generated first. Then, the A plugin will create the `a.ts` file, and then the B plugin will generate the `b.ts` file.
85
-
86
- ### Custom
87
-
88
- For custom generator plugins, only one plugin can be executed at a time. When declaring the `--plugin` parameter for `@modern-js/create`, a selection option for the scenario of choosing the project scheme will be added after selecting the project scheme, which is the new name defined in the `package.json`. Choosing the corresponding generator plugin for the name will execute the corresponding generator plugin logic after the default project scheme is completed. When declaring the `--plugin` parameter, the corresponding generator plugin names will be listed one by one for selection in the project scheme scenario.