@modern-js/main-doc 2.21.0 → 2.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. package/CHANGELOG.md +24 -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/global-proxy.mdx +7 -7
  28. package/docs/en/components/init-app.mdx +3 -3
  29. package/docs/en/components/init-rspack-app.mdx +4 -4
  30. package/docs/en/components/language-config.mdx +9 -0
  31. package/docs/en/components/package-manager.mdx +11 -0
  32. package/docs/en/components/ua-polyfill.mdx +2 -2
  33. package/docs/en/configure/app/source/config-dir.mdx +1 -1
  34. package/docs/en/configure/app/source/design-system.mdx +67 -67
  35. package/docs/en/configure/app/source/disable-default-entries.mdx +6 -5
  36. package/docs/en/configure/app/source/disable-entry-dirs.mdx +5 -5
  37. package/docs/en/configure/app/source/enable-async-entry.mdx +9 -9
  38. package/docs/en/configure/app/source/entries-dir.mdx +3 -3
  39. package/docs/en/configure/app/source/entries.mdx +21 -19
  40. package/docs/en/configure/app/tools/swc.mdx +2 -2
  41. package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
  42. package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
  43. package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
  44. package/docs/en/guides/advanced-features/rspack-start.mdx +6 -6
  45. package/docs/en/guides/advanced-features/ssg.mdx +2 -2
  46. package/docs/en/guides/advanced-features/testing.mdx +2 -2
  47. package/docs/en/guides/advanced-features/web-server.mdx +2 -2
  48. package/docs/en/guides/basic-features/css.mdx +2 -2
  49. package/docs/en/guides/basic-features/mock.mdx +1 -1
  50. package/docs/en/guides/basic-features/proxy.mdx +4 -5
  51. package/docs/en/guides/basic-features/routes.mdx +11 -7
  52. package/docs/en/guides/concept/entries.mdx +3 -3
  53. package/docs/en/guides/topic-detail/generator/create/_category_.json +4 -0
  54. package/docs/en/guides/topic-detail/generator/create/config.mdx +75 -0
  55. package/docs/en/guides/topic-detail/generator/create/option.md +151 -0
  56. package/docs/en/guides/topic-detail/generator/create/use.mdx +66 -0
  57. package/docs/en/guides/topic-detail/generator/new/_category_.json +4 -0
  58. package/docs/en/guides/topic-detail/generator/new/config.md +155 -0
  59. package/docs/en/guides/topic-detail/generator/new/option.md +67 -0
  60. package/docs/en/guides/topic-detail/generator/new/use.md +95 -0
  61. package/docs/en/guides/topic-detail/generator/plugin/_category_.json +2 -2
  62. package/docs/en/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
  63. package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +49 -0
  64. package/docs/en/guides/topic-detail/generator/plugin/api/context.md +184 -0
  65. package/docs/en/guides/topic-detail/generator/plugin/api/input.md +124 -0
  66. package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
  67. package/docs/en/guides/topic-detail/generator/plugin/category.md +88 -0
  68. package/docs/en/guides/topic-detail/generator/plugin/context.md +104 -0
  69. package/docs/en/guides/topic-detail/generator/plugin/structure.md +106 -0
  70. package/docs/en/guides/topic-detail/generator/plugin/use.md +33 -0
  71. package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
  72. package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
  73. package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
  74. package/docs/zh/apis/app/commands.mdx +3 -3
  75. package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
  76. package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
  77. package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
  78. package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
  79. package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
  80. package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
  81. package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
  82. package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
  83. package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
  84. package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
  85. package/docs/zh/apis/app/hooks/shared.mdx +1 -1
  86. package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
  87. package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
  88. package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
  89. package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
  90. package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
  91. package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +5 -1
  92. package/docs/zh/components/language-config.mdx +9 -0
  93. package/docs/zh/components/package-manager.mdx +11 -0
  94. package/docs/zh/components/ua-polyfill.mdx +1 -1
  95. package/docs/zh/configure/app/source/design-system.mdx +3 -4
  96. package/docs/zh/configure/app/source/enable-async-entry.mdx +2 -5
  97. package/docs/zh/configure/app/source/entries.mdx +2 -2
  98. package/docs/zh/configure/app/tools/swc.mdx +2 -2
  99. package/docs/zh/guides/advanced-features/rspack-start.mdx +6 -6
  100. package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
  101. package/docs/zh/guides/advanced-features/testing.mdx +2 -2
  102. package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
  103. package/docs/zh/guides/basic-features/css.mdx +1 -1
  104. package/docs/zh/guides/basic-features/mock.mdx +1 -1
  105. package/docs/zh/guides/basic-features/routes.mdx +7 -4
  106. package/docs/zh/guides/concept/entries.mdx +3 -3
  107. package/docs/zh/guides/topic-detail/generator/create/_category_.json +4 -0
  108. package/docs/zh/guides/topic-detail/generator/create/config.mdx +76 -0
  109. package/docs/zh/guides/topic-detail/generator/create/option.md +151 -0
  110. package/docs/zh/guides/topic-detail/generator/create/use.mdx +66 -0
  111. package/docs/zh/guides/topic-detail/generator/new/_category_.json +4 -0
  112. package/docs/zh/guides/topic-detail/generator/new/config.md +153 -0
  113. package/docs/zh/guides/topic-detail/generator/new/option.md +67 -0
  114. package/docs/zh/guides/topic-detail/generator/new/use.md +94 -0
  115. package/docs/zh/guides/topic-detail/generator/plugin/_category_.json +2 -2
  116. package/docs/zh/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
  117. package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +50 -0
  118. package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +184 -0
  119. package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +124 -0
  120. package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
  121. package/docs/zh/guides/topic-detail/generator/plugin/category.md +93 -0
  122. package/docs/zh/guides/topic-detail/generator/plugin/context.md +105 -0
  123. package/docs/zh/guides/topic-detail/generator/plugin/structure.md +106 -0
  124. package/docs/zh/guides/topic-detail/generator/plugin/use.md +33 -0
  125. package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
  126. package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
  127. package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
  128. package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
  129. package/modern.config.ts +2 -1
  130. package/package.json +5 -5
  131. package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
  132. package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
  133. package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
  134. package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
  135. package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
  136. package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
  137. package/docs/en/guides/topic-detail/generator/codesmith/_category_.json +0 -4
  138. package/docs/en/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
  139. package/docs/en/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
  140. package/docs/en/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
  141. package/docs/en/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
  142. package/docs/en/guides/topic-detail/generator/codesmith/api/git.mdx +0 -50
  143. package/docs/en/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -57
  144. package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
  145. package/docs/en/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -48
  146. package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
  147. package/docs/en/guides/topic-detail/generator/codesmith/introduce.mdx +0 -47
  148. package/docs/en/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
  149. package/docs/en/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
  150. package/docs/en/guides/topic-detail/generator/config/_category_.json +0 -4
  151. package/docs/en/guides/topic-detail/generator/config/app.mdx +0 -82
  152. package/docs/en/guides/topic-detail/generator/config/common.mdx +0 -100
  153. package/docs/en/guides/topic-detail/generator/config/module.mdx +0 -42
  154. package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +0 -28
  155. package/docs/en/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
  156. package/docs/en/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
  157. package/docs/en/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
  158. package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
  159. package/docs/en/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -58
  160. package/docs/en/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
  161. package/docs/en/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
  162. package/docs/en/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
  163. package/docs/en/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
  164. package/docs/en/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
  165. package/docs/en/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
  166. package/docs/en/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
  167. package/docs/en/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
  168. package/docs/en/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
  169. package/docs/en/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
  170. package/docs/en/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
  171. package/docs/en/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
  172. package/docs/en/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
  173. package/docs/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
  174. package/docs/en/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
  175. package/docs/en/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
  176. package/docs/en/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
  177. package/docs/en/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
  178. package/docs/en/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
  179. package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -55
  180. package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -55
  181. package/docs/en/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
  182. package/docs/en/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -31
  183. package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
  184. package/docs/en/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -90
  185. package/docs/en/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
  186. package/docs/en/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
  187. package/docs/en/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
  188. package/docs/en/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
  189. package/docs/en/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
  190. package/docs/en/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
  191. package/docs/en/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -18
  192. package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +0 -125
  193. package/docs/en/guides/topic-detail/generator/plugin/use.mdx +0 -61
  194. package/docs/en/guides/topic-detail/generator/project.mdx +0 -118
  195. package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
  196. package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
  197. package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
  198. package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
  199. package/docs/zh/guides/topic-detail/generator/codesmith/_category_.json +0 -4
  200. package/docs/zh/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
  201. package/docs/zh/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
  202. package/docs/zh/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
  203. package/docs/zh/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
  204. package/docs/zh/guides/topic-detail/generator/codesmith/api/git.mdx +0 -49
  205. package/docs/zh/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -56
  206. package/docs/zh/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
  207. package/docs/zh/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -47
  208. package/docs/zh/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
  209. package/docs/zh/guides/topic-detail/generator/codesmith/introduce.mdx +0 -59
  210. package/docs/zh/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
  211. package/docs/zh/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
  212. package/docs/zh/guides/topic-detail/generator/config/_category_.json +0 -4
  213. package/docs/zh/guides/topic-detail/generator/config/app.mdx +0 -82
  214. package/docs/zh/guides/topic-detail/generator/config/common.mdx +0 -100
  215. package/docs/zh/guides/topic-detail/generator/config/module.mdx +0 -42
  216. package/docs/zh/guides/topic-detail/generator/config/monorepo.mdx +0 -28
  217. package/docs/zh/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
  218. package/docs/zh/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
  219. package/docs/zh/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
  220. package/docs/zh/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
  221. package/docs/zh/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -55
  222. package/docs/zh/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
  223. package/docs/zh/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
  224. package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
  225. package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
  226. package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
  227. package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
  228. package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
  229. package/docs/zh/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
  230. package/docs/zh/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
  231. package/docs/zh/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
  232. package/docs/zh/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
  233. package/docs/zh/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
  234. package/docs/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
  235. package/docs/zh/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
  236. package/docs/zh/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
  237. package/docs/zh/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
  238. package/docs/zh/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
  239. package/docs/zh/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
  240. package/docs/zh/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
  241. package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -57
  242. package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -56
  243. package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
  244. package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -29
  245. package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
  246. package/docs/zh/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -92
  247. package/docs/zh/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
  248. package/docs/zh/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
  249. package/docs/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
  250. package/docs/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
  251. package/docs/zh/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
  252. package/docs/zh/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
  253. package/docs/zh/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -16
  254. package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +0 -125
  255. package/docs/zh/guides/topic-detail/generator/plugin/use.mdx +0 -61
  256. package/docs/zh/guides/topic-detail/generator/project.mdx +0 -118
