@modern-js/main-doc 2.60.6 → 2.62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) 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/basic-features/render/ssr.mdx +23 -1
  7. package/docs/en/guides/concept/entries.mdx +58 -5
  8. package/docs/en/guides/get-started/introduction.mdx +1 -38
  9. package/docs/en/guides/get-started/tech-stack.mdx +1 -1
  10. package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +86 -33
  11. package/docs/zh/components/default-mwa-generate.mdx +0 -1
  12. package/docs/zh/components/init-app.mdx +0 -1
  13. package/docs/zh/components/init-rspack-app.mdx +0 -1
  14. package/docs/zh/guides/advanced-features/source-build.mdx +11 -4
  15. package/docs/zh/guides/basic-features/deploy.mdx +103 -5
  16. package/docs/zh/guides/basic-features/render/ssr.mdx +23 -1
  17. package/docs/zh/guides/concept/entries.mdx +52 -4
  18. package/docs/zh/guides/get-started/introduction.mdx +1 -36
  19. package/docs/zh/guides/get-started/tech-stack.mdx +1 -1
  20. package/package.json +4 -4
  21. package/src/i18n/enUS.ts +0 -7
  22. package/src/i18n/zhCN.ts +0 -7
  23. package/src/pages/index.tsx +3 -32
  24. package/docs/en/guides/topic-detail/generator/_meta.json +0 -17
  25. package/docs/en/guides/topic-detail/generator/create/_meta.json +0 -1
  26. package/docs/en/guides/topic-detail/generator/create/config.mdx +0 -59
  27. package/docs/en/guides/topic-detail/generator/create/option.md +0 -146
  28. package/docs/en/guides/topic-detail/generator/create/use.mdx +0 -48
  29. package/docs/en/guides/topic-detail/generator/new/_meta.json +0 -1
  30. package/docs/en/guides/topic-detail/generator/new/config.md +0 -115
  31. package/docs/en/guides/topic-detail/generator/new/option.md +0 -67
  32. package/docs/en/guides/topic-detail/generator/new/use.md +0 -75
  33. package/docs/en/guides/topic-detail/generator/plugin/_meta.json +0 -11
  34. package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +0 -49
  35. package/docs/en/guides/topic-detail/generator/plugin/api/context.md +0 -184
  36. package/docs/en/guides/topic-detail/generator/plugin/api/input.md +0 -124
  37. package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +0 -310
  38. package/docs/en/guides/topic-detail/generator/plugin/category.md +0 -88
  39. package/docs/en/guides/topic-detail/generator/plugin/context.md +0 -104
  40. package/docs/en/guides/topic-detail/generator/plugin/structure.md +0 -106
  41. package/docs/en/guides/topic-detail/generator/plugin/use.md +0 -33
  42. package/docs/zh/guides/topic-detail/generator/_meta.json +0 -17
  43. package/docs/zh/guides/topic-detail/generator/create/_meta.json +0 -1
  44. package/docs/zh/guides/topic-detail/generator/create/config.mdx +0 -60
  45. package/docs/zh/guides/topic-detail/generator/create/option.md +0 -146
  46. package/docs/zh/guides/topic-detail/generator/create/use.mdx +0 -48
  47. package/docs/zh/guides/topic-detail/generator/new/_meta.json +0 -1
  48. package/docs/zh/guides/topic-detail/generator/new/config.md +0 -116
  49. package/docs/zh/guides/topic-detail/generator/new/option.md +0 -67
  50. package/docs/zh/guides/topic-detail/generator/new/use.md +0 -74
  51. package/docs/zh/guides/topic-detail/generator/plugin/_meta.json +0 -11
  52. package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +0 -50
  53. package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +0 -184
  54. package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +0 -124
  55. package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +0 -310
  56. package/docs/zh/guides/topic-detail/generator/plugin/category.md +0 -93
  57. package/docs/zh/guides/topic-detail/generator/plugin/context.md +0 -105
  58. package/docs/zh/guides/topic-detail/generator/plugin/structure.md +0 -106
  59. package/docs/zh/guides/topic-detail/generator/plugin/use.md +0 -33
