@modern-js/main-doc 2.0.0-beta.1 → 2.0.0-beta.2

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 (157) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/build.md +1 -1
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/dev.md +1 -1
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/lint.md +1 -1
  5. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +1 -2
  6. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/start.md +1 -1
  7. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/test.md +1 -1
  8. package/en/docusaurus-plugin-content-docs/current/apis/app/overview.md +1 -1
  9. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/auto-actions.md +1 -1
  10. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/connect.md +1 -1
  11. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-app.md +1 -1
  12. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-store.md +1 -1
  13. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/handle-effect.md +1 -1
  14. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/model_.md +1 -1
  15. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-local-model.md +1 -1
  16. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-model.md +1 -1
  17. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-static-model.md +1 -1
  18. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-store.md +1 -1
  19. package/en/docusaurus-plugin-content-docs/current/components/command-tip.md +56 -0
  20. package/en/docusaurus-plugin-content-docs/current/components/reduck-tip.md +5 -0
  21. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-extract.md +12 -0
  22. package/en/docusaurus-plugin-content-docs/current/configure/app/runtime/router.md +1 -1
  23. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/_category_.json +4 -0
  24. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/_category_.json +4 -0
  25. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/_category_.json +4 -0
  26. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/app.md +152 -0
  27. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/ejs.md +56 -0
  28. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/fs.md +54 -0
  29. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/git.md +49 -0
  30. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/handlebars.md +58 -0
  31. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/json.md +59 -0
  32. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/api/npm.md +49 -0
  33. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/develop.md +52 -0
  34. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/introduce.md +46 -0
  35. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/run-in-js.md +48 -0
  36. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/codesmith/structure.md +87 -0
  37. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/_category_.json +4 -0
  38. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/common.md +106 -0
  39. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/module.md +39 -0
  40. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/monorepo.md +28 -0
  41. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/config/mwa.md +89 -0
  42. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/_category_.json +4 -0
  43. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/abstract.md +26 -0
  44. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/_category_.json +4 -0
  45. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/_category_.json +4 -0
  46. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addFile.md +52 -0
  47. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addHelper.md +26 -0
  48. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addManyFile.md +58 -0
  49. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/addPartial.md +26 -0
  50. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/introduce.md +38 -0
  51. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/rmDir.md +24 -0
  52. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/rmFile.md +24 -0
  53. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/updateJSONFile.md +54 -0
  54. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/updateModernConfig.md +26 -0
  55. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.md +33 -0
  56. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/_category_.json +4 -0
  57. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.md +20 -0
  58. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/initGitRepo.md +16 -0
  59. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/git/isInGitRepo.md +16 -0
  60. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/hook/_category_.json +4 -0
  61. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/hook/afterForged.md +35 -0
  62. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/hook/onForged.md +36 -0
  63. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/_category_.json +4 -0
  64. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/isFileExit.md +22 -0
  65. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/locale.md +17 -0
  66. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/info/readDir.md +22 -0
  67. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/_category_.json +4 -0
  68. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/addInputAfter.md +57 -0
  69. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/addInputBefore.md +56 -0
  70. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/setInput.md +42 -0
  71. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/setInputValue.md +30 -0
  72. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/input/type.md +65 -0
  73. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/introduce.md +91 -0
  74. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/_category_.json +4 -0
  75. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/createElement.md +33 -0
  76. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/createSubProject.md +35 -0
  77. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/enableFunc.md +44 -0
  78. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/new/introduce.md +15 -0
  79. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/npm/_category_.json +4 -0
  80. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/api/npm/install.md +18 -0
  81. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/develop.md +125 -0
  82. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/plugin/use.md +61 -0
  83. package/en/docusaurus-plugin-content-docs/current/guides/topic-detail/generator/project.md +118 -0
  84. package/en/docusaurus-plugin-content-docs/current.json +39 -3
  85. package/package.json +3 -3
  86. package/scripts/summary.en.json +1 -1
  87. package/scripts/summary.zh.json +1 -1
  88. package/zh/apis/app/commands/new.md +0 -1
  89. package/zh/apis/app/hooks/server/test.md +2 -2
  90. package/zh/apis/app/runtime/web-server/hook.md +4 -4
  91. package/zh/apis/app/runtime/web-server/middleware.md +4 -4
  92. package/zh/configure/app/output/disable-css-extract.md +12 -0
  93. package/zh/guides/advanced-features/bff/_category_.json +5 -1
  94. package/zh/guides/advanced-features/bff/bff-proxy.md +5 -3
  95. package/zh/guides/advanced-features/bff/frameworks.md +72 -51
  96. package/zh/guides/advanced-features/bff/function.md +16 -30
  97. package/zh/guides/advanced-features/bff/index.md +20 -0
  98. package/zh/guides/advanced-features/bff/type.md +43 -0
  99. package/zh/guides/advanced-features/custom-app.md +63 -1
  100. package/zh/guides/advanced-features/web-server.md +21 -110
  101. package/zh/guides/basic-features/data-fetch.md +61 -0
  102. package/zh/guides/basic-features/env-vars.md +88 -41
  103. package/zh/guides/basic-features/routes.md +267 -0
  104. package/zh/guides/concept/entries.md +112 -0
  105. package/zh/guides/concept/lifecycle.md +10 -0
  106. package/zh/guides/get-started/quick-start.md +199 -1
  107. package/zh/guides/get-started/upgrade.md +75 -1
  108. package/zh/guides/topic-detail/generator/codesmith/api/_category_.json +4 -0
  109. package/zh/guides/topic-detail/generator/codesmith/api/app.md +152 -0
  110. package/zh/guides/topic-detail/generator/codesmith/api/ejs.md +56 -0
  111. package/zh/guides/topic-detail/generator/codesmith/api/fs.md +54 -0
  112. package/zh/guides/topic-detail/generator/codesmith/api/git.md +48 -0
  113. package/zh/guides/topic-detail/generator/codesmith/api/handlebars.md +56 -0
  114. package/zh/guides/topic-detail/generator/codesmith/api/json.md +58 -0
  115. package/zh/guides/topic-detail/generator/codesmith/api/npm.md +45 -0
  116. package/zh/guides/topic-detail/generator/codesmith/develop.md +52 -0
  117. package/zh/guides/topic-detail/generator/codesmith/introduce.md +42 -1
  118. package/zh/guides/topic-detail/generator/codesmith/run-in-js.md +48 -0
  119. package/zh/guides/topic-detail/generator/codesmith/structure.md +86 -0
  120. package/zh/guides/topic-detail/generator/config/mwa.md +4 -8
  121. package/zh/guides/topic-detail/generator/plugin/api/file/addFile.md +1 -1
  122. package/zh/guides/topic-detail/generator/plugin/api/file/addHelper.md +1 -1
  123. package/zh/guides/topic-detail/generator/plugin/api/file/addPartial.md +2 -2
  124. package/zh/guides/topic-detail/generator/plugin/api/file/introduce.md +1 -1
  125. package/zh/guides/topic-detail/generator/plugin/api/file/rmDir.md +1 -1
  126. package/zh/guides/topic-detail/generator/plugin/api/file/rmFile.md +1 -1
  127. package/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.md +3 -2
  128. package/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.md +2 -2
  129. package/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.md +1 -1
  130. package/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.md +3 -3
  131. package/zh/guides/topic-detail/generator/plugin/api/hook/onForged.md +3 -3
  132. package/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.md +1 -1
  133. package/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.md +1 -1
  134. package/zh/guides/topic-detail/generator/plugin/api/input/type.md +1 -1
  135. package/zh/guides/topic-detail/generator/plugin/api/new/createElement.md +1 -1
  136. package/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.md +1 -1
  137. package/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.md +1 -1
  138. package/zh/guides/topic-detail/generator/plugin/api/npm/install.md +1 -1
  139. package/zh/guides/topic-detail/generator/plugin/develop.md +11 -7
  140. package/zh/guides/topic-detail/monorepo/sub-project-interface.md +0 -2
  141. package/zh/tutorials/first-app/c01-getting-started/1.1-prerequisites.md +2 -2
  142. package/zh/tutorials/first-app/c02-generator-and-studio/2.1-generator.md +0 -8
  143. package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +15 -7
  144. package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +1 -1
  145. package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +1 -5
  146. package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +0 -8
  147. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/env.md +0 -72
  148. package/zh/apis/app/runtime/env.md +0 -70
  149. package/zh/components/deploy.md +0 -60
  150. package/zh/components/dev-ide.md +0 -1
  151. package/zh/components/entry-name.md +0 -15
  152. package/zh/components/env-prepare.md +0 -1
  153. package/zh/components/launch-bff-choices.md +0 -6
  154. package/zh/guides/advanced-features/bff/bff-server.md +0 -142
  155. package/zh/guides/advanced-features/typescript.md +0 -4
  156. package/zh/guides/concept/integrated.md +0 -4
  157. package/zh/guides/concept/solutions.md +0 -4
