oak-domain 6.0.0 → 6.1.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.
- package/README.md +5 -1
- package/es/actions/action.d.ts +1 -1
- package/es/base-app-domain/EntityDict.d.ts +27 -0
- package/es/base-app-domain/LocalizedContent/Schema.d.ts +19 -0
- package/es/base-app-domain/LocalizedContent/Schema.js +1 -0
- package/es/base-app-domain/LocalizedContent/Storage.d.ts +3 -0
- package/es/base-app-domain/LocalizedContent/Storage.js +75 -0
- package/es/base-app-domain/LocalizedContent/Style.d.ts +3 -0
- package/es/base-app-domain/LocalizedContent/Style.js +12 -0
- package/es/base-app-domain/LocalizedContent/_baseSchema.d.ts +58 -0
- package/es/base-app-domain/Storage.js +2 -0
- package/es/base-app-domain/StyleDict.js +2 -0
- package/es/compiler/customChecks/i18n.js +4 -1
- package/es/compiler/customChecks/runner.d.ts +1 -1
- package/es/compiler/customChecks/runner.js +1 -1
- package/es/compiler/customChecks/types.d.ts +2 -1
- package/es/compiler/dependencyBuilder.d.ts +11 -2
- package/es/compiler/dependencyBuilder.js +188 -199
- package/es/compiler/entityDescEnum.d.ts +5 -0
- package/es/compiler/entityDescEnum.js +443 -0
- package/es/compiler/entitySource.d.ts +28 -0
- package/es/compiler/entitySource.js +521 -0
- package/es/compiler/localeBuilder.d.ts +7 -2
- package/es/compiler/localeBuilder.js +52 -56
- package/es/compiler/routerBuilder.d.ts +32 -3
- package/es/compiler/routerBuilder.js +157 -45
- package/es/compiler/schemaBuilder.d.ts +12 -2
- package/es/compiler/schemaBuilder.js +653 -148
- package/es/compiler/tscBuilder.d.ts +20 -2
- package/es/compiler/tscBuilder.js +231 -45
- package/es/context/BackendRuntimeContext.d.ts +6 -4
- package/es/context/BackendRuntimeContext.js +9 -1
- package/es/context/ContextComposer.d.ts +93 -0
- package/es/context/ContextComposer.js +353 -0
- package/es/context/SerializedData.d.ts +2 -1
- package/es/data/i18n.d.ts +1 -1
- package/es/data/i18n.js +1 -86
- package/es/data/i18n.json +86 -0
- package/es/entities/ActionAuth.d.ts +3 -3
- package/es/entities/I18n.d.ts +2 -2
- package/es/entities/LocalizedContent.d.ts +22 -0
- package/es/entities/LocalizedContent.js +101 -0
- package/es/entities/Log.d.ts +3 -3
- package/es/entities/Modi.d.ts +2 -2
- package/es/entities/ModiEntity.d.ts +3 -3
- package/es/entities/Oper.d.ts +5 -5
- package/es/entities/OperEntity.d.ts +3 -3
- package/es/entities/Path.d.ts +2 -2
- package/es/entities/Relation.d.ts +2 -2
- package/es/entities/RelationAuth.d.ts +3 -3
- package/es/entities/User.d.ts +4 -4
- package/es/entities/UserEntityClaim.d.ts +6 -6
- package/es/entities/UserEntityGrant.d.ts +2 -2
- package/es/entities/UserRelation.d.ts +4 -4
- package/es/store/AsyncRowStore.d.ts +2 -2
- package/es/store/AsyncRowStore.js +2 -2
- package/es/store/CascadeStore.d.ts +5 -3
- package/es/store/CascadeStore.js +56 -24
- package/es/store/IntrinsicCheckers.d.ts +1 -1
- package/es/store/IntrinsicCheckers.js +2 -2
- package/es/store/IntrinsicLogics.d.ts +1 -1
- package/es/store/RelationAuth.js +3 -3
- package/es/store/SyncRowStore.d.ts +1 -1
- package/es/store/SyncRowStore.js +1 -1
- package/es/store/TriggerExecutor.d.ts +6 -4
- package/es/store/TriggerExecutor.js +16 -4
- package/es/store/checker.d.ts +2 -2
- package/es/store/checker.js +45 -9
- package/es/store/filter.d.ts +3 -3
- package/es/store/filter.js +4 -4
- package/es/store/modi.d.ts +5 -5
- package/es/store/modi.js +4 -4
- package/es/store/projection.d.ts +1 -1
- package/es/store/relation.js +1 -1
- package/es/store/triggers.d.ts +4 -4
- package/es/store/triggers.js +2 -2
- package/es/timers/oper.d.ts +3 -3
- package/es/timers/oper.js +1 -1
- package/es/timers/vaccum.d.ts +3 -3
- package/es/types/Action.d.ts +1 -1
- package/es/types/AppLoader.d.ts +1 -1
- package/es/types/Aspect.d.ts +1 -1
- package/es/types/Auth.d.ts +2 -2
- package/es/types/Configuration.d.ts +7 -6
- package/es/types/Connector.d.ts +47 -1
- package/es/types/DataType.d.ts +2 -2
- package/es/types/Demand.d.ts +40 -6
- package/es/types/Endpoint.d.ts +17 -1
- package/es/types/Entity.d.ts +21 -4
- package/es/types/Entity.js +23 -0
- package/es/types/EntityDesc.d.ts +9 -8
- package/es/types/Environment.d.ts +17 -0
- package/es/types/Exception.d.ts +1 -1
- package/es/types/Exception.js +1 -1
- package/es/types/Expression.d.ts +13 -2
- package/es/types/Expression.js +36 -1
- package/es/types/Locale.d.ts +14 -1
- package/es/types/Locale.js +13 -1
- package/es/types/OakPackage.d.ts +29 -0
- package/es/types/OakPackage.js +30 -0
- package/es/types/Port.d.ts +1 -1
- package/es/types/RowStore.d.ts +9 -7
- package/es/types/Storage.d.ts +11 -3
- package/es/types/Storage.js +12 -1
- package/es/types/Style.d.ts +2 -2
- package/es/types/Sync.d.ts +3 -3
- package/es/types/Timer.d.ts +14 -2
- package/es/types/Trigger.d.ts +1 -1
- package/es/types/Watcher.d.ts +1 -1
- package/es/types/index.d.ts +1 -0
- package/es/types/index.js +1 -0
- package/es/utils/SimpleConnector.d.ts +30 -4
- package/es/utils/SimpleConnector.js +294 -21
- package/es/utils/concurrent.js +1 -1
- package/es/utils/decimal.d.ts +26 -0
- package/es/utils/decimal.js +87 -0
- package/es/utils/fetch/index.d.ts +1 -0
- package/es/utils/fetch/index.js +3 -0
- package/es/utils/fetch/index.mp.d.ts +3 -0
- package/es/utils/fetch/index.mp.js +280 -0
- package/es/utils/fetch/index.native.d.ts +1 -0
- package/es/utils/fetch/index.native.js +3 -0
- package/es/utils/fetch/index.web.d.ts +1 -0
- package/es/utils/fetch/index.web.js +3 -0
- package/es/utils/fetch/shared.d.ts +6 -0
- package/es/utils/fetch/shared.js +23 -0
- package/es/utils/localizedContent.d.ts +11 -0
- package/es/utils/localizedContent.js +346 -0
- package/es/utils/lodash.d.ts +1 -35
- package/es/utils/lodash.js +1 -52
- package/es/utils/module/combine.common.d.ts +3 -3
- package/es/utils/module/combine.common.js +2 -2
- package/es/utils/module/combine.dev.d.ts +2 -2
- package/es/utils/module/combine.dev.js +2 -2
- package/es/utils/module/combine.prod.d.ts +1 -1
- package/es/utils/module/combine.server.d.ts +2 -2
- package/es/utils/module/combine.server.js +2 -2
- package/es/utils/money.d.ts +2 -2
- package/es/utils/money.js +2 -2
- package/es/utils/operationResult.js +1 -1
- package/es/utils/projection.d.ts +3 -3
- package/es/utils/projection.js +1 -1
- package/es/utils/relationPath.d.ts +1 -1
- package/es/utils/relationPath.js +1 -1
- package/es/utils/row.d.ts +3 -3
- package/es/utils/row.js +2 -2
- package/es/utils/sseEndpoint.d.ts +41 -0
- package/es/utils/sseEndpoint.js +151 -0
- package/es/utils/toolkit.d.ts +28 -0
- package/es/utils/toolkit.js +220 -0
- package/es/utils/url/index.d.ts +1 -3
- package/es/utils/url/index.js +1 -1
- package/es/utils/url/index.mp.d.ts +16 -3
- package/es/utils/url/index.mp.js +2 -2
- package/es/utils/url/index.native.d.ts +13 -1
- package/es/utils/url/index.native.js +3 -1
- package/es/utils/url/index.web.d.ts +13 -1
- package/es/utils/url/index.web.js +3 -1
- package/es/utils/url/lightweight.d.ts +65 -0
- package/es/utils/url/lightweight.js +530 -0
- package/es/utils/url/urlObject.d.ts +16 -0
- package/es/utils/validate/id.d.ts +5 -0
- package/es/utils/validate/id.js +28 -0
- package/es/utils/validate/index.d.ts +4 -0
- package/es/utils/validate/index.js +4 -0
- package/es/utils/validate/mobile.d.ts +6 -0
- package/es/utils/validate/mobile.js +49 -0
- package/es/utils/validate/nationality.d.ts +14 -0
- package/es/utils/validate/nationality.data.d.ts +9 -0
- package/es/utils/validate/nationality.data.js +257 -0
- package/es/utils/validate/nationality.js +64 -0
- package/es/utils/validate/passport.d.ts +3 -0
- package/es/utils/validate/passport.js +19 -0
- package/es/utils/validator.d.ts +10 -8
- package/es/utils/validator.js +24 -40
- package/lib/actions/action.d.ts +1 -1
- package/lib/base-app-domain/EntityDict.d.ts +27 -0
- package/lib/base-app-domain/LocalizedContent/Schema.d.ts +19 -0
- package/lib/base-app-domain/LocalizedContent/Schema.js +4 -0
- package/lib/base-app-domain/LocalizedContent/Storage.d.ts +3 -0
- package/lib/base-app-domain/LocalizedContent/Storage.js +78 -0
- package/lib/base-app-domain/LocalizedContent/Style.d.ts +3 -0
- package/lib/base-app-domain/LocalizedContent/Style.js +15 -0
- package/lib/base-app-domain/LocalizedContent/_baseSchema.d.ts +58 -0
- package/lib/base-app-domain/Storage.js +26 -24
- package/lib/base-app-domain/StyleDict.js +10 -8
- package/lib/compiler/customChecks/i18n.js +5 -2
- package/lib/compiler/customChecks/runner.d.ts +1 -1
- package/lib/compiler/customChecks/types.d.ts +2 -1
- package/lib/compiler/dependencyBuilder.d.ts +11 -2
- package/lib/compiler/dependencyBuilder.js +237 -243
- package/lib/compiler/entityDescEnum.d.ts +5 -0
- package/lib/compiler/entityDescEnum.js +450 -0
- package/lib/compiler/entitySource.d.ts +28 -0
- package/lib/compiler/entitySource.js +529 -0
- package/lib/compiler/localeBuilder.d.ts +7 -2
- package/lib/compiler/localeBuilder.js +52 -56
- package/lib/compiler/routerBuilder.d.ts +32 -3
- package/lib/compiler/routerBuilder.js +160 -48
- package/lib/compiler/schemaBuilder.d.ts +12 -2
- package/lib/compiler/schemaBuilder.js +855 -350
- package/lib/compiler/tscBuilder.d.ts +20 -2
- package/lib/compiler/tscBuilder.js +217 -37
- package/lib/context/BackendRuntimeContext.d.ts +6 -4
- package/lib/context/BackendRuntimeContext.js +10 -3
- package/lib/context/ContextComposer.d.ts +93 -0
- package/lib/context/ContextComposer.js +361 -0
- package/lib/context/SerializedData.d.ts +2 -1
- package/lib/data/i18n.d.ts +1 -1
- package/lib/data/i18n.js +1 -86
- package/lib/data/i18n.json +86 -0
- package/lib/entities/ActionAuth.d.ts +3 -3
- package/lib/entities/I18n.d.ts +2 -2
- package/lib/entities/LocalizedContent.d.ts +22 -0
- package/lib/entities/LocalizedContent.js +104 -0
- package/lib/entities/Log.d.ts +3 -3
- package/lib/entities/Modi.d.ts +2 -2
- package/lib/entities/ModiEntity.d.ts +3 -3
- package/lib/entities/Oper.d.ts +5 -5
- package/lib/entities/OperEntity.d.ts +3 -3
- package/lib/entities/Path.d.ts +2 -2
- package/lib/entities/Relation.d.ts +2 -2
- package/lib/entities/RelationAuth.d.ts +3 -3
- package/lib/entities/User.d.ts +4 -4
- package/lib/entities/UserEntityClaim.d.ts +6 -6
- package/lib/entities/UserEntityGrant.d.ts +2 -2
- package/lib/entities/UserRelation.d.ts +4 -4
- package/lib/store/AsyncRowStore.d.ts +2 -2
- package/lib/store/AsyncRowStore.js +6 -7
- package/lib/store/CascadeStore.d.ts +5 -3
- package/lib/store/CascadeStore.js +101 -70
- package/lib/store/IntrinsicCheckers.d.ts +1 -1
- package/lib/store/IntrinsicCheckers.js +12 -13
- package/lib/store/IntrinsicLogics.d.ts +1 -1
- package/lib/store/RelationAuth.js +42 -43
- package/lib/store/SyncRowStore.d.ts +1 -1
- package/lib/store/SyncRowStore.js +4 -5
- package/lib/store/TriggerExecutor.d.ts +6 -4
- package/lib/store/TriggerExecutor.js +39 -28
- package/lib/store/checker.d.ts +2 -2
- package/lib/store/checker.js +55 -20
- package/lib/store/filter.d.ts +3 -3
- package/lib/store/filter.js +47 -48
- package/lib/store/modi.d.ts +5 -5
- package/lib/store/modi.js +5 -6
- package/lib/store/projection.d.ts +1 -1
- package/lib/store/relation.js +4 -5
- package/lib/store/triggers.d.ts +4 -4
- package/lib/store/triggers.js +13 -14
- package/lib/timers/oper.d.ts +3 -3
- package/lib/timers/vaccum.d.ts +3 -3
- package/lib/types/Action.d.ts +1 -1
- package/lib/types/AppLoader.d.ts +1 -1
- package/lib/types/Aspect.d.ts +1 -1
- package/lib/types/Auth.d.ts +2 -2
- package/lib/types/Configuration.d.ts +7 -6
- package/lib/types/Connector.d.ts +47 -1
- package/lib/types/DataType.d.ts +2 -2
- package/lib/types/Demand.d.ts +40 -6
- package/lib/types/Endpoint.d.ts +17 -1
- package/lib/types/Entity.d.ts +21 -4
- package/lib/types/Entity.js +27 -0
- package/lib/types/EntityDesc.d.ts +9 -8
- package/lib/types/Environment.d.ts +17 -0
- package/lib/types/Exception.d.ts +1 -1
- package/lib/types/Exception.js +2 -2
- package/lib/types/Expression.d.ts +13 -2
- package/lib/types/Expression.js +40 -5
- package/lib/types/Locale.d.ts +14 -1
- package/lib/types/Locale.js +14 -0
- package/lib/types/OakPackage.d.ts +29 -0
- package/lib/types/OakPackage.js +36 -0
- package/lib/types/Port.d.ts +1 -1
- package/lib/types/RowStore.d.ts +9 -7
- package/lib/types/Storage.d.ts +11 -3
- package/lib/types/Storage.js +13 -0
- package/lib/types/Style.d.ts +2 -2
- package/lib/types/Sync.d.ts +3 -3
- package/lib/types/Timer.d.ts +14 -2
- package/lib/types/Trigger.d.ts +1 -1
- package/lib/types/Watcher.d.ts +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/utils/SimpleConnector.d.ts +30 -4
- package/lib/utils/SimpleConnector.js +297 -24
- package/lib/utils/concurrent.js +4 -5
- package/lib/utils/decimal.d.ts +26 -0
- package/lib/utils/decimal.js +112 -0
- package/lib/utils/fetch/index.d.ts +1 -0
- package/lib/utils/fetch/index.js +6 -0
- package/lib/utils/fetch/index.mp.d.ts +3 -0
- package/lib/utils/fetch/index.mp.js +285 -0
- package/lib/utils/fetch/index.native.d.ts +1 -0
- package/lib/utils/fetch/index.native.js +6 -0
- package/lib/utils/fetch/index.web.d.ts +1 -0
- package/lib/utils/fetch/index.web.js +6 -0
- package/lib/utils/fetch/shared.d.ts +6 -0
- package/lib/utils/fetch/shared.js +28 -0
- package/lib/utils/localizedContent.d.ts +11 -0
- package/lib/utils/localizedContent.js +352 -0
- package/lib/utils/lodash.d.ts +1 -35
- package/lib/utils/lodash.js +1 -76
- package/lib/utils/module/combine.common.d.ts +3 -3
- package/lib/utils/module/combine.common.js +6 -7
- package/lib/utils/module/combine.dev.d.ts +2 -2
- package/lib/utils/module/combine.dev.js +19 -19
- package/lib/utils/module/combine.prod.d.ts +1 -1
- package/lib/utils/module/combine.server.d.ts +2 -2
- package/lib/utils/module/combine.server.js +19 -19
- package/lib/utils/money.d.ts +2 -2
- package/lib/utils/money.js +2 -2
- package/lib/utils/operationResult.js +4 -4
- package/lib/utils/projection.d.ts +3 -3
- package/lib/utils/relationPath.d.ts +1 -1
- package/lib/utils/relationPath.js +10 -11
- package/lib/utils/row.d.ts +3 -3
- package/lib/utils/row.js +4 -5
- package/lib/utils/sseEndpoint.d.ts +41 -0
- package/lib/utils/sseEndpoint.js +156 -0
- package/lib/utils/toolkit.d.ts +28 -0
- package/lib/utils/toolkit.js +253 -0
- package/lib/utils/url/index.d.ts +1 -3
- package/lib/utils/url/index.js +3 -1
- package/lib/utils/url/index.mp.d.ts +16 -3
- package/lib/utils/url/index.mp.js +6 -4
- package/lib/utils/url/index.native.d.ts +13 -1
- package/lib/utils/url/index.native.js +5 -1
- package/lib/utils/url/index.web.d.ts +13 -1
- package/lib/utils/url/index.web.js +5 -1
- package/lib/utils/url/lightweight.d.ts +65 -0
- package/lib/utils/url/lightweight.js +535 -0
- package/lib/utils/url/urlObject.d.ts +16 -0
- package/lib/utils/url/urlObject.js +2 -0
- package/lib/utils/url/whatwg-url/lib/URL-impl.d.ts +8 -15
- package/lib/utils/url/whatwg-url/lib/infra.js +5 -4
- package/lib/utils/url/whatwg-url/lib/urlencoded.d.ts +3 -1
- package/lib/utils/url/whatwg-url/lib/utils.d.ts +1 -1
- package/lib/utils/validate/id.d.ts +5 -0
- package/lib/utils/validate/id.js +35 -0
- package/lib/utils/validate/index.d.ts +4 -0
- package/lib/utils/validate/index.js +7 -0
- package/lib/utils/validate/mobile.d.ts +6 -0
- package/lib/utils/validate/mobile.js +57 -0
- package/lib/utils/validate/nationality.d.ts +14 -0
- package/lib/utils/validate/nationality.data.d.ts +9 -0
- package/lib/utils/validate/nationality.data.js +260 -0
- package/lib/utils/validate/nationality.js +76 -0
- package/lib/utils/validate/passport.d.ts +3 -0
- package/lib/utils/validate/passport.js +24 -0
- package/lib/utils/validator.d.ts +10 -8
- package/lib/utils/validator.js +38 -42
- package/package.json +19 -9
- package/es/utils/url/whatwg-url/index.d.ts +0 -3
- package/es/utils/url/whatwg-url/index.js +0 -12
- package/es/utils/url/whatwg-url/lib/URL-impl.d.ts +0 -27
- package/es/utils/url/whatwg-url/lib/URL-impl.js +0 -172
- package/es/utils/url/whatwg-url/lib/URL.js +0 -295
- package/es/utils/url/whatwg-url/lib/URLSearchParams-impl.d.ts +0 -19
- package/es/utils/url/whatwg-url/lib/URLSearchParams-impl.js +0 -123
- package/es/utils/url/whatwg-url/lib/URLSearchParams.js +0 -423
- package/es/utils/url/whatwg-url/lib/infra.d.ts +0 -12
- package/es/utils/url/whatwg-url/lib/infra.js +0 -19
- package/es/utils/url/whatwg-url/lib/url-state-machine.d.ts +0 -24
- package/es/utils/url/whatwg-url/lib/url-state-machine.js +0 -1228
- package/es/utils/url/whatwg-url/lib/urlencoded.d.ts +0 -14
- package/es/utils/url/whatwg-url/lib/urlencoded.js +0 -160
- package/es/utils/url/whatwg-url/lib/utils.d.ts +0 -37
- package/es/utils/url/whatwg-url/lib/utils.js +0 -99
- package/lib/store/diffSchema.d.ts +0 -1
- package/lib/utils/url/whatwg-url/index.d.ts +0 -3
- package/lib/utils/url/whatwg-url/index.js +0 -16
- package/lib/utils/url/whatwg-url/lib/URL-impl.js +0 -175
- package/lib/utils/url/whatwg-url/lib/URL.d.ts +0 -1
- package/lib/utils/url/whatwg-url/lib/URL.js +0 -298
- package/lib/utils/url/whatwg-url/lib/URLSearchParams-impl.d.ts +0 -19
- package/lib/utils/url/whatwg-url/lib/URLSearchParams-impl.js +0 -126
- package/lib/utils/url/whatwg-url/lib/URLSearchParams.d.ts +0 -1
- package/lib/utils/url/whatwg-url/lib/URLSearchParams.js +0 -426
- package/lib/utils/url/whatwg-url/lib/infra.d.ts +0 -12
- package/lib/utils/url/whatwg-url/lib/url-state-machine.d.ts +0 -24
- package/lib/utils/url/whatwg-url/lib/url-state-machine.js +0 -1238
- package/lib/utils/url/whatwg-url/lib/urlencoded.js +0 -162
- package/lib/utils/url/whatwg-url/lib/utils.js +0 -101
- package/src/entities/ActionAuth.ts +0 -50
- package/src/entities/I18n.ts +0 -53
- package/src/entities/Log.ts +0 -62
- package/src/entities/Modi.ts +0 -107
- package/src/entities/ModiEntity.ts +0 -35
- package/src/entities/Oper.ts +0 -115
- package/src/entities/OperEntity.ts +0 -36
- package/src/entities/Path.ts +0 -56
- package/src/entities/Relation.ts +0 -53
- package/src/entities/RelationAuth.ts +0 -53
- package/src/entities/User.ts +0 -85
- package/src/entities/UserEntityClaim.ts +0 -41
- package/src/entities/UserEntityGrant.ts +0 -33
- package/src/entities/UserRelation.ts +0 -60
- /package/es/{utils/url/whatwg-url/lib/URL.d.ts → base-app-domain/LocalizedContent/_baseSchema.js} +0 -0
- /package/es/utils/url/{whatwg-url/lib/URLSearchParams.d.ts → urlObject.js} +0 -0
- /package/lib/{store/diffSchema.js → base-app-domain/LocalizedContent/_baseSchema.js} +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
1
|
+
import { assert } from '../utils/assert';
|
|
2
2
|
import { join as pathJoin } from 'path';
|
|
3
3
|
import { existsSync, readFileSync, writeFileSync, readdirSync, statSync } from 'fs';
|
|
4
4
|
import * as ts from 'typescript';
|
|
5
5
|
import { firstLetterLowerCase, firstLetterUpperCase } from '../utils/string';
|
|
6
6
|
import { OAK_CLI_MODULE_NAME } from './env';
|
|
7
7
|
import { copySync, mkdirSync } from 'fs-extra';
|
|
8
|
-
import {
|
|
8
|
+
import { getOakBusinessDependencies, isOakBusinessModule, } from '../types/OakPackage';
|
|
9
9
|
const { factory } = ts;
|
|
10
|
+
const PROJECT_NAME_PLACEHOLDER = '__OAK_PROJECT_NAME__';
|
|
10
11
|
function uniqueDependencies(dependencies) {
|
|
11
12
|
return Array.from(new Set(dependencies.filter((dep) => !!dep)));
|
|
12
13
|
}
|
|
@@ -46,7 +47,7 @@ function collectInstalledOakLibDependencies(dir) {
|
|
|
46
47
|
return false;
|
|
47
48
|
}
|
|
48
49
|
const dependencyManifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
49
|
-
return dependencyManifest
|
|
50
|
+
return isOakBusinessModule(dependencyManifest);
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
function collectOakDepLibGraph(cwd, dependencies) {
|
|
@@ -54,12 +55,12 @@ function collectOakDepLibGraph(cwd, dependencies) {
|
|
|
54
55
|
const depLibGraph = {};
|
|
55
56
|
dependencies.forEach((dep) => {
|
|
56
57
|
const packageManifest = readInstalledPackageManifest(cwd, dep);
|
|
57
|
-
const depLib = packageManifest
|
|
58
|
+
const depLib = getOakBusinessDependencies(packageManifest);
|
|
58
59
|
depLibGraph[dep] = uniqueDependencies(Object.keys(depLib).map((depName) => depName).filter((depName) => depName !== dep && dependencySet.has(depName)));
|
|
59
60
|
});
|
|
60
61
|
return depLibGraph;
|
|
61
62
|
}
|
|
62
|
-
export function
|
|
63
|
+
export function resolveDependencyRootPlan(cwd, dependencies) {
|
|
63
64
|
const depLibGraph = collectOakDepLibGraph(cwd, dependencies);
|
|
64
65
|
const transitiveCoveredDependencies = new Set();
|
|
65
66
|
const closureCache = {};
|
|
@@ -95,7 +96,7 @@ export function resolveFeatureInitializationPlan(cwd, dependencies) {
|
|
|
95
96
|
rootDependencies,
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
|
-
function resolveDeclaredDependencies(dir) {
|
|
99
|
+
export function resolveDeclaredDependencies(dir) {
|
|
99
100
|
return uniqueDependencies([
|
|
100
101
|
...readDependencyConfiguration(dir),
|
|
101
102
|
...collectInstalledOakLibDependencies(dir),
|
|
@@ -113,74 +114,6 @@ function readProjectPackageName(cwd) {
|
|
|
113
114
|
}
|
|
114
115
|
return packageName.replace(/^@/, '').replace(/\//g, '-');
|
|
115
116
|
}
|
|
116
|
-
function getOakPackageFeatureInit(cwd, dependency) {
|
|
117
|
-
return readInstalledPackageManifest(cwd, dependency)?.oak?.featureInit;
|
|
118
|
-
}
|
|
119
|
-
function collectFeatureInitializationDependencyOrder(dependency, depLibGraph, visited, order) {
|
|
120
|
-
if (visited.has(dependency)) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
visited.add(dependency);
|
|
124
|
-
(depLibGraph[dependency] || []).forEach((dep) => collectFeatureInitializationDependencyOrder(dep, depLibGraph, visited, order));
|
|
125
|
-
order.push(dependency);
|
|
126
|
-
}
|
|
127
|
-
function resolveFeatureInitializationMetadata(cwd, rootDependencies, depLibGraph) {
|
|
128
|
-
const importKeySet = new Set();
|
|
129
|
-
const statementKeySet = new Set();
|
|
130
|
-
const importBindingOwner = new Map();
|
|
131
|
-
const imports = [];
|
|
132
|
-
const roots = [];
|
|
133
|
-
const statements = [];
|
|
134
|
-
const registerImportConfig = (importConfig, owner) => {
|
|
135
|
-
const bindings = [
|
|
136
|
-
importConfig.default,
|
|
137
|
-
...(importConfig.named || []).map(({ imported, local }) => local || imported),
|
|
138
|
-
].filter(Boolean);
|
|
139
|
-
const importSignature = JSON.stringify(importConfig);
|
|
140
|
-
bindings.forEach((binding) => {
|
|
141
|
-
const existingOwner = importBindingOwner.get(binding);
|
|
142
|
-
if (existingOwner && existingOwner !== importSignature) {
|
|
143
|
-
throw new Error(`依赖模块${owner}的 featureInit import 绑定「${binding}」与其它模块冲突,请调整 metadata 中的导入命名`);
|
|
144
|
-
}
|
|
145
|
-
importBindingOwner.set(binding, importSignature);
|
|
146
|
-
});
|
|
147
|
-
if (!importKeySet.has(importSignature)) {
|
|
148
|
-
importKeySet.add(importSignature);
|
|
149
|
-
imports.push(importConfig);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const registerStatement = (statement) => {
|
|
153
|
-
const statementSignature = JSON.stringify(statement);
|
|
154
|
-
if (!statementKeySet.has(statementSignature)) {
|
|
155
|
-
statementKeySet.add(statementSignature);
|
|
156
|
-
statements.push(statement);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
rootDependencies.forEach((rootDependency) => {
|
|
160
|
-
const order = [];
|
|
161
|
-
collectFeatureInitializationDependencyOrder(rootDependency, depLibGraph, new Set(), order);
|
|
162
|
-
order.forEach((dependency) => {
|
|
163
|
-
const featureInit = getOakPackageFeatureInit(cwd, dependency);
|
|
164
|
-
if (!featureInit) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
featureInit.imports?.forEach((importConfig) => registerImportConfig(importConfig, dependency));
|
|
168
|
-
featureInit.statements?.forEach(registerStatement);
|
|
169
|
-
});
|
|
170
|
-
const rootFeatureInit = getOakPackageFeatureInit(cwd, rootDependency);
|
|
171
|
-
if (rootFeatureInit?.initializeArgs) {
|
|
172
|
-
roots.push({
|
|
173
|
-
dependency: rootDependency,
|
|
174
|
-
initializeArgs: rootFeatureInit.initializeArgs,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return {
|
|
179
|
-
imports,
|
|
180
|
-
roots,
|
|
181
|
-
statements,
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
117
|
/**
|
|
185
118
|
* 构建项目依赖关系图
|
|
186
119
|
* @param cwd
|
|
@@ -201,7 +134,7 @@ export function analyzeDepedency(cwd) {
|
|
|
201
134
|
}
|
|
202
135
|
const dependencies = resolveDeclaredDependencies(dir);
|
|
203
136
|
if (dependencies.length === 0) {
|
|
204
|
-
// 没有依赖文件,且没有可自动识别的
|
|
137
|
+
// 没有依赖文件,且没有可自动识别的 Oak 业务模块依赖,直接返回
|
|
205
138
|
return;
|
|
206
139
|
}
|
|
207
140
|
dependencies.forEach((dep) => {
|
|
@@ -235,10 +168,10 @@ export function analyzeDepedency(cwd) {
|
|
|
235
168
|
}
|
|
236
169
|
assert(freeNodes.length > 0, '依赖关系成环!');
|
|
237
170
|
freeNodes.forEach((n) => {
|
|
238
|
-
|
|
239
|
-
|
|
171
|
+
delete depGraph.nodes[n];
|
|
172
|
+
delete depGraph.dependencies[n];
|
|
240
173
|
for (const n2 in depGraph.dependencies) {
|
|
241
|
-
|
|
174
|
+
delete depGraph.dependencies[n2][n];
|
|
242
175
|
}
|
|
243
176
|
depGraph.ascOrder.push(n);
|
|
244
177
|
});
|
|
@@ -351,7 +284,7 @@ function outputPolyfillDts(dependencies, briefNames, sourceFile, printer, filena
|
|
|
351
284
|
writeFileSync(filename, result, { flag: 'w' });
|
|
352
285
|
console.log(`构建${filename}文件成功`);
|
|
353
286
|
}
|
|
354
|
-
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename) {
|
|
287
|
+
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
355
288
|
let statements2 = [];
|
|
356
289
|
if (dependencies.length > 0) {
|
|
357
290
|
const { statements } = sourceFile;
|
|
@@ -382,6 +315,13 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
|
|
|
382
315
|
else {
|
|
383
316
|
statements2 = [...sourceFile.statements];
|
|
384
317
|
}
|
|
318
|
+
if (isModule) {
|
|
319
|
+
const entityDictImport = statements2[0];
|
|
320
|
+
assert(ts.isImportDeclaration(entityDictImport));
|
|
321
|
+
Object.assign(entityDictImport, {
|
|
322
|
+
moduleSpecifier: factory.createStringLiteral('../oak-app-domain'),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
385
325
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
386
326
|
writeFileSync(filename, result, { flag: 'w' });
|
|
387
327
|
console.log(`构建${filename}文件成功`);
|
|
@@ -462,6 +402,122 @@ function outputContext(depGraph, sourceFile, printer, filename) {
|
|
|
462
402
|
writeFileSync(filename, result, { flag: 'w' });
|
|
463
403
|
console.log(`构建${filename}文件成功`);
|
|
464
404
|
}
|
|
405
|
+
function hasRuntimeContextEntry(cwd, dependency, target) {
|
|
406
|
+
const dependencyDir = join(cwd, 'node_modules', dependency);
|
|
407
|
+
const fileName = `${target}RuntimeContext`;
|
|
408
|
+
return [
|
|
409
|
+
join(dependencyDir, 'src', 'context', `${fileName}.ts`),
|
|
410
|
+
join(dependencyDir, 'lib', 'context', `${fileName}.js`),
|
|
411
|
+
join(dependencyDir, 'es', 'context', `${fileName}.js`),
|
|
412
|
+
join(dependencyDir, 'lib', 'context', `${fileName}.d.ts`),
|
|
413
|
+
join(dependencyDir, 'es', 'context', `${fileName}.d.ts`),
|
|
414
|
+
].some((filePath) => existsSync(filePath));
|
|
415
|
+
}
|
|
416
|
+
export function resolveContextRootDependencies(cwd, target) {
|
|
417
|
+
const directDependencies = resolveDeclaredDependencies(cwd);
|
|
418
|
+
const contextDependencies = directDependencies.filter((dependency) => hasRuntimeContextEntry(cwd, dependency, target));
|
|
419
|
+
return resolveDependencyRootPlan(cwd, contextDependencies).rootDependencies;
|
|
420
|
+
}
|
|
421
|
+
function contextDependencyName(dependency, index) {
|
|
422
|
+
return `${dependency.replace(/[^a-zA-Z0-9]/g, '_')}${index}`;
|
|
423
|
+
}
|
|
424
|
+
export function renderGeneratedContextSource(cwd, target, isModule) {
|
|
425
|
+
const isBackend = target === 'Backend';
|
|
426
|
+
const dependencies = resolveContextRootDependencies(cwd, target);
|
|
427
|
+
const baseImport = isBackend
|
|
428
|
+
? '@oak-domain/context/BackendRuntimeContext'
|
|
429
|
+
: '@oak-frontend-base/context/FrontendRuntimeContext';
|
|
430
|
+
const baseName = `Base${target}RuntimeContext`;
|
|
431
|
+
const generatedName = `Generated${target}RuntimeContext`;
|
|
432
|
+
const contractName = `Generated${target}Context`;
|
|
433
|
+
const dependencyNames = dependencies.map(contextDependencyName);
|
|
434
|
+
const entityDictImport = isModule
|
|
435
|
+
? '../oak-app-domain'
|
|
436
|
+
: '@project/oak-app-domain';
|
|
437
|
+
const imports = [
|
|
438
|
+
`import type { EntityDict } from '${entityDictImport}';`,
|
|
439
|
+
...(isModule
|
|
440
|
+
? [`import type { RuntimeContext } from './RuntimeContext';`]
|
|
441
|
+
: []),
|
|
442
|
+
`import { ${target}RuntimeContext as ${baseName} } from '${baseImport}';`,
|
|
443
|
+
`import type { MergeContextContracts } from '@oak-domain/context/ContextComposer';`,
|
|
444
|
+
...dependencies.map((dependency, index) => `import type { ${target}RuntimeContext as ${dependencyNames[index]}RuntimeContext } from '${makeOakImport(dependency, `context/${target}RuntimeContext`)}';`),
|
|
445
|
+
];
|
|
446
|
+
const contractTypes = [
|
|
447
|
+
`${baseName}<EntityDict>`,
|
|
448
|
+
...dependencyNames.map((name) => `${name}RuntimeContext<EntityDict>`),
|
|
449
|
+
...(isModule ? ['RuntimeContext'] : []),
|
|
450
|
+
];
|
|
451
|
+
if (isModule) {
|
|
452
|
+
return `${imports.join('\n')}
|
|
453
|
+
|
|
454
|
+
export type ${contractName}<
|
|
455
|
+
ED extends EntityDict = EntityDict,
|
|
456
|
+
> = MergeContextContracts<[
|
|
457
|
+
${contractTypes.map((contractType) => contractType.replace(/<EntityDict>/g, '<ED>')).join(',\n ')}
|
|
458
|
+
]>;
|
|
459
|
+
|
|
460
|
+
type ${generatedName}Constructor = abstract new <
|
|
461
|
+
ED extends EntityDict = EntityDict,
|
|
462
|
+
>(
|
|
463
|
+
...args: ConstructorParameters<typeof ${baseName}<ED>>
|
|
464
|
+
) => ${contractName}<ED>;
|
|
465
|
+
|
|
466
|
+
const ${generatedName} = ${baseName} as unknown as ${generatedName}Constructor;
|
|
467
|
+
|
|
468
|
+
export { ${generatedName} };
|
|
469
|
+
export default ${generatedName};
|
|
470
|
+
`;
|
|
471
|
+
}
|
|
472
|
+
imports.push(`import { composeContextModules } from '@oak-domain/context/ContextComposer';`, ...dependencies.map((dependency, index) => `import { ${target.toLowerCase()}ContextModule as ${dependencyNames[index]}ContextModule } from '${makeOakImport(dependency, `context/${target}RuntimeContext`)}';`));
|
|
473
|
+
const typedBaseName = `TypedBase${target}RuntimeContext`;
|
|
474
|
+
const constructorName = `${generatedName}Constructor`;
|
|
475
|
+
return `${imports.join('\n')}
|
|
476
|
+
|
|
477
|
+
type ${contractName} = MergeContextContracts<[
|
|
478
|
+
${contractTypes.join(',\n ')}
|
|
479
|
+
]>;
|
|
480
|
+
|
|
481
|
+
const ${typedBaseName} = ${baseName}<EntityDict>;
|
|
482
|
+
type ${constructorName} = abstract new (
|
|
483
|
+
...args: ConstructorParameters<typeof ${typedBaseName}>
|
|
484
|
+
) => ${contractName};
|
|
485
|
+
|
|
486
|
+
const ${generatedName} = composeContextModules(
|
|
487
|
+
${typedBaseName},
|
|
488
|
+
[${dependencyNames.map((name) => `${name}ContextModule`).join(', ')}],
|
|
489
|
+
{
|
|
490
|
+
scope: '${target.toLowerCase()}',
|
|
491
|
+
}
|
|
492
|
+
) as unknown as ${constructorName};
|
|
493
|
+
|
|
494
|
+
export { ${generatedName} };
|
|
495
|
+
export default ${generatedName};
|
|
496
|
+
`;
|
|
497
|
+
}
|
|
498
|
+
function outputGeneratedContext(cwd, target, isModule) {
|
|
499
|
+
const fileName = join(cwd, 'src', 'context', `generated${target}.ts`);
|
|
500
|
+
writeFileSync(fileName, renderGeneratedContextSource(cwd, target, isModule), { flag: 'w' });
|
|
501
|
+
console.log(`构建${fileName}文件成功`);
|
|
502
|
+
}
|
|
503
|
+
function outputProjectContextShell(templateFile, targetFile) {
|
|
504
|
+
if (existsSync(targetFile)) {
|
|
505
|
+
console.log(`[${targetFile}]文件已经存在,保留项目自定义上下文。`);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
writeFileSync(targetFile, readFileSync(templateFile, 'utf-8'), { flag: 'w' });
|
|
509
|
+
console.log(`构建${targetFile}文件成功`);
|
|
510
|
+
}
|
|
511
|
+
export function writeContextCompositionFiles(cwd, isModule, templates) {
|
|
512
|
+
outputGeneratedContext(cwd, 'Backend', isModule);
|
|
513
|
+
outputGeneratedContext(cwd, 'Frontend', isModule);
|
|
514
|
+
if (isModule) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
assert(templates, '应用项目生成 Context 时缺少 RuntimeContext 模板');
|
|
518
|
+
outputProjectContextShell(templates.backendRuntimeContext, join(cwd, 'src', 'context', 'BackendRuntimeContext.ts'));
|
|
519
|
+
outputProjectContextShell(templates.frontendRuntimeContext, join(cwd, 'src', 'context', 'FrontendRuntimeContext.ts'));
|
|
520
|
+
}
|
|
465
521
|
/**
|
|
466
522
|
* 生成initialize.prod.ts
|
|
467
523
|
* @param cwd
|
|
@@ -818,63 +874,10 @@ function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, prin
|
|
|
818
874
|
writeFileSync(filename, result, { flag: 'w' });
|
|
819
875
|
console.log(`构建${filename}文件成功`);
|
|
820
876
|
}
|
|
821
|
-
function createFeatureInitImportStatement(importConfig) {
|
|
822
|
-
const namedImports = importConfig.named?.length ? factory.createNamedImports(importConfig.named.map(({ imported, local }) => factory.createImportSpecifier(false, local ? factory.createIdentifier(imported) : undefined, factory.createIdentifier(local || imported)))) : undefined;
|
|
823
|
-
const importClause = importConfig.default || namedImports ? factory.createImportClause(false, importConfig.default ? factory.createIdentifier(importConfig.default) : undefined, namedImports) : undefined;
|
|
824
|
-
return factory.createImportDeclaration(undefined, importClause, factory.createStringLiteral(importConfig.from), undefined);
|
|
825
|
-
}
|
|
826
|
-
function isIdentifierLike(name) {
|
|
827
|
-
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
|
|
828
|
-
}
|
|
829
|
-
function createObjectPropertyName(name) {
|
|
830
|
-
return isIdentifierLike(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
|
|
831
|
-
}
|
|
832
|
-
function createFeatureInitExpression(expression, projectName) {
|
|
833
|
-
switch (expression.kind) {
|
|
834
|
-
case 'array':
|
|
835
|
-
return factory.createArrayLiteralExpression(expression.elements.map((element) => createFeatureInitExpression(element, projectName)), false);
|
|
836
|
-
case 'await':
|
|
837
|
-
return factory.createAwaitExpression(createFeatureInitExpression(expression.expression, projectName));
|
|
838
|
-
case 'boolean':
|
|
839
|
-
return expression.value ? factory.createTrue() : factory.createFalse();
|
|
840
|
-
case 'call':
|
|
841
|
-
return factory.createCallExpression(createFeatureInitExpression(expression.callee, projectName), undefined, (expression.arguments || []).map((arg) => createFeatureInitExpression(arg, projectName)));
|
|
842
|
-
case 'identifier':
|
|
843
|
-
return factory.createIdentifier(expression.name);
|
|
844
|
-
case 'null':
|
|
845
|
-
return factory.createNull();
|
|
846
|
-
case 'number':
|
|
847
|
-
return factory.createNumericLiteral(expression.value);
|
|
848
|
-
case 'object':
|
|
849
|
-
return factory.createObjectLiteralExpression(expression.properties.map(({ key, value }) => factory.createPropertyAssignment(createObjectPropertyName(key), createFeatureInitExpression(value, projectName))), false);
|
|
850
|
-
case 'propertyAccess':
|
|
851
|
-
return factory.createPropertyAccessExpression(createFeatureInitExpression(expression.expression, projectName), factory.createIdentifier(expression.name));
|
|
852
|
-
case 'projectLocaleNamespace':
|
|
853
|
-
return factory.createStringLiteral(`${projectName}-l-${expression.suffix}`);
|
|
854
|
-
case 'projectPackageName':
|
|
855
|
-
return factory.createStringLiteral(projectName);
|
|
856
|
-
case 'string':
|
|
857
|
-
return factory.createStringLiteral(expression.value);
|
|
858
|
-
case 'undefined':
|
|
859
|
-
return factory.createIdentifier('undefined');
|
|
860
|
-
default: {
|
|
861
|
-
const exhaustiveCheck = expression;
|
|
862
|
-
return exhaustiveCheck;
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function createFeatureInitStatement(statement, projectName) {
|
|
867
|
-
return factory.createExpressionStatement(createFeatureInitExpression(statement.expression, projectName));
|
|
868
|
-
}
|
|
869
877
|
export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
870
878
|
const { statements } = sourceFile;
|
|
871
|
-
const projectName = readProjectPackageName(cwd);
|
|
872
|
-
const dependencyBriefNameMap = Object.fromEntries(dependencies.map((dep, idx) => [dep, briefNames[idx]]));
|
|
873
879
|
const features = [];
|
|
874
|
-
const
|
|
875
|
-
const featureInitializationMetadata = resolveFeatureInitializationMetadata(cwd, dependencyFeatureInitPlan.rootDependencies, dependencyFeatureInitPlan.depLibGraph);
|
|
876
|
-
const featureInitializationRootSet = new Set(featureInitializationMetadata.roots.map(({ dependency }) => dependency));
|
|
877
|
-
const importStatements = featureInitializationMetadata.imports.map(createFeatureInitImportStatement);
|
|
880
|
+
const importStatements = [];
|
|
878
881
|
dependencies.forEach((dep, idx) => {
|
|
879
882
|
const depDir = join(cwd, 'node_modules', dep);
|
|
880
883
|
if (!existsSync(depDir)) {
|
|
@@ -890,12 +893,9 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
|
|
|
890
893
|
const destDir = esDirExisted ? esDir : libDir;
|
|
891
894
|
const destDirName = esDirExisted ? 'es' : 'lib';
|
|
892
895
|
if (existsSync(join(destDir, 'features'))) {
|
|
893
|
-
|
|
894
|
-
const namedImports = [
|
|
895
|
-
shouldImportInitialize ? factory.createImportSpecifier(false, factory.createIdentifier('initialize'), factory.createIdentifier(`initialize${firstLetterUpperCase(briefNames[idx])}Features`)) : undefined,
|
|
896
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports([
|
|
896
897
|
factory.createImportSpecifier(false, factory.createIdentifier('FeatureDict'), factory.createIdentifier(`${firstLetterUpperCase(briefNames[idx])}FeatureDict`)),
|
|
897
|
-
].
|
|
898
|
-
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(!shouldImportInitialize, undefined, factory.createNamedImports(namedImports)), factory.createStringLiteral(makeDependencyImport(dep, destDirName, 'features')), undefined));
|
|
898
|
+
])), factory.createStringLiteral(makeDependencyImport(dep, destDirName, 'features')), undefined));
|
|
899
899
|
features.push(briefNames[idx]);
|
|
900
900
|
}
|
|
901
901
|
});
|
|
@@ -918,19 +918,19 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
|
|
|
918
918
|
])))
|
|
919
919
|
});
|
|
920
920
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
});
|
|
921
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
922
|
+
return result.replaceAll(PROJECT_NAME_PLACEHOLDER, readProjectPackageName(cwd));
|
|
923
|
+
}
|
|
924
|
+
export function resolveDependencyTemplateFile(cwd, dependencies, templateFileName, fallback) {
|
|
925
|
+
const rootPlan = resolveDependencyRootPlan(cwd, dependencies);
|
|
926
|
+
const candidates = rootPlan.rootDependencies.map((dependency) => ({
|
|
927
|
+
dependency,
|
|
928
|
+
filePath: join(cwd, 'node_modules', dependency, 'template', templateFileName),
|
|
929
|
+
})).filter(({ filePath }) => existsSync(filePath));
|
|
930
|
+
if (candidates.length > 1) {
|
|
931
|
+
throw new Error(`多个顶层依赖同时提供 template/${templateFileName}:${candidates.map(({ dependency }) => dependency).join(', ')},无法确定使用哪个模板`);
|
|
932
932
|
}
|
|
933
|
-
return
|
|
933
|
+
return candidates[0]?.filePath || fallback;
|
|
934
934
|
}
|
|
935
935
|
function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|
936
936
|
const sourceFile = ts.createSourceFile('index.ts', readFileSync(dataIndexFile, 'utf-8'), ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
|
|
@@ -1111,15 +1111,30 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1111
1111
|
export default function buildDependency(rebuild) {
|
|
1112
1112
|
const cwd = process.cwd();
|
|
1113
1113
|
const { depGraph, dependencies, briefNames, isModule, } = resolveDependencyBuildContext(cwd);
|
|
1114
|
-
const
|
|
1114
|
+
const defaultTemplateFiles = {
|
|
1115
1115
|
initializeServer: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'initialize.server.ts'),
|
|
1116
1116
|
initializeFeatures: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'initializeFeatures.ts'),
|
|
1117
1117
|
runtimeCxt: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'RuntimeCxt.ts'),
|
|
1118
1118
|
dependentExceptions: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'DependentExceptions.ts'),
|
|
1119
1119
|
polyfillDts: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'polyfill.d.ts'),
|
|
1120
|
-
featureIndex: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments',
|
|
1121
|
-
|
|
1122
|
-
|
|
1120
|
+
featureIndex: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', !isModule && dependencies.length === 0
|
|
1121
|
+
? 'features/index.standalone.ts'
|
|
1122
|
+
: 'features/index.ts'),
|
|
1123
|
+
backendRuntimeContext: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', dependencies.length === 0
|
|
1124
|
+
? 'BackendRuntimeContext.standalone.ts'
|
|
1125
|
+
: 'BackendRuntimeContext.ts'),
|
|
1126
|
+
frontendRuntimeContext: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', dependencies.length === 0
|
|
1127
|
+
? 'FrontendRuntimeContext.standalone.ts'
|
|
1128
|
+
: 'FrontendRuntimeContext.ts'),
|
|
1129
|
+
};
|
|
1130
|
+
const templateFiles = {
|
|
1131
|
+
...defaultTemplateFiles,
|
|
1132
|
+
initializeFeatures: !isModule
|
|
1133
|
+
? resolveDependencyTemplateFile(cwd, dependencies, 'initializeFeatures.ts', defaultTemplateFiles.initializeFeatures)
|
|
1134
|
+
: defaultTemplateFiles.initializeFeatures,
|
|
1135
|
+
featureIndex: !isModule
|
|
1136
|
+
? resolveDependencyTemplateFile(cwd, dependencies, 'featuresIndex.ts', defaultTemplateFiles.featureIndex)
|
|
1137
|
+
: defaultTemplateFiles.featureIndex,
|
|
1123
1138
|
};
|
|
1124
1139
|
const program = ts.createProgram(Object.values(templateFiles), {});
|
|
1125
1140
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
@@ -1186,21 +1201,26 @@ export default function buildDependency(rebuild) {
|
|
|
1186
1201
|
if (output) {
|
|
1187
1202
|
outputRuntimeCxt(dependencies, briefNames, program.getSourceFile(templateFiles.runtimeCxt), printer, runtimeCxtFile);
|
|
1188
1203
|
}
|
|
1189
|
-
output = true;
|
|
1190
1204
|
const dependentExceptionsFile = join(cwd, 'src', 'types', 'DependentExceptions.ts');
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1205
|
+
const shouldOutputDependentExceptions = !isModule
|
|
1206
|
+
|| dependencies.length > 0
|
|
1207
|
+
|| existsSync(dependentExceptionsFile);
|
|
1208
|
+
if (shouldOutputDependentExceptions) {
|
|
1209
|
+
output = true;
|
|
1210
|
+
if (existsSync(dependentExceptionsFile) && !rebuild) {
|
|
1211
|
+
let tips = `[${dependentExceptionsFile}]文件已经存在`;
|
|
1212
|
+
if (!rebuild) {
|
|
1213
|
+
tips += ',忽略构建。';
|
|
1214
|
+
output = false;
|
|
1215
|
+
}
|
|
1216
|
+
else {
|
|
1217
|
+
tips += ',将重新构建';
|
|
1218
|
+
}
|
|
1219
|
+
console.log(tips);
|
|
1196
1220
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1221
|
+
if (output) {
|
|
1222
|
+
outputDependentExceptions(dependencies, briefNames, program.getSourceFile(templateFiles.dependentExceptions), printer, dependentExceptionsFile, isModule);
|
|
1199
1223
|
}
|
|
1200
|
-
console.log(tips);
|
|
1201
|
-
}
|
|
1202
|
-
if (output) {
|
|
1203
|
-
outputDependentExceptions(dependencies, briefNames, program.getSourceFile(templateFiles.dependentExceptions), printer, dependentExceptionsFile);
|
|
1204
1224
|
}
|
|
1205
1225
|
output = true;
|
|
1206
1226
|
const polyfillDtsFile = join(cwd, 'typings', 'polyfill.d.ts');
|
|
@@ -1231,39 +1251,8 @@ export default function buildDependency(rebuild) {
|
|
|
1231
1251
|
}
|
|
1232
1252
|
console.log(tips);
|
|
1233
1253
|
}
|
|
1234
|
-
else {
|
|
1235
|
-
outputFeatureIndex(dependencies, briefNames, program.getSourceFile(templateFiles.featureIndex), printer, featureIndexFile, isModule);
|
|
1236
|
-
}
|
|
1237
|
-
output = true;
|
|
1238
|
-
let contextFile = join(cwd, 'src', 'context', 'BackendRuntimeContext.ts');
|
|
1239
|
-
if (existsSync(contextFile) && !rebuild) {
|
|
1240
|
-
let tips = `[${contextFile}]文件已经存在`;
|
|
1241
|
-
if (!rebuild) {
|
|
1242
|
-
tips += ',忽略构建。';
|
|
1243
|
-
output = false;
|
|
1244
|
-
}
|
|
1245
|
-
else {
|
|
1246
|
-
tips += ',将重新构建,注意如果自定义过上下文的其它方法或属性,需要重新输入';
|
|
1247
|
-
}
|
|
1248
|
-
console.log(tips);
|
|
1249
|
-
}
|
|
1250
1254
|
if (output) {
|
|
1251
|
-
|
|
1252
|
-
}
|
|
1253
|
-
output = true;
|
|
1254
|
-
contextFile = join(cwd, 'src', 'context', 'FrontendRuntimeContext.ts');
|
|
1255
|
-
if (existsSync(contextFile) && !rebuild) {
|
|
1256
|
-
let tips = `[${contextFile}]文件已经存在`;
|
|
1257
|
-
if (!rebuild) {
|
|
1258
|
-
tips += ',忽略构建。';
|
|
1259
|
-
output = false;
|
|
1260
|
-
}
|
|
1261
|
-
else {
|
|
1262
|
-
tips += ',将重新构建,注意如果自定义过上下文的其它方法或属性,需要重新输入';
|
|
1263
|
-
}
|
|
1264
|
-
console.log(tips);
|
|
1265
|
-
}
|
|
1266
|
-
if (output) {
|
|
1267
|
-
outputContext(depGraph, program.getSourceFile(templateFiles.frontendRuntimeContext), printer, contextFile);
|
|
1255
|
+
outputFeatureIndex(dependencies, briefNames, program.getSourceFile(templateFiles.featureIndex), printer, featureIndexFile, isModule);
|
|
1268
1256
|
}
|
|
1257
|
+
writeContextCompositionFiles(cwd, isModule, templateFiles);
|
|
1269
1258
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
export declare function hasTypeAliasDeclaration(sourceFile: ts.SourceFile, name: string): boolean;
|
|
3
|
+
export declare function hasTypeAliasOrEnumDeclaration(sourceFile: ts.SourceFile, name: string): boolean;
|
|
4
|
+
export declare function tryGetStringLiteralValuesFromTypeNode(typeNode: ts.TypeNode, checker: ts.TypeChecker, visitedSymbols?: Set<ts.Symbol>, visitedTypeAliases?: Set<string>): string[];
|
|
5
|
+
export declare function collectEntityDescEnumAttrs(declaration: ts.VariableDeclaration, filename: string, checker: ts.TypeChecker): Record<string, string[]>;
|