@modern-js/main-doc 2.21.1 → 2.22.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +42 -0
- package/docs/en/apis/app/commands.mdx +5 -5
- package/docs/en/apis/app/hooks/api/api.mdx +80 -0
- package/docs/en/apis/app/hooks/api/app.mdx +12 -0
- package/docs/en/apis/app/hooks/api/lambda.mdx +57 -0
- package/docs/en/apis/app/hooks/api/test.mdx +1 -1
- package/docs/en/apis/app/hooks/config/html.mdx +2 -2
- package/docs/en/apis/app/hooks/config/icon.mdx +19 -19
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/en/apis/app/hooks/config/public.mdx +10 -10
- package/docs/en/apis/app/hooks/config/storybook.mdx +3 -3
- package/docs/en/apis/app/hooks/config/upload.mdx +13 -13
- package/docs/en/apis/app/hooks/modern-config.mdx +4 -4
- package/docs/en/apis/app/hooks/server/index_.mdx +2 -9
- package/docs/en/apis/app/hooks/server/test.mdx +5 -2
- package/docs/en/apis/app/hooks/shared.mdx +1 -1
- package/docs/en/apis/app/hooks/src/app.mdx +17 -27
- package/docs/en/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/en/apis/app/hooks/src/pages.mdx +41 -37
- package/docs/en/apis/app/hooks/src/routes.mdx +16 -36
- package/docs/en/apis/app/hooks/src/server.mdx +1 -1
- package/docs/en/apis/app/hooks/src/stories.mdx +6 -3
- package/docs/en/apis/app/hooks/src/test.mdx +4 -3
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/en/apis/app/runtime/web-server/hook.mdx +2 -2
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +2 -2
- package/docs/en/components/debug-app.mdx +1 -1
- package/docs/en/components/deploy.mdx +1 -0
- package/docs/en/components/entry-mode.mdx +0 -0
- package/docs/en/components/init-app.mdx +6 -10
- package/docs/en/components/init-rspack-app.mdx +4 -4
- package/docs/en/components/language-config.mdx +9 -0
- package/docs/en/components/package-manager.mdx +11 -0
- package/docs/en/components/release-note.mdx +1 -0
- package/docs/en/components/ua-polyfill.mdx +2 -2
- package/docs/en/configure/app/output/css-modules.mdx +13 -0
- package/docs/en/configure/app/source/config-dir.mdx +1 -1
- package/docs/en/configure/app/source/design-system.mdx +67 -67
- package/docs/en/configure/app/source/disable-default-entries.mdx +6 -5
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +5 -5
- package/docs/en/configure/app/source/enable-async-entry.mdx +9 -9
- package/docs/en/configure/app/source/entries-dir.mdx +3 -3
- package/docs/en/configure/app/source/entries.mdx +21 -19
- package/docs/en/configure/app/tools/swc.mdx +2 -16
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -2
- package/docs/en/guides/advanced-features/bff/function.mdx +4 -4
- package/docs/en/guides/advanced-features/bff/type.mdx +5 -5
- package/docs/en/guides/advanced-features/rspack-start.mdx +7 -8
- package/docs/en/guides/advanced-features/ssg.mdx +2 -2
- package/docs/en/guides/advanced-features/testing.mdx +2 -2
- package/docs/en/guides/advanced-features/web-server.mdx +2 -2
- package/docs/en/guides/basic-features/css.mdx +2 -2
- package/docs/en/guides/basic-features/mock.mdx +1 -1
- package/docs/en/guides/basic-features/routes.mdx +11 -7
- package/docs/en/guides/concept/builder.mdx +15 -15
- package/docs/en/guides/concept/entries.mdx +50 -49
- package/docs/en/guides/get-started/glossary.mdx +12 -12
- package/docs/en/guides/get-started/introduction.mdx +17 -20
- package/docs/en/guides/get-started/quick-start.mdx +21 -37
- package/docs/en/guides/get-started/upgrade.mdx +15 -13
- package/docs/en/guides/topic-detail/changesets/_category_.json +4 -0
- package/docs/en/guides/topic-detail/changesets/add.mdx +125 -0
- package/docs/en/guides/topic-detail/changesets/changelog.mdx +238 -0
- package/docs/en/guides/topic-detail/changesets/commit.mdx +269 -0
- package/docs/en/guides/topic-detail/changesets/config.mdx +147 -0
- package/docs/en/guides/topic-detail/changesets/github.mdx +175 -0
- package/docs/en/guides/topic-detail/changesets/introduce.mdx +56 -0
- package/docs/en/guides/topic-detail/changesets/release-note.mdx +273 -0
- package/docs/en/guides/topic-detail/changesets/release-pre.mdx +49 -0
- package/docs/en/guides/topic-detail/changesets/release.mdx +229 -0
- package/docs/en/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/create/config.mdx +75 -0
- package/docs/en/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/en/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/en/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/en/guides/topic-detail/generator/new/config.md +155 -0
- package/docs/en/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/en/guides/topic-detail/generator/new/use.md +95 -0
- package/docs/en/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/en/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/en/guides/topic-detail/generator/plugin/api/afterForged.md +49 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/en/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/en/guides/topic-detail/generator/plugin/category.md +88 -0
- package/docs/en/guides/topic-detail/generator/plugin/context.md +104 -0
- package/docs/en/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/en/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +8 -8
- package/docs/en/guides/troubleshooting/builder.mdx +8 -0
- package/docs/en/tutorials/first-app/c03-css.mdx +2 -2
- package/docs/en/tutorials/first-app/c08-entries.mdx +3 -3
- package/docs/zh/apis/app/commands.mdx +3 -3
- package/docs/zh/apis/app/hooks/api/{functions/api.mdx → api.mdx} +4 -4
- package/docs/zh/apis/app/hooks/api/app.mdx +12 -0
- package/docs/zh/apis/app/hooks/api/{framework/lambda.mdx → lambda.mdx} +5 -5
- package/docs/zh/apis/app/hooks/api/test.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/icon.mdx +15 -15
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/public.mdx +3 -3
- package/docs/zh/apis/app/hooks/config/upload.mdx +1 -1
- package/docs/zh/apis/app/hooks/modern-config.mdx +3 -3
- package/docs/zh/apis/app/hooks/server/index_.mdx +1 -6
- package/docs/zh/apis/app/hooks/shared.mdx +1 -1
- package/docs/zh/apis/app/hooks/src/app.mdx +15 -25
- package/docs/zh/apis/app/hooks/src/index_.mdx +6 -6
- package/docs/zh/apis/app/hooks/src/pages.mdx +7 -3
- package/docs/zh/apis/app/hooks/src/routes.mdx +4 -4
- package/docs/zh/apis/app/hooks/src/stories.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +5 -1
- package/docs/zh/community/blog/v2-release-note.mdx +1 -1
- package/docs/zh/community/contributing-guide.mdx +1 -1
- package/docs/zh/components/entry-mode.mdx +0 -0
- package/docs/zh/components/init-app.mdx +5 -9
- package/docs/zh/components/language-config.mdx +9 -0
- package/docs/zh/components/package-manager.mdx +11 -0
- package/docs/zh/components/ua-polyfill.mdx +1 -1
- package/docs/zh/configure/app/output/css-modules.mdx +13 -0
- package/docs/zh/configure/app/source/design-system.mdx +3 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +2 -5
- package/docs/zh/configure/app/source/entries.mdx +2 -2
- package/docs/zh/configure/app/tools/swc.mdx +2 -16
- package/docs/zh/guides/advanced-features/rspack-start.mdx +7 -8
- package/docs/zh/guides/advanced-features/ssg.mdx +1 -1
- package/docs/zh/guides/advanced-features/testing.mdx +2 -2
- package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
- package/docs/zh/guides/basic-features/css.mdx +1 -1
- package/docs/zh/guides/basic-features/mock.mdx +1 -1
- package/docs/zh/guides/basic-features/routes.mdx +7 -4
- package/docs/zh/guides/concept/builder.mdx +1 -1
- package/docs/zh/guides/concept/entries.mdx +21 -17
- package/docs/zh/guides/get-started/quick-start.mdx +7 -10
- package/docs/zh/guides/get-started/upgrade.mdx +1 -1
- package/docs/zh/guides/topic-detail/changesets/add.mdx +15 -13
- package/docs/zh/guides/topic-detail/changesets/changelog.mdx +20 -20
- package/docs/zh/guides/topic-detail/changesets/commit.mdx +12 -14
- package/docs/zh/guides/topic-detail/changesets/config.mdx +5 -5
- package/docs/zh/guides/topic-detail/changesets/github.mdx +38 -27
- package/docs/zh/guides/topic-detail/changesets/introduce.mdx +12 -12
- package/docs/zh/guides/topic-detail/changesets/release-note.mdx +84 -70
- package/docs/zh/guides/topic-detail/changesets/release-pre.mdx +9 -9
- package/docs/zh/guides/topic-detail/changesets/release.mdx +29 -29
- package/docs/zh/guides/topic-detail/generator/create/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/create/config.mdx +76 -0
- package/docs/zh/guides/topic-detail/generator/create/option.md +151 -0
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +66 -0
- package/docs/zh/guides/topic-detail/generator/new/_category_.json +4 -0
- package/docs/zh/guides/topic-detail/generator/new/config.md +153 -0
- package/docs/zh/guides/topic-detail/generator/new/option.md +67 -0
- package/docs/zh/guides/topic-detail/generator/new/use.md +94 -0
- package/docs/zh/guides/topic-detail/generator/plugin/_category_.json +2 -2
- package/docs/zh/guides/topic-detail/generator/plugin/api/_category_.json +1 -1
- package/docs/zh/guides/topic-detail/generator/plugin/api/afterForged.md +50 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/context.md +184 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/input.md +124 -0
- package/docs/zh/guides/topic-detail/generator/plugin/api/onForged.md +310 -0
- package/docs/zh/guides/topic-detail/generator/plugin/category.md +93 -0
- package/docs/zh/guides/topic-detail/generator/plugin/context.md +105 -0
- package/docs/zh/guides/topic-detail/generator/plugin/structure.md +106 -0
- package/docs/zh/guides/topic-detail/generator/plugin/use.md +33 -0
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +4 -4
- package/docs/zh/guides/topic-detail/model/test-model.mdx +1 -1
- package/docs/zh/guides/troubleshooting/builder.mdx +8 -0
- package/docs/zh/tutorials/first-app/c03-css.mdx +1 -1
- package/docs/zh/tutorials/first-app/c08-entries.mdx +1 -1
- package/package.json +5 -5
- package/docs/en/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/framework/lambda.mdx +0 -57
- package/docs/en/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/en/apis/app/hooks/api/functions/api.mdx +0 -81
- package/docs/en/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/en/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/en/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/en/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/codesmith/api/git.mdx +0 -50
- package/docs/en/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -57
- package/docs/en/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/en/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -48
- package/docs/en/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/en/guides/topic-detail/generator/codesmith/introduce.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/en/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/en/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/en/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/en/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/en/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/en/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/en/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -58
- package/docs/en/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/en/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/en/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/en/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/en/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/en/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -55
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/en/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -31
- package/docs/en/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/en/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -90
- package/docs/en/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/en/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/en/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/en/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/en/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -18
- package/docs/en/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/en/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/en/guides/topic-detail/generator/project.mdx +0 -118
- package/docs/zh/apis/app/hooks/api/framework/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/_category_.json +0 -4
- package/docs/zh/apis/app/hooks/api/functions/app.mdx +0 -12
- package/docs/zh/apis/app/hooks/api/functions/common.mdx +0 -9
- package/docs/zh/guides/topic-detail/generator/codesmith/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/codesmith/api/app.mdx +0 -152
- package/docs/zh/guides/topic-detail/generator/codesmith/api/ejs.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/fs.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/codesmith/api/git.mdx +0 -49
- package/docs/zh/guides/topic-detail/generator/codesmith/api/handlebars.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/json.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/codesmith/api/npm.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/develop.mdx +0 -53
- package/docs/zh/guides/topic-detail/generator/codesmith/introduce.mdx +0 -59
- package/docs/zh/guides/topic-detail/generator/codesmith/run-in-js.mdx +0 -47
- package/docs/zh/guides/topic-detail/generator/codesmith/structure.mdx +0 -89
- package/docs/zh/guides/topic-detail/generator/config/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/config/app.mdx +0 -82
- package/docs/zh/guides/topic-detail/generator/config/common.mdx +0 -100
- package/docs/zh/guides/topic-detail/generator/config/module.mdx +0 -42
- package/docs/zh/guides/topic-detail/generator/config/monorepo.mdx +0 -28
- package/docs/zh/guides/topic-detail/generator/plugin/abstract.mdx +0 -23
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addFile.mdx +0 -52
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addHelper.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addManyFile.mdx +0 -55
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/addPartial.mdx +0 -26
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/introduce.mdx +0 -39
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmDir.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/rmFile.mdx +0 -24
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateJSONFile.mdx +0 -54
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateModernConfig.mdx +0 -27
- package/docs/zh/guides/topic-detail/generator/plugin/api/file/updateTextRawFile.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/gitAddAndCommit.mdx +0 -20
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/initGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/git/isInGitRepo.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/afterForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/hook/onForged.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/isFileExit.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/locale.mdx +0 -17
- package/docs/zh/guides/topic-detail/generator/plugin/api/info/readDir.mdx +0 -22
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputAfter.mdx +0 -57
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +0 -56
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInput.mdx +0 -43
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/setInputValue.mdx +0 -29
- package/docs/zh/guides/topic-detail/generator/plugin/api/input/type.mdx +0 -65
- package/docs/zh/guides/topic-detail/generator/plugin/api/introduce.mdx +0 -92
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createElement.mdx +0 -33
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/createSubProject.mdx +0 -35
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +0 -44
- package/docs/zh/guides/topic-detail/generator/plugin/api/new/introduce.mdx +0 -15
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/generator/plugin/api/npm/install.mdx +0 -16
- package/docs/zh/guides/topic-detail/generator/plugin/develop.mdx +0 -125
- package/docs/zh/guides/topic-detail/generator/plugin/use.mdx +0 -61
- package/docs/zh/guides/topic-detail/generator/project.mdx +0 -118
@@ -0,0 +1,184 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 1
|
3
|
+
---
|
4
|
+
|
5
|
+
# context
|
6
|
+
|
7
|
+
The generator plugin exports a function by default in the `main` file, and the function parameter is `context`. All APIs provided by the generator plugin are provided by this `context`.
|
8
|
+
|
9
|
+
## Types
|
10
|
+
|
11
|
+
Let's first understand the type definition of `context`:
|
12
|
+
|
13
|
+
```ts
|
14
|
+
export interface IPluginContext {
|
15
|
+
locale?: string;
|
16
|
+
addInputBefore: (key: string, input: Schema) => void;
|
17
|
+
addInputAfter: (key: string, input: Schema) => void;
|
18
|
+
setInput: (key: string, field: string, value: unknown) => void;
|
19
|
+
setInputValue: (value: Record<string, unknown>) => void;
|
20
|
+
setDefaultConfig: (value: Record<string, unknown>) => void;
|
21
|
+
isFileExist: (fileName: string) => Promise<boolean>;
|
22
|
+
readDir: (dir: string) => Promise<string[]>;
|
23
|
+
setGitMessage: (gitMessage: string) => void;
|
24
|
+
onForged: (func: PluginForgedFunc) => void;
|
25
|
+
afterForged: (func: PluginAfterForgedFunc) => void;
|
26
|
+
}
|
27
|
+
```
|
28
|
+
|
29
|
+
The contents provided by `context` can be mainly divided into three categories:
|
30
|
+
|
31
|
+
- Get the information of the current generator execution environment.
|
32
|
+
|
33
|
+
- Operate input.
|
34
|
+
|
35
|
+
- Generator plugin lifecycle function.
|
36
|
+
|
37
|
+
|
38
|
+
The generator plugin APIs will be introduced from these three categories below.
|
39
|
+
|
40
|
+
### Get Information
|
41
|
+
|
42
|
+
#### locale
|
43
|
+
|
44
|
+
Gets the language of the generator plugin execution environment. `@modern-js/create` provides two languages, `zh` and `en`, which correspond to these two values.
|
45
|
+
|
46
|
+
#### isFileExist
|
47
|
+
|
48
|
+
Checks whether a file exists. We often need to confirm whether the target project file exists before defining the operation. This API can be used directly for this purpose.
|
49
|
+
|
50
|
+
For example, we need to find out if the `package.json` file exists and then do someing:
|
51
|
+
|
52
|
+
```ts
|
53
|
+
const isExist = await context.isFileExist('package.json');
|
54
|
+
if (isExist) {
|
55
|
+
...
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
#### readDir
|
60
|
+
|
61
|
+
Gets the file list in a folder. We often need to get the file list under the target project folder before defining the operation. This API can be used directly for this purpose.
|
62
|
+
|
63
|
+
For example, we need to get all files under the `src` folder and then do someing:
|
64
|
+
|
65
|
+
```ts
|
66
|
+
const files = await context.readDir('src');
|
67
|
+
|
68
|
+
files.map(name => {
|
69
|
+
...
|
70
|
+
});
|
71
|
+
```
|
72
|
+
|
73
|
+
### Input Operations
|
74
|
+
|
75
|
+
The `key` parameter used in input operations can refer to [Configuration Parameters](/guides/topic-detail/generator/create/config.html) and use the key under the solution’s scheme, that is, it does not support `solution` and `scenes`.
|
76
|
+
|
77
|
+
The input parameter in input operations corresponds to the schema type described in [Input](/guides/topic-detail/generator/plugin/api/input.html).
|
78
|
+
|
79
|
+
#### addInputBefore
|
80
|
+
|
81
|
+
Adds a question before the specified input `key`.
|
82
|
+
|
83
|
+
For example:
|
84
|
+
|
85
|
+
```ts
|
86
|
+
context.addInputBefore('packageManager', {
|
87
|
+
type: 'object',
|
88
|
+
properties: {
|
89
|
+
language: {
|
90
|
+
type: 'string',
|
91
|
+
title: 'Please select the programming language:',
|
92
|
+
enum: [
|
93
|
+
{ label: 'TS', value: 'ts' },
|
94
|
+
{ label: 'ES6+', value: 'js' },
|
95
|
+
],
|
96
|
+
},
|
97
|
+
},
|
98
|
+
});
|
99
|
+
```
|
100
|
+
|
101
|
+
#### addInputAfter
|
102
|
+
|
103
|
+
Adds a question after the specified input `key`.
|
104
|
+
|
105
|
+
For example:
|
106
|
+
|
107
|
+
```ts
|
108
|
+
context.addInputAfter('packageManager', {
|
109
|
+
type: 'object',
|
110
|
+
properties: {
|
111
|
+
language: {
|
112
|
+
type: 'string',
|
113
|
+
title: 'Please select the programming language:',
|
114
|
+
enum: [
|
115
|
+
{ label: 'TS', value: 'ts' },
|
116
|
+
{ label: 'ES6+', value: 'js' },
|
117
|
+
],
|
118
|
+
},
|
119
|
+
},
|
120
|
+
});
|
121
|
+
```
|
122
|
+
|
123
|
+
:::info
|
124
|
+
1. The `key` for adding a question cannot be the same as the `key` of the question provided by Modern.js solution scheme itself.
|
125
|
+
2. The priority of adding a question with `addInputAfter` is higher than that of `addInputBefore`. When adding an After question to a key and adding a Before question to the next key, the After question will be before the Before question.
|
126
|
+
3. When adding multiple questions before or after the same `key`, this method can be called multiple times, and the order of the questions will be arranged according to the calling sequence.
|
127
|
+
|
128
|
+
:::
|
129
|
+
|
130
|
+
#### setInput
|
131
|
+
|
132
|
+
Sets the attributes of the specified input `key`.
|
133
|
+
|
134
|
+
For example, set the `title` attribute of `packageName`:
|
135
|
+
|
136
|
+
```ts
|
137
|
+
context.setInput('packageName', 'title', "Name");
|
138
|
+
```
|
139
|
+
|
140
|
+
:::info
|
141
|
+
For input options provided by Modern.js solution schemes, only deletion is supported, and adding will cause logical judgment problems in the code.
|
142
|
+
:::
|
143
|
+
|
144
|
+
|
145
|
+
#### setInputValue
|
146
|
+
|
147
|
+
Sets the default value of the specified input `key`.
|
148
|
+
|
149
|
+
For example, set the default value of `packageManager`:
|
150
|
+
|
151
|
+
```ts
|
152
|
+
context.setInputValue({
|
153
|
+
packageManager: 'npm',
|
154
|
+
});
|
155
|
+
```
|
156
|
+
|
157
|
+
:::info
|
158
|
+
After setting, the question still needs to be interactive, but the default value configured by the generator plugin will be used.
|
159
|
+
:::
|
160
|
+
|
161
|
+
#### setDefaultConfig
|
162
|
+
|
163
|
+
Sets the default value of the specified input `key`.
|
164
|
+
|
165
|
+
For example, set the default value of `packageManager`:
|
166
|
+
|
167
|
+
```ts
|
168
|
+
context.setDefaultConfig({
|
169
|
+
packageManager: 'npm',
|
170
|
+
});
|
171
|
+
```
|
172
|
+
|
173
|
+
:::info
|
174
|
+
After setting, the corresponding question will no longer be displayed, which is consistent with the `--config` behavior specified by `@modern-js/create`. Does not support setting `vertical` and `projectOrg`.
|
175
|
+
:::
|
176
|
+
|
177
|
+
#### setGitMessage
|
178
|
+
|
179
|
+
Sets the initial git commit message. Modern.js defaults to the git initialization commit message as `feat: init`, which can be modified by this function.
|
180
|
+
|
181
|
+
|
182
|
+
### Lifecycle Functions
|
183
|
+
|
184
|
+
The lifecycle functions are relatively complex and will be introduced separately in the following two sections, [`onForged`](/guides/topic-detail/generator/plugin/api/onForged.html) and [`afterForged`](/guides/topic-detail/generator/plugin/api/afterForged.html).
|
@@ -0,0 +1,124 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 4
|
3
|
+
---
|
4
|
+
|
5
|
+
# Input
|
6
|
+
|
7
|
+
Generator plugin provides a way to interact with users through Input, which is defined using JSON Schema:
|
8
|
+
|
9
|
+
For example:
|
10
|
+
|
11
|
+
```js
|
12
|
+
const schema = {
|
13
|
+
type: 'object',
|
14
|
+
properties: {
|
15
|
+
language: {
|
16
|
+
type: 'string',
|
17
|
+
title: 'Please select the programming language:',
|
18
|
+
enum: [
|
19
|
+
{ label: 'TS', value: 'ts' },
|
20
|
+
{ label: 'ES6+', value: 'js' },
|
21
|
+
],
|
22
|
+
},
|
23
|
+
},
|
24
|
+
};
|
25
|
+
```
|
26
|
+
|
27
|
+
JSON Schema format is based on the open source [Formily](https://formilyjs.org/) Schema format. The following are the supported fields:
|
28
|
+
|
29
|
+
## type
|
30
|
+
|
31
|
+
Defines the type of the current schema. Currently supported types are `string`, `number`, and `object`. `string` type is used for string inputs and dropdown options. `object` type is used for nesting schemas and needs to be used with the `properties` attribute.
|
32
|
+
|
33
|
+
## title
|
34
|
+
|
35
|
+
Defines the display name of the current schema.
|
36
|
+
|
37
|
+
## default
|
38
|
+
|
39
|
+
Defines the default value of the current schema.
|
40
|
+
|
41
|
+
## enum
|
42
|
+
|
43
|
+
Defines the options when the current schema is a dropdown selection.
|
44
|
+
|
45
|
+
The sub-items support `string` or `{ label: string; value: string}` types. When the value and display value are the same in the dropdown options, `string` can be used directly to define the options.
|
46
|
+
|
47
|
+
When representing multiple selection options, set the `default` field to `[]`.
|
48
|
+
|
49
|
+
## x-validator
|
50
|
+
|
51
|
+
Defines the validation rules for the current schema. When the schema is an input type, validation will be automatically performed after input completion.
|
52
|
+
|
53
|
+
The validation rules supported here are provided by [Formily](https://formilyjs.org/zh-CN/guide/advanced/validate), for example, the maximum value is 5:
|
54
|
+
|
55
|
+
```js
|
56
|
+
const schema = {
|
57
|
+
type: 'object',
|
58
|
+
properties: {
|
59
|
+
max_5: {
|
60
|
+
type: 'number',
|
61
|
+
title: 'Maximum value (>5 will cause an error)',
|
62
|
+
'x-validator': {
|
63
|
+
maximum: 5,
|
64
|
+
},
|
65
|
+
},
|
66
|
+
},
|
67
|
+
};
|
68
|
+
```
|
69
|
+
|
70
|
+
It also supports using validation functions directly:
|
71
|
+
|
72
|
+
```js
|
73
|
+
const schema = {
|
74
|
+
type: 'object',
|
75
|
+
properties: {
|
76
|
+
path: {
|
77
|
+
type: 'string',
|
78
|
+
title: 'Can only contain numbers and letters',
|
79
|
+
'x-validator': value => {
|
80
|
+
if (!/^[0-9a-zA-Z]*$/g.test(value)) {
|
81
|
+
return 'Incorrect format';
|
82
|
+
}
|
83
|
+
return '';
|
84
|
+
},
|
85
|
+
},
|
86
|
+
},
|
87
|
+
};
|
88
|
+
```
|
89
|
+
|
90
|
+
## x-reactions
|
91
|
+
|
92
|
+
Use linkage between schemas. This is exactly the same as [Formily linkage rules](https://formilyjs.org/zh-CN/guide/advanced/linkages).
|
93
|
+
|
94
|
+
For example:
|
95
|
+
|
96
|
+
```js
|
97
|
+
const schema = {
|
98
|
+
type: 'object',
|
99
|
+
properties: {
|
100
|
+
name: {
|
101
|
+
type: 'string',
|
102
|
+
title: 'Name',
|
103
|
+
},
|
104
|
+
path: {
|
105
|
+
type: 'string',
|
106
|
+
title: 'Path',
|
107
|
+
'x-reactions': [
|
108
|
+
{
|
109
|
+
dependencies: ['name'],
|
110
|
+
fulfill: {
|
111
|
+
state: {
|
112
|
+
value: '{{$deps[0]}}',
|
113
|
+
},
|
114
|
+
},
|
115
|
+
},
|
116
|
+
],
|
117
|
+
},
|
118
|
+
},
|
119
|
+
};
|
120
|
+
```
|
121
|
+
|
122
|
+
## properties
|
123
|
+
|
124
|
+
Organize the structure of the current schema and define sub-forms. `properties` is an object, where the `key` is the schema keyword and the `value` is a schema object as described above.
|
@@ -0,0 +1,310 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 2
|
3
|
+
---
|
4
|
+
|
5
|
+
# onForged
|
6
|
+
|
7
|
+
`onForged` is a lifecycle function used for file operations in generator plugin.
|
8
|
+
|
9
|
+
## Types
|
10
|
+
|
11
|
+
```ts
|
12
|
+
export type ForgedAPI = {
|
13
|
+
addFile: (params: AddFileParams) => Promise<void>;
|
14
|
+
addManyFiles: (params: AddManyFilesParams) => Promise<void>;
|
15
|
+
updateJSONFile: (fileName: string, updateInfo: Record<string, unknown>) => Promise<void>;
|
16
|
+
updateTextRawFile: (fileName: string, update: (content: string[]) => string[]) => Promise<void>;
|
17
|
+
updateModernConfig: (updateInfo: Record<string, any>) => Promise<void>;
|
18
|
+
rmFile: (fileName: string) => Promise<void>;
|
19
|
+
rmDir: (dirName: string) => Promise<void>;
|
20
|
+
addHelper: (name: string, fn: Handlebars.HelperDelegate) => void;
|
21
|
+
addPartial: (name: string, str: Handlebars.Template) => void;
|
22
|
+
createElement: (element: ActionElement, params: Record<string, unknown>) => Promise<void>;
|
23
|
+
enableFunc: (func: ActionFunction, params?: Record<string, unknown> | undefined) => Promise<void>;
|
24
|
+
};
|
25
|
+
|
26
|
+
export type PluginForgedFunc = (
|
27
|
+
api: ForgedAPI,
|
28
|
+
inputData: Record<string, unknown>,
|
29
|
+
) => void | Promise<void>;
|
30
|
+
|
31
|
+
export interface IPluginContext {
|
32
|
+
onForged: (func: PluginForgedFunc) => void;
|
33
|
+
...
|
34
|
+
}
|
35
|
+
```
|
36
|
+
|
37
|
+
The `onForged` parameter is a callback function with `api` and `input` as parameters, which are used to provide the APIs and current input information provided by the lifecycle function.
|
38
|
+
|
39
|
+
## Concepts
|
40
|
+
|
41
|
+
### File Types
|
42
|
+
|
43
|
+
The generator plugin classifies files into four categories:
|
44
|
+
|
45
|
+
- Text files
|
46
|
+
|
47
|
+
Files with pure text content that can be processed using [Handlebars](https://handlebarsjs.com/) or [EJS](https://ejs.co/) templates.
|
48
|
+
|
49
|
+
- Binary files
|
50
|
+
|
51
|
+
Files such as images, audio, and video.
|
52
|
+
|
53
|
+
- JSON files
|
54
|
+
|
55
|
+
Files in JSON format.
|
56
|
+
|
57
|
+
- Text list files
|
58
|
+
|
59
|
+
Files composed of lines of text, such as `.gitignore`, `.editorconfig`, and `.npmrc`.
|
60
|
+
|
61
|
+
The type definitions for the four types of files are:
|
62
|
+
|
63
|
+
```ts
|
64
|
+
export enum FileType {
|
65
|
+
Text = 'text',
|
66
|
+
Binary = 'binary',
|
67
|
+
Json = 'json',
|
68
|
+
TextRaw = 'textRaw',
|
69
|
+
}
|
70
|
+
```
|
71
|
+
|
72
|
+
## API
|
73
|
+
|
74
|
+
The APIs provided by the `api` parameter will be introduced below.
|
75
|
+
|
76
|
+
### addFile
|
77
|
+
|
78
|
+
Adds a single file.
|
79
|
+
|
80
|
+
Parameter types:
|
81
|
+
|
82
|
+
```ts
|
83
|
+
export interface AddFileParams {
|
84
|
+
type: FileType;
|
85
|
+
file: string;
|
86
|
+
template?: string;
|
87
|
+
templateFile?: string;
|
88
|
+
force?: boolean;
|
89
|
+
data?: Record<string, string>;
|
90
|
+
}
|
91
|
+
```
|
92
|
+
|
93
|
+
- `type`: File type.
|
94
|
+
- `file`: Target file path, relative to the target project directory.
|
95
|
+
- `template`: Template content, the value of this field can be directly used to render the file. Lower priority than `templateFile`.
|
96
|
+
- `templateFile`: Template file path, relative to the templates directory.
|
97
|
+
- `force`: Whether to force overwrite when the target file exists, default is false.
|
98
|
+
- `data`: Template rendering data.
|
99
|
+
|
100
|
+
:::info
|
101
|
+
Text files are processed using Handlebars by default. If the template file ends with `.ejs`, [EJS](https://ejs.co/) will be used for template rendering.
|
102
|
+
:::
|
103
|
+
|
104
|
+
For example, add the template file `App.tsx.hanlebars` to `src/App.tsx`:
|
105
|
+
|
106
|
+
```ts
|
107
|
+
context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
|
108
|
+
await api.addFile({
|
109
|
+
type: FileType.Text,
|
110
|
+
file: `src/App.tsx`,
|
111
|
+
templateFile: `App.tsx.handlebars`,
|
112
|
+
});
|
113
|
+
})
|
114
|
+
```
|
115
|
+
|
116
|
+
### addManyFiles
|
117
|
+
|
118
|
+
Adds multiple files, usually used to add multiple files to the same target directory.
|
119
|
+
|
120
|
+
Parameter types:
|
121
|
+
|
122
|
+
```ts
|
123
|
+
export interface AddManyFilesParams {
|
124
|
+
type: FileType;
|
125
|
+
destination: string;
|
126
|
+
templateFiles: string[] | (() => string[]);
|
127
|
+
templateBase?: string;
|
128
|
+
fileNameFunc?: (name: string) => string;
|
129
|
+
data?: Record<string, string>;
|
130
|
+
}
|
131
|
+
```
|
132
|
+
|
133
|
+
- `type`: File type.
|
134
|
+
- `destination`: Target folder, relative path to the target project directory.
|
135
|
+
- `templateFiles`: Template file list, supporting regular expressions from [globby](https://www.npmjs.com/package/globby).
|
136
|
+
- `templateBase`: Common path of template files. When using this parameter, the target file will automatically delete this path.
|
137
|
+
- `fileNameFunc`: Function to rename files. During the file addition process, the file name will be passed to this function in turn, and the renaming can be performed as needed.
|
138
|
+
- `data`: Template rendering data.
|
139
|
+
|
140
|
+
For example, render all files in the `src-ts` directory of the template file to the `src` directory:
|
141
|
+
|
142
|
+
```ts
|
143
|
+
context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
|
144
|
+
await api.addManyFiles({
|
145
|
+
type: FileType.Text,
|
146
|
+
destination: 'src',
|
147
|
+
templateFiles: ['src-ts/**/*'],
|
148
|
+
templateBase: 'src-ts',
|
149
|
+
fileNameFunc: name => name.replace('.handlebars', ''),
|
150
|
+
});
|
151
|
+
})
|
152
|
+
```
|
153
|
+
|
154
|
+
### updateJSONFile
|
155
|
+
|
156
|
+
Update fields in a JSON file.
|
157
|
+
|
158
|
+
Parameter types:
|
159
|
+
|
160
|
+
```ts
|
161
|
+
fileName: strings
|
162
|
+
updateInfo: Record<string, unknown>
|
163
|
+
```
|
164
|
+
|
165
|
+
- `fileName`: JSON file path, relative to the target project path.
|
166
|
+
- `updateInfo`: Update information. Nested field updates need to be flattened, otherwise the entire update will cause content loss.
|
167
|
+
|
168
|
+
For example, update the `name` field of `package.json`:
|
169
|
+
|
170
|
+
```ts
|
171
|
+
context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
|
172
|
+
await api.updateJSONFile('package.json', { name: 'new_name' });
|
173
|
+
})
|
174
|
+
```
|
175
|
+
|
176
|
+
For example, update the version of `react-dom` in `dependencies`:
|
177
|
+
|
178
|
+
```ts
|
179
|
+
context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
|
180
|
+
await api.updateJSONFile('package.json', {
|
181
|
+
'dependencies.react-dom': '^18',
|
182
|
+
});
|
183
|
+
})
|
184
|
+
```
|
185
|
+
|
186
|
+
### updateTextRawFile
|
187
|
+
|
188
|
+
Update the contents of a text list file.
|
189
|
+
|
190
|
+
Parameter types:
|
191
|
+
|
192
|
+
```ts
|
193
|
+
fileName: string
|
194
|
+
update: (content: string[]) => string[]
|
195
|
+
```
|
196
|
+
|
197
|
+
- `fileName`: Text list file path, relative to the target project path.
|
198
|
+
- `update`: Update function. The parameter is an array divided by `\n` of the current file content, and the return value is also the modified array after modification. `@modern-js/create` will automatically merge it with `\n` and write it to the source file.
|
199
|
+
|
200
|
+
For example, add the `dist` directory to the `.gitinore` file:
|
201
|
+
|
202
|
+
```ts
|
203
|
+
context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
|
204
|
+
await api.updateTextRawFile('.gitinore', (content) => [...content, 'dist']);
|
205
|
+
})
|
206
|
+
```
|
207
|
+
|
208
|
+
### updateModernConfig (not recommended)
|
209
|
+
|
210
|
+
In addition to configuring in `modern.config.[tj]s`, Modern.js configuration also supports configuring `modernConfig` in `package.json`. This function is used to update this field.
|
211
|
+
|
212
|
+
Parameter types:
|
213
|
+
|
214
|
+
```ts
|
215
|
+
updateInfo: Record<string, any>
|
216
|
+
```
|
217
|
+
|
218
|
+
- `updateInfo`: Update content information. `updateModernConfig` is a package based on `updateJSONFile`, which will automatically update under the `edenxConfig` field. Only the configuration fields under `modernConfig` need to be filled in `updateInfo`.
|
219
|
+
|
220
|
+
For example, enable SSR:
|
221
|
+
|
222
|
+
```ts
|
223
|
+
context.onForged(async (api: ForgedAPI, _input: Record<string, unknown>) => {
|
224
|
+
await api.updateModernConfig({ 'server.ssr': true });
|
225
|
+
})
|
226
|
+
```
|
227
|
+
|
228
|
+
### rmFile
|
229
|
+
|
230
|
+
Delete files.
|
231
|
+
|
232
|
+
Parameter types:
|
233
|
+
|
234
|
+
```ts
|
235
|
+
fileName: string
|
236
|
+
```
|
237
|
+
|
238
|
+
- `fileName`: The path of the file to be deleted, relative to the target project path.
|
239
|
+
|
240
|
+
### rmDir
|
241
|
+
|
242
|
+
Delete a folder.
|
243
|
+
|
244
|
+
Parameter types:
|
245
|
+
|
246
|
+
```ts
|
247
|
+
dirName: string
|
248
|
+
```
|
249
|
+
|
250
|
+
- `dirName`: The path of the folder to be deleted, relative to the target project path.
|
251
|
+
|
252
|
+
### addHelper
|
253
|
+
|
254
|
+
Add a [custom helper](https://handlebarsjs.com/guide/#custom-helpers) rendered by handlebrs.
|
255
|
+
|
256
|
+
Parameter types:
|
257
|
+
|
258
|
+
```ts
|
259
|
+
name: string
|
260
|
+
fn: Handlebars.HelperDelegate
|
261
|
+
```
|
262
|
+
|
263
|
+
- `name`: Helper function name.
|
264
|
+
- `fn`: Helper function implementation.
|
265
|
+
|
266
|
+
### addPartial
|
267
|
+
|
268
|
+
Add a [Partial](https://handlebarsjs.com/guide/partials.html#basic-partials) rendered by Handlebars.
|
269
|
+
|
270
|
+
Parameter types:
|
271
|
+
|
272
|
+
```ts
|
273
|
+
name: string
|
274
|
+
str: Handlebars.Template
|
275
|
+
```
|
276
|
+
|
277
|
+
- `name`: Partial name.
|
278
|
+
- `str`: Template string of the Partial.
|
279
|
+
|
280
|
+
### createElement
|
281
|
+
|
282
|
+
Automatically run the `new` command to create project elements.
|
283
|
+
|
284
|
+
Parameter types:
|
285
|
+
|
286
|
+
```ts
|
287
|
+
element: ActionElement
|
288
|
+
params: Record<string, unknown>
|
289
|
+
```
|
290
|
+
|
291
|
+
- `element`: Type of project element, new entry or new custom Web Server source directory.
|
292
|
+
- `params`: Other parameters corresponding to creating project elements.
|
293
|
+
|
294
|
+
### enableFunc
|
295
|
+
|
296
|
+
Automatically run the `new` command to enable optional features.
|
297
|
+
|
298
|
+
Parameter types:
|
299
|
+
|
300
|
+
```ts
|
301
|
+
func: ActionFunction
|
302
|
+
params?: Record<string, unknown>
|
303
|
+
```
|
304
|
+
|
305
|
+
- `func`: Name of the feature to enable.
|
306
|
+
- `params`: Other parameters corresponding to enabling the feature.
|
307
|
+
|
308
|
+
:::info
|
309
|
+
Refer to [Configuration Parameters](/guides/topic-detail/generator/new/config.html) for creating project elements and enabling feature configurations.
|
310
|
+
:::
|
@@ -0,0 +1,88 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 2
|
3
|
+
---
|
4
|
+
|
5
|
+
## Introduction
|
6
|
+
|
7
|
+
There are two types of generator plugin:
|
8
|
+
|
9
|
+
- Extension: Web App(Npm Module) = Web App(Npm Module) + Generator Plugin
|
10
|
+
|
11
|
+
- Custom: New Application(Npm Module) = Web App(Npm Module) + Generator Plugin
|
12
|
+
|
13
|
+
|
14
|
+
In simpler terms, extension means using the original project name of Modern.js, while custom means creating a new name.
|
15
|
+
|
16
|
+
## Identifier
|
17
|
+
|
18
|
+
The type of generator plugin is provided through the `meta` field in `package.json`:
|
19
|
+
|
20
|
+
### Extension
|
21
|
+
|
22
|
+
```json title="package.json"
|
23
|
+
{
|
24
|
+
"meta": {
|
25
|
+
"extend": "mwa" // module
|
26
|
+
}
|
27
|
+
}
|
28
|
+
```
|
29
|
+
|
30
|
+
### Custom
|
31
|
+
|
32
|
+
```json title="package.json"
|
33
|
+
{
|
34
|
+
"meta": {
|
35
|
+
"key": "new_app",
|
36
|
+
"name": "new App",
|
37
|
+
"type": "mwa" // module and custom
|
38
|
+
}
|
39
|
+
}
|
40
|
+
```
|
41
|
+
|
42
|
+
:::info
|
43
|
+
For custom type, the `type` field supports the `custom` value, which utilizes some best practice templates for project development provided by Modern.js, such as `.gitignore`, `.editorConfig`, etc. Other business-related code templates need to be manually provided through generator plugin.
|
44
|
+
:::
|
45
|
+
|
46
|
+
# Creating Initial Project
|
47
|
+
|
48
|
+
### Extension
|
49
|
+
|
50
|
+
```bash
|
51
|
+
npx @modern-js/create@latest plugin --plugin @modern-js/generator-plugin-plugin
|
52
|
+
? Please select the type of project you want to create: Npm Module
|
53
|
+
? Please select the project scenario: Generator Plugin
|
54
|
+
? Please fill in the package name of the generator plugin: plugin
|
55
|
+
? Please select the programming language: TS
|
56
|
+
? Please select the package manager: pnpm
|
57
|
+
? Please select the type of plugin: extend
|
58
|
+
? Please select the base type of the plugin: Web App
|
59
|
+
```
|
60
|
+
|
61
|
+
### 自定义
|
62
|
+
|
63
|
+
```bash
|
64
|
+
npx @modern-js/create@latest plugin --plugin @modern-js/generator-plugin-plugin
|
65
|
+
? Please select the type of project you want to create: Npm Module
|
66
|
+
? Please select the project scenario: Generator Plugin
|
67
|
+
? Please fill in the package name of the generator plugin: plugin
|
68
|
+
? Please select the programming language: TS
|
69
|
+
? Please select the package manager: pnpm
|
70
|
+
? Please select the type of plugin: custom
|
71
|
+
? Please fill in the plugin keyword: new_app
|
72
|
+
? Please fill in the display name of the plugin: new App
|
73
|
+
? Please select the base type of the plugin: Web App
|
74
|
+
```
|
75
|
+
|
76
|
+
## Execution Order
|
77
|
+
|
78
|
+
Generator plugins support using multiple plugins at the same time, which means that multiple `--plugin` parameters are supported when executing `@modern-js/create`.
|
79
|
+
|
80
|
+
### Extension
|
81
|
+
|
82
|
+
For extension generator plugins, when executing with the declared generator plugin parameters, the corresponding lifecycle functions of the project scheme that is extended will be executed in order.
|
83
|
+
|
84
|
+
For example, if there are two generator plugins A and B, both of which extend the Modern.js application scheme. A plugin declares to add the `a.ts` file, and B plugin declares to add the `b.ts` file. When executing `npx @modern-js/create@latest --plugin A --plugin B`, and selecting the Web APP scheme, the default project files of the Web APP will be generated first. Then, the A plugin will create the `a.ts` file, and then the B plugin will generate the `b.ts` file.
|
85
|
+
|
86
|
+
### Custom
|
87
|
+
|
88
|
+
For custom generator plugins, only one plugin can be executed at a time. When declaring the `--plugin` parameter for `@modern-js/create`, a selection option for the scenario of choosing the project scheme will be added after selecting the project scheme, which is the new name defined in the `package.json`. Choosing the corresponding generator plugin for the name will execute the corresponding generator plugin logic after the default project scheme is completed. When declaring the `--plugin` parameter, the corresponding generator plugin names will be listed one by one for selection in the project scheme scenario.
|