@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,59 @@
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
+ ```typescript
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(
17
+ context.materials.default.get('package.json'),
18
+ {
19
+ query: {},
20
+ update: {
21
+ $set: {
22
+ 'dependencies.@modern-js/plugin-bff': `^2.0.0`,
23
+ },
24
+ },
25
+ },
26
+ );
27
+ }
28
+ ```
29
+
30
+ - Create JsonAPI instance, the parameter is the generator of the microgenerator function parameter, please see the composition of the microgenerator project for details.
31
+ - Just call the API on its example.
32
+
33
+
34
+ ## API
35
+
36
+ ### get
37
+
38
+ Get the JSON file content.
39
+
40
+ Parameter:
41
+ - resource: `FsResource`. A file resource,get by `context.materials.default.get(<filename>)`.
42
+
43
+ ### extend
44
+
45
+ Merge objects into a JSON file.
46
+
47
+ Parameter:
48
+
49
+ - resource: `FsResource`. A file resource,get by `context.materials.default.get(<filename>)`.
50
+ - obj: `Record<string, any>`. Object to be merged.
51
+
52
+ ### update
53
+
54
+ pdate object fields to JSON file.
55
+
56
+ Parameter:
57
+
58
+ - resource: `FsResource`. A file resource,get by `context.materials.default.get(<filename>)`.
59
+ - 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.
@@ -0,0 +1,49 @@
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 management tools.
8
+
9
+ ## Use
10
+
11
+ ```typescript
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
+
25
+ ## API
26
+
27
+ ### npmInstall
28
+
29
+ Install dependency using npm.
30
+
31
+ Parameter:
32
+
33
+ - cwd?: `string`. The execution directory of the install command, the default is microgenerator `outputPath`.
34
+
35
+ ### yarnInstall
36
+
37
+ Install dependency using yarn.
38
+
39
+ Parameter:
40
+
41
+ - cwd?: `string`. The execution directory of the install command, the default is microgenerator `outputPath`.
42
+
43
+ ### pnpmInstall
44
+
45
+ Install dependency using pnpm.
46
+
47
+ Parameter:
48
+
49
+ - cwd?: `string`. The execution directory of the install command, the default is microgenerator `outputPath`.
@@ -0,0 +1,52 @@
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 Management Tool 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 --generator <generatorName>` to run customized micro-generators.
52
+ :::
@@ -0,0 +1,46 @@
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
+ ```typescript
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
+ ```typescript
39
+ class MaterialsManager {
40
+ materialMap: { // 资源映射关系
41
+ [materialUri: string]: FsMaterial;
42
+ };
43
+ loadLocalGenerator(generator: string): Promise<FsMaterial>;
44
+ loadRemoteGenerator(generator: string): Promise<FsMaterial>;
45
+ }
46
+ ```
@@ -0,0 +1,48 @@
1
+ ---
2
+ sidebar_position: 4
3
+ ---
4
+
5
+
6
+ # Execute microgenerator with JS code
7
+
8
+ 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.
9
+
10
+ ## install codesmith dependency
11
+
12
+ ```bash
13
+ pnpm add @modern-js/codesmith
14
+ ```
15
+
16
+ ## Create codesmith instance
17
+
18
+ ```typescript
19
+ import { CodeSmith, Logger } from '@modern-js/codesmith';
20
+
21
+ const smith = new CodeSmith({
22
+ debug: false, //Whether to enable debug mode, if true, the debug information in the generator will be displayed
23
+ });
24
+ ```
25
+
26
+ ## Call the forge method to execute the generator
27
+
28
+ ```typescript
29
+ type RunnerTask = Array<{
30
+ name: string;
31
+ config: Record<string, any>;
32
+ }>;
33
+
34
+ const task: RunnerTask = [
35
+ {
36
+ name: "generator", // generator npm package name
37
+ config: {}, //The default configuration performed by the generator
38
+ },
39
+ ];
40
+
41
+ await smith.forge({
42
+ tasks: task.map(runner => ({
43
+ generator: runner.name,
44
+ config: runner.config,
45
+ })),
46
+ pwd: '.', // generator implementation path
47
+ });
48
+ ```
@@ -0,0 +1,87 @@
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
+ ```typescript
18
+ export default async (context: GeneratorContext, generator: GeneratorCore) => {
19
+
20
+ };
21
+ ```
22
+
23
+ The function parameters are context and generator:
24
+
25
+ ### context
26
+
27
+ Context provides context information maintained by the codesmith runtime. Its type is defined as:
28
+
29
+ ```typescript
30
+ interface GeneratorContext {
31
+ materials: Record<string, FsMaterial>;
32
+ config: Record<string, any>;
33
+ data?: Record<string, any>;
34
+ current: { material: FsMaterial; } | null;
35
+ [key: string]: any;
36
+ }
37
+ ```
38
+
39
+ Materials is an abstract file system for codesmith that maintains the mapping between generator names and actionable files.
40
+
41
+ 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.
42
+
43
+ For example, when you need to modify a field in the `package.json` of the current project:
44
+
45
+ ```typescript
46
+ const resource = context.materials.default.get(path.join(appDir, 'package.json'))
47
+ ```
48
+
49
+ Pass the acquired resources to the JSON API provided by codesmith to implement json operations.
50
+
51
+ The currently running generator file resource is maintained on the current field of `GeneratorContext`, and the current `FsMaterial` can be obtained through `current.material`.
52
+
53
+ 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.
54
+
55
+ For example:
56
+
57
+ ```typescript
58
+ const resourceMap = await material.find('templates/**/*');
59
+ ```
60
+
61
+ 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.
62
+
63
+ ### generator
64
+
65
+ Generator provides the function method of the codesmith runtime. Its type is defined as:
66
+
67
+ ```typescript
68
+ interface GeneratorCore {
69
+ logger: Logger;
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
+ 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.
79
+
80
+
81
+ `runSubGenerator` provides a way to run other microgenerators in one microgenerator, which will automatically update and maintain new context information.
82
+
83
+ ## Template File
84
+
85
+ Generator template file.
86
+
87
+ 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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "Engineering configuration",
3
+ "position": 3
4
+ }
@@ -0,0 +1,106 @@
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
+ ### scenes
22
+
23
+ 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.
24
+
25
+ :::info
26
+ scenes configuration can only be used in the `--config` parameter of `@modern-js/create`, not by setting the default value in the generator plugin.
27
+ :::
28
+
29
+ ### language
30
+
31
+ Development language (language), the options are as follows:
32
+
33
+ - TS(ts)
34
+
35
+ - ES6+(js)
36
+
37
+ ### packageManager
38
+
39
+ Package management tool (packageManager), the options are as follows:
40
+
41
+ - pnpm(pnpm)
42
+
43
+ - Yarn(yarn)
44
+
45
+
46
+ :::info
47
+ In the custom type of the generator plugin to create a project scenario, only the `packageManager` configuration is provided by default.
48
+ :::
49
+
50
+ ## 其他配置
51
+
52
+ ### noNeedInstall
53
+
54
+ * Type: Boolean
55
+
56
+ * Default: false
57
+
58
+ Whether to skip the dependency installation.
59
+
60
+ ### noNeedGit
61
+
62
+ * Type: Boolean
63
+
64
+ * Default: false
65
+
66
+ Whether to skip git initialization and commit initial commit.
67
+
68
+ ### successInfo
69
+
70
+ * Type: String
71
+
72
+ * Default: Command operation prompts for different project schemes.
73
+
74
+ Customize prompt information to create project success.
75
+
76
+ ### isMonorepoSubProject
77
+
78
+ * Type: Boolean
79
+
80
+ * Default: false
81
+
82
+ Whether it is a Monorepo subproject.
83
+
84
+ ### isTest
85
+
86
+ * Type: Boolean
87
+
88
+ - true: create project to `examples/`
89
+
90
+ - false: create project to `apps/`
91
+
92
+ * Default: false
93
+
94
+ Works on an Application (MWA) project to identify whether it is a test project.
95
+
96
+ ### isPublic
97
+
98
+ * Type: Boolean
99
+
100
+ - true: create project to `packages/`
101
+
102
+ - false: create project to `features/`
103
+
104
+ * Default: false
105
+
106
+ Used in the Module project to identify whether it needs to be published to npm.
@@ -0,0 +1,39 @@
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](/docs/guides/topic-detail/generator/config/common).
12
+
13
+ ### packageName
14
+
15
+ Package name (packageName), character string type.
16
+
17
+ ## New 命令
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
+ ### function
32
+
33
+ Optional function name (function), supports the following options:
34
+
35
+ - Tailwind CSS(tailwindcss)
36
+
37
+ - Storybook(mwa_storybook)
38
+
39
+ - Runtime API(runtimeApi)
@@ -0,0 +1,28 @@
1
+ ---
2
+ sidebar_position: 4
3
+ ---
4
+
5
+ # Monorepo
6
+
7
+ Monorepo projects only need [PackageManager](/docs/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.
@@ -0,0 +1,89 @@
1
+ ---
2
+ sidebar_position: 2
3
+ ---
4
+
5
+ # MWA
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](/docs/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
+ ### element
30
+
31
+ Element name (element), supports two options:
32
+
33
+ - Create an application entry(entry)
34
+
35
+ - Create customized server dir(server)
36
+
37
+ These two options also need to be used in conjunction with the specific configuration, which is described as follows:
38
+
39
+ #### name
40
+
41
+ Entry name (name), character `string` type.
42
+
43
+ #### framework
44
+
45
+ Customized server runtime framework(framework),supports two options::
46
+
47
+ - Express(express)
48
+
49
+ - Koa(koa)
50
+
51
+ ### function
52
+
53
+ Optional function name (function), supports the following options:
54
+
55
+ - Tailwind CSS(tailwindcss)
56
+
57
+ - BFF(bff)
58
+
59
+ - SSG(ssg)
60
+
61
+ - Micro Frontend(micro_frontend)
62
+
63
+ - Unit Test / Integration Test(test)
64
+
65
+ - Storybook(mwa_storybook)
66
+
67
+ - UA-based Polyfill Feature'(polyfill)
68
+
69
+ - Global Proxy(proxy)
70
+
71
+ `bff` also need to be used in conjunction with configuration, as described below:
72
+
73
+ #### BFF parameters
74
+
75
+ ##### bffType
76
+
77
+ BFF type (bffType), supports two options:
78
+
79
+ - Function mode(function)
80
+
81
+ - Framework mode(framework)
82
+
83
+ ##### framework
84
+
85
+ BFF runtime framework (framework),supports two options:
86
+
87
+ - Express(express)
88
+
89
+ - Koa(koa)
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "Development Generator Plugin",
3
+ "position": 4
4
+ }
@@ -0,0 +1,26 @@
1
+ ---
2
+ sidebar_position: 1
3
+ ---
4
+
5
+ # Why do you need a generator plugin
6
+
7
+ Modern.js provides application (MWA), 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
+
14
+ The generator plugin can help you precipitate these individual or team-specific changes. Simply bring the `--plugin` parameter when executing `npx @modern-js/create` to avoid the need to repeatedly modify the project every time the project is created..
15
+
16
+ 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.
17
+
18
+ The generator plugin provides two ways of customization:
19
+
20
+ 1. Extended engineering: directly customize the three major engineering provided by default.
21
+
22
+
23
+ 2. Create engineering scenes: Create corresponding engineering scenes based on the default three major engineering.
24
+
25
+
26
+ The next step will introduce how to use and develop the generator plugin step by step.