@macrowing/inbiz-codegen 0.0.0-stage → 1.0.0

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 (163) hide show
  1. package/README.md +592 -2
  2. package/bin/inbiz-codegen.mjs +7 -0
  3. package/package.json +32 -4
  4. package/scripts/prepare-templates.mjs +35 -0
  5. package/src/backend/init.mjs +170 -0
  6. package/src/config.mjs +150 -0
  7. package/src/favicon.mjs +100 -0
  8. package/src/generate.mjs +935 -0
  9. package/src/generated-output.mjs +107 -0
  10. package/src/index.mjs +346 -0
  11. package/src/menu/build.mjs +252 -0
  12. package/src/menu/check.mjs +163 -0
  13. package/src/menu/command.mjs +179 -0
  14. package/src/migrate-runtime.mjs +106 -0
  15. package/src/platform/client.mjs +167 -0
  16. package/src/platform/command.mjs +386 -0
  17. package/src/platform/pack.mjs +591 -0
  18. package/src/platform/recover.mjs +236 -0
  19. package/src/platform/startup.mjs +343 -0
  20. package/src/platform/state.mjs +116 -0
  21. package/src/platform/update.mjs +157 -0
  22. package/src/platform/zip.mjs +134 -0
  23. package/src/pull.mjs +284 -0
  24. package/src/scaffold/commands.mjs +349 -0
  25. package/src/scaffold/init.mjs +370 -0
  26. package/src/scaffold/template-files.mjs +40 -0
  27. package/src/scaffold/template-source.mjs +235 -0
  28. package/src/scaffold/template-sync.mjs +335 -0
  29. package/src/transform/heaviness.mjs +380 -0
  30. package/src/transform/preview-props.mjs +108 -0
  31. package/src/transform/published-page-links.mjs +61 -0
  32. package/src/transform/published-script.mjs +110 -0
  33. package/src/transform/registry.mjs +781 -0
  34. package/src/transform/schema-to-jsx.mjs +1708 -0
  35. package/src/util/des.mjs +10 -0
  36. package/templates/README.md +34 -0
  37. package/templates/backend/Directory.Build.props +19 -0
  38. package/templates/backend/Directory.Packages.props +49 -0
  39. package/templates/backend/Macrowing.Scaffold.slnx +13 -0
  40. package/templates/backend/host/Macrowing.Start/Init/app.json +8 -0
  41. package/templates/backend/host/Macrowing.Start/Init/menus.json +4 -0
  42. package/templates/backend/host/Macrowing.Start/Initialization/InitializationDefinition.cs +245 -0
  43. package/templates/backend/host/Macrowing.Start/Initialization/InitializationEndpoints.cs +57 -0
  44. package/templates/backend/host/Macrowing.Start/Initialization/InitializationHostedService.cs +63 -0
  45. package/templates/backend/host/Macrowing.Start/Initialization/InitializationOptions.cs +44 -0
  46. package/templates/backend/host/Macrowing.Start/Initialization/InitializationRunner.cs +294 -0
  47. package/templates/backend/host/Macrowing.Start/Initialization/InitializationState.cs +72 -0
  48. package/templates/backend/host/Macrowing.Start/Initialization/MenuFactory.cs +118 -0
  49. package/templates/backend/host/Macrowing.Start/Initialization/PackageBuilder.cs +317 -0
  50. package/templates/backend/host/Macrowing.Start/Initialization/PlatformAppImporter.cs +371 -0
  51. package/templates/backend/host/Macrowing.Start/Macrowing.Start.csproj +26 -0
  52. package/templates/backend/host/Macrowing.Start/Program.cs +33 -0
  53. package/templates/backend/host/Macrowing.Start/StartModule.cs +67 -0
  54. package/templates/backend/host/Macrowing.Start/appsettings.json +38 -0
  55. package/templates/backend/modules/Macrowing.Generated/Application/GeneratedApplicationAutoMapperProfile.cs +42 -0
  56. package/templates/backend/modules/Macrowing.Generated/Domain/Entities/GeneratedEntityBase.cs +72 -0
  57. package/templates/backend/modules/Macrowing.Generated/Domain/GeneratedConsts.cs +50 -0
  58. package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContext.cs +55 -0
  59. package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/GeneratedDbContextModelBuilderExtensions.cs +61 -0
  60. package/templates/backend/modules/Macrowing.Generated/EntityFrameworkCore/IGeneratedDbContext.cs +32 -0
  61. package/templates/backend/modules/Macrowing.Generated/GeneratedModule.cs +89 -0
  62. package/templates/backend/modules/Macrowing.Generated/Macrowing.Generated.csproj +22 -0
  63. package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsClient.cs +95 -0
  64. package/templates/backend/modules/Macrowing.InBiz.SDK/Cms/CmsModels.cs +81 -0
  65. package/templates/backend/modules/Macrowing.InBiz.SDK/Dictionary/DictionaryClient.cs +44 -0
  66. package/templates/backend/modules/Macrowing.InBiz.SDK/InBizSdkModule.cs +16 -0
  67. package/templates/backend/modules/Macrowing.InBiz.SDK/InterfaceEngine/InterfaceEngineClient.cs +50 -0
  68. package/templates/backend/modules/Macrowing.InBiz.SDK/Localization/LocalizationClient.cs +28 -0
  69. package/templates/backend/modules/Macrowing.InBiz.SDK/Macrowing.InBiz.SDK.csproj +16 -0
  70. package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageClient.cs +99 -0
  71. package/templates/backend/modules/Macrowing.InBiz.SDK/Message/MessageModels.cs +63 -0
  72. package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelClient.cs +131 -0
  73. package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelQuery.cs +108 -0
  74. package/templates/backend/modules/Macrowing.InBiz.SDK/Model/ModelWrite.cs +44 -0
  75. package/templates/backend/modules/Macrowing.InBiz.SDK/Permission/PermissionClient.cs +86 -0
  76. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformException.cs +42 -0
  77. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformRegistration.cs +60 -0
  78. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizPlatformTransport.cs +96 -0
  79. package/templates/backend/modules/Macrowing.InBiz.SDK/Platform/InBizRequestContext.cs +27 -0
  80. package/templates/backend/modules/Macrowing.InBiz.SDK/README.md +117 -0
  81. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsClient.cs +35 -0
  82. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Details/WorkFlowDetailsQuery.cs +20 -0
  83. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationRequests.cs +105 -0
  84. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Operations/WorkFlowOperationsClient.cs +53 -0
  85. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/README.md +132 -0
  86. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Tracking/WorkFlowTrackingClient.cs +50 -0
  87. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeClient.cs +78 -0
  88. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Upgrade/WorkFlowUpgradeModels.cs +34 -0
  89. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowContracts.cs +88 -0
  90. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowRegistration.cs +59 -0
  91. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/WorkFlowTransport.cs +163 -0
  92. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchClient.cs +59 -0
  93. package/templates/backend/modules/Macrowing.InBiz.SDK/WorkFlow/Workbench/WorkFlowWorkbenchModels.cs +76 -0
  94. package/templates/backend/modules/Macrowing.OC.SDK/Macrowing.OC.SDK.csproj +20 -0
  95. package/templates/backend/modules/Macrowing.OC.SDK/OcSdkModule.cs +18 -0
  96. package/templates/backend/modules/Macrowing.OC.SDK/Protos/README.md +22 -0
  97. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/Macrowing.InBiz.SDK.Tests.csproj +14 -0
  98. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformContractTests.cs +288 -0
  99. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/PlatformLiveTests.cs +173 -0
  100. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowHttpServer.cs +113 -0
  101. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowLiveTests.cs +269 -0
  102. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowOperationsTests.cs +80 -0
  103. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowQueryTests.cs +163 -0
  104. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowTransportTests.cs +111 -0
  105. package/templates/backend/tests/Macrowing.InBiz.SDK.Tests/WorkFlowUpgradeTests.cs +87 -0
  106. package/templates/frontend/components/README.md +39 -0
  107. package/templates/frontend/components/app-components/README.md +33 -0
  108. package/templates/frontend/components/app-components/common/.gitkeep +0 -0
  109. package/templates/frontend/components/app-components/components/.gitkeep +0 -0
  110. package/templates/frontend/components/app-components/package.json +20 -0
  111. package/templates/frontend/mgt/.umirc.ts +574 -0
  112. package/templates/frontend/mgt/package.json +96 -0
  113. package/templates/frontend/mgt/src/app-extends.ts +9 -0
  114. package/templates/frontend/mgt/src/app.tsx +20 -0
  115. package/templates/frontend/mgt/src/config/app.ts +31 -0
  116. package/templates/frontend/mgt/src/layout/header.tsx +14 -0
  117. package/templates/frontend/mgt/src/layout/index.tsx +11 -0
  118. package/templates/frontend/mgt/src/layout/sidebar.tsx +14 -0
  119. package/templates/frontend/mgt/src/locales.ts +8 -0
  120. package/templates/frontend/mgt/src/pages/.gitkeep +0 -0
  121. package/templates/frontend/mgt/src/root.tsx +12 -0
  122. package/templates/frontend/mgt/src/route-view.tsx +3 -0
  123. package/templates/frontend/mgt/src/runtime.ts +21 -0
  124. package/templates/frontend/mgt/src/styles/app.css +1 -0
  125. package/templates/frontend/mgt/src/styles/layout.less +79 -0
  126. package/templates/frontend/mgt/tsconfig.json +65 -0
  127. package/templates/frontend/mgt/typings.d.ts +57 -0
  128. package/templates/frontend/wap/.umirc.ts +574 -0
  129. package/templates/frontend/wap/package.json +73 -0
  130. package/templates/frontend/wap/src/app-extends.ts +9 -0
  131. package/templates/frontend/wap/src/app.tsx +28 -0
  132. package/templates/frontend/wap/src/config/app.ts +31 -0
  133. package/templates/frontend/wap/src/layout/header.tsx +14 -0
  134. package/templates/frontend/wap/src/layout/index.tsx +18 -0
  135. package/templates/frontend/wap/src/layout/sidebar.tsx +14 -0
  136. package/templates/frontend/wap/src/locales.ts +8 -0
  137. package/templates/frontend/wap/src/pages/.gitkeep +0 -0
  138. package/templates/frontend/wap/src/root.tsx +12 -0
  139. package/templates/frontend/wap/src/route-view.tsx +3 -0
  140. package/templates/frontend/wap/src/runtime.ts +21 -0
  141. package/templates/frontend/wap/src/styles/adaptation.less +190 -0
  142. package/templates/frontend/wap/src/styles/app.css +7 -0
  143. package/templates/frontend/wap/src/styles/global.less +81 -0
  144. package/templates/frontend/wap/src/styles/layout.less +92 -0
  145. package/templates/frontend/wap/tsconfig.json +66 -0
  146. package/templates/frontend/wap/typings.d.ts +24 -0
  147. package/templates/frontend/web/.umirc.ts +574 -0
  148. package/templates/frontend/web/package.json +26 -0
  149. package/templates/frontend/web/src/app-extends.ts +9 -0
  150. package/templates/frontend/web/src/app.tsx +25 -0
  151. package/templates/frontend/web/src/config/app.ts +31 -0
  152. package/templates/frontend/web/src/layout/header.tsx +14 -0
  153. package/templates/frontend/web/src/layout/index.tsx +11 -0
  154. package/templates/frontend/web/src/layout/sidebar.tsx +14 -0
  155. package/templates/frontend/web/src/locales.ts +8 -0
  156. package/templates/frontend/web/src/root.tsx +12 -0
  157. package/templates/frontend/web/src/route-view.tsx +3 -0
  158. package/templates/frontend/web/src/runtime.ts +21 -0
  159. package/templates/frontend/web/src/styles/app.css +104 -0
  160. package/templates/frontend/web/src/styles/layout.less +124 -0
  161. package/templates/frontend/web/tsconfig.json +91 -0
  162. package/templates/frontend/web/typings.d.ts +46 -0
  163. package/templates/package.json +14 -0