@@ -1,152 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # @modern-js/codesmith-api-app
6
-
7
- The combination encapsulation of APIs commonly used in the development of microgenerators, including APIs encapsulation of other packages such as fs, git, npm, etc. When the requirements can be met, it is recommended to use the API of the npm package.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { AppAPI } from '@modern-js/codesmith-api-app';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const appApi = new AppAPI(context, generator);
16
- await appApi.runInstall();
17
- };
18
- ```
19
-
20
- - Create AppAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
21
- - Just call the API on its example.
22
-
23
- ## API
24
-
25
- ### checkEnvironment
26
-
27
- Check the current generator operating environment, the check items are:
28
-
29
- 1. The node and node versions, the default is greater than 12.22.12, and the node version can be executed by passing parameters.
30
- 2. Yarn, pnpm or npm can be used.
31
-
32
- Parameter:
33
-
34
- - nodeVersion?: `string`. Node version want to check.
35
-
36
- ### runInstall
37
-
38
- To install dependency, you can pass in the install dependency command, which defaults to the `packageManager` value in config.
39
-
40
- Parameter:
41
-
42
- - command?: `string`, Install dependency command.
43
-
44
- ### runGitAndInstall
45
-
46
- This function performs the following actions:
47
-
48
- 1. Check whether the current generator execution directory is a git repository.
49
- 2. If not a git repository, initialization is a git repository.
50
- 3. Install dependencies.
51
- 4. Commit the initial commit in a non-monorepo project (judging the condition, `isMonorepoSubProject` does not exist or is false in the config), the commit information is feat: init, and customize is supported.
52
-
53
- Parameter:
54
-
55
- - commitMessage?: `string`, Initialization commit message
56
- - installFunc?: `() => Promise<void>`. Install dependency function
57
-
58
- ### forgeTemplate
59
-
60
- Render generator template file.
61
-
62
- Parameter:
63
-
64
- - templatePattern: `string`. Template files match regularities,for example: `templates/base-templates/**/*` .
65
- - filter?: `(resourceKey: string) => boolean`. Filter function, the parameter is the file path matching the `templatePattern`, return true to render the file, return false to render the file.
66
- - rename?: `(resourceKey: string) => string`. Rename function, the parameter is the file path matching `templatePattern`, and the new filename is returned. The templates directory at the beginning of `resourceKey` and the `.handlebars` suffix at the end will be replaced by default.
67
- - parameters?: `Record<string, any>`. Render parameter, when there is a handlebars or ejs variable in the template, use it to pass the corresponding variable value.
68
- - type?: `'handlebars' | 'ejs'`. Template file type, defaults to handlebars.
69
-
70
- For example:
71
-
72
- ```ts
73
- await appApi.forgeTemplate(
74
- 'templates/base-templates/**/*',
75
- undefined,
76
- resourceKey =>
77
- resourceKey
78
- .replace('templates/base-templates/', '')
79
- .replace('.handlebars', ''),
80
- );
81
-
82
- await appApi.forgeTemplate(
83
- 'templates/base-template/**/*',
84
- resourceKey => !resourceKey.include('eslintrc.json'),
85
- resourceKey =>
86
- resourceKey
87
- .replace('templates/base-template/', projectPath)
88
- .replace('language', language as string)
89
- .replace('.handlebars', ''),
90
- {
91
- name: packageName as string,
92
- language,
93
- isTs: language === Language.TS,
94
- packageManager: getPackageManagerText(packageManager as any),
95
- },
96
- );
97
- ```
98
-
99
- ### showSuccessInfo
100
-
101
- Display success information.
102
-
103
- Parameter:
104
-
105
- - successInfo?: `string`. Default is Success.
106
-
107
- ### runSubGenerator
108
-
109
- Run the subgenerator.
110
-
111
- Parameter:
112
-
113
- - subGenerator: `string`. Subgenerator name or path.
114
- - relativePwdPath?: `string`. The relative path to which the'string 'subgenerator runs.
115
- - config?: `Record<string, unknown>`. Default config configuration for subgenerator runs.
116
-
117
- For example:
118
-
119
- ```ts
120
- await appApi.runSubGenerator(
121
- getGeneratorPath('@modern-js/repo-generator', context.config.distTag),
122
- undefined,
123
- { ...context.config, hasPlugin: false },
124
- );
125
- ```
126
-
127
- ### getInputBySchema
128
-
129
- User interaction input is done through schema.
130
-
131
- Parameter:
132
-
133
- - schema: `FormilySchema | Question[]`. Question list, supports Formily schema and inquirer types.
134
- - type: `'formily' | 'inquirer'`. Schema type, the default value is formily.
135
- - configValue: `Record<string, unknown> = {}`. Schema default value, the problem corresponding to the schema field passed in this value will no longer interact with the user.
136
- - validateMap?: `Record<string, (input: unknown, data?: Record<string, unknown>) => { success: boolean; error?: string }>`. Validation function for special fields in schema.
137
- - initValue?: `Record<string, any>`. Schema the initialization value of the field.
138
-
139
- For Formily Schema type support, please refer to [Customize input related type definition](/guides/topic-detail/generator/plugin/api/input/type).
140
-
141
- ### getInputBySchemaFunc
142
-
143
- By schema to complete user interaction input, schema parameter value as function, the user handles globalization problems, and only supports Formily schema.
144
-
145
- Parameter:
146
-
147
- - schema: `config?: Record<string, any>) => FormilySchema`. Get the problem list function, the config parameter is the config configuration information in the current generator.
148
- - configValue: `Record<string, unknown> = {}`. Schema default value, the problem corresponding to the schema field passed in this value will no longer interact with the user.
149
- - validateMap?: `Record<string, (input: unknown, data?: Record<string, unknown>) => { success: boolean; error?: string }>`. Validation function for special fields in schema.
150
- - initValue?: `Record<string, any>`. Schema the initialization value of the field.
151
-
152
- For Formily Schema type support, please refer to [Customize input related type definition](/guides/topic-detail/generator/plugin/api/input/type).
@@ -1,56 +0,0 @@
1
- ---
2
- sidebar_position: 6
3
- ---
4
-
5
- # @modern-js/codesmith-api-ejs
6
-
7
- An API wrapper for file operations using [ejs] (https://ejs.co/) in microgenerators, providing a way to render individual template files and folders.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { EjsAPI } from '@modern-js/codesmith-api-ejs';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const ejsAPI = new EjsAPI(generator);
16
- await ejsAPI.renderTemplate(
17
- material.get('templates/a.js'),
18
- target: 'b.js',
19
- { data: "data" }
20
- );
21
- }
22
- ```
23
-
24
- - Create EjsAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
25
- - Just call the API on its example.
26
-
27
- ## API
28
-
29
- ### renderTemplate
30
-
31
- Render a single template file.
32
-
33
- Parameter:
34
-
35
- - templateResource: `FsResource`. Template file resource, used by `context.materials.get(<filename>)`.
36
- - target: `string`. Target file path name.
37
- - parameters?: `Record<string, string>`. Render parameter.
38
-
39
- ### renderTemplateDir
40
-
41
- Render template folder.
42
-
43
- Parameter:
44
-
45
- - material: `FsMaterial`. The material context of the current microgenerator execution.
46
- - findGlob: `string`. Template file matches the regular.
47
- - target: `(globMatch: string) => string`. The target file path generation function, the parameter is `resourceKey.`
48
- - options?: `RenderTemplateDirOptions`. Glob Find the file configuration, the specific function viewable is here [glob] (https://www.npmjs.com/package/glob).
49
-
50
- ```ts
51
- type RenderTemplateDirOptions = {
52
- nodir?: boolean;
53
- dot?: boolean;
54
- ignore?: string | readonly string[];
55
- };
56
- ```
@@ -1,54 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # @modern-js/codesmith-api-fs
6
-
7
- API wrapper for file operations in microgenerators, providing methods to render individual template files and folders. FsAPI is usually used to handle binaries or template files that cannot be handled with handlebars, ejs.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { FsAPI } from '@modern-js/codesmith-api-fs';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const fsApi = new FsAPI(generator);
16
- await fsApi.renderFile(
17
- material.get('templates/a.js'),
18
- target: 'b.js'
19
- );
20
- }
21
- ```
22
-
23
- - Create FsAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
24
- - Just call the API on its example.
25
-
26
- ## API
27
-
28
- ### renderFile
29
-
30
- Render a single template file.
31
-
32
- Parameter:
33
-
34
- - resource: `FsResource`. Template file resource, used by `context.materials.get(<filename>)`.
35
- - target: `string`. Target file path name.
36
-
37
- ### renderDir
38
-
39
- Render template folder.
40
-
41
- Parameter:
42
-
43
- - material: `FsMaterial`. The material context of the current microgenerator execution.
44
- - findGlob: `string`. Template file matches the regular.
45
- - target: `(globMatch: string) => string`. The target file path generation function, the parameter is `resourceKey.`
46
- - options?: `RenderTemplateDirOptions`. Glob Find the file configuration, the specific function viewable is here [glob] (https://www.npmjs.com/package/glob).
47
-
48
- ```ts
49
- type RenderTemplateDirOptions = {
50
- nodir?: boolean;
51
- dot?: boolean;
52
- ignore?: string | readonly string[];
53
- };
54
- ```
@@ -1,50 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # @modern-js/codesmith-api-git
6
-
7
- The API encapsulation of git-related operations in the micro-generator provides methods for judging git repository, initialization and commit code.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { GitAPI } from '@modern-js/codesmith-api-git';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const gitApi = new GitAPI(generatorCore, generatorContext);
16
- await gitApi.initGitRepo();
17
- };
18
- ```
19
-
20
- - Create GitAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
21
-
22
- - Just call the API on its example.
23
-
24
- ## API
25
-
26
- ### isInGitRepo
27
-
28
- Whether the current directory is a git repository.
29
-
30
- Parameter:
31
-
32
- - cwd?: `string`. The execution directory of the git command, the default is microgenerator `outputPath`.
33
-
34
- ### initGitRepo
35
-
36
- The initialization is the git repository. The default branch name for init can be configured via `defaultBranch` in the generator config.
37
-
38
- Parameter:
39
-
40
- - cwd?: `string`. The execution directory of the git command, the default is microgenerator `outputPath`.
41
- - force?: `boolean`. Use this parameter to force git init when the current directory is already a git repository.
42
-
43
- ### addAndCommit
44
-
45
- Execute `git add .` and `git commit` commit the current changes.
46
-
47
- Parameter:
48
-
49
- - commitMessage: `string`. Commit information.
50
- - cwd?: `string`. The execution directory of the git command, the default is microgenerator `outputPath`.
@@ -1,57 +0,0 @@
1
- ---
2
- sidebar_position: 5
3
- ---
4
-
5
- # @modern-js/codesmith-api-handlebars
6
-
7
- An API wrapper for file operations using [handlebars] (https://handlebarsjs.com/) in the microgenerator, providing a way to render individual template files and folders.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { HandlebarsAPI } from '@modern-js/codesmith-api-handlebars';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const handlebarApi = new HandlebarsAPI(generator);
16
- await handlebarsAPI.renderTemplate(
17
- material.get('templates/a.js'),
18
- target: 'b.js',
19
- { data: "data" }
20
- );
21
- }
22
- ```
23
-
24
- - Create HandlebarsAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
25
-
26
- - Just call the API on its example.
27
-
28
- ## API
29
-
30
- ### renderTemplate
31
-
32
- Render a single template file.
33
-
34
- Parameter:
35
-
36
- - templateResource: `FsResource`. Template file resource, used by `context.materials.get(<filename>)`.
37
- - target: `string`. Target file path name.
38
- - parameters?: `Record<string, string>`. Render parameter.
39
-
40
- ### renderTemplateDir
41
-
42
- Render template folder.
43
-
44
- Parameter:
45
-
46
- - material: `FsMaterial`. The material context of the current microgenerator execution.
47
- - findGlob: `string`. Template file matches the regular.
48
- - target: `(globMatch: string) => string`. The target file path generation function, the parameter is `resourceKey.`
49
- - options?: `RenderTemplateDirOptions`. Glob Find the file configuration, the specific function viewable is here [glob] (https://www.npmjs.com/package/glob).
50
-
51
- ```ts
52
- type RenderTemplateDirOptions = {
53
- nodir?: boolean;
54
- dot?: boolean;
55
- ignore?: string | readonly string[];
56
- };
57
- ```
@@ -1,56 +0,0 @@
1
- ---
2
- sidebar_position: 2
3
- ---
4
-
5
- # @modern-js/codesmith-api-json
6
-
7
- The JSON API encapsulation in the microgenerator provides common JSON file operation methods.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { JsonAPI } from '@modern-js/codesmith-api-json';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const jsonAPI = new JsonAPI(generator);
16
- await jsonAPI.update(context.materials.default.get('package.json'), {
17
- query: {},
18
- update: {
19
- $set: {
20
- 'dependencies.@modern-js/plugin-bff': `^2.0.0`,
21
- },
22
- },
23
- });
24
- };
25
- ```
26
-
27
- - Create JsonAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
28
- - Just call the API on its example.
29
-
30
- ## API
31
-
32
- ### get
33
-
34
- Get the JSON file content.
35
-
36
- Parameter:
37
-
38
- - resource: `FsResource`. A file resource, get by `context.materials.default.get(<filename>)`.
39
-
40
- ### extend
41
-
42
- Merge objects into a JSON file.
43
-
44
- Parameter:
45
-
46
- - resource: `FsResource`. A file resource, get by `context.materials.default.get(<filename>)`.
47
- - obj: `Record<string, any>`. Object to be merged.
48
-
49
- ### update
50
-
51
- pdate object fields to JSON file.
52
-
53
- Parameter:
54
-
55
- - resource: `FsResource`. A file resource, get by `context.materials.default.get(<filename>)`.
56
- - operation: `{ query: Record<string, any>; update: Record<string, any> }`. Update operation, use gesture to view [declaration-update](https://www.npmjs.com/package/declaration-update) in detail.
@@ -1,48 +0,0 @@
1
- ---
2
- sidebar_position: 7
3
- ---
4
-
5
- # @modern-js/codesmith-api-npm
6
-
7
- The NPM API encapsulation in the microgenerator provides a common method for installing dependencies of different NPM package managers.
8
-
9
- ## Use
10
-
11
- ```ts
12
- import { NpmAPI } from '@modern-js/codesmith-api-npm';
13
-
14
- export default async (context: GeneratorContext, generator: GeneratorCore) => {
15
- const npmApi = new NpmAPI(generator);
16
- await npmApi.pnpmInstall();
17
- };
18
- ```
19
-
20
- - Create NpmAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
21
-
22
- - Just call the API on its example.
23
-
24
- ## API
25
-
26
- ### npmInstall
27
-
28
- Install dependency using npm.
29
-
30
- Parameter:
31
-
32
- - cwd?: `string`. The execution directory of the install command, the default is microgenerator `outputPath`.
33
-
34
- ### yarnInstall
35
-
36
- Install dependency using yarn.
37
-
38
- Parameter:
39
-
40
- - cwd?: `string`. The execution directory of the install command, the default is microgenerator `outputPath`.
41
-
42
- ### pnpmInstall
43
-
44
- Install dependency using pnpm.
45
-
46
- Parameter:
47
-
48
- - cwd?: `string`. The execution directory of the install command, the default is microgenerator `outputPath`.
@@ -1,53 +0,0 @@
1
- ---
2
- sidebar_position: 3
3
- ---
4
-
5
- # Develop a microgenerator project
6
-
7
- ## Create project
8
-
9
- Modern.js provides a microgenerator to create a microgenerator project, you can directly create a microgenerator project with the following commands:
10
-
11
- ```bash
12
- $ mkdir <projectDir>
13
- $ npx @modern-js/codesmith-cli @modern-js/generator-generator
14
-
15
- ? Package Name: <generatorName>
16
- ? Package Manager: pnpm
17
- ? Development Language: TS
18
- ```
19
-
20
- ## Add template file
21
-
22
- In the templates folder of the project directory, it is used to store the template files required by the generator. If there is no template file, this step can be skipped.
23
-
24
- ## Develop generator core logic
25
-
26
- In the project generated by default, it has been implemented to directly copy the templates directory file to the target project, and the core logic development of the generator can be completed directly in the `handleTemplateFile` function.
27
-
28
- ## Test microgenerator
29
-
30
- After the development of the microgenerator is completed, you need to execute `pnpm run build` to compile the code. In development mode, you can use `pnpm run build --watch`.
31
-
32
- Codesmith provides the cli tool for running and testing the microgenerator. Execute it in the target directory with the following command:
33
-
34
- ```bash
35
- npx @modern-js/codesmith-cli <generatorPath>
36
- ```
37
-
38
- Where `generatorPath` is the absolute path of the above generator project.
39
-
40
- ## Run the microgenerator
41
-
42
- After the generator publishes to npm, use the following command to execute:
43
-
44
- ```bash
45
- npx @modern-js/codesmith-cli <generatorName>
46
- ```
47
-
48
- Where generatorName is the generator package name.
49
-
50
- :::info
51
- `@modern-js/create` also supports running micro-generators, you can use `npx @modern-js/create@latest --generator <generatorName>` to run customized micro-generators.
52
-
53
- :::
@@ -1,47 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- ---
4
-
5
- # What is a microgenerator
6
-
7
- Modern.js provides the `@modern-js/create` tool and the `new` command for initialization to create projects and the ability to enable some plugin functions, respectively, these tools are based on microgenerators, also known as codesmith implementations.
8
-
9
- Codesmith is committed to providing a set of micro-generator operating mechanism, and maintain the context information in the execution process of the micro-generator, so as to implement various operations based on files, commands, etc., to complete sophisticated operations.
10
-
11
- Codesmith also encapsulates the commonly used methods, and can directly use the API functions it provides, which can more easily implement its own micro-generator.
12
-
13
- ## Core concept
14
-
15
- ### GeneratorCore
16
-
17
- GeneratorCore is the core of codesmith running generator, maintaining the context and running methods during the execution of the generator.
18
-
19
- ```ts
20
- class GeneratorCore {
21
- logger: ILogger;
22
- materialsManager: MaterialsManager;
23
- outputPath: string;
24
- output:
25
- fs: (file: string | number, data: any, options?: fs.WriteFileOptions | string) => Promise<void>;
26
- };
27
- _context: GeneratorContext;
28
- addMaterial(key: string, material: FsMaterial): void;
29
- runGenerator(generator: string, config?: Record<string, unknown>): Promise<void>;
30
- runSubGenerator(subGenerator: string, relativePwdPath?: string, config?: Record<string, any>): Promise<void>;
31
- }
32
- ```
33
-
34
- ### Materials
35
-
36
- The micro-generator resource information currently only includes file resources (fsMaterials). Through this field, the template resources in the generator execution process can be obtained and operated through the API.
37
-
38
- ```ts
39
- class MaterialsManager {
40
- materialMap: {
41
- // 资源映射关系
42
- [materialUri: string]: FsMaterial;
43
- };
44
- loadLocalGenerator(generator: string): Promise<FsMaterial>;
45
- loadRemoteGenerator(generator: string): Promise<FsMaterial>;
46
- }
47
- ```
@@ -1,47 +0,0 @@
1
- ---
2
- sidebar_position: 4
3
- ---
4
-
5
- # Execute microgenerator with JS code
6
-
7
- In addition to using the cli method to execute the micro generator, we inevitably need to execute the micro generator in the code. The following describes how to execute the micro generator in the js code.
8
-
9
- ## install codesmith dependency
10
-
11
- ```bash
12
- pnpm add @modern-js/codesmith
13
- ```
14
-
15
- ## Create codesmith instance
16
-
17
- ```ts
18
- import { CodeSmith, Logger } from '@modern-js/codesmith';
19
-
20
- const smith = new CodeSmith({
21
- debug: false, //Whether to enable debug mode, if true, the debug information in the generator will be displayed
22
- });
23
- ```
24
-
25
- ## Call the forge method to execute the generator
26
-
27
- ```ts
28
- type RunnerTask = Array<{
29
- name: string;
30
- config: Record<string, any>;
31
- }>;
32
-
33
- const task: RunnerTask = [
34
- {
35
- name: 'generator', // generator npm package name
36
- config: {}, //The default configuration performed by the generator
37
- },
38
- ];
39
-
40
- await smith.forge({
41
- tasks: task.map(runner => ({
42
- generator: runner.name,
43
- config: runner.config,
44
- })),
45
- pwd: '.', // generator implementation path
46
- });
47
- ```