@@ -0,0 +1,86 @@
1
+ ---
2
+ sidebar_position: 2
3
+ ---
4
+
5
+ # 微生成器的组成
6
+
7
+ 一个微生成器项目为一个模块项目或者一个 Npm 包,包中包含几个基本部分:
8
+
9
+ ## package.json
10
+
11
+ npm 包描述信息,包含 name、version、main 等字段。
12
+
13
+ ## 入口文件
14
+
15
+ 上述 main 字段对应的 js 文件。文件为默认导出一个生成器函数,函数格式如下:
16
+
17
+ ```typescript
18
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
19
+
20
+ };
21
+ ```
22
+
23
+ 该函数参数为 context 和 generator:
24
+
25
+ ### context
26
+
27
+ context 提供 codesmith 运行时维护的上下文信息。其类型定义为:
28
+
29
+ ```typescript
30
+ interface GeneratorContext {
31
+ materials: Record<string, FsMaterial>; // 资源
32
+ config: Record<string, any>; // 用户 config 配置
33
+ data?: Record<string, any>; // 用户 data 配置
34
+ current: { material: FsMaterial; } | null; // 当前生成器运行可获取的文件资源
35
+ [key: string]: any; // 其他补充字段
36
+ }
37
+ ```
38
+
39
+ materials 是 codesmith 的抽象文件系统,维护这生成器名称和可操作文件的映射关系。
40
+
41
+ materials 中还维护这一个 default 的映射关系,用于维护当前生成器执行目录的资源信息,通过该字段可以对目标项目资源进行操作。
42
+
43
+ 例如当需要修改当前项目的 `package.json` 中的字段:
44
+
45
+ ```typescript
46
+ const resource = context.materials.default.get(path.join(appDir, 'package.json'))
47
+ ```
48
+
49
+ 将获取到的 resource 传递给 codesmith 提供的 JSON API 即可实现 json 操作。
50
+
51
+ GeneratorContext 的 current 字段上维护这当前运行的生成器文件资源,可以通过 `current.material` 获取到当前的 `FsMaterial`.
52
+
53
+ FsMaterial 中提供了 get 方法用于获取资源文件并将资源文件传给生成器支持的 API 即可对模板文件进行处理。
54
+
55
+ 例如:
56
+
57
+ ```typescript
58
+ const resourceMap = await material.find('templates/**/*');
59
+ ```
60
+
61
+ 通过上述方式可以获取到生成器中符合 `templates/**/*` 规则的所有模板文件,遍历该对象即可对资源文件进行操作。
62
+
63
+ ### generator
64
+
65
+ generator 提供 codesmith 运行时的函数方法。其类型定义为:
66
+
67
+ ```typescript
68
+ interface GeneratorCore {
69
+ logger: Logger; // log 函数,支持 info、warning、debug、error、verbose、stream
70
+ outputPath: string; // 输出文件路径
71
+ output: {
72
+ fs: (file: string | number, data: any, options?: string | fs.WriteFileOptions | undefined) => Promise<void>
73
+ }; // 写文件方法
74
+ runSubGenerator: (subGenerator: string, relativePwdPath?: string | undefined, config?: Record<string, any> | undefined): Promise<void> // 运行子生成器
75
+ }
76
+ ```
77
+
78
+ 其中 outputPath 和 context 中的 `materials.default` 指向相同的目录,outputPath 用于直接计算目标路径并操作,`materials.default` 用于获取资源文件。
79
+
80
+ runSubGenerator 提供了在一个微生成器中去运行其他微生成器的方法,该方法将自动更新和维护新的 context 上下文信息。
81
+
82
+ ## Template 文件
83
+
84
+ 生成器模板文件。
85
+
86
+ 推荐在项目根目录创建一个 templates 目录,用于维护该微生成器的模板文件,微生成器执行过程中只能使用自身的模板文件,对于需要共用的模板文件,建议通过共用子生成器实现。
@@ -32,7 +32,7 @@ New 命令的操作类型(actionType),类型支持两种:
32
32
 