@@ -1,50 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # afterForged
6
-
7
- `afterForged` 为生成器插件中用于文件操作后其他步骤操作的生命周期函数。
8
-
9
- ## 类型
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
- 下面将分别介绍 api 参数提供的 API。
30
-
31
- ### isInGitRepo
32
-
33
- 判断当前项目是否为一个 Git 仓库。
34
-
35
- ### initGitRepo
36
-
37
- 初始化当前项目为 Git 仓库。
38
-
39
- ### gitAddAndCommit
40
-
41
- 提交当前仓库变更。
42
-
43
- 参数:
44
-
45
- - `commitMessage`: commit 信息。
46
-
47
-
48
- ### install
49
-
50
- 在项目根目录安装依赖。`install` 函数中将根据 `packageManager` 的值使用对应的包管理工具安装依赖。
@@ -1,184 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # context
6
-
7
- 生成器插件在 `main` 文件中默认导出了一个函数,函数参数为 `context`,生成器插件提供的所有 API 都是由这个 `context` 提供的。
8
-
9
- ## 类型
10
-
11
- 我们先大概了解一下 `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
- `context` 提供的内容主要分为三类:
30
-
31
- - 获取当前生成器执行环境信息
32
-
33
- - 操作 input 输入
34
-
35
- - 生成器插件生命周期函数
36
-
37
- 下面将从这三个分类分别介绍生成器插件 API。
38
-
39
-
40
- ### 获取信息
41
-
42
- #### locale
43
-
44
- 获取生成器插件执行环境的语言。`@modern-js/create` 提供了 `zh` 和 `en` 两种语言,这里即为对应的这两种值。
45
-
46
- #### isFileExist
47
-
48
- 判断文件是否存在。我们很多时候需要在定义操作前确认目标项目文件是否已经存在,可以直接通过该 API 获取。
49
-
50
- 例如我们需要获取 `package.json` 文件是否存在,然后做相应的操作:
51
-
52
- ```ts
53
- const isExist = await context.isFileExist('package.json');
54
- if (isExist) {
55
- ...
56
- }
57
- ```
58
-
59
- #### readDir
60
-
61
- 获取文件夹内文件列表。我们很多时候需要在定义操作前获取目标项目文件夹下面文件列表,可以直接通过该 API 获取。
62
-
63
- 例如我们需要获取 src 文件夹下所有文件,然后进行相应操作:
64
-
65
- ```ts
66
- const files = await context.readDir('src');
67
-
68
- files.map(name => {
69
- ...
70
- });
71
- ```
72
-
73
- ### input 操作
74
-
75
- input 操作中使用的 key 参数可参考[配置参数](/guides/topic-detail/generator/create/config.html),需要在使用对应工程方案下的 key,即不支持在 `solution` 和 `scenes`。
76
-
77
- input 操作中的 input 参数对应的 Schema 类型可参考 [Input](/guides/topic-detail/generator/plugin/api/input.html)。
78
-
79
- #### addInputBefore
80
-
81
- 在指定的 input `key` 前添加问题。
82
-
83
- 例如:
84
-
85
- ```ts
86
- context.addInputBefore('packageManager', {
87
- type: 'object',
88
- properties: {
89
- language: {
90
- type: 'string',
91
- title: '开发语言',
92
- enum: [
93
- { label: 'TS', value: 'ts' },
94
- { label: 'ES6+', value: 'js' },
95
- ],
96
- },
97
- },
98
- });
99
- ```
100
-
101
- #### addInputAfter
102
-
103
- 在指定的 input `key` 后添加问题。
104
-
105
- 例如:
106
-
107
- ```ts
108
- context.addInputAfter('packageManager', {
109
- type: 'object',
110
- properties: {
111
- language: {
112
- type: 'string',
113
- title: '开发语言',
114
- enum: [
115
- { label: 'TS', value: 'ts' },
116
- { label: 'ES6+', value: 'js' },
117
- ],
118
- },
119
- },
120
- });
121
- ```
122
-
123
- :::info
124
- 1. 添加问题的 `key` 不能和 Modern.js 提供的工程方案自身的问题的 `key` 重复。
125
- 2. 添加问题 `addInputAfter` 的优先级高于 `addInputBefore`,当同时对一个 key 添加 After 问题和对其后一个key 添加 Before 问题时,After 问题会在 Before 之前。
126
- 3. 当需要在相同 `key` 前面或者后面添加多个问题时,可多次调用该方法,问题的顺序会按照调用顺序进行排列。
127
-
128
- :::
129
-
130
- #### setInput
131
-
132
- 设置指定 input `key` 的属性。
133
-
134
- 例如设置 `packageName` 的 `title` 属性:
135
-
136
- ```ts
137
- context.setInput('packageName', 'title', "展示名称");
138
- ```
139
-
140
- :::info
141
- 对于 Modern.js 工程方案提供的输入选项,只支持删除,不支持增加,增加会造成代码中的逻辑判断存在问题。
142
- :::
143
-
144
-
145
- #### setInputValue
146
-
147
- 设置指定 input `key` 的选项默认值。
148
-
149
- 例如设置 `packageManager` 的默认值:
150
-
151
- ```ts
152
- context.setInputValue({
153
- packageManager: 'npm',
154
- });
155
- ```
156
-
157
- :::info
158
- 设置完成后,该问题还是需要交互,只是会使用生成器插件配置的默认值。
159
- :::
160
-
161
- #### setDefaultConfig
162
-
163
- 设置指定 input `key` 的默认值。
164
-
165
- 例如设置 `packageManager` 的默认值:
166
-
167
- ```ts
168
- context.setDefaultConfig({
169
- packageManager: 'npm',
170
- });
171
- ```
172
-
173
- :::info
174
- 设置完成后,将不再展示对应问题,和 `@modern-js/create` 制定 `--config` 行为一致。不支持设置 `vertical` 和 `projectOrg`。
175
- :::
176
-
177
- #### setGitMessage
178
-
179
- 设置 Git 初始提交信息。Modern.js 默认 Git 初始化提交信息为 `feat: init`,通过该函数可以修改。
180
-
181
-
182
- ### 生命周期函数
183
-
184
- 生命周期函数比较复杂,将通过后面两节 [`onForged`](/guides/topic-detail/generator/plugin/api/onForged.html) 和 [`afterForged`](/guides/topic-detail/generator/plugin/api/afterForged.html) 分别介绍。
@@ -1,124 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # Input
6
-
7
- 生成器插件提供了 Input 的方式完成与用户的问题交互,使用 JSON Schema 的方式进行定义:
8
-
9
- 例如:
10
-
11
- ```js
12
- const schema = {
13
- type: 'object',
14
- properties: {
15
- language: {
16
- type: 'string',
17
- title: '开发语言',
18
- enum: [
19
- { label: 'TS', value: 'ts' },
20
- { label: 'ES6+', value: 'js' },
21
- ],
22
- },
23
- },
24
- };
25
- ```
26
-
27
- JSON Schema 的格式参考了开源的 [Formily](https://formilyjs.org/) Schema 的格式,下面将对支持的字段进行介绍:
28
-
29
- ## type
30
-
31
- 定义当前 Schema 类型,当前支持的类型为 `string`、`number` 和 `object`。字符串输入和下拉选项都需要使用 `string` 类型。 `object` 类型用于实现 Schema 之间嵌套,需要配和 `properties` 属性使用。
32
-
33
- ## title
34
-
35
- 定义当前 Schema 展示名称。
36
-
37
- ## default
38
-
39
- 定义当前 Schema 的默认值。
40
-
41
- ## enum
42
-
43
- 当前 Schema 为下列选项时,定义选项内容。
44
-
45
- 子项支持 `string` 或者 `{ label: string; value: string}` 类型,当下拉选项中值和展示值相同时,可直接使用 `string` 定义。
46
-
47
- 当需要表示多选选项时,设置 `default` 字段为 `[]` 即可。
48
-
49
- ## x-validator
50
-
51
- 当前 Schema 的校验规则。当 Schema 为输入类型时,在输入完成后会自动完成校验。
52
-
53
- 这里校验规则支持[ Formily 提供的校验规则](https://formilyjs.org/zh-CN/guide/advanced/validate),例如最大值为 5:
54
-
55
- ```js
56
- const schema = {
57
- type: 'object',
58
- properties: {
59
- max_5: {
60
- type: 'number',
61
- title: '最大值(>5报错)',
62
- 'x-validator': {
63
- maximum: 5,
64
- },
65
- },
66
- },
67
- };
68
- ```
69
-
70
- 也支持直接使用验证函数:
71
-
72
- ```js
73
- const schema = {
74
- type: 'object',
75
- properties: {
76
- path: {
77
- type: 'string',
78
- title: '只能包含数字和字母',
79
- 'x-validator': value => {
80
- if (!/^[0-9a-zA-Z]*$/g.test(value)) {
81
- return '格式不正确';
82
- }
83
- return '';
84
- },
85
- },
86
- },
87
- };
88
- ```
89
-
90
- ## x-reactions
91
-
92
- 使用 Schema 之间的联动,这里和[ Formily 联动规则](https://formilyjs.org/zh-CN/guide/advanced/linkages)完全相同。
93
-
94
- 例如:
95
-
96
- ```js
97
- const schema = {
98
- type: 'object',
99
- properties: {
100
- name: {
101
- type: 'string',
102
- title: '名称',
103
- },
104
- path: {
105
- type: 'string',
106
- title: '路径',
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
- 组织当前 Schema 的结构,定义子表单。`properties` 为对象,`key` 为 Schema 关键字,`value` 为上述描述的 Schema 对象。
@@ -1,310 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # onForged
6
-
7
- `onForged` 为生成器插件中用于文件操作的生命周期函数。
8
-
9
- ## 类型
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
- `onForged` 参数为一个回调函数,回调函数参数为 `api` 和 `input`,分别用于提供该生命周期函数提供的 API 及当前输入信息。
38
-
39
- ## 概念
40
-
41
- ### 文件类型
42
-
43
- 生成器插件将文件类型分为四类:
44
-
45
- - 文本文件
46
-
47
- 纯文本内容文件,可使用 [Handlebars](https://handlebarsjs.com/) 或 [EJS](https://ejs.co/) 进行模板处理的文件。
48
-
49
- - 二进制文件
50
-
51
- 图片、音频、视频等文件。
52
-
53
- - JSON 文件
54
-
55
- JSON 格式的文件。
56
-
57
- - 文本列表文件
58
-
59
- 文件由行文本组成的文件,例如 `.gitignore`, `.editorconfig`, `.npmrc`。
60
-
61
- 对应四种文件的类型定义为:
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
- 下面将分别介绍 api 参数提供的 API。
75
-
76
- ### addFile
77
-
78
- 添加单个文件。
79
-
80
- 参数类型:
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`: 文件类型。
94
- - `file`:目标文件路径,相对于目标项目目录的相对路径。
95
- - `template`:模板内容,该字段值可直接用于模板渲染文件。优先级低于 `templateFile`。
96
- - `templateFile`:模板文件路径,相对于 templates 目录的相对路径即可。
97
- - `force`:是否强制覆盖,当目标文件存在时是否强制覆盖,默认为 false。
98
- - `data`:模板渲染数据。
99
-
100
- :::info
101
- 文本类型文件默认使用 Handlebars 进行处理,当模板文件以 `.ejs` 结尾的话,会使用 [EJS](https://ejs.co/) 进行模板渲染。
102
- :::
103
-
104
- 例如添加模板文件 `App.tsx.hanlebars` 到 `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
- ### addManyFiless
117
-
118
- 批量添加文件,一般用于添加多个文件到同一个目标目录。
119
-
120
- 参数类型:
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`: 文件类型。
134
- - `destination`:目标文件夹,相对于目标项目目录的相对路径。
135
- - `templateFiles`:模板文件列表,支持 [globby](https://www.npmjs.com/package/globby) 正则表达式
136
- - `templateBase`:模板文件的公共路径,使用该参数时目标文件会自动删除该路径。
137
- - `fileNameFunc`:重命名文件函数,添加文件过程中会依次将文件名传入到该函数,可以根据需要进行重命名。
138
- - `data`:模板渲染数据。
139
-
140
- 例如将模板文件 `src-ts` 目录下所有文件渲染到 `src` 目录:
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
- 更新 JSON 文件字段。
157
-
158
- 参数类型:
159
-
160
- ```ts
161
- fileName: strings
162
- updateInfo: Record<string, unknown>
163
- ```
164
-
165
- - `fileName`:JSON 文件路径,相对于目标项目的路径。
166
- - `updateInfo`:更新信息,嵌套字段更新需要平铺,不然会更新整体造成内容丢失。
167
-
168
- 例如更新 `package.json` 的 name 字段:
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
- 例如更新 `dependencies` 的 `react-dom` 版本:
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
- 更新文本列表文件内容。
189
-
190
- 参数类型:
191
-
192
- ```ts
193
- fileName: string
194
- update: (content: string[]) => string[]
195
- ```
196
-
197
- - `fileName`: 文本列表文件路径,相对于目标项目的路径。
198
- - `update`:更新函数,参数为当前文件内容以 `\n` 进行分割的数组,返回值也为修改完成后的数组,`@modern-js/create` 会自动以 `\n` 合并,并写入源文件。
199
-
200
- 例如 `.gitinore` 文件中增加 dist 目录:
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(不推荐)
209
-
210
- Modern.js 配置除了可以在 `modern.config.[tj]s` 中配置外,还支持 `package.json` 中配置 `modernConfig` 配置。该函数用于更新该字段。
211
-
212
- 参数类型:
213
-
214
- ```ts
215
- updateInfo: Record<string, any>
216
- ```
217
-
218
- - `updateInfo`: 更新内容信息。updateModernConfig 是基于 updateJSONFile 的封装,将自动更新到 `modernConfig` 字段下,updateInfo 中只需填写 `modernConfig` 下的配置字段即可。
219
-
220
- 例如开启 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
- 删除文件。
231
-
232
- 参数类型:
233
-
234
- ```ts
235
- fileName: string
236
- ```
237
-
238
- - `fileName`:删除的文件路径,相对于目标项目的路径。
239
-
240
- ### rmDir
241
-
242
- 删除文件夹。
243
-
244
- 参数类型:
245
-
246
- ```ts
247
- dirName: string
248
- ```
249
-
250
- - `dirName`:删除的文件夹路径,相对于目标项目的路径。
251
-
252
- ### addHelper
253
-
254
- 添加 handlebrs 渲染的[自定义 Helper](https://handlebarsjs.com/guide/#custom-helpers)。
255
-
256
- 参数类型:
257
-
258
- ```ts
259
- name: string
260
- fn: Handlebars.HelperDelegate
261
- ```
262
-
263
- - `name`:Helper 函数名称。
264
- - `fn`:Helper 函数实现。
265
-
266
- ### addPartial
267
-
268
- 添加 Handlebars 渲染的 [Partial](https://handlebarsjs.com/guide/partials.html#basic-partials)。
269
-
270
- 参数类型:
271
-
272
- ```ts
273
- name: string
274
- str: Handlebars.Template
275
- ```
276
-
277
- - `name`:Partial 名称。
278
- - `str`:Partial 的模板字符串。
279
-
280
- ### createElement
281
-
282
- 自动调用 new 命令创建工程元素。
283
-
284
- 参数类型:
285
-
286
- ```ts
287
- element: ActionElement
288
- params: Record<string, unknown>
289
- ```
290
-
291
- - `element`:工程元素类型,新建入口或者新建自定义 Web Server 源码目录。
292
- - `params`:对应创建工程元素的其他参数。
293
-
294
- ### enableFunc
295
-
296
- 自动调用 new 命令开启可选功能。
297
-
298
- 参数类型:
299
-
300
- ```ts
301
- func: ActionFunction
302
- params?: Record<string, unknown>
303
- ```
304
-
305
- - `func`:开启功能名称。
306
- - `params`:对应开启功能的其他参数。
307
-
308
- :::info
309
- 创建工程元素和开启功能配置可参考[配置参数](/guides/topic-detail/generator/new/config.html)。
310
- :::