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,8 +1,8 @@
|
|
|
1
|
-
import assert from 'assert';
|
|
1
|
+
import { assert } from '../utils/assert';
|
|
2
2
|
import * as ts from 'typescript';
|
|
3
3
|
const { factory } = ts;
|
|
4
4
|
import { join } from 'path';
|
|
5
|
-
import { createHash } from
|
|
5
|
+
import { createHash } from "crypto";
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import { firstLetterLowerCase, unescapeUnicode } from '../utils/string';
|
|
8
8
|
import { analyzeDepedency } from './dependencyBuilder';
|
|
@@ -79,20 +79,6 @@ function collectOakPackages(nodeModulesPath) {
|
|
|
79
79
|
oakPackageCache.set(normalizedNodeModulesPath, packages);
|
|
80
80
|
return packages;
|
|
81
81
|
}
|
|
82
|
-
/**
|
|
83
|
-
* 将一个object展开编译为一棵语法树,只有string和object两种键值对象
|
|
84
|
-
* @param data
|
|
85
|
-
*/
|
|
86
|
-
function transferObjectToObjectLiteral(data) {
|
|
87
|
-
return factory.createObjectLiteralExpression(Object.keys(data).map((k) => {
|
|
88
|
-
const type = typeof data[k];
|
|
89
|
-
if (type === 'string') {
|
|
90
|
-
return factory.createPropertyAssignment(factory.createStringLiteral(k), factory.createStringLiteral(data[k]));
|
|
91
|
-
}
|
|
92
|
-
assert(type === 'object');
|
|
93
|
-
return factory.createPropertyAssignment(factory.createStringLiteral(k), transferObjectToObjectLiteral(data[k]));
|
|
94
|
-
}), true);
|
|
95
|
-
}
|
|
96
82
|
/**
|
|
97
83
|
* 这个类的作用是把项目和所有相关的模块下的locales编译成为src/data/i18n中的数据
|
|
98
84
|
*/
|
|
@@ -104,21 +90,17 @@ export default class LocaleBuilder {
|
|
|
104
90
|
locales; // key: namespace+language, value: [namespace, module, position, language, data]
|
|
105
91
|
hash;
|
|
106
92
|
projectName;
|
|
107
|
-
|
|
93
|
+
localeWorkspaces;
|
|
94
|
+
constructor(asLib, localeWorkspaces) {
|
|
108
95
|
const pwd = process.cwd();
|
|
109
96
|
this.pwd = pwd;
|
|
110
97
|
this.asLib = !!asLib;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
const depGraph = analyzeDepedency(pwd);
|
|
114
|
-
this.dependencies = depGraph.ascOrder;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
this.dependencies = [];
|
|
118
|
-
}
|
|
98
|
+
const depGraph = analyzeDepedency(pwd);
|
|
99
|
+
this.dependencies = depGraph.ascOrder;
|
|
119
100
|
this.oakPackages = collectOakPackages(join(pwd, 'node_modules'));
|
|
120
101
|
this.locales = {};
|
|
121
102
|
this.hash = createHash('md5');
|
|
103
|
+
this.localeWorkspaces = localeWorkspaces;
|
|
122
104
|
}
|
|
123
105
|
/**
|
|
124
106
|
* 将locales输出成为data/i18n.ts中的数据
|
|
@@ -126,28 +108,34 @@ export default class LocaleBuilder {
|
|
|
126
108
|
*/
|
|
127
109
|
outputDataFile() {
|
|
128
110
|
const appDomainDir = this.projectName === 'oak-domain' ? 'base-app-domain' : 'oak-app-domain';
|
|
111
|
+
const rows = Object.keys(this.locales).map((k) => {
|
|
112
|
+
const [namespace, module, position, language, data] = this.locales[k];
|
|
113
|
+
// 用哈希计算来保证id唯一性
|
|
114
|
+
const h = this.hash.copy();
|
|
115
|
+
h.update(`${namespace}-${language}`);
|
|
116
|
+
const id = h.digest('hex');
|
|
117
|
+
assert(id.length <= 36);
|
|
118
|
+
return {
|
|
119
|
+
id,
|
|
120
|
+
namespace,
|
|
121
|
+
language,
|
|
122
|
+
module,
|
|
123
|
+
position,
|
|
124
|
+
data,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
129
127
|
const statements = [
|
|
130
|
-
factory.createImportDeclaration(undefined, factory.createImportClause(
|
|
128
|
+
factory.createImportDeclaration(undefined, factory.createImportClause(true, undefined, factory.createNamedImports([
|
|
131
129
|
factory.createImportSpecifier(false, factory.createIdentifier('CreateOperationData'), factory.createIdentifier('I18n')),
|
|
132
130
|
])), factory.createStringLiteral(`../${appDomainDir}/I18n/Schema`), undefined),
|
|
131
|
+
factory.createVariableStatement([factory.createModifier(ts.SyntaxKind.DeclareKeyword)], factory.createVariableDeclarationList([
|
|
132
|
+
factory.createVariableDeclaration(factory.createIdentifier('require'), undefined, factory.createFunctionTypeNode(undefined, [
|
|
133
|
+
factory.createParameterDeclaration(undefined, undefined, factory.createIdentifier('path'), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined),
|
|
134
|
+
], factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)), undefined),
|
|
135
|
+
], ts.NodeFlags.Const)),
|
|
133
136
|
];
|
|
134
137
|
statements.push(factory.createVariableStatement(undefined, factory.createVariableDeclarationList([
|
|
135
|
-
factory.createVariableDeclaration(factory.createIdentifier('i18ns'), undefined, factory.
|
|
136
|
-
const [namespace, module, position, language, data] = this.locales[k];
|
|
137
|
-
// 用哈希计算来保证id唯一性
|
|
138
|
-
const h = this.hash.copy();
|
|
139
|
-
h.update(`${namespace}-${language}`);
|
|
140
|
-
const id = h.digest('hex');
|
|
141
|
-
assert(id.length <= 36);
|
|
142
|
-
return factory.createObjectLiteralExpression([
|
|
143
|
-
factory.createPropertyAssignment(factory.createIdentifier('id'), factory.createStringLiteral(id)),
|
|
144
|
-
factory.createPropertyAssignment(factory.createIdentifier('namespace'), factory.createStringLiteral(namespace)),
|
|
145
|
-
factory.createPropertyAssignment(factory.createIdentifier('language'), factory.createStringLiteral(language)),
|
|
146
|
-
factory.createPropertyAssignment(factory.createIdentifier('module'), factory.createStringLiteral(module)),
|
|
147
|
-
factory.createPropertyAssignment(factory.createIdentifier('position'), factory.createStringLiteral(position)),
|
|
148
|
-
factory.createPropertyAssignment(factory.createIdentifier('data'), transferObjectToObjectLiteral(data)),
|
|
149
|
-
], true);
|
|
150
|
-
}), true)),
|
|
138
|
+
factory.createVariableDeclaration(factory.createIdentifier('i18ns'), undefined, undefined, factory.createAsExpression(factory.createCallExpression(factory.createIdentifier('require'), undefined, [factory.createStringLiteral('./i18n.json')]), factory.createArrayTypeNode(factory.createTypeReferenceNode(factory.createIdentifier('I18n'), undefined)))),
|
|
151
139
|
], ts.NodeFlags.Const)));
|
|
152
140
|
statements.push(factory.createExportAssignment(undefined, undefined, factory.createIdentifier('i18ns')));
|
|
153
141
|
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
@@ -157,8 +145,11 @@ export default class LocaleBuilder {
|
|
|
157
145
|
fs.mkdirSync(dataDir);
|
|
158
146
|
}
|
|
159
147
|
const filename = join(dataDir, 'i18n.ts');
|
|
148
|
+
const jsonFilename = join(dataDir, 'i18n.json');
|
|
160
149
|
const result2 = unescapeUnicode(`// 本文件为自动编译产生,请勿直接修改\n\n${result}`);
|
|
150
|
+
const jsonResult = unescapeUnicode(`${JSON.stringify(rows, null, 4)}\n`);
|
|
161
151
|
fs.writeFileSync(filename, result2, { flag: 'w' });
|
|
152
|
+
fs.writeFileSync(jsonFilename, jsonResult, { flag: 'w' });
|
|
162
153
|
}
|
|
163
154
|
/**
|
|
164
155
|
* 这里不能直接用require, webpack貌似有缓存
|
|
@@ -245,23 +236,28 @@ export default class LocaleBuilder {
|
|
|
245
236
|
if (fs.existsSync(domainPath)) {
|
|
246
237
|
this.traverse('', '', 'oak-app-domain', domainPath, false, 'locales', watch);
|
|
247
238
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
239
|
+
const localeWorkspaces = this.localeWorkspaces || (() => {
|
|
240
|
+
const legacyWorkspaces = [
|
|
241
|
+
{ namespacePrefix: 'w', relativePath: 'web' },
|
|
242
|
+
{ namespacePrefix: 'wmp', relativePath: 'wechatMp' },
|
|
243
|
+
];
|
|
244
|
+
let iter = 1;
|
|
245
|
+
while (fs.existsSync(join(root, `wechatMp${iter}`, 'src'))) {
|
|
246
|
+
legacyWorkspaces.push({
|
|
247
|
+
namespacePrefix: `wmp${iter}`,
|
|
248
|
+
relativePath: `wechatMp${iter}`,
|
|
249
|
+
});
|
|
259
250
|
iter++;
|
|
260
251
|
}
|
|
261
|
-
|
|
262
|
-
|
|
252
|
+
return legacyWorkspaces;
|
|
253
|
+
})();
|
|
254
|
+
localeWorkspaces.forEach(({ namespacePrefix, relativePath }) => {
|
|
255
|
+
const workspaceSrcPath = join(relativePath, 'src');
|
|
256
|
+
const workspaceSrcAbsolutePath = join(root, workspaceSrcPath);
|
|
257
|
+
if (fs.existsSync(workspaceSrcAbsolutePath)) {
|
|
258
|
+
this.traverse(name, namespacePrefix, workspaceSrcPath, workspaceSrcAbsolutePath, false, 'locales', watch);
|
|
263
259
|
}
|
|
264
|
-
}
|
|
260
|
+
});
|
|
265
261
|
}
|
|
266
262
|
}
|
|
267
263
|
build(watch) {
|
|
@@ -1,8 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type PageConfig = {
|
|
2
|
+
enablePullDownRefresh?: boolean;
|
|
3
|
+
route?: {
|
|
4
|
+
path?: string;
|
|
5
|
+
/** Web document title literal. */
|
|
6
|
+
title?: string;
|
|
7
|
+
/** Web document title i18n key. Defaults to the page locale pageTitle key. */
|
|
8
|
+
titleI18nKey?: string;
|
|
9
|
+
/** Web route pull-down refresh behavior. Falls back to top-level enablePullDownRefresh. */
|
|
10
|
+
enablePullDownRefresh?: boolean;
|
|
11
|
+
access?: unknown;
|
|
12
|
+
};
|
|
13
|
+
menu?: unknown;
|
|
14
|
+
mp?: {
|
|
15
|
+
/** Mini-program page pull-down refresh behavior; not used by web router generation. */
|
|
16
|
+
enablePullDownRefresh?: boolean;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type NamespaceConfig = {
|
|
20
|
+
route?: {
|
|
21
|
+
path?: string;
|
|
22
|
+
notFound?: string;
|
|
23
|
+
first?: string;
|
|
24
|
+
params?: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
type BuildRouterOptions = {
|
|
3
28
|
useOutlet?: boolean;
|
|
4
29
|
onWarning?: (message: string) => void;
|
|
5
|
-
|
|
30
|
+
getPageConfig?: (pageDirectoryPath: string) => PageConfig | undefined;
|
|
31
|
+
getNamespaceConfig?: (namespaceDirectoryPath: string, namespace: string) => NamespaceConfig | undefined;
|
|
32
|
+
};
|
|
33
|
+
declare function closeCurrentWatchSession(): void;
|
|
34
|
+
export declare function buildRouter(projectDir: string, startupDir: string, watch?: boolean, options?: BuildRouterOptions): {
|
|
6
35
|
close: typeof closeCurrentWatchSession;
|
|
7
36
|
} | undefined;
|
|
8
37
|
export {};
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { join, relative, dirname } from 'path';
|
|
2
2
|
import { readdirSync, statSync, existsSync, writeFileSync, readFileSync, removeSync } from 'fs-extra';
|
|
3
|
-
import assert from 'assert';
|
|
3
|
+
import { assert } from '../utils/assert';
|
|
4
4
|
import * as ts from 'typescript';
|
|
5
5
|
import NodeWatch from 'node-watch';
|
|
6
6
|
import { OAK_CLI_MODULE_NAME } from './env';
|
|
7
7
|
const { factory } = ts;
|
|
8
8
|
const NameSpaceDescDict = {};
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
const WEB_PAGE_RENDER_FILES = ['web.tsx', 'web.pc.tsx', 'web.mobile.tsx'];
|
|
10
|
+
const DESKTOP_PAGE_RENDER_FILES = [
|
|
11
|
+
'render.desktop.tsx',
|
|
12
|
+
'render.windows.tsx',
|
|
13
|
+
'render.macos.tsx',
|
|
14
|
+
'render.linux.tsx',
|
|
15
|
+
];
|
|
16
|
+
const PAGE_RENDER_FILES = [
|
|
17
|
+
...WEB_PAGE_RENDER_FILES,
|
|
18
|
+
...DESKTOP_PAGE_RENDER_FILES,
|
|
19
|
+
'render.native.tsx',
|
|
20
|
+
'render.ios.tsx',
|
|
21
|
+
'render.android.tsx',
|
|
22
|
+
'index.xml',
|
|
23
|
+
];
|
|
24
|
+
const PAGE_WATCH_FILTER = /(?:^|[\\/])(?:web\.tsx|web\.pc\.tsx|web\.mobile\.tsx|index\.json|index\.config\.(?:ts|mts|cts|js|mjs|cjs)|index\.xml|render\.(?:desktop|windows|macos|linux|native|ios|android)\.tsx)$/;
|
|
25
|
+
const NAMESPACE_WATCH_FILTER = /(?:^|[\\/])(?:index\.json|index\.config\.(?:ts|mts|cts|js|mjs|cjs))$/;
|
|
12
26
|
const VALID_PAGE_DIR_NAME = /^[A-Za-z0-9_-]+$/;
|
|
13
27
|
function normalizePath(path) {
|
|
14
28
|
return path.replace(/\\/g, '/');
|
|
@@ -27,6 +41,13 @@ function normalizeRoutePath(path) {
|
|
|
27
41
|
function isValidPageDirName(name) {
|
|
28
42
|
return VALID_PAGE_DIR_NAME.test(name);
|
|
29
43
|
}
|
|
44
|
+
function isDesktopRenderProfile() {
|
|
45
|
+
return process.env.OAK_RENDER === 'tauri'
|
|
46
|
+
|| process.env.OAK_RENDER === 'electron';
|
|
47
|
+
}
|
|
48
|
+
function isWebStartupDir(startupDir) {
|
|
49
|
+
return startupDir.startsWith('web') || isDesktopRenderProfile();
|
|
50
|
+
}
|
|
30
51
|
function getInvalidPageDirPath(relativePath) {
|
|
31
52
|
const segments = normalizeRelativePath(relativePath).split('/').filter(Boolean);
|
|
32
53
|
const validSegments = [];
|
|
@@ -40,16 +61,28 @@ function getInvalidPageDirPath(relativePath) {
|
|
|
40
61
|
function readJsonFresh(filename) {
|
|
41
62
|
return JSON.parse(readFileSync(filename, 'utf-8'));
|
|
42
63
|
}
|
|
64
|
+
function getProjectPackageName(projectDir) {
|
|
65
|
+
const packageJson = readJsonFresh(join(projectDir, 'package.json'));
|
|
66
|
+
assert(typeof packageJson.name === 'string' && packageJson.name, `${projectDir}下的package.json缺少name字段`);
|
|
67
|
+
return packageJson.name;
|
|
68
|
+
}
|
|
69
|
+
function createPageTitleI18nKey(packageName, namespaceKey, fullPath) {
|
|
70
|
+
const pagePath = normalizeRoutePath(fullPath).replace(/\//g, '-');
|
|
71
|
+
return `${packageName}-p-${namespaceKey}-${pagePath}.pageTitle`;
|
|
72
|
+
}
|
|
43
73
|
function hasPageDescChanged(prev, next) {
|
|
44
74
|
if (!prev || !next) {
|
|
45
75
|
return prev !== next;
|
|
46
76
|
}
|
|
47
77
|
return prev.path !== next.path
|
|
48
78
|
|| prev.routePath !== next.routePath
|
|
79
|
+
|| prev.routeTitle !== next.routeTitle
|
|
80
|
+
|| prev.routeTitleI18nKey !== next.routeTitleI18nKey
|
|
49
81
|
|| prev.oakDisablePulldownRefresh !== next.oakDisablePulldownRefresh
|
|
50
82
|
|| prev.hasWeb !== next.hasWeb
|
|
51
83
|
|| prev.hasNative !== next.hasNative
|
|
52
|
-
|| prev.hasWechatMp !== next.hasWechatMp
|
|
84
|
+
|| prev.hasWechatMp !== next.hasWechatMp
|
|
85
|
+
|| JSON.stringify(prev.access) !== JSON.stringify(next.access);
|
|
53
86
|
}
|
|
54
87
|
function getNamespaceFromFilepath(rootDir, filepath) {
|
|
55
88
|
const normalizedRelativePath = normalizeRelativePath(relative(rootDir, filepath));
|
|
@@ -87,7 +120,9 @@ function checkPageDir(dir, relativePath, ns, type) {
|
|
|
87
120
|
if (['render.native.tsx', 'render.ios.tsx', 'render.android.tsx'].includes(file)) {
|
|
88
121
|
hasNative = true;
|
|
89
122
|
}
|
|
90
|
-
else if (
|
|
123
|
+
else if (WEB_PAGE_RENDER_FILES.includes(file)
|
|
124
|
+
|| (isDesktopRenderProfile()
|
|
125
|
+
&& DESKTOP_PAGE_RENDER_FILES.includes(file))) {
|
|
91
126
|
hasWeb = true;
|
|
92
127
|
}
|
|
93
128
|
else if (file === 'index.xml') {
|
|
@@ -108,20 +143,37 @@ function checkPageDir(dir, relativePath, ns, type) {
|
|
|
108
143
|
const indexJsonFile = join(dir, 'index.json');
|
|
109
144
|
let oakDisablePulldownRefresh = false;
|
|
110
145
|
let routePath;
|
|
146
|
+
let routeTitle;
|
|
147
|
+
let routeTitleI18nKey;
|
|
148
|
+
let access;
|
|
149
|
+
let indexJson = {};
|
|
111
150
|
if (existsSync(indexJsonFile)) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
151
|
+
indexJson = readJsonFresh(indexJsonFile);
|
|
152
|
+
}
|
|
153
|
+
const pageConfig = BuildRouterContext.options?.getPageConfig?.(dir);
|
|
154
|
+
const enablePullDownRefresh = pageConfig?.route?.enablePullDownRefresh ?? pageConfig?.enablePullDownRefresh ?? indexJson.enablePullDownRefresh ?? true;
|
|
155
|
+
const routePath2 = pageConfig?.route?.path ?? indexJson.path;
|
|
156
|
+
oakDisablePulldownRefresh = !enablePullDownRefresh;
|
|
157
|
+
if (typeof routePath2 === 'string') {
|
|
158
|
+
routePath = normalizeRoutePath(routePath2);
|
|
159
|
+
}
|
|
160
|
+
if (typeof pageConfig?.route?.title === 'string') {
|
|
161
|
+
routeTitle = pageConfig.route.title;
|
|
162
|
+
}
|
|
163
|
+
if (typeof pageConfig?.route?.titleI18nKey === 'string') {
|
|
164
|
+
routeTitleI18nKey = pageConfig.route.titleI18nKey;
|
|
117
165
|
}
|
|
166
|
+
access = pageConfig?.route?.access;
|
|
118
167
|
nextPageDesc = {
|
|
119
168
|
path: normalizeRelativePath(relativePath),
|
|
120
169
|
routePath,
|
|
170
|
+
routeTitle,
|
|
171
|
+
routeTitleI18nKey,
|
|
121
172
|
oakDisablePulldownRefresh,
|
|
122
173
|
hasNative,
|
|
123
174
|
hasWeb,
|
|
124
175
|
hasWechatMp,
|
|
176
|
+
access,
|
|
125
177
|
};
|
|
126
178
|
}
|
|
127
179
|
if (hasPageDescChanged(pages[dir], nextPageDesc)) {
|
|
@@ -201,6 +253,44 @@ function createLazyImportExpression(importPath) {
|
|
|
201
253
|
factory.createStringLiteral(importPath)
|
|
202
254
|
]))]);
|
|
203
255
|
}
|
|
256
|
+
function createLiteralExpressionFromValue(value) {
|
|
257
|
+
if (value === null) {
|
|
258
|
+
return factory.createNull();
|
|
259
|
+
}
|
|
260
|
+
if (typeof value === 'string') {
|
|
261
|
+
return factory.createStringLiteral(value);
|
|
262
|
+
}
|
|
263
|
+
if (typeof value === 'number') {
|
|
264
|
+
return factory.createNumericLiteral(value);
|
|
265
|
+
}
|
|
266
|
+
if (typeof value === 'boolean') {
|
|
267
|
+
return value ? factory.createTrue() : factory.createFalse();
|
|
268
|
+
}
|
|
269
|
+
if (Array.isArray(value)) {
|
|
270
|
+
return factory.createArrayLiteralExpression(value.map((item) => createLiteralExpressionFromValue(item)));
|
|
271
|
+
}
|
|
272
|
+
if (value && typeof value === 'object') {
|
|
273
|
+
return factory.createObjectLiteralExpression(Object.entries(value)
|
|
274
|
+
.filter(([, currentValue]) => currentValue !== undefined)
|
|
275
|
+
.map(([key, currentValue]) => factory.createPropertyAssignment(/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key)
|
|
276
|
+
? factory.createIdentifier(key)
|
|
277
|
+
: factory.createStringLiteral(key), createLiteralExpressionFromValue(currentValue))), true);
|
|
278
|
+
}
|
|
279
|
+
return factory.createIdentifier('undefined');
|
|
280
|
+
}
|
|
281
|
+
function createWebRouteMetaExpression(page, titleI18nKey) {
|
|
282
|
+
const properties = [
|
|
283
|
+
factory.createPropertyAssignment('oakDisablePulldownRefresh', page.oakDisablePulldownRefresh ? factory.createTrue() : factory.createFalse())
|
|
284
|
+
];
|
|
285
|
+
if (page.routeTitle !== undefined) {
|
|
286
|
+
properties.push(factory.createPropertyAssignment('title', factory.createStringLiteral(page.routeTitle)));
|
|
287
|
+
}
|
|
288
|
+
properties.push(factory.createPropertyAssignment('titleI18nKey', factory.createStringLiteral(page.routeTitleI18nKey || titleI18nKey)));
|
|
289
|
+
if (page.access !== undefined) {
|
|
290
|
+
properties.push(factory.createPropertyAssignment('access', createLiteralExpressionFromValue(page.access)));
|
|
291
|
+
}
|
|
292
|
+
return factory.createObjectLiteralExpression(properties, true);
|
|
293
|
+
}
|
|
204
294
|
function appendRouteParam(path, paramName) {
|
|
205
295
|
if (!paramName) {
|
|
206
296
|
return path;
|
|
@@ -338,15 +428,13 @@ function getValidWebRouteChildren(parentNode, ns, params) {
|
|
|
338
428
|
});
|
|
339
429
|
return candidates.filter((candidate) => !ignoredNodePaths.has(candidate.node.fullPath)).map((candidate) => candidate.node);
|
|
340
430
|
}
|
|
341
|
-
function createWebPageRouteExpression(ns, page, projectDir, routerFileDir, path, fullPath, options) {
|
|
431
|
+
function createWebPageRouteExpression(ns, namespacePath, packageName, page, projectDir, routerFileDir, path, fullPath, options) {
|
|
342
432
|
const properties = [];
|
|
343
433
|
properties.push(factory.createPropertyAssignment('path', factory.createStringLiteral(options?.isFirst ? '' : path)), factory.createPropertyAssignment('fullPath', factory.createStringLiteral(fullPath)));
|
|
344
434
|
if (options?.isFirst) {
|
|
345
435
|
properties.push(factory.createPropertyAssignment('isFirst', factory.createTrue()));
|
|
346
436
|
}
|
|
347
|
-
properties.push(factory.createPropertyAssignment('namespace', factory.createStringLiteral(ns)), factory.createPropertyAssignment('meta', factory.
|
|
348
|
-
factory.createPropertyAssignment('oakDisablePulldownRefresh', page.oakDisablePulldownRefresh ? factory.createTrue() : factory.createFalse())
|
|
349
|
-
])), factory.createPropertyAssignment(factory.createIdentifier('Component'), createLazyImportExpression(normalizePath(relative(routerFileDir, join(projectDir, 'src', 'pages', ns, page.path))))));
|
|
437
|
+
properties.push(factory.createPropertyAssignment('namespace', factory.createStringLiteral(ns)), factory.createPropertyAssignment('namespaceKey', factory.createStringLiteral(ns)), factory.createPropertyAssignment('namespacePath', factory.createStringLiteral(namespacePath)), factory.createPropertyAssignment('meta', createWebRouteMetaExpression(page, createPageTitleI18nKey(packageName, ns, fullPath))), factory.createPropertyAssignment(factory.createIdentifier('Component'), createLazyImportExpression(normalizePath(relative(routerFileDir, join(projectDir, 'src', 'pages', ns, page.path))))));
|
|
350
438
|
if (options?.children?.length) {
|
|
351
439
|
properties.push(factory.createPropertyAssignment('children', factory.createArrayLiteralExpression(options.children)));
|
|
352
440
|
}
|
|
@@ -358,22 +446,22 @@ function createWebGroupRouteExpression(path, children) {
|
|
|
358
446
|
factory.createPropertyAssignment('children', factory.createArrayLiteralExpression(children))
|
|
359
447
|
], true);
|
|
360
448
|
}
|
|
361
|
-
function makeWebRoutesFromTreeNode(node, ns, params, projectDir, routerFileDir, useOutlet) {
|
|
362
|
-
const children = getValidWebRouteChildren(node, ns, params).map((child) => makeWebRoutesFromTreeNode(child, ns, params, projectDir, routerFileDir, useOutlet));
|
|
449
|
+
function makeWebRoutesFromTreeNode(node, ns, namespacePath, packageName, params, projectDir, routerFileDir, useOutlet) {
|
|
450
|
+
const children = getValidWebRouteChildren(node, ns, params).map((child) => makeWebRoutesFromTreeNode(child, ns, namespacePath, packageName, params, projectDir, routerFileDir, useOutlet));
|
|
363
451
|
const groupPath = getGroupRoutePath(node, params);
|
|
364
452
|
if (node.page) {
|
|
365
453
|
const path = getPageRoutePath(node, node.page, params);
|
|
366
454
|
const fullPath = node.page.path;
|
|
367
455
|
if (children.length === 0) {
|
|
368
|
-
return createWebPageRouteExpression(ns, node.page, projectDir, routerFileDir, path, fullPath);
|
|
456
|
+
return createWebPageRouteExpression(ns, namespacePath, packageName, node.page, projectDir, routerFileDir, path, fullPath);
|
|
369
457
|
}
|
|
370
458
|
if (useOutlet) {
|
|
371
|
-
return createWebPageRouteExpression(ns, node.page, projectDir, routerFileDir, path, fullPath, {
|
|
459
|
+
return createWebPageRouteExpression(ns, namespacePath, packageName, node.page, projectDir, routerFileDir, path, fullPath, {
|
|
372
460
|
children,
|
|
373
461
|
});
|
|
374
462
|
}
|
|
375
463
|
return createWebGroupRouteExpression(path, [
|
|
376
|
-
createWebPageRouteExpression(ns, node.page, projectDir, routerFileDir, path, fullPath, {
|
|
464
|
+
createWebPageRouteExpression(ns, namespacePath, packageName, node.page, projectDir, routerFileDir, path, fullPath, {
|
|
377
465
|
isFirst: true,
|
|
378
466
|
}),
|
|
379
467
|
...children,
|
|
@@ -382,7 +470,11 @@ function makeWebRoutesFromTreeNode(node, ns, params, projectDir, routerFileDir,
|
|
|
382
470
|
return createWebGroupRouteExpression(groupPath, children);
|
|
383
471
|
}
|
|
384
472
|
function makeWebAllRouters(namespaceDir, projectDir, routerFileDir, options) {
|
|
473
|
+
const packageName = getProjectPackageName(projectDir);
|
|
385
474
|
const nss = readdirSync(namespaceDir).filter((ns) => {
|
|
475
|
+
if (!statSync(join(namespaceDir, ns)).isDirectory()) {
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
386
478
|
if (isValidPageDirName(ns)) {
|
|
387
479
|
return true;
|
|
388
480
|
}
|
|
@@ -392,67 +484,87 @@ function makeWebAllRouters(namespaceDir, projectDir, routerFileDir, options) {
|
|
|
392
484
|
return factory.createArrayLiteralExpression(nss.map((ns) => {
|
|
393
485
|
assert(NameSpaceDescDict[ns], `${ns}在pages下没有对应的目录`);
|
|
394
486
|
const { pages } = NameSpaceDescDict[ns];
|
|
395
|
-
const
|
|
487
|
+
const nsDirectory = join(namespaceDir, ns);
|
|
488
|
+
const nsIndexJsonFile = join(nsDirectory, 'index.json');
|
|
396
489
|
let path2 = `/${ns}`;
|
|
397
490
|
let notFound2 = '', first2 = '';
|
|
398
491
|
let params2 = {};
|
|
492
|
+
let namespaceIndexJson = {};
|
|
399
493
|
if (existsSync(nsIndexJsonFile)) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
494
|
+
namespaceIndexJson = readJsonFresh(nsIndexJsonFile);
|
|
495
|
+
}
|
|
496
|
+
const namespaceRouteConfig = BuildRouterContext.options?.getNamespaceConfig?.(nsDirectory, ns)?.route;
|
|
497
|
+
const namespacePath = namespaceRouteConfig?.path ?? namespaceIndexJson.path;
|
|
498
|
+
const notFound = namespaceRouteConfig?.notFound ?? namespaceIndexJson.notFound;
|
|
499
|
+
const first = namespaceRouteConfig?.first ?? namespaceIndexJson.first;
|
|
500
|
+
const params = namespaceRouteConfig?.params ?? namespaceIndexJson.params;
|
|
501
|
+
if (typeof namespacePath === 'string' && namespacePath) {
|
|
502
|
+
path2 = normalizePath(namespacePath);
|
|
503
|
+
}
|
|
504
|
+
if (typeof notFound === 'string' && notFound) {
|
|
505
|
+
notFound2 = normalizePath(notFound);
|
|
506
|
+
}
|
|
507
|
+
if (typeof first === 'string' && first) {
|
|
508
|
+
first2 = normalizePath(first);
|
|
509
|
+
if (first2.startsWith('/')) {
|
|
510
|
+
first2 = first2.slice(1);
|
|
415
511
|
}
|
|
416
512
|
}
|
|
513
|
+
if (params) {
|
|
514
|
+
params2 = params;
|
|
515
|
+
}
|
|
417
516
|
const routeTree = buildWebRouteTree(pages);
|
|
418
|
-
const pageChildren = getValidWebRouteChildren(routeTree, ns, params2).map((child) => makeWebRoutesFromTreeNode(child, ns, params2, projectDir, routerFileDir, options?.useOutlet));
|
|
517
|
+
const pageChildren = getValidWebRouteChildren(routeTree, ns, params2).map((child) => makeWebRoutesFromTreeNode(child, ns, path2, packageName, params2, projectDir, routerFileDir, options?.useOutlet));
|
|
419
518
|
const children = [...pageChildren];
|
|
420
519
|
if (routeTree.page) {
|
|
421
520
|
const rootPagePath = getPageRoutePath(routeTree, routeTree.page, params2);
|
|
422
521
|
const rootFullPath = routeTree.page.path;
|
|
423
522
|
if (options?.useOutlet && pageChildren.length > 0) {
|
|
424
523
|
children.length = 0;
|
|
425
|
-
children.push(createWebPageRouteExpression(ns, routeTree.page, projectDir, routerFileDir, rootPagePath, rootFullPath, {
|
|
524
|
+
children.push(createWebPageRouteExpression(ns, path2, packageName, routeTree.page, projectDir, routerFileDir, rootPagePath, rootFullPath, {
|
|
426
525
|
children: pageChildren,
|
|
427
526
|
}));
|
|
428
527
|
}
|
|
429
528
|
else if (!rootPagePath) {
|
|
430
|
-
children.unshift(createWebPageRouteExpression(ns, routeTree.page, projectDir, routerFileDir, rootPagePath, rootFullPath, {
|
|
529
|
+
children.unshift(createWebPageRouteExpression(ns, path2, packageName, routeTree.page, projectDir, routerFileDir, rootPagePath, rootFullPath, {
|
|
431
530
|
isFirst: true,
|
|
432
531
|
}));
|
|
433
532
|
}
|
|
434
533
|
else {
|
|
435
|
-
children.unshift(createWebPageRouteExpression(ns, routeTree.page, projectDir, routerFileDir, rootPagePath, rootFullPath));
|
|
534
|
+
children.unshift(createWebPageRouteExpression(ns, path2, packageName, routeTree.page, projectDir, routerFileDir, rootPagePath, rootFullPath));
|
|
436
535
|
}
|
|
437
536
|
}
|
|
438
537
|
const firstPage = Object.values(pages).find((page) => page.hasWeb && page.path === first2);
|
|
439
538
|
if (firstPage) {
|
|
440
|
-
children.push(createWebPageRouteExpression(ns, firstPage, projectDir, routerFileDir, '', firstPage.path, {
|
|
539
|
+
children.push(createWebPageRouteExpression(ns, path2, packageName, firstPage, projectDir, routerFileDir, '', firstPage.path, {
|
|
441
540
|
isFirst: true,
|
|
442
541
|
}));
|
|
443
542
|
}
|
|
444
543
|
if (notFound2) {
|
|
544
|
+
const notFoundPage = pages[notFound2];
|
|
545
|
+
const notFoundMetaPage = notFoundPage || {
|
|
546
|
+
path: notFound2,
|
|
547
|
+
oakDisablePulldownRefresh: false,
|
|
548
|
+
hasWeb: true,
|
|
549
|
+
hasNative: false,
|
|
550
|
+
hasWechatMp: false,
|
|
551
|
+
};
|
|
445
552
|
children.push(factory.createObjectLiteralExpression([
|
|
446
553
|
factory.createPropertyAssignment('path', factory.createStringLiteral('*')),
|
|
447
554
|
factory.createPropertyAssignment('namespace', factory.createStringLiteral(ns)),
|
|
555
|
+
factory.createPropertyAssignment('namespaceKey', factory.createStringLiteral(ns)),
|
|
556
|
+
factory.createPropertyAssignment('namespacePath', factory.createStringLiteral(path2)),
|
|
448
557
|
factory.createPropertyAssignment('fullPath', factory.createStringLiteral(notFound2)),
|
|
558
|
+
factory.createPropertyAssignment('meta', createWebRouteMetaExpression(notFoundMetaPage, createPageTitleI18nKey(packageName, ns, notFound2))),
|
|
449
559
|
factory.createPropertyAssignment(factory.createIdentifier("Component"), createLazyImportExpression(normalizePath(relative(routerFileDir, join(projectDir, 'src', 'pages', ns, notFound2)))))
|
|
450
560
|
], true));
|
|
451
561
|
}
|
|
452
562
|
return factory.createObjectLiteralExpression([
|
|
453
563
|
factory.createPropertyAssignment('path', factory.createStringLiteral(path2)),
|
|
454
564
|
factory.createPropertyAssignment('namespace', factory.createStringLiteral(path2)),
|
|
455
|
-
factory.createPropertyAssignment(factory.
|
|
565
|
+
factory.createPropertyAssignment('namespaceKey', factory.createStringLiteral(ns)),
|
|
566
|
+
factory.createPropertyAssignment('namespacePath', factory.createStringLiteral(path2)),
|
|
567
|
+
factory.createPropertyAssignment(factory.createIdentifier("Component"), createLazyImportExpression(normalizePath(relative(routerFileDir, nsDirectory)))),
|
|
456
568
|
factory.createPropertyAssignment('children', factory.createArrayLiteralExpression(children))
|
|
457
569
|
], true);
|
|
458
570
|
}), true);
|
|
@@ -632,7 +744,7 @@ function watchDir(projectDir, startupDir, type) {
|
|
|
632
744
|
BuildRouterContext.watchHandles.push(handle);
|
|
633
745
|
}
|
|
634
746
|
};
|
|
635
|
-
if (startupDir
|
|
747
|
+
if (isWebStartupDir(startupDir)) {
|
|
636
748
|
const srcAppDir = join(projectDir, startupDir, 'src', 'app');
|
|
637
749
|
const namespaceDir = join(srcAppDir, 'namespaces');
|
|
638
750
|
const tryOutputAppDir = (ns) => {
|
|
@@ -715,11 +827,11 @@ export function buildRouter(projectDir, startupDir, watch, options) {
|
|
|
715
827
|
BuildRouterContext.options = options;
|
|
716
828
|
BuildRouterContext.warnedInvalidDirs = new Set();
|
|
717
829
|
BuildRouterContext.warnedRouteConflicts = new Set();
|
|
718
|
-
const type = startupDir
|
|
830
|
+
const type = isWebStartupDir(startupDir) ? 'web' : (startupDir.startsWith('native') ? 'native' : 'wechatMp');
|
|
719
831
|
traversePageDir(projectDir, type);
|
|
720
832
|
const subDir = readdirSync(projectDir);
|
|
721
833
|
assert(subDir.includes(startupDir));
|
|
722
|
-
if (startupDir
|
|
834
|
+
if (isWebStartupDir(startupDir)) {
|
|
723
835
|
outputInWebDir(join(projectDir, startupDir));
|
|
724
836
|
}
|
|
725
837
|
// todo native
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
|
-
import { CompilerOutputOptions } from
|
|
2
|
+
import { CompilerOutputOptions } from "./env";
|
|
3
|
+
export type SchemaBuilderProjectOptions = {
|
|
4
|
+
pwd: string;
|
|
5
|
+
configFile?: string;
|
|
6
|
+
};
|
|
3
7
|
declare const Schema: Record<string, {
|
|
4
8
|
schemaAttrs: Array<ts.PropertySignature>;
|
|
5
9
|
fulltextIndex?: true;
|
|
@@ -13,6 +17,7 @@ declare const Schema: Record<string, {
|
|
|
13
17
|
static: boolean;
|
|
14
18
|
recursiveDepth?: number;
|
|
15
19
|
style?: StaticLiteralObject;
|
|
20
|
+
localizedContent?: ParsedLocalizedContentConfig;
|
|
16
21
|
inModi: boolean;
|
|
17
22
|
relations: false | string[];
|
|
18
23
|
extendsFrom: string[];
|
|
@@ -43,6 +48,7 @@ type ParsedIndexConfig = {
|
|
|
43
48
|
parser?: string;
|
|
44
49
|
tsConfig?: string | string[];
|
|
45
50
|
chineseParser?: string;
|
|
51
|
+
include?: string[];
|
|
46
52
|
};
|
|
47
53
|
type ParsedIndex = {
|
|
48
54
|
name: string;
|
|
@@ -53,6 +59,10 @@ type ParsedIndex = {
|
|
|
53
59
|
attributeKey: string;
|
|
54
60
|
origin: MetadataOrigin;
|
|
55
61
|
};
|
|
62
|
+
type ParsedLocalizedContentConfig = {
|
|
63
|
+
attributes: string[];
|
|
64
|
+
sourceLanguage?: string;
|
|
65
|
+
};
|
|
56
66
|
export declare function constructAttributes(entity: string): ts.PropertyAssignment[];
|
|
57
67
|
export declare function translateLocaleObject(locale: ts.ObjectLiteralExpression): LocaleObject;
|
|
58
68
|
/**
|
|
@@ -81,7 +91,7 @@ export declare function registerFixedDestinationPathMap(map: Record<string, stri
|
|
|
81
91
|
*/
|
|
82
92
|
export declare function registerDeducedRelationMap(map: Record<string, string>): void;
|
|
83
93
|
export declare const getAnalizedSchema: () => typeof Schema;
|
|
84
|
-
export declare function analyzeEntities(inputDir: string, relativePath?: string, options?: CompilerOutputOptions): void;
|
|
94
|
+
export declare function analyzeEntities(inputDir: string, relativePath?: string, options?: CompilerOutputOptions, projectOptions?: SchemaBuilderProjectOptions): void;
|
|
85
95
|
export declare function getProjectionKeys(entity: string): string[];
|
|
86
96
|
export declare function buildSchema(outputDir: string, options?: CompilerOutputOptions): void;
|
|
87
97
|
export {};
|