@modern-js/main-doc 2.21.1 → 2.22.0

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