@@ -0,0 +1,10 @@
1
+ /**
2
+ * InBiz 登录加密(DES)。与平台前端 login/umi.*.js 逐字节一致,
3
+ * 由 packages/inbiz-runtime/web/des.ts 抽取生成,勿手工修改。
4
+ * 已验证:encryptData("admin") => 7bc1354103b5e838249a070a350cdf86
5
+ */
6
+ var r = {encryptData:function(e){return e&&0!=e.length?r.stringToHex(r.des(r.getKey(),e,1,0)):""},decryptData:function(e){return e&&0!=e.length?r.des(r.getKey(),r.HexTostring(e),0,0):""},getKey:function(){var e="";return e||(e=r.stringToHex(r.des("macrowing","macrowing",1,0))),e},des:function(e,t,n,a,o){var i,s,l,c,u,d,f,h,p,m,v,y,b,g,_=new Array(16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756),w=new Array(-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344),M=new Array(520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584),O=new Array(8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928),j=new Array(256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080),x=new Array(536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312),k=new Array(2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154),L=new Array(268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696),S=r.des_createKeys(e),E=0,F=t.length,T=0,C=32==S.length?3:9;h=3==C?n?new Array(0,32,2):new Array(30,-2,-2):n?new Array(0,32,2,62,30,-2,64,96,2):new Array(94,62,-2,32,64,2,30,-2,-2),t+="\0\0\0\0\0\0\0\0";var D="",A="";1==a&&(p=o.charCodeAt(E++)<<24|o.charCodeAt(E++)<<16|o.charCodeAt(E++)<<8|o.charCodeAt(E++),v=o.charCodeAt(E++)<<24|o.charCodeAt(E++)<<16|o.charCodeAt(E++)<<8|o.charCodeAt(E++),E=0);while(E<F){for(n?(d=t.charCodeAt(E++)<<16|t.charCodeAt(E++),f=t.charCodeAt(E++)<<16|t.charCodeAt(E++)):(d=t.charCodeAt(E++)<<24|t.charCodeAt(E++)<<16|t.charCodeAt(E++)<<8|t.charCodeAt(E++),f=t.charCodeAt(E++)<<24|t.charCodeAt(E++)<<16|t.charCodeAt(E++)<<8|t.charCodeAt(E++)),1==a&&(n?(d^=p,f^=v):(m=p,y=v,p=d,v=f)),l=252645135&(d>>>4^f),f^=l,d^=l<<4,l=65535&(d>>>16^f),f^=l,d^=l<<16,l=858993459&(f>>>2^d),d^=l,f^=l<<2,l=16711935&(f>>>8^d),d^=l,f^=l<<8,l=1431655765&(d>>>1^f),f^=l,d^=l<<1,d=d<<1|d>>>31,f=f<<1|f>>>31,s=0;s<C;s+=3){for(b=h[s+1],g=h[s+2],i=h[s];i!=b;i+=g)c=f^S[i],u=(f>>>4|f<<28)^S[i+1],l=d,d=f,f=l^(w[c>>>24&63]|O[c>>>16&63]|x[c>>>8&63]|L[63&c]|_[u>>>24&63]|M[u>>>16&63]|j[u>>>8&63]|k[63&u]);l=d,d=f,f=l}d=d>>>1|d<<31,f=f>>>1|f<<31,l=1431655765&(d>>>1^f),f^=l,d^=l<<1,l=16711935&(f>>>8^d),d^=l,f^=l<<8,l=858993459&(f>>>2^d),d^=l,f^=l<<2,l=65535&(d>>>16^f),f^=l,d^=l<<16,l=252645135&(d>>>4^f),f^=l,d^=l<<4,1==a&&(n?(p=d,v=f):(d^=m,f^=y)),A+=n?String.fromCharCode(d>>>24,d>>>16&255,d>>>8&255,255&d,f>>>24,f>>>16&255,f>>>8&255,255&f):String.fromCharCode(d>>>16&65535,65535&d,f>>>16&65535,65535&f),T+=n?16:8,512==T&&(D+=A,A="",T=0)}return D+A},des_createKeys:function(e){for(var t,n,r,a=new Array(0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964),o=new Array(0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697),i=new Array(0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272),s=new Array(0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144),l=new Array(0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256),c=new Array(0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488),u=new Array(0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746),d=new Array(0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568),f=new Array(0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578),h=new Array(0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488),p=new Array(0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800),m=new Array(0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744),v=new Array(0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128),y=new Array(0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261),b=e.length>=24?3:1,g=new Array(32*b),_=new Array(0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0),w=0,M=0,O=0;O<b;O++){var j=e.charCodeAt(w++)<<24|e.charCodeAt(w++)<<16|e.charCodeAt(w++)<<8|e.charCodeAt(w++),x=e.charCodeAt(w++)<<24|e.charCodeAt(w++)<<16|e.charCodeAt(w++)<<8|e.charCodeAt(w++);r=252645135&(j>>>4^x),x^=r,j^=r<<4,r=65535&(x>>>-16^j),j^=r,x^=r<<-16,r=858993459&(j>>>2^x),x^=r,j^=r<<2,r=65535&(x>>>-16^j),j^=r,x^=r<<-16,r=1431655765&(j>>>1^x),x^=r,j^=r<<1,r=16711935&(x>>>8^j),j^=r,x^=r<<8,r=1431655765&(j>>>1^x),x^=r,j^=r<<1,r=j<<8|x>>>20&240,j=x<<24|x<<8&16711680|x>>>8&65280|x>>>24&240,x=r;for(var k=0;k<_.length;k++)_[k]?(j=j<<2|j>>>26,x=x<<2|x>>>26):(j=j<<1|j>>>27,x=x<<1|x>>>27),j&=-15,x&=-15,t=a[j>>>28]|o[j>>>24&15]|i[j>>>20&15]|s[j>>>16&15]|l[j>>>12&15]|c[j>>>8&15]|u[j>>>4&15],n=d[x>>>28]|f[x>>>24&15]|h[x>>>20&15]|p[x>>>16&15]|m[x>>>12&15]|v[x>>>8&15]|y[x>>>4&15],r=65535&(n>>>16^t),g[M++]=t^r,g[M++]=n^r<<16}return g},stringToHex:function(e){for(var t="",n=new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"),r=0;r<e.length;r++)t+=n[e.charCodeAt(r)>>4]+n[15&e.charCodeAt(r)];return t},HexTostring:function(e){for(var t="",n=0;n<e.length;n+=2){var r=parseInt(e.substring(n,n+2),16);t+=String.fromCharCode(r)}return t}};
7
+
8
+ export const encryptData = (s) => r.encryptData(s);
9
+ export const decryptData = (s) => r.decryptData(s);
10
+ export default r;
@@ -0,0 +1,34 @@
1
+ # @macrowing/inbiz-templates
2
+
3
+ 出码工程模板包。`inbiz-codegen init` 默认从 npmjs 拉取本包的最新版本;
4
+ 拉取失败(离线、包未发布、网络不可达)时回退到 CLI 内置的同一份目录。
5
+
6
+ ## 目录
7
+
8
+ ```
9
+ frontend/
10
+ web/ SiteType 0,端口 8021
11
+ mgt/ SiteType 2,端口 8022
12
+ wap/ SiteType 1,端口 8023
13
+ components/ 应用定制组件包:根目录只放文档,一个包一个子目录
14
+ backend/ ABP:host + modules + tests
15
+ ```
16
+
17
+ ## 发布
18
+
19
+ ```bash
20
+ cd codegen/templates
21
+ npm publish --access public
22
+ ```
23
+
24
+ 版本语义:模板结构变化(新增/删除文件、改装配方式)走 minor;
25
+ 只改文案、注释走 patch;不兼容的目录调整走 major。
26
+
27
+ 发布后无需再发 CLI:`init` 默认取 `dist-tags.latest`,
28
+ 需要固定版本时用 `inbiz-codegen init --template-version 1.2.0`。
29
+
30
+ ## 约束
31
+
32
+ - 模板必须纯净:不含业务页面、平台地址、账号口令、`node_modules`、构建产物;
33
+ - `frontend/components` 根目录只放文档,一个组件包一个子目录;
34
+ - 后端 `Init/*.json` 只放空占位,真实内容由 pull 写入。
@@ -0,0 +1,19 @@
1
+ <Project>
2
+
3
+ <PropertyGroup>
4
+ <TargetFramework>net10.0</TargetFramework>
5
+ <LangVersion>latest</LangVersion>
6
+ <Nullable>enable</Nullable>
7
+ <ImplicitUsings>enable</ImplicitUsings>
8
+ <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
9
+ <GenerateDocumentationFile>false</GenerateDocumentationFile>
10
+ <NoWarn>$(NoWarn);CS1591</NoWarn>
11
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
12
+ </PropertyGroup>
13
+
14
+ <!-- 出码产物标记:便于三方 diff 识别哪些文件是生成的 -->
15
+ <PropertyGroup Condition="'$(IsGenerated)' == 'true'">
16
+ <NoWarn>$(NoWarn);CS8618</NoWarn>
17
+ </PropertyGroup>
18
+
19
+ </Project>
@@ -0,0 +1,49 @@
1
+ <Project>
2
+
3
+ <PropertyGroup>
4
+ <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
5
+ <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
6
+ </PropertyGroup>
7
+
8
+ <ItemGroup Label="ABP">
9
+ <PackageVersion Include="Volo.Abp.Core" Version="10.7.1" />
10
+ <PackageVersion Include="Volo.Abp.AspNetCore.Mvc" Version="10.7.1" />
11
+ <PackageVersion Include="Volo.Abp.Autofac" Version="10.7.1" />
12
+ <PackageVersion Include="Volo.Abp.AspNetCore.Serilog" Version="10.7.1" />
13
+ <PackageVersion Include="Volo.Abp.Swashbuckle" Version="10.7.1" />
14
+ <PackageVersion Include="Volo.Abp.Ddd.Domain" Version="10.7.1" />
15
+ <PackageVersion Include="Volo.Abp.Ddd.Application" Version="10.7.1" />
16
+ <PackageVersion Include="Volo.Abp.EntityFrameworkCore" Version="10.7.1" />
17
+ <PackageVersion Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="10.7.1" />
18
+ <PackageVersion Include="Volo.Abp.EntityFrameworkCore.MySQL" Version="10.7.1" />
19
+ <PackageVersion Include="Volo.Abp.AutoMapper" Version="10.7.1" />
20
+ <PackageVersion Include="Volo.Abp.MultiTenancy" Version="10.7.1" />
21
+ </ItemGroup>
22
+
23
+ <ItemGroup Label="Host">
24
+ <PackageVersion Include="Serilog.AspNetCore" Version="9.0.0" />
25
+ <PackageVersion Include="Serilog.Sinks.Async" Version="2.1.0" />
26
+ <PackageVersion Include="Swashbuckle.AspNetCore" Version="7.2.0" />
27
+ <PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.0" />
28
+ <PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.0" />
29
+ </ItemGroup>
30
+
31
+ <ItemGroup Label="SDK 依赖">
32
+ <PackageVersion Include="Grpc.Net.Client" Version="2.71.0" />
33
+ <PackageVersion Include="Grpc.Tools" Version="2.71.0" />
34
+ <PackageVersion Include="Google.Protobuf" Version="3.29.3" />
35
+ <PackageVersion Include="Microsoft.Extensions.Http" Version="10.0.11" />
36
+ </ItemGroup>
37
+
38
+ <ItemGroup Label="Tests">
39
+ <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
40
+ <PackageVersion Include="xunit" Version="2.9.3" />
41
+ <PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
42
+ </ItemGroup>
43
+
44
+ <ItemGroup Label="出码约束">
45
+ <!-- 出码器生成的代码引用此包,锁定运行时契约版本 -->
46
+ <PackageVersion Include="Macrowing.CodeGen.Runtime" Version="1.0.0" />
47
+ </ItemGroup>
48
+
49
+ </Project>
@@ -0,0 +1,13 @@
1
+ <Solution>
2
+ <Folder Name="/host/">
3
+ <Project Path="host/Macrowing.Start/Macrowing.Start.csproj" />
4
+ </Folder>
5
+ <Folder Name="/modules/">
6
+ <Project Path="modules/Macrowing.Generated/Macrowing.Generated.csproj" />
7
+ <Project Path="modules/Macrowing.InBiz.SDK/Macrowing.InBiz.SDK.csproj" />
8
+ <Project Path="modules/Macrowing.OC.SDK/Macrowing.OC.SDK.csproj" />
9
+ </Folder>
10
+ <Folder Name="/tests/">
11
+ <Project Path="tests/Macrowing.InBiz.SDK.Tests/Macrowing.InBiz.SDK.Tests.csproj" />
12
+ </Folder>
13
+ </Solution>
@@ -0,0 +1,8 @@
1
+ {
2
+ "app": {
3
+ "appName": "",
4
+ "domain": "",
5
+ "tableNamePrefix": "Gen_"
6
+ },
7
+ "sites": []
8
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "end": "web",
3
+ "menus": []
4
+ }
@@ -0,0 +1,245 @@
1
+ using System.Text.Json;
2
+ using System.Text.Json.Serialization;
3
+
4
+ namespace Macrowing.Start.Initialization;
5
+
6
+ /// <summary>
7
+ /// 初始化文件模型(<c>Init/*.json</c>)与加载器。
8
+ ///
9
+ /// 设计原则:**文件是期望态,程序只负责把它应用到线上**。
10
+ /// 所以这里不做任何业务推断,字段与平台菜单模型的字段一一对应,
11
+ /// 缺省值也只给「平台本身有默认」的那几个。
12
+ /// </summary>
13
+ public class InitializationDefinition
14
+ {
15
+ [JsonPropertyName("app")]
16
+ public AppDefinition App { get; set; } = new();
17
+
18
+ [JsonPropertyName("sites")]
19
+ public List<SiteDefinition> Sites { get; set; } = new();
20
+
21
+ [JsonPropertyName("menus")]
22
+ public List<MenuDefinition> Menus { get; set; } = new();
23
+
24
+ /// <summary>
25
+ /// 读取 <c>&lt;dir&gt;/app.json</c> 与 <c>&lt;dir&gt;/menus.json</c>。
26
+ /// 两者也可以合并写在 <c>&lt;dir&gt;/initialization.json</c> 里。
27
+ /// </summary>
28
+ public static InitializationDefinition Load(string directory)
29
+ {
30
+ var combined = Path.Combine(directory, "initialization.json");
31
+ if (File.Exists(combined))
32
+ {
33
+ return JsonSerializer.Deserialize<InitializationDefinition>(File.ReadAllText(combined), Json.Options)
34
+ ?? new InitializationDefinition();
35
+ }
36
+
37
+ var definition = new InitializationDefinition();
38
+
39
+ var appFile = Path.Combine(directory, "app.json");
40
+ if (File.Exists(appFile))
41
+ {
42
+ var app = JsonSerializer.Deserialize<AppFile>(File.ReadAllText(appFile), Json.Options);
43
+ if (app is not null)
44
+ {
45
+ // app.json 既支持 {"app": {...}, "sites": [...]} 也支持直接一个应用对象
46
+ definition.App = app.App ?? new AppDefinition
47
+ {
48
+ AppName = app.AppName,
49
+ Domain = app.Domain,
50
+ TableNamePrefix = app.TableNamePrefix,
51
+ };
52
+ definition.Sites = app.Sites ?? new List<SiteDefinition>();
53
+ }
54
+ }
55
+
56
+ var menusFile = Path.Combine(directory, "menus.json");
57
+ if (File.Exists(menusFile))
58
+ {
59
+ var menus = JsonSerializer.Deserialize<MenusFile>(File.ReadAllText(menusFile), Json.Options);
60
+ if (menus?.Menus is not null) definition.Menus = menus.Menus;
61
+ }
62
+
63
+ return definition;
64
+ }
65
+
66
+ /// <summary>
67
+ /// 校验。返回的错误要能直接指出文件里的位置,否则运维只能整份重写。
68
+ /// </summary>
69
+ public List<InitializationError> Validate()
70
+ {
71
+ var errors = new List<InitializationError>();
72
+
73
+ if (string.IsNullOrWhiteSpace(App.Domain))
74
+ {
75
+ errors.Add(InitializationError.Of("APP_DOMAIN_MISSING", "app.domain", "应用必须声明 domain"));
76
+ }
77
+ if (string.IsNullOrWhiteSpace(App.AppName))
78
+ {
79
+ errors.Add(InitializationError.Of("APP_NAME_MISSING", "app.appName", "应用必须声明 appName"));
80
+ }
81
+
82
+ var byRoute = new Dictionary<string, MenuDefinition>(StringComparer.Ordinal);
83
+ for (var i = 0; i < Menus.Count; i++)
84
+ {
85
+ var menu = Menus[i];
86
+ var at = $"menus[{i}]";
87
+ if (string.IsNullOrWhiteSpace(menu.Route))
88
+ {
89
+ errors.Add(InitializationError.Of("MENU_ROUTE_MISSING", $"{at}.route", "菜单必须有 route"));
90
+ continue;
91
+ }
92
+ if (byRoute.ContainsKey(menu.Route))
93
+ {
94
+ errors.Add(InitializationError.Of("MENU_ROUTE_DUPLICATED", $"{at}.route", $"route 重复:{menu.Route}"));
95
+ continue;
96
+ }
97
+ byRoute[menu.Route] = menu;
98
+ if (string.IsNullOrWhiteSpace(menu.Name))
99
+ {
100
+ errors.Add(InitializationError.Of("MENU_NAME_MISSING", $"{at}.name", $"route {menu.Route} 缺少 name"));
101
+ }
102
+ }
103
+
104
+ // 父子层级:只能挂在分组下,最多三级
105
+ for (var i = 0; i < Menus.Count; i++)
106
+ {
107
+ var menu = Menus[i];
108
+ if (string.IsNullOrWhiteSpace(menu.Parent)) continue;
109
+ if (!byRoute.TryGetValue(menu.Parent!, out var parent))
110
+ {
111
+ errors.Add(InitializationError.Of("MENU_PARENT_NOT_FOUND", $"menus[{i}].parent", $"父级 {menu.Parent} 不存在"));
112
+ continue;
113
+ }
114
+ if (!parent.IsGroup)
115
+ {
116
+ errors.Add(InitializationError.Of("MENU_PARENT_NOT_GROUP", $"menus[{i}].parent",
117
+ $"父级 {menu.Parent} 是页面菜单,页面菜单只能挂在分组下"));
118
+ }
119
+
120
+ var depth = 1;
121
+ var cursor = parent;
122
+ var seen = new HashSet<string>(StringComparer.Ordinal) { menu.Route! };
123
+ while (!string.IsNullOrWhiteSpace(cursor.Parent))
124
+ {
125
+ if (!seen.Add(cursor.Route!))
126
+ {
127
+ errors.Add(InitializationError.Of("MENU_PARENT_CYCLE", $"menus[{i}].parent", "父子关系成环"));
128
+ break;
129
+ }
130
+ depth++;
131
+ if (depth > 3)
132
+ {
133
+ errors.Add(InitializationError.Of("MENU_DEPTH_EXCEEDED", $"menus[{i}].parent", "层级超过 3 级"));
134
+ break;
135
+ }
136
+ if (!byRoute.TryGetValue(cursor.Parent!, out var next)) break;
137
+ cursor = next;
138
+ }
139
+ }
140
+
141
+ return errors;
142
+ }
143
+ }
144
+
145
+ public class AppFile
146
+ {
147
+ [JsonPropertyName("app")] public AppDefinition? App { get; set; }
148
+ [JsonPropertyName("sites")] public List<SiteDefinition>? Sites { get; set; }
149
+ // 兼容「app.json 就是一个应用对象」的写法
150
+ [JsonPropertyName("appName")] public string? AppName { get; set; }
151
+ [JsonPropertyName("domain")] public string? Domain { get; set; }
152
+ [JsonPropertyName("tableNamePrefix")] public string? TableNamePrefix { get; set; }
153
+ }
154
+
155
+ public class MenusFile
156
+ {
157
+ [JsonPropertyName("end")] public string? End { get; set; }
158
+ [JsonPropertyName("menus")] public List<MenuDefinition>? Menus { get; set; }
159
+ }
160
+
161
+ public class AppDefinition
162
+ {
163
+ [JsonPropertyName("appName")] public string AppName { get; set; } = string.Empty;
164
+ [JsonPropertyName("domain")] public string Domain { get; set; } = string.Empty;
165
+ [JsonPropertyName("tableNamePrefix")] public string TableNamePrefix { get; set; } = "app_";
166
+ }
167
+
168
+ public class SiteDefinition
169
+ {
170
+ [JsonPropertyName("end")] public string End { get; set; } = "web";
171
+ [JsonPropertyName("siteType")] public int SiteType { get; set; }
172
+
173
+ // ---- 站点元数据:导入包里的 standard/<end>/info.json ----
174
+ // 这些值平台是**必须**有的(缺 AppTemplateId 时规则校验直接报错),
175
+ // 所以出码时从源应用站点上读下来写进 app.json,不要在运行时猜。
176
+
177
+ /// <summary>站点模板 id。平台模板表的 id,换平台会变,所以按环境写。</summary>
178
+ [JsonPropertyName("appTemplateId")] public string AppTemplateId { get; set; } = string.Empty;
179
+
180
+ /// <summary>主题 id。</summary>
181
+ [JsonPropertyName("theme")] public string Theme { get; set; } = string.Empty;
182
+
183
+ [JsonPropertyName("layoutType")] public int LayoutType { get; set; }
184
+
185
+ [JsonPropertyName("defaultPageName")] public string DefaultPageName { get; set; } = string.Empty;
186
+ [JsonPropertyName("defaultPageRoute")] public string DefaultPageRoute { get; set; } = string.Empty;
187
+ [JsonPropertyName("defaultPageId")] public string DefaultPageId { get; set; } = string.Empty;
188
+
189
+ [JsonPropertyName("isSkipMenuPerm")] public bool IsSkipMenuPerm { get; set; }
190
+ }
191
+
192
+ /// <summary>
193
+ /// 菜单定义。字段名用小写驼峰(与前端工程里的 <c>menus.json</c> 同一份),
194
+ /// 落库/发平台时再映射成平台的 PascalCase 字段。
195
+ /// </summary>
196
+ public class MenuDefinition
197
+ {
198
+ /// <summary>
199
+ /// 平台菜单 id。**从平台拉下来的菜单必须原样带上**:
200
+ /// 重新生成时若按 route 重新派生,会得到另一个 OutId,
201
+ /// 导入后就是"新增一批菜单"而不是"改名字/改图标"。
202
+ /// 只有全新菜单才允许为空(此时按 route 派生)。
203
+ /// </summary>
204
+ [JsonPropertyName("outId")] public string? OutId { get; set; }
205
+
206
+ [JsonPropertyName("route")] public string? Route { get; set; }
207
+ [JsonPropertyName("name")] public string? Name { get; set; }
208
+ [JsonPropertyName("displayName")] public string? DisplayName { get; set; }
209
+ [JsonPropertyName("parent")] public string? Parent { get; set; }
210
+ [JsonPropertyName("type")] public string? Type { get; set; }
211
+ [JsonPropertyName("icon")] public string? Icon { get; set; }
212
+ [JsonPropertyName("order")] public int? Order { get; set; }
213
+ [JsonPropertyName("visible")] public bool? Visible { get; set; }
214
+ [JsonPropertyName("external")] public bool? External { get; set; }
215
+ [JsonPropertyName("url")] public string? Url { get; set; }
216
+ [JsonPropertyName("pageOutId")] public string? PageOutId { get; set; }
217
+
218
+ [JsonIgnore]
219
+ public bool IsGroup =>
220
+ string.Equals(Type, "group", StringComparison.OrdinalIgnoreCase)
221
+ || string.Equals(Type, "folder", StringComparison.OrdinalIgnoreCase);
222
+ }
223
+
224
+ public class InitializationError
225
+ {
226
+ public string Code { get; init; } = string.Empty;
227
+ public string Path { get; init; } = string.Empty;
228
+ public string Message { get; init; } = string.Empty;
229
+
230
+ public static InitializationError Of(string code, string path, string message) =>
231
+ new() { Code = code, Path = path, Message = message };
232
+ }
233
+
234
+ internal static class Json
235
+ {
236
+ public static readonly JsonSerializerOptions Options = new()
237
+ {
238
+ PropertyNameCaseInsensitive = true,
239
+ PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
240
+ WriteIndented = true,
241
+ // 文件是给人维护的,允许注释能省掉很多"这行为什么这么写"的口口相传
242
+ ReadCommentHandling = JsonCommentHandling.Skip,
243
+ AllowTrailingCommas = true,
244
+ };
245
+ }
@@ -0,0 +1,57 @@
1
+ using Microsoft.AspNetCore.Builder;
2
+ using Microsoft.AspNetCore.Http;
3
+ using Microsoft.Extensions.DependencyInjection;
4
+ using Microsoft.Extensions.Options;
5
+
6
+ namespace Macrowing.Start.Initialization;
7
+
8
+ /// <summary>
9
+ /// 初始化的运维入口。
10
+ ///
11
+ /// 为什么要有 HTTP 入口:开发期改完 <c>Init/menus.json</c> 想立刻生效,
12
+ /// 不应该要求重启宿主;CI/部署也能用一条 curl 复现同样的动作。
13
+ ///
14
+ /// 安全:默认只在非生产环境开放。生产上的初始化由启动期自动完成,
15
+ /// 开放写入口等于允许任何人重放导入,风险不对等。
16
+ /// </summary>
17
+ public static class InitializationEndpoints
18
+ {
19
+ public static WebApplication MapInitializationEndpoints(this WebApplication app, bool exposeWrites)
20
+ {
21
+ var group = app.MapGroup("/api/init").WithTags("Initialization");
22
+
23
+ group.MapGet("/status", (IHostEnvironment env, IOptions<InitializationOptions> options) =>
24
+ {
25
+ var directory = Path.Combine(env.ContentRootPath, options.Value.Directory);
26
+ var state = InitializationState.Load(directory);
27
+ return Results.Ok(new
28
+ {
29
+ ok = true,
30
+ enabled = options.Value.Enabled,
31
+ directory = options.Value.Directory,
32
+ state = state is null ? null : new
33
+ {
34
+ state.AppId,
35
+ state.Domain,
36
+ state.MenusHash,
37
+ state.MenusCount,
38
+ state.DataVersionId,
39
+ state.InitializedAt,
40
+ state.UpdatedAt,
41
+ },
42
+ });
43
+ });
44
+
45
+ if (exposeWrites)
46
+ {
47
+ group.MapPost("/apply", async (
48
+ InitializationRunner runner, IHostEnvironment env, CancellationToken ct) =>
49
+ {
50
+ var report = await runner.RunAsync(env.ContentRootPath, ct);
51
+ return Results.Json(report, statusCode: report.Ok ? StatusCodes.Status200OK : StatusCodes.Status409Conflict);
52
+ });
53
+ }
54
+
55
+ return app;
56
+ }
57
+ }
@@ -0,0 +1,63 @@
1
+ using Microsoft.Extensions.Options;
2
+
3
+ namespace Macrowing.Start.Initialization;
4
+
5
+ /// <summary>
6
+ /// 启动期执行一次初始化。
7
+ ///
8
+ /// 放在 <see cref="IHostedService"/> 而不是 ABP 的 OnApplicationInitialization:
9
+ /// 前者能 await、能注入 scoped 服务,而且失败时可以选择不让宿主起来
10
+ /// (<see cref="InitializationOptions.FailOnError"/>)。
11
+ /// </summary>
12
+ public class InitializationHostedService : IHostedService
13
+ {
14
+ private readonly IServiceScopeFactory _scopes;
15
+ private readonly InitializationOptions _options;
16
+ private readonly IHostEnvironment _environment;
17
+ private readonly ILogger<InitializationHostedService> _logger;
18
+
19
+ public InitializationHostedService(
20
+ IServiceScopeFactory scopes,
21
+ IOptions<InitializationOptions> options,
22
+ IHostEnvironment environment,
23
+ ILogger<InitializationHostedService> logger)
24
+ {
25
+ _scopes = scopes;
26
+ _options = options.Value;
27
+ _environment = environment;
28
+ _logger = logger;
29
+ }
30
+
31
+ public async Task StartAsync(CancellationToken cancellationToken)
32
+ {
33
+ if (!_options.Enabled)
34
+ {
35
+ _logger.LogInformation("应用初始化已关闭(Initialization:Enabled=false)");
36
+ return;
37
+ }
38
+
39
+ // Runner 依赖 typed HttpClient(transient),宿主服务是单例 —— 必须自己开作用域
40
+ using var scope = _scopes.CreateScope();
41
+ var runner = scope.ServiceProvider.GetRequiredService<InitializationRunner>();
42
+ var report = await runner.RunAsync(_environment.ContentRootPath, cancellationToken);
43
+
44
+ if (report.Ok)
45
+ {
46
+ _logger.LogInformation("应用初始化:{Action},appId={AppId},菜单 {Count} 条",
47
+ report.Action, report.AppId, report.MenusCount);
48
+ foreach (var warning in report.Warnings)
49
+ _logger.LogWarning("初始化提示 {Code}: {Message}", warning.Code, warning.Message);
50
+ return;
51
+ }
52
+
53
+ foreach (var error in report.Errors)
54
+ _logger.LogError("初始化错误 {Code}({Path}): {Message}", error.Code, error.Path, error.Message);
55
+
56
+ // 已初始化过的环境不该因为平台暂时不可达而起不来,
57
+ // 所以默认只记录;需要严格时打开 FailOnError。
58
+ if (_options.FailOnError)
59
+ throw new InvalidOperationException("应用初始化失败:" + string.Join(";", report.Errors.Select(e => e.Message)));
60
+ }
61
+
62
+ public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
63
+ }
@@ -0,0 +1,44 @@
1
+ namespace Macrowing.Start.Initialization;
2
+
3
+ /// <summary>
4
+ /// 初始化配置。绑定 <c>appsettings.json</c> 的 <c>"Initialization"</c> 节点。
5
+ ///
6
+ /// 为什么放在宿主而不是 business module:初始化是「部署行为」,
7
+ /// 它决定这个应用在平台上有没有、菜单对不对;业务模块只管业务本身。
8
+ /// </summary>
9
+ public class InitializationOptions
10
+ {
11
+ public const string SectionName = "Initialization";
12
+
13
+ /// <summary>应用启动时自动执行。生产默认 true —— 部署完就能用。</summary>
14
+ public bool Enabled { get; set; } = true;
15
+
16
+ /// <summary>初始化文件目录(相对宿主内容根)。缺省 <c>Init</c>。</summary>
17
+ public string Directory { get; set; } = "Init";
18
+
19
+ /// <summary>
20
+ /// 失败策略:<c>true</c> 时初始化失败会让宿主启动失败。
21
+ /// 已初始化过的环境不应该因为平台不可达而起不来,所以默认 <c>false</c>(记录后继续)。
22
+ /// </summary>
23
+ public bool FailOnError { get; set; }
24
+
25
+ /// <summary>
26
+ /// 允许在文件与线上不一致时**更新**线上菜单。
27
+ /// 关闭时只报告差异(dry-run 语义),不会改动平台数据。
28
+ /// </summary>
29
+ public bool AllowMenuUpdate { get; set; } = true;
30
+
31
+ /// <summary>平台地址;为空时从 InBiz SDK 的配置读取。</summary>
32
+ public string? ServerUrl { get; set; }
33
+
34
+ /// <summary>
35
+ /// 预签发的 Token。给了就直接用,跳过集成登录 —— 适用于 CI 或临时验证。
36
+ /// 和 UserName/IntegrationKey 二选一。
37
+ /// </summary>
38
+ public string? Token { get; set; }
39
+
40
+ /// <summary>集成登录账号与密钥(服务账号),只在需要换取 Token 时使用。</summary>
41
+ public string? UserName { get; set; }
42
+
43
+ public string? IntegrationKey { get; set; }
44
+ }