33
33
  - 创建应用入口(entry)
34
34
 
35
- - 新建 Server 自定义源码目(server)
35
+ - 新建自定义 Web Serve 源码目录(server)
36
36
 
37
37
  这两个选项还需要配置具体的配合使用,介绍如下:
38
38
 
@@ -40,11 +40,9 @@ New 命令的操作类型(actionType),类型支持两种:
40
40
 
41
41
  入口名称(name), 字符串类型。
42
42
 
43
- 创建入口除了`name`之外,还需要 `needModifyMWAConfig`、`clientRoute` 字段。
44
-
45
43
  #### framework
46
44
 
47
- 自定义 Server 运行时框架(framework),支持两个选项:
45
+ 自定义 Web Serve 运行时框架(framework),支持两个选项:
48
46
 
49
47
  - Express(express)
50
48
 
@@ -66,13 +64,11 @@ New 命令的操作类型(actionType),类型支持两种:
66
64
 
67
65
  - Storybook(mwa_storybook)
68
66
 
69
- - 部署(deploy)
70
-
71
67
  - 启用「基于 UA 的 Polyfill」功能(polyfill)
72
68
 
73
69
  - 启用「全局代理」(proxy)
74
70
 
75
- `bff` 和 `deploy` 和还需要配置具体的配合使用,介绍如下:
71
+ `bff` 和还需要配置具体的配合使用,介绍如下:
76
72
 
