oak-domain 6.0.0 → 6.1.1
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 +256 -234
- 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 +304 -277
- 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 +21 -11
- 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,20 +1,40 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
2
|
-
import { join as pathJoin } from 'path';
|
|
1
|
+
import { assert } from '../utils/assert';
|
|
2
|
+
import { dirname, 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
|
}
|
|
14
|
+
function resolveInstalledPackageDir(fromDir, packageName) {
|
|
15
|
+
let currentDir = fromDir;
|
|
16
|
+
while (true) {
|
|
17
|
+
const packageDir = join(currentDir, 'node_modules', packageName);
|
|
18
|
+
if (existsSync(join(packageDir, 'package.json'))) {
|
|
19
|
+
return packageDir;
|
|
20
|
+
}
|
|
21
|
+
const parentDir = dirname(currentDir);
|
|
22
|
+
if (parentDir === currentDir) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
currentDir = parentDir;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function writeGeneratedFile(filename, content) {
|
|
29
|
+
mkdirSync(dirname(filename), { recursive: true });
|
|
30
|
+
writeFileSync(filename, content, { flag: 'w' });
|
|
31
|
+
}
|
|
13
32
|
function readInstalledPackageManifest(dir, packageName) {
|
|
14
|
-
const
|
|
15
|
-
if (!
|
|
33
|
+
const packageDir = resolveInstalledPackageDir(dir, packageName);
|
|
34
|
+
if (!packageDir) {
|
|
16
35
|
return undefined;
|
|
17
36
|
}
|
|
37
|
+
const packageJsonPath = join(packageDir, 'package.json');
|
|
18
38
|
return JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
19
39
|
}
|
|
20
40
|
function readDependencyConfiguration(dir) {
|
|
@@ -41,12 +61,13 @@ function collectInstalledOakLibDependencies(dir) {
|
|
|
41
61
|
...Object.keys(packageJson.devDependencies || {}),
|
|
42
62
|
]).sort((left, right) => left.localeCompare(right));
|
|
43
63
|
return dependencyNames.filter((dep) => {
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
64
|
+
const packageDir = resolveInstalledPackageDir(dir, dep);
|
|
65
|
+
if (!packageDir) {
|
|
46
66
|
return false;
|
|
47
67
|
}
|
|
68
|
+
const manifestPath = join(packageDir, 'package.json');
|
|
48
69
|
const dependencyManifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
49
|
-
return dependencyManifest
|
|
70
|
+
return isOakBusinessModule(dependencyManifest);
|
|
50
71
|
});
|
|
51
72
|
}
|
|
52
73
|
function collectOakDepLibGraph(cwd, dependencies) {
|
|
@@ -54,12 +75,12 @@ function collectOakDepLibGraph(cwd, dependencies) {
|
|
|
54
75
|
const depLibGraph = {};
|
|
55
76
|
dependencies.forEach((dep) => {
|
|
56
77
|
const packageManifest = readInstalledPackageManifest(cwd, dep);
|
|
57
|
-
const depLib = packageManifest
|
|
78
|
+
const depLib = getOakBusinessDependencies(packageManifest);
|
|
58
79
|
depLibGraph[dep] = uniqueDependencies(Object.keys(depLib).map((depName) => depName).filter((depName) => depName !== dep && dependencySet.has(depName)));
|
|
59
80
|
});
|
|
60
81
|
return depLibGraph;
|
|
61
82
|
}
|
|
62
|
-
export function
|
|
83
|
+
export function resolveDependencyRootPlan(cwd, dependencies) {
|
|
63
84
|
const depLibGraph = collectOakDepLibGraph(cwd, dependencies);
|
|
64
85
|
const transitiveCoveredDependencies = new Set();
|
|
65
86
|
const closureCache = {};
|
|
@@ -95,7 +116,7 @@ export function resolveFeatureInitializationPlan(cwd, dependencies) {
|
|
|
95
116
|
rootDependencies,
|
|
96
117
|
};
|
|
97
118
|
}
|
|
98
|
-
function resolveDeclaredDependencies(dir) {
|
|
119
|
+
export function resolveDeclaredDependencies(dir) {
|
|
99
120
|
return uniqueDependencies([
|
|
100
121
|
...readDependencyConfiguration(dir),
|
|
101
122
|
...collectInstalledOakLibDependencies(dir),
|
|
@@ -113,74 +134,6 @@ function readProjectPackageName(cwd) {
|
|
|
113
134
|
}
|
|
114
135
|
return packageName.replace(/^@/, '').replace(/\//g, '-');
|
|
115
136
|
}
|
|
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
137
|
/**
|
|
185
138
|
* 构建项目依赖关系图
|
|
186
139
|
* @param cwd
|
|
@@ -201,7 +154,7 @@ export function analyzeDepedency(cwd) {
|
|
|
201
154
|
}
|
|
202
155
|
const dependencies = resolveDeclaredDependencies(dir);
|
|
203
156
|
if (dependencies.length === 0) {
|
|
204
|
-
// 没有依赖文件,且没有可自动识别的
|
|
157
|
+
// 没有依赖文件,且没有可自动识别的 Oak 业务模块依赖,直接返回
|
|
205
158
|
return;
|
|
206
159
|
}
|
|
207
160
|
dependencies.forEach((dep) => {
|
|
@@ -209,12 +162,10 @@ export function analyzeDepedency(cwd) {
|
|
|
209
162
|
depGraph.dependencies[name][dep] = 1;
|
|
210
163
|
}
|
|
211
164
|
if (!depGraph.nodes[dep]) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
217
|
-
}
|
|
165
|
+
const dir2 = resolveInstalledPackageDir(dir, dep)
|
|
166
|
+
|| resolveInstalledPackageDir(cwd, dep);
|
|
167
|
+
if (!dir2) {
|
|
168
|
+
throw new Error(`找不到依赖包${dep}的安装位置,当前包是${dir}`);
|
|
218
169
|
}
|
|
219
170
|
analyzeOne(dir2, dep);
|
|
220
171
|
}
|
|
@@ -235,10 +186,10 @@ export function analyzeDepedency(cwd) {
|
|
|
235
186
|
}
|
|
236
187
|
assert(freeNodes.length > 0, '依赖关系成环!');
|
|
237
188
|
freeNodes.forEach((n) => {
|
|
238
|
-
|
|
239
|
-
|
|
189
|
+
delete depGraph.nodes[n];
|
|
190
|
+
delete depGraph.dependencies[n];
|
|
240
191
|
for (const n2 in depGraph.dependencies) {
|
|
241
|
-
|
|
192
|
+
delete depGraph.dependencies[n2][n];
|
|
242
193
|
}
|
|
243
194
|
depGraph.ascOrder.push(n);
|
|
244
195
|
});
|
|
@@ -348,10 +299,10 @@ function outputPolyfillDts(dependencies, briefNames, sourceFile, printer, filena
|
|
|
348
299
|
statements2 = [...sourceFile.statements];
|
|
349
300
|
}
|
|
350
301
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
351
|
-
|
|
302
|
+
writeGeneratedFile(filename, result);
|
|
352
303
|
console.log(`构建${filename}文件成功`);
|
|
353
304
|
}
|
|
354
|
-
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename) {
|
|
305
|
+
function outputDependentExceptions(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
355
306
|
let statements2 = [];
|
|
356
307
|
if (dependencies.length > 0) {
|
|
357
308
|
const { statements } = sourceFile;
|
|
@@ -382,8 +333,15 @@ function outputDependentExceptions(dependencies, briefNames, sourceFile, printer
|
|
|
382
333
|
else {
|
|
383
334
|
statements2 = [...sourceFile.statements];
|
|
384
335
|
}
|
|
336
|
+
if (isModule) {
|
|
337
|
+
const entityDictImport = statements2[0];
|
|
338
|
+
assert(ts.isImportDeclaration(entityDictImport));
|
|
339
|
+
Object.assign(entityDictImport, {
|
|
340
|
+
moduleSpecifier: factory.createStringLiteral('../oak-app-domain'),
|
|
341
|
+
});
|
|
342
|
+
}
|
|
385
343
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
386
|
-
|
|
344
|
+
writeGeneratedFile(filename, result);
|
|
387
345
|
console.log(`构建${filename}文件成功`);
|
|
388
346
|
}
|
|
389
347
|
function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filename) {
|
|
@@ -441,7 +399,7 @@ function outputRuntimeCxt(dependencies, briefNames, sourceFile, printer, filenam
|
|
|
441
399
|
];
|
|
442
400
|
}
|
|
443
401
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
444
|
-
|
|
402
|
+
writeGeneratedFile(filename, result);
|
|
445
403
|
console.log(`构建${filename}文件成功`);
|
|
446
404
|
}
|
|
447
405
|
function outputContext(depGraph, sourceFile, printer, filename) {
|
|
@@ -459,9 +417,128 @@ function outputContext(depGraph, sourceFile, printer, filename) {
|
|
|
459
417
|
...statements
|
|
460
418
|
];
|
|
461
419
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
462
|
-
|
|
420
|
+
writeGeneratedFile(filename, result);
|
|
463
421
|
console.log(`构建${filename}文件成功`);
|
|
464
422
|
}
|
|
423
|
+
function hasRuntimeContextEntry(cwd, dependency, target) {
|
|
424
|
+
const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
|
|
425
|
+
if (!dependencyDir) {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
const fileName = `${target}RuntimeContext`;
|
|
429
|
+
return [
|
|
430
|
+
join(dependencyDir, 'src', 'context', `${fileName}.ts`),
|
|
431
|
+
join(dependencyDir, 'lib', 'context', `${fileName}.js`),
|
|
432
|
+
join(dependencyDir, 'es', 'context', `${fileName}.js`),
|
|
433
|
+
join(dependencyDir, 'lib', 'context', `${fileName}.d.ts`),
|
|
434
|
+
join(dependencyDir, 'es', 'context', `${fileName}.d.ts`),
|
|
435
|
+
].some((filePath) => existsSync(filePath));
|
|
436
|
+
}
|
|
437
|
+
export function resolveContextRootDependencies(cwd, target) {
|
|
438
|
+
const directDependencies = resolveDeclaredDependencies(cwd);
|
|
439
|
+
const contextDependencies = directDependencies.filter((dependency) => hasRuntimeContextEntry(cwd, dependency, target));
|
|
440
|
+
return resolveDependencyRootPlan(cwd, contextDependencies).rootDependencies;
|
|
441
|
+
}
|
|
442
|
+
function contextDependencyName(dependency, index) {
|
|
443
|
+
return `${dependency.replace(/[^a-zA-Z0-9]/g, '_')}${index}`;
|
|
444
|
+
}
|
|
445
|
+
export function renderGeneratedContextSource(cwd, target, isModule) {
|
|
446
|
+
const isBackend = target === 'Backend';
|
|
447
|
+
const dependencies = resolveContextRootDependencies(cwd, target);
|
|
448
|
+
const baseImport = isBackend
|
|
449
|
+
? '@oak-domain/context/BackendRuntimeContext'
|
|
450
|
+
: '@oak-frontend-base/context/FrontendRuntimeContext';
|
|
451
|
+
const baseName = `Base${target}RuntimeContext`;
|
|
452
|
+
const generatedName = `Generated${target}RuntimeContext`;
|
|
453
|
+
const contractName = `Generated${target}Context`;
|
|
454
|
+
const dependencyNames = dependencies.map(contextDependencyName);
|
|
455
|
+
const entityDictImport = isModule
|
|
456
|
+
? '../oak-app-domain'
|
|
457
|
+
: '@project/oak-app-domain';
|
|
458
|
+
const imports = [
|
|
459
|
+
`import type { EntityDict } from '${entityDictImport}';`,
|
|
460
|
+
...(isModule
|
|
461
|
+
? [`import type { RuntimeContext } from './RuntimeContext';`]
|
|
462
|
+
: []),
|
|
463
|
+
`import { ${target}RuntimeContext as ${baseName} } from '${baseImport}';`,
|
|
464
|
+
`import type { MergeContextContracts } from '@oak-domain/context/ContextComposer';`,
|
|
465
|
+
...dependencies.map((dependency, index) => `import type { ${target}RuntimeContext as ${dependencyNames[index]}RuntimeContext } from '${makeOakImport(dependency, `context/${target}RuntimeContext`)}';`),
|
|
466
|
+
];
|
|
467
|
+
const contractTypes = [
|
|
468
|
+
`${baseName}<EntityDict>`,
|
|
469
|
+
...dependencyNames.map((name) => `${name}RuntimeContext<EntityDict>`),
|
|
470
|
+
...(isModule ? ['RuntimeContext'] : []),
|
|
471
|
+
];
|
|
472
|
+
if (isModule) {
|
|
473
|
+
return `${imports.join('\n')}
|
|
474
|
+
|
|
475
|
+
export type ${contractName}<
|
|
476
|
+
ED extends EntityDict = EntityDict,
|
|
477
|
+
> = MergeContextContracts<[
|
|
478
|
+
${contractTypes.map((contractType) => contractType.replace(/<EntityDict>/g, '<ED>')).join(',\n ')}
|
|
479
|
+
]>;
|
|
480
|
+
|
|
481
|
+
type ${generatedName}Constructor = abstract new <
|
|
482
|
+
ED extends EntityDict = EntityDict,
|
|
483
|
+
>(
|
|
484
|
+
...args: ConstructorParameters<typeof ${baseName}<ED>>
|
|
485
|
+
) => ${contractName}<ED>;
|
|
486
|
+
|
|
487
|
+
const ${generatedName} = ${baseName} as unknown as ${generatedName}Constructor;
|
|
488
|
+
|
|
489
|
+
export { ${generatedName} };
|
|
490
|
+
export default ${generatedName};
|
|
491
|
+
`;
|
|
492
|
+
}
|
|
493
|
+
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`)}';`));
|
|
494
|
+
const typedBaseName = `TypedBase${target}RuntimeContext`;
|
|
495
|
+
const constructorName = `${generatedName}Constructor`;
|
|
496
|
+
return `${imports.join('\n')}
|
|
497
|
+
|
|
498
|
+
type ${contractName} = MergeContextContracts<[
|
|
499
|
+
${contractTypes.join(',\n ')}
|
|
500
|
+
]>;
|
|
501
|
+
|
|
502
|
+
const ${typedBaseName} = ${baseName}<EntityDict>;
|
|
503
|
+
type ${constructorName} = abstract new (
|
|
504
|
+
...args: ConstructorParameters<typeof ${typedBaseName}>
|
|
505
|
+
) => ${contractName};
|
|
506
|
+
|
|
507
|
+
const ${generatedName} = composeContextModules(
|
|
508
|
+
${typedBaseName},
|
|
509
|
+
[${dependencyNames.map((name) => `${name}ContextModule`).join(', ')}],
|
|
510
|
+
{
|
|
511
|
+
scope: '${target.toLowerCase()}',
|
|
512
|
+
}
|
|
513
|
+
) as unknown as ${constructorName};
|
|
514
|
+
|
|
515
|
+
export { ${generatedName} };
|
|
516
|
+
export default ${generatedName};
|
|
517
|
+
`;
|
|
518
|
+
}
|
|
519
|
+
function outputGeneratedContext(cwd, target, isModule) {
|
|
520
|
+
const fileName = join(cwd, 'src', 'context', `generated${target}.ts`);
|
|
521
|
+
writeGeneratedFile(fileName, renderGeneratedContextSource(cwd, target, isModule));
|
|
522
|
+
console.log(`构建${fileName}文件成功`);
|
|
523
|
+
}
|
|
524
|
+
function outputProjectContextShell(templateFile, targetFile) {
|
|
525
|
+
if (existsSync(targetFile)) {
|
|
526
|
+
console.log(`[${targetFile}]文件已经存在,保留项目自定义上下文。`);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
writeGeneratedFile(targetFile, readFileSync(templateFile, 'utf-8'));
|
|
530
|
+
console.log(`构建${targetFile}文件成功`);
|
|
531
|
+
}
|
|
532
|
+
export function writeContextCompositionFiles(cwd, isModule, templates) {
|
|
533
|
+
outputGeneratedContext(cwd, 'Backend', isModule);
|
|
534
|
+
outputGeneratedContext(cwd, 'Frontend', isModule);
|
|
535
|
+
if (isModule) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
assert(templates, '应用项目生成 Context 时缺少 RuntimeContext 模板');
|
|
539
|
+
outputProjectContextShell(templates.backendRuntimeContext, join(cwd, 'src', 'context', 'BackendRuntimeContext.ts'));
|
|
540
|
+
outputProjectContextShell(templates.frontendRuntimeContext, join(cwd, 'src', 'context', 'FrontendRuntimeContext.ts'));
|
|
541
|
+
}
|
|
465
542
|
/**
|
|
466
543
|
* 生成initialize.prod.ts
|
|
467
544
|
* @param cwd
|
|
@@ -476,9 +553,9 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
476
553
|
// 所有的import
|
|
477
554
|
const importStatements = [];
|
|
478
555
|
dependencies.forEach((dep, idx) => {
|
|
479
|
-
const depDir =
|
|
480
|
-
if (!
|
|
481
|
-
throw new Error(`依赖模块${dep}
|
|
556
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
557
|
+
if (!depDir) {
|
|
558
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
482
559
|
}
|
|
483
560
|
const esDir = join(depDir, 'es');
|
|
484
561
|
const libDir = join(depDir, 'lib');
|
|
@@ -587,7 +664,7 @@ function outputIntializeProd(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
587
664
|
});
|
|
588
665
|
}
|
|
589
666
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
590
|
-
|
|
667
|
+
writeGeneratedFile(filename, result);
|
|
591
668
|
console.log(`构建${filename}文件成功`);
|
|
592
669
|
}
|
|
593
670
|
/**
|
|
@@ -604,9 +681,9 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
604
681
|
// 所有的import
|
|
605
682
|
const importStatements = [];
|
|
606
683
|
dependencies.forEach((dep, idx) => {
|
|
607
|
-
const depDir =
|
|
608
|
-
if (!
|
|
609
|
-
throw new Error(`依赖模块${dep}
|
|
684
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
685
|
+
if (!depDir) {
|
|
686
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
610
687
|
}
|
|
611
688
|
const esDir = join(depDir, 'es');
|
|
612
689
|
const libDir = join(depDir, 'lib');
|
|
@@ -736,7 +813,7 @@ function outputIntializeDev(cwd, dependencies, briefNames, sourceFile, printer,
|
|
|
736
813
|
});
|
|
737
814
|
}
|
|
738
815
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
739
|
-
|
|
816
|
+
writeGeneratedFile(filename, result);
|
|
740
817
|
console.log(`构建${filename}文件成功`);
|
|
741
818
|
}
|
|
742
819
|
export function renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
@@ -810,75 +887,22 @@ export function renderFeatureIndexSource(dependencies, briefNames, sourceFile, i
|
|
|
810
887
|
*/
|
|
811
888
|
function outputFeatureIndex(dependencies, briefNames, sourceFile, printer, filename, isModule) {
|
|
812
889
|
const result = renderFeatureIndexSource(dependencies, briefNames, sourceFile, isModule, printer);
|
|
813
|
-
|
|
890
|
+
writeGeneratedFile(filename, result);
|
|
814
891
|
console.log(`构建${filename}文件成功`);
|
|
815
892
|
}
|
|
816
893
|
function outputIntializeFeatures(cwd, dependencies, briefNames, sourceFile, printer, filename) {
|
|
817
894
|
const result = renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer);
|
|
818
|
-
|
|
895
|
+
writeGeneratedFile(filename, result);
|
|
819
896
|
console.log(`构建${filename}文件成功`);
|
|
820
897
|
}
|
|
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
898
|
export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, sourceFile, printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed })) {
|
|
870
899
|
const { statements } = sourceFile;
|
|
871
|
-
const projectName = readProjectPackageName(cwd);
|
|
872
|
-
const dependencyBriefNameMap = Object.fromEntries(dependencies.map((dep, idx) => [dep, briefNames[idx]]));
|
|
873
900
|
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);
|
|
901
|
+
const importStatements = [];
|
|
878
902
|
dependencies.forEach((dep, idx) => {
|
|
879
|
-
const depDir =
|
|
880
|
-
if (!
|
|
881
|
-
throw new Error(`依赖模块${dep}
|
|
903
|
+
const depDir = resolveInstalledPackageDir(cwd, dep);
|
|
904
|
+
if (!depDir) {
|
|
905
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
882
906
|
}
|
|
883
907
|
const esDir = join(depDir, 'es');
|
|
884
908
|
const libDir = join(depDir, 'lib');
|
|
@@ -890,12 +914,9 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
|
|
|
890
914
|
const destDir = esDirExisted ? esDir : libDir;
|
|
891
915
|
const destDirName = esDirExisted ? 'es' : 'lib';
|
|
892
916
|
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,
|
|
917
|
+
importStatements.push(factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports([
|
|
896
918
|
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));
|
|
919
|
+
])), factory.createStringLiteral(makeDependencyImport(dep, destDirName, 'features')), undefined));
|
|
899
920
|
features.push(briefNames[idx]);
|
|
900
921
|
}
|
|
901
922
|
});
|
|
@@ -918,19 +939,24 @@ export function renderInitializeFeaturesSource(cwd, dependencies, briefNames, so
|
|
|
918
939
|
])))
|
|
919
940
|
});
|
|
920
941
|
}
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
942
|
+
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
943
|
+
return result.replaceAll(PROJECT_NAME_PLACEHOLDER, readProjectPackageName(cwd));
|
|
944
|
+
}
|
|
945
|
+
export function resolveDependencyTemplateFile(cwd, dependencies, templateFileName, fallback) {
|
|
946
|
+
const rootPlan = resolveDependencyRootPlan(cwd, dependencies);
|
|
947
|
+
const candidates = rootPlan.rootDependencies.map((dependency) => {
|
|
948
|
+
const dependencyDir = resolveInstalledPackageDir(cwd, dependency);
|
|
949
|
+
return {
|
|
950
|
+
dependency,
|
|
951
|
+
filePath: dependencyDir
|
|
952
|
+
? join(dependencyDir, 'template', templateFileName)
|
|
953
|
+
: '',
|
|
954
|
+
};
|
|
955
|
+
}).filter(({ filePath }) => existsSync(filePath));
|
|
956
|
+
if (candidates.length > 1) {
|
|
957
|
+
throw new Error(`多个顶层依赖同时提供 template/${templateFileName}:${candidates.map(({ dependency }) => dependency).join(', ')},无法确定使用哪个模板`);
|
|
932
958
|
}
|
|
933
|
-
return
|
|
959
|
+
return candidates[0]?.filePath || fallback;
|
|
934
960
|
}
|
|
935
961
|
function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|
936
962
|
const sourceFile = ts.createSourceFile('index.ts', readFileSync(dataIndexFile, 'utf-8'), ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
|
|
@@ -962,7 +988,7 @@ function injectDataIndexFile(dataIndexFile, briefNames, printer) {
|
|
|
962
988
|
...statements,
|
|
963
989
|
];
|
|
964
990
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
965
|
-
|
|
991
|
+
writeGeneratedFile(dataIndexFile, result);
|
|
966
992
|
console.log(`注入${dataIndexFile}文件成功,共注入了${briefNames.length}个初始化数据引用`);
|
|
967
993
|
}
|
|
968
994
|
/**
|
|
@@ -1013,7 +1039,10 @@ function tryCopyModuleTemplateFiles(cwd, dependencies, briefNames, printer, rebu
|
|
|
1013
1039
|
const injectDataIndexFileDependencies = [];
|
|
1014
1040
|
const injectDataIndexFileBriefNames = [];
|
|
1015
1041
|
dependencies.forEach((dep, idx) => {
|
|
1016
|
-
const moduleDir =
|
|
1042
|
+
const moduleDir = resolveInstalledPackageDir(cwd, dep);
|
|
1043
|
+
if (!moduleDir) {
|
|
1044
|
+
throw new Error(`依赖模块${dep}未能找到相应的安装目录`);
|
|
1045
|
+
}
|
|
1017
1046
|
const moduleTemplateDir = join(moduleDir, 'template');
|
|
1018
1047
|
if (existsSync(moduleTemplateDir)) {
|
|
1019
1048
|
// data.ts中规定的初始化数据,拷贝到data目录下,并注入到data/index.ts
|
|
@@ -1100,7 +1129,7 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1100
1129
|
], undefined, factory.createBlock([], true))
|
|
1101
1130
|
];
|
|
1102
1131
|
const result = printer.printList(ts.ListFormat.SourceFileStatements, factory.createNodeArray(statements2), sourceFile);
|
|
1103
|
-
|
|
1132
|
+
writeGeneratedFile(featureIndexFile, result);
|
|
1104
1133
|
console.log(`注入${featureIndexFile}文件成功,用户可以自己修正initialize函数的参数和逻辑`);
|
|
1105
1134
|
}
|
|
1106
1135
|
}
|
|
@@ -1111,15 +1140,34 @@ function injectInitializeToFeatureIndex(cwd, dependencies, briefNames, printer)
|
|
|
1111
1140
|
export default function buildDependency(rebuild) {
|
|
1112
1141
|
const cwd = process.cwd();
|
|
1113
1142
|
const { depGraph, dependencies, briefNames, isModule, } = resolveDependencyBuildContext(cwd);
|
|
1143
|
+
const oakCliDir = resolveInstalledPackageDir(cwd, OAK_CLI_MODULE_NAME);
|
|
1144
|
+
if (!oakCliDir) {
|
|
1145
|
+
throw new Error(`找不到依赖包${OAK_CLI_MODULE_NAME}的安装位置,当前包是${cwd}`);
|
|
1146
|
+
}
|
|
1147
|
+
const defaultTemplateFiles = {
|
|
1148
|
+
initializeServer: join(oakCliDir, 'scaffold', 'fragments', 'initialize.server.ts'),
|
|
1149
|
+
initializeFeatures: join(oakCliDir, 'scaffold', 'fragments', 'initializeFeatures.ts'),
|
|
1150
|
+
runtimeCxt: join(oakCliDir, 'scaffold', 'fragments', 'RuntimeCxt.ts'),
|
|
1151
|
+
dependentExceptions: join(oakCliDir, 'scaffold', 'fragments', 'DependentExceptions.ts'),
|
|
1152
|
+
polyfillDts: join(oakCliDir, 'scaffold', 'fragments', 'polyfill.d.ts'),
|
|
1153
|
+
featureIndex: join(oakCliDir, 'scaffold', 'fragments', !isModule && dependencies.length === 0
|
|
1154
|
+
? 'features/index.standalone.ts'
|
|
1155
|
+
: 'features/index.ts'),
|
|
1156
|
+
backendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
|
|
1157
|
+
? 'BackendRuntimeContext.standalone.ts'
|
|
1158
|
+
: 'BackendRuntimeContext.ts'),
|
|
1159
|
+
frontendRuntimeContext: join(oakCliDir, 'scaffold', 'fragments', dependencies.length === 0
|
|
1160
|
+
? 'FrontendRuntimeContext.standalone.ts'
|
|
1161
|
+
: 'FrontendRuntimeContext.ts'),
|
|
1162
|
+
};
|
|
1114
1163
|
const templateFiles = {
|
|
1115
|
-
|
|
1116
|
-
initializeFeatures:
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
frontendRuntimeContext: join(cwd, 'node_modules', OAK_CLI_MODULE_NAME, 'scaffold', 'fragments', 'FrontendRuntimeContext.ts'),
|
|
1164
|
+
...defaultTemplateFiles,
|
|
1165
|
+
initializeFeatures: !isModule
|
|
1166
|
+
? resolveDependencyTemplateFile(cwd, dependencies, 'initializeFeatures.ts', defaultTemplateFiles.initializeFeatures)
|
|
1167
|
+
: defaultTemplateFiles.initializeFeatures,
|
|
1168
|
+
featureIndex: !isModule
|
|
1169
|
+
? resolveDependencyTemplateFile(cwd, dependencies, 'featuresIndex.ts', defaultTemplateFiles.featureIndex)
|
|
1170
|
+
: defaultTemplateFiles.featureIndex,
|
|
1123
1171
|
};
|
|
1124
1172
|
const program = ts.createProgram(Object.values(templateFiles), {});
|
|
1125
1173
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
@@ -1186,21 +1234,26 @@ export default function buildDependency(rebuild) {
|
|
|
1186
1234
|
if (output) {
|
|
1187
1235
|
outputRuntimeCxt(dependencies, briefNames, program.getSourceFile(templateFiles.runtimeCxt), printer, runtimeCxtFile);
|
|
1188
1236
|
}
|
|
1189
|
-
output = true;
|
|
1190
1237
|
const dependentExceptionsFile = join(cwd, 'src', 'types', 'DependentExceptions.ts');
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1238
|
+
const shouldOutputDependentExceptions = !isModule
|
|
1239
|
+
|| dependencies.length > 0
|
|
1240
|
+
|| existsSync(dependentExceptionsFile);
|
|
1241
|
+
if (shouldOutputDependentExceptions) {
|
|
1242
|
+
output = true;
|
|
1243
|
+
if (existsSync(dependentExceptionsFile) && !rebuild) {
|
|
1244
|
+
let tips = `[${dependentExceptionsFile}]文件已经存在`;
|
|
1245
|
+
if (!rebuild) {
|
|
1246
|
+
tips += ',忽略构建。';
|
|
1247
|
+
output = false;
|
|
1248
|
+
}
|
|
1249
|
+
else {
|
|
1250
|
+
tips += ',将重新构建';
|
|
1251
|
+
}
|
|
1252
|
+
console.log(tips);
|
|
1196
1253
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1254
|
+
if (output) {
|
|
1255
|
+
outputDependentExceptions(dependencies, briefNames, program.getSourceFile(templateFiles.dependentExceptions), printer, dependentExceptionsFile, isModule);
|
|
1199
1256
|
}
|
|
1200
|
-
console.log(tips);
|
|
1201
|
-
}
|
|
1202
|
-
if (output) {
|
|
1203
|
-
outputDependentExceptions(dependencies, briefNames, program.getSourceFile(templateFiles.dependentExceptions), printer, dependentExceptionsFile);
|
|
1204
1257
|
}
|
|
1205
1258
|
output = true;
|
|
1206
1259
|
const polyfillDtsFile = join(cwd, 'typings', 'polyfill.d.ts');
|
|
@@ -1231,39 +1284,8 @@ export default function buildDependency(rebuild) {
|
|
|
1231
1284
|
}
|
|
1232
1285
|
console.log(tips);
|
|
1233
1286
|
}
|
|
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
1287
|
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);
|
|
1288
|
+
outputFeatureIndex(dependencies, briefNames, program.getSourceFile(templateFiles.featureIndex), printer, featureIndexFile, isModule);
|
|
1268
1289
|
}
|
|
1290
|
+
writeContextCompositionFiles(cwd, isModule, templateFiles);
|
|
1269
1291
|
}
|