77
73
  #### BFF 相关参数
78
74
 
@@ -86,7 +82,7 @@ BFF 类型(bffType),支持两个选项:
86
82
 
87
83
  ##### framework
88
84
 
89
- 扩展 Web Server 运行时框架(framework),支持两个选项:
85
+ BFF 运行时框架(framework),支持两个选项:
90
86
 
91
87
  - Express(express)
92
88
 
@@ -8,7 +8,7 @@ sidebar_position: 4
8
8
 
9
9
  该方法可用于任何文件类型,对于二进制以外的文件类型,添加文件时会进行 Handlebars 渲染。
10
10
 
11
- 该方法可在 onForged 生命周期的 api 参数上获取。
11
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
12
12
 
13
13
  其类型定义为:
14
14
 
@@ -6,7 +6,7 @@ sidebar_position: 2
6
6
 
7
7
  针对于文本类型文件,增加 Handlebars 的自定义 Help 函数,具体可查看文档[Custom Helpers](https://handlebarsjs.com/guide/#custom-helpers)。
8
8
 
9
- 该方法可在 onForged 生命周期的 api 参数上获取。
9
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
10
10
 
11
11
  其类型定义为:
12
12
 
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
 
7
7
  针对于文本类型文件,增加 Handlebars 的自定义 Partial 片段,具体可查看文档[Partials](https://handlebarsjs.com/guide/#partials)。
8
8
 
9
- 该方法可在 onForged 生命周期的 api 参数上获取。
9
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
10
10
 
11
11
  其类型定义为:
12
12
 
@@ -19,7 +19,7 @@ export type ForgedAPI = {
19
19
 
20
20
  ## name
21
21
 
22
- partial名称。
22
+ partial 名称。
23
23
 
24
24
  ## str
25
25
 
@@ -4,7 +4,7 @@ sidebar_position: 1
4
4
 
5
5
  # 介绍
6
6
 
7
- 文件操作 API 可在 onForged 生命周期函数中使用,可对当前项目文件进行增、删、改的操作。
7
+ 文件操作 API 可在 `onForged` 生命周期函数中使用,可对当前项目文件进行增、删、改的操作。
8
8
 
9
9
  文件操作 API 相关路径填写项目相对路径即可,生成器插件会自动添加当前项目路径前缀。
10
10
 
@@ -8,7 +8,7 @@ sidebar_position: 10
8
8
 
9
9
  该方法可用于任何文件类型。
10
10
 
11
- 该方法可在 onForged 生命周期的 api 参数上获取。
11
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
12
12
 
13
13
  其类型定义为:
14
14
 
@@ -8,7 +8,7 @@ sidebar_position: 9
8
8
 
9
9
  该方法可用于任何文件类型。
10
10
 
11
- 该方法可在 onForged 生命周期的 api 参数上获取。
11
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
12
12
 
13
13
  其类型定义为:
14
14
 
@@ -8,7 +8,7 @@ sidebar_position: 6
8
8
 
9
9
  该方法适用于 JSON 文件类型,可批量更新 JSON 文件中字段值。
10
10
 
11
- 该方法可在 onForged 生命周期的 api 参数上获取。
11
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
12
12
 
13
13
  其类型定义为:
14
14
 
@@ -29,7 +29,8 @@ JSON 文件的文件名或者文件路径。
29
29
  ## updateInfo
30
30
 
31
31
  字段更新信息。
32
- 该信息使用 Record 形式表示。
32
+
33
+ 该信息使用 `Record` 形式表示。
33
34
 
34
35
  例如需要更新 name 字段:
35
36
 
@@ -6,7 +6,7 @@ sidebar_position: 8
6
6
 
7
7
  更新 `package.json` 中 `modernConfig` 字段。
8
8
 
9
- 该方法可在 onForged 生命周期的 api 参数上获取。
9
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
10
10
 
11
11
  其类型定义为:
12
12
 
@@ -22,5 +22,5 @@ export type ForgedAPI = {
22
22
  字段更新信息。
23
23
 
24
24
  :::info
25
- 该函数为 updateJSONFile 的封装,将自动更新 `package.json` 的 `modernConfig` 字段 updateInfo 中只需填写相对于 `modernConfig` 的更新信息即可。
25
+ 该函数为 updateJSONFile 的封装,将自动更新 `package.json` 的 `modernConfig` 字段 `updateInfo` 中只需填写相对于 `modernConfig` 的更新信息即可。
26
26
  :::
@@ -8,7 +8,7 @@ sidebar_position: 7
8
8
 
9
9
  该方法适用与文本列表文件类型。
10
10
 
11
- 该方法可在 onForged 生命周期的 api 参数上获取。
11
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
12
12
 
13
13
  其类型定义为:
14
14
 
@@ -4,7 +4,7 @@ sidebar_position: 2
4
4
 
5
5
  # AfterForged
6
6
 
7
- afterForged 函数为生成器插件生命周期函数,其通常用于定义安装依赖、Git 等操作,专业些操作将会在 onForged 函数执行完成后进行。
7
+ `afterForged` 函数为生成器插件生命周期函数,其通常用于定义安装依赖、Git 等操作,这些操作将会在 `onForged` 函数执行完成后进行。
8
8
 
9
9
  该方法可直接在 context 上获取。
10
10
 
@@ -24,11 +24,11 @@ export interface IPluginContext {
24
24
 
25
25
  ## func
26
26
 
27
- afterForged 参数是一个回调函数,函数参数为 api 和 inputData
27
+ `afterForged` 参数是一个回调函数,函数参数为 `api``inputData。`
28
28
 
29
29
  ### api
30
30
 
31
- 在 afterForged 生命周期中支持的函数列表,具体可查看 [Git API](/docs/guides/topic-detail/generator/plugin/api/git/isInGitRepo) 和 [NPM API](/docs/guides/topic-detail/generator/plugin/api/npm/install)。
31
+ `afterForged` 生命周期中支持的函数列表,具体可查看 [Git API](/docs/guides/topic-detail/generator/plugin/api/git/isInGitRepo) 和 [NPM API](/docs/guides/topic-detail/generator/plugin/api/npm/install)。
32
32
 
33
33
  ### inputData
34
34
 
@@ -4,7 +4,7 @@ sidebar_position: 1
4
4
 
5
5
  # OnForged
6
6
 
7
- onForged 函数为生成器插件生命周期函数,其通常用于定义文件类型操作,这些操作将在 base 的工程方案文件操作完成后进行。
7
+ `onForged` 函数为生成器插件生命周期函数,其通常用于定义文件类型操作,这些操作将在 base 的工程方案文件操作完成后进行。
8
8
 
9
9
  该方法可直接在 context 上获取。
10
10
 
@@ -24,11 +24,11 @@ export interface IPluginContext {
24
24
 
25
25
  ## func
26
26
 
27
- onForged 参数是一个回调函数,函数参数为 api 和 inputData。
27
+ `onForged` 参数是一个回调函数,函数参数为 api 和 inputData。
28
28
 
29
29
  ### api
30
30
 
31
- 在 onForged 生命周期中支持的函数列表,具体可查看[文件操作 API](/docs/guides/topic-detail/generator/plugin/api/file/introduce) 和[启用功能 API](/docs/guides/topic-detail/generator/plugin/api/new/introduce)。
31
+ `onForged` 生命周期中支持的函数列表,具体可查看[文件操作 API](/docs/guides/topic-detail/generator/plugin/api/file/introduce) 和[启用功能 API](/docs/guides/topic-detail/generator/plugin/api/new/introduce)。
32
32
 
33
33
  ### inputData
34
34
 
@@ -35,7 +35,7 @@ context.addInputAfter('packageManager', {
35
35
  properties: {
36
36
  language: {
37
37
  type: 'string',
38
- title: i18n.t(localeKeys.plugin_type.self),
38
+ title: '开发语言',
39
39
  enum: [
40
40
  { label: 'TS', value: 'ts' },
41
41
  { label: 'ES6+', value: 'js' },
@@ -35,7 +35,7 @@ context.addInputBefore('packageManager', {
35
35
  properties: {
36
36
  language: {
37
37
  type: 'string',
38
- title: i18n.t(localeKeys.plugin_type.self),
38
+ title: '开发语言',
39
39
  enum: [
40
40
  { label: 'TS', value: 'ts' },
41
41
  { label: 'ES6+', value: 'js' },
@@ -54,7 +54,7 @@ const schema = {
54
54
  properties: {
55
55
  language: {
56
56
  type: 'string',
57
- title: i18n.t(localeKeys.plugin_type.self),
57
+ title: '开发语言',
58
58
  enum: [
59
59
  { label: 'TS', value: 'ts' },
60
60
  { label: 'ES6+', value: 'js' },
@@ -6,7 +6,7 @@ sidebar_position: 2
6
6
 
7
7
  创建工程元素,只支持应用工程方案。
8
8
 
9
- 该方法可在 onForged 生命周期的 api 参数上获取。
9
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
10
10
 
11
11
  其类型定义为:
12
12
 
@@ -6,7 +6,7 @@ sidebar_position: 4
6
6
 
7
7
  创建子项目,只支持 Monorepo 工程方案。
8
8
 
9
- 该方法可在 onForged 生命周期的 api 参数上获取。
9
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
10
10
 
11
11
  其类型定义为:
12
12
 
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
 
7
7
  启用功能,支持应用和模块工程方案。
8
8
 
9
- 该方法可在 onForged 生命周期的 api 参数上获取。
9
+ 该方法可在 `onForged` 生命周期的 api 参数上获取。
10
10
 
11
11
  其类型定义为:
12
12
 
@@ -6,7 +6,7 @@ sidebar_position: 1
6
6
 
7
7
  在项目根目录安装依赖。
8
8
 
9
- install 函数中将根据 packageManager 的值使用对应的包管理工具安装依赖。
9
+ install 函数中将根据 `packageManager` 的值使用对应的包管理工具安装依赖。
10
10
 
11
11
  ```ts
12
12
  export type AfterForgedAPI = {
@@ -61,11 +61,15 @@ npx @modern-js/create plugin --plugin @modern-js/generator-plugin-plugin
61
61
  在默认的输入前添加输入,比如在`选择包管理工具`问题前添加问题,具体 Modern.js 每个问题的配置可查看[工程方案配置](/docs/guides/topic-detail/generator/config/common)。
62
62
 
63
63
  ```ts
64
- context.addInputBefore('packageManager', {
65
- key: 'test',
66
- name: '测试输入',
67
- type: 'input'
68
- })
64
+ context.addInputBefore('input2', {
65
+ type: 'object',
66
+ properties: {
67
+ 'input1.2': {
68
+ type: 'string',
69
+ title: 'input1.2',
70
+ },
71
+ },
72
+ });
69
73
  ```
70
74
 
71
75
  - setInput
@@ -73,8 +77,8 @@ context.addInputBefore('packageManager', {
73
77
  设置已经存在问题的属性
74
78
 
75
79
  ```ts
76
- context.setInput('test', 'type', 'radio')
77
- context.setInput('test', 'options', [{ key: 'option1', name: '选项一' }])
80
+ context.setInput('test', 'type', 'number')
81
+ context.setInput('test', 'enum', [{ value: 'option1', label: '选项一' }])
78
82
  ```
79
83
 
80
84
  ### onForged
@@ -22,8 +22,6 @@ sidebar_position: 3
22
22
  ? 请填写子项目名称 app
23
23
  ? 请填写子项目目录名称 app
24
24
  ? 请选择开发语言 TS
25
- ? 是否需要支持以下类型应用 不需要
26
- ? 是否需要调整默认配置? 否
27
25
  ```
28
26
 
29
27
  **「模块(内部)」子项目:**
@@ -10,11 +10,11 @@ title: 环境准备
10
10
 
11
11
  ## 1. Node.js
12
12
 
13
- 需要 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 14.17.6。
13
+ 需要 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 14.19.0, 推荐使用 16.x 版本。
14
14
 
15
15
  Modern.js 推荐在开发环境里先安装 [nvm](https://github.com/nvm-sh/nvm#install--update-script),在 shell 里集成[自动切换 node 版本的脚本](https://github.com/nvm-sh/nvm#deeper-shell-integration)。
16
16
 
17
- 然后只要仓库根目录下有内容为 `lts/fermium` 或 `lts/erbium` 的 `.nvmrc` 文件,进入这个仓库时就会自动安装或切换到正确的 Node.js 版本。
17
+ 然后只要仓库根目录下有内容为 `lts/fermium` 或 `lts/gallium` 的 `.nvmrc` 文件,进入这个仓库时就会自动安装或切换到正确的 Node.js 版本。
18
18
 
19
19
  ## 2. pnpm
20
20
 
@@ -54,14 +54,6 @@ Modern.js 生成器会通过交互式的问题获取一些必要信息,动态
54
54
  # 请选择包管理工具
55
55
  ❯ pnpm
56
56
  Yarn
57
-
58
- # 是否需要支持以下类型应用
59
- ❯ 不需要
60
- Electron
61
-
62
- # 是否需要调整默认配置
63
- ❯ 否
64
-
65
57
  ```
66
58
 
67
59
  项目生成后,在项目根目录执行 `pnpm run dev` 就可以直接进行调试了:
@@ -6,18 +6,26 @@ title: 样板文件
6
6
 
7
7
  ```md
8
8
  .
9
- ├── .vscode/
10
- ├── src/
11
- │   ├── .eslintrc.json
12
- │   ├── App.css
13
- │   └── App.jsx
14
- ├── .editorconfig
9
+ ├── .eslintrc.js
15
10
  ├── .gitignore
11
+ ├── .husky
12
+ ├── .idea
16
13
  ├── .npmrc
17
14
  ├── .nvmrc
15
+ ├── .prettierrc
16
+ ├── .vscode
18
17
  ├── README.md
18
+ ├── modern.config.ts
19
19
  ├── package.json
20
- └── pnpm-lock.yaml
20
+ ├── pnpm-lock.yaml
21
+ ├── src
22
+ │   ├── .eslintrc.js
23
+ │   ├── modern-app-env.d.ts
24
+ │   └── routes
25
+ │   ├── index.css
26
+ │   ├── layout.tsx
27
+ │   └── page.tsx
28
+ └── tsconfig.json
21
29
  ```
22
30
 
23
31
  和上一章节手动创建出来的项目一样,仍然是零配置、极简和轻量的,但功能更完整,最佳实践开箱即用,比如:
@@ -47,7 +47,7 @@ hello-modern 项目是一个应用工程,`src/` 目录里是应用工程源代
47
47
  一个应用入口适用于:
48
48
 
49
49
  - 一个中后台应用(SPA)
50
- - 一个桌面应用(SPA、Electron App
50
+ - 一个桌面应用(SPA)
51
51
  - 一个PWA
52
52
  - 一个大型的多页网站(SPA + SSR)
53
53
  - 一个落地页、活动页或分享页
@@ -13,14 +13,10 @@ Modern.js 支持自动创建新入口,前面的章节中提到过,`pnpm run
13
13
 
14
14
  # 创建工程元素
15
15
  ❯ 新建「应用入口」
16
- 新建「Server 自定义」源码目录
16
+ 新建「自定义 Web Serve」源码目录
17
17
 
18
18
  # 请填写入口名称
19
19
  - landing-page
20
-
21
- # 是否需要调整默认配置
22
- ❯ 否
23
-
24
20
  ```
25
21
 
26
22
  创建完成,项目会变成这样:
@@ -91,14 +91,6 @@ ni src/landing-page/pages/docs.tsx
91
91
 
92
92
  #填写入口名称:
93
93
  landing-page
94
-
95
- # 是否需要调整默认配置?
96
- ❯ 是
97
-
98
- # 请选择客户端路由方式
99
- 自控路由
100
- ❯ 约定式路由
101
- 不启用
102
94
  ```
103
95
 
104
96
  假设这个 `landing-page` 入口是一个简单的有导航栏的落地页,包含两个子页面:一个首页和一个文档页,我们用客户端路由的方式来区别这两个子页面。
@@ -1,72 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- title: Environment Variables
4
- ---
5
-
6
- Modern.js has built-in support for environment variables, including built-in environment variables and custom environment variables.
7
-
8
- ## Built-in Environment Variables
9
-
10
- ### NODE_ENV
11
-
12
- A **read-only** environment variable, whose have different values under different execution commands:
13
-
14
- - `production`: default value when executing `modern build`、`modern preview` commands.
15
- - `test`: default value when executing `modern test` commands.
16
- - `development`: default value when executing `modern dev` commands, also the default value in all other cases.
17
-
18
- ### MODERN_ENV
19
-
20
- Used to set the current execution environment.In addition to the values corresponding to the above NODE_ENV, custom environment names are supported here, such as `staging`, `boe`.
21
-
22
- Modern.js loads the environment variables values set in the `.env.{process.env.MODERN_ENV}` file for that environment variable.
23
-
24
- When you need to use different configurations through the environment name, you can define environment variables in the `.env` file of the corresponding environment name.
25
-
26
- MODERN_ENV priority is higher than NODE_ENV.
27
-
28
- ## Custom Environment Variables
29
-
30
- Modern.js support custom environment variables, which starting with MODERN_ can be used directly in the code.
31
-
32
- If you need to automatically use environment variables with any name, you need to declare them in the ['source.define'](/docs/configure/app/source/define) configuration.
33
-
34
- ## Define Environment Variables
35
-
36
- Environment variables are specified in both `shell` and `.env` files.
37
-
38
- ### Specify Via Shell
39
-
40
- Add custom environment variables before the command:
41
-
42
- ```shell
43
- REACT_APP_FOO=123 BAR=456 pnpm run dev
44
- ```
45
-
46
- ### Specify Via File
47
-
48
- Create a `.env` file in the project with custom environment variables:
49
-
50
- ```env
51
- REACT_APP_FOO=123
52
- BAR=456
53
- ```
54
-
55
- `.env` files support suffixes NODE_ENV or MODERN_ENV defined environment names, such as `env.development`. Modern.js reads the env file based on the environment name variable value.
56
-
57
- ## Using Environment Variables
58
-
59
- ### Use In JS
60
-
61
- Get environment variables directly with `process.env.*`.
62
-
63
- ```js
64
- console.log(process.env.NODE_ENV);
65
- // "development"
66
- ```
67
-
68
- ### Use In HTML
69
-
70
- ```html title="config/html/head.ejs"
71
- <meta name="env" content="<%=process.env.NODE_ENV %>" />
72
- ```
@@ -1,70 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- title: 环境变量
4
- ---
5
-
6
- Modern.js 内置了对环境变量的支持,包含内置的环境变量和自定义的环境变量。
7
-
8
- ## 内置的环境变量
9
-
10
- ### NODE_ENV
11
-
12
- 表示当前的执行环境,是**只读的**的环境变量,其值在不同的执行命令下具有不同的值:
13
-
14
- - `production`:执行 `modern build`、`modern preview` 命令时的默认值。
15
- - `test`:执行 `modern test` 命令时的默认值。
16
- - `development`:执行 `modern dev` 命令时的默认值,同时也是其他所有情况下的默认值。
17
-
18
- ### MODERN_ENV
19
-
20
- 用于设置当前的执行环境,除了上述 NODE_ENV 对应的值之外,这里支持自定义环境名称,比如 `staging`、`boe` 等,Modern.js 会根据该环境变量对应的加载 env.{process.env.MODERN_ENV} 文件中设置的环境变量值。
21
-
22
- 当需要通过环境名称使用不同的配置时,可以把环境变量定义到对应的环境名称的 env 文件中。
23
-
24
- MODERN_ENV 的优先级高于 NODE_ENV。
25
-
26
- ## 自定义环境变量
27
-
28
- Modern.js 支持自定义的环境变量,以 `MODERN_` 开头的环境变量可以在代码中直接使用。
29
-
30
- 如果需要自动以任意名称的环境变量,需要在 [`source.define`](/docs/configure/app/source/define) 配置中声明后使用。
31
-
32
- ## 定义环境变量
33
-
34
- 环境变量支持通过 `shell` 和 `.env` 文件两种方式指定。
35
-
36
- ### 通过 `shell` 指定
37
-
38
- 在命令前添加自定义环境变量:
39
-
40
- ```shell
41
- REACT_APP_FOO=123 BAR=456 pnpm run dev
42
- ```
43
-
44
- ### 通过 `.env` 文件指定
45
-
46
- 在项目根目录创建 `.env` 文件,其中添加自定义环境变量:
47
-
48
- ```env
49
- REACT_APP_FOO=123
50
- BAR=456
51
- ```
52
-
53
- .env 文件支持后缀名后 NODE_ENV 或 MODERN_ENV 定义的环境名称,如 `.env.development`,可根据项目需求进行定义。Modern.js 会根据环境名称变量值读取对应的 env 文件。
54
-
55
- ## 使用环境变量
56
-
57
- ### JS/TS 代码内使用
58
-
59
- 通过 `process.env.*` 直接获取环境变量。
60
-
61
- ```js
62
- console.log(process.env.NODE_ENV);
63
- // "development"
64
- ```
65
-
66
- ### HTML 代码片段使用
67
-
68
- ```html title="config/html/head.ejs"
69
- <meta name="env" content="<%=process.env.NODE_ENV %>" />
70
- ```