@dcl-regenesislabs/sdk-commands 0.0.0-stage → 7.0.0-42707159203.commit-ff138cd
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/.dclrc +19 -0
- package/LICENSE +201 -0
- package/README.md +106 -2
- package/dist/commands/build/index.d.ts +23 -0
- package/dist/commands/build/index.js +80 -0
- package/dist/commands/build/index.js.map +1 -0
- package/dist/commands/code-to-composite/asset-migrator.d.ts +25 -0
- package/dist/commands/code-to-composite/asset-migrator.js +238 -0
- package/dist/commands/code-to-composite/asset-migrator.js.map +1 -0
- package/dist/commands/code-to-composite/code-commenter.d.ts +11 -0
- package/dist/commands/code-to-composite/code-commenter.js +87 -0
- package/dist/commands/code-to-composite/code-commenter.js.map +1 -0
- package/dist/commands/code-to-composite/composite-generator.d.ts +6 -0
- package/dist/commands/code-to-composite/composite-generator.js +65 -0
- package/dist/commands/code-to-composite/composite-generator.js.map +1 -0
- package/dist/commands/code-to-composite/index.d.ts +16 -0
- package/dist/commands/code-to-composite/index.js +130 -0
- package/dist/commands/code-to-composite/index.js.map +1 -0
- package/dist/commands/code-to-composite/name-generator.d.ts +9 -0
- package/dist/commands/code-to-composite/name-generator.js +139 -0
- package/dist/commands/code-to-composite/name-generator.js.map +1 -0
- package/dist/commands/code-to-composite/scene-executor.d.ts +15 -0
- package/dist/commands/code-to-composite/scene-executor.js +421 -0
- package/dist/commands/code-to-composite/scene-executor.js.map +1 -0
- package/dist/commands/deploy/analytics-features.d.ts +4 -0
- package/dist/commands/deploy/analytics-features.js +11 -0
- package/dist/commands/deploy/analytics-features.js.map +1 -0
- package/dist/commands/deploy/deployment.d.ts +51 -0
- package/dist/commands/deploy/deployment.js +122 -0
- package/dist/commands/deploy/deployment.js.map +1 -0
- package/dist/commands/deploy/index.d.ts +37 -0
- package/dist/commands/deploy/index.js +312 -0
- package/dist/commands/deploy/index.js.map +1 -0
- package/dist/commands/deploy/routes.d.ts +27 -0
- package/dist/commands/deploy/routes.js +144 -0
- package/dist/commands/deploy/routes.js.map +1 -0
- package/dist/commands/deploy/state.d.ts +60 -0
- package/dist/commands/deploy/state.js +144 -0
- package/dist/commands/deploy/state.js.map +1 -0
- package/dist/commands/deploy/upload.d.ts +23 -0
- package/dist/commands/deploy/upload.js +120 -0
- package/dist/commands/deploy/upload.js.map +1 -0
- package/dist/commands/deploy/utils.d.ts +131 -0
- package/dist/commands/deploy/utils.js +432 -0
- package/dist/commands/deploy/utils.js.map +1 -0
- package/dist/commands/export-static/index.d.ts +27 -0
- package/dist/commands/export-static/index.js +155 -0
- package/dist/commands/export-static/index.js.map +1 -0
- package/dist/commands/get-context-files/index.d.ts +12 -0
- package/dist/commands/get-context-files/index.js +119 -0
- package/dist/commands/get-context-files/index.js.map +1 -0
- package/dist/commands/init/download-github-folder.d.ts +2 -0
- package/dist/commands/init/download-github-folder.js +69 -0
- package/dist/commands/init/download-github-folder.js.map +1 -0
- package/dist/commands/init/index.d.ts +18 -0
- package/dist/commands/init/index.js +98 -0
- package/dist/commands/init/index.js.map +1 -0
- package/dist/commands/init/project.d.ts +7 -0
- package/dist/commands/init/project.js +36 -0
- package/dist/commands/init/project.js.map +1 -0
- package/dist/commands/init/repos.d.ts +4 -0
- package/dist/commands/init/repos.js +21 -0
- package/dist/commands/init/repos.js.map +1 -0
- package/dist/commands/pack-smart-wearable/index.d.ts +16 -0
- package/dist/commands/pack-smart-wearable/index.js +108 -0
- package/dist/commands/pack-smart-wearable/index.js.map +1 -0
- package/dist/commands/quests/index.d.ts +28 -0
- package/dist/commands/quests/index.js +271 -0
- package/dist/commands/quests/index.js.map +1 -0
- package/dist/commands/quests/types.d.ts +41 -0
- package/dist/commands/quests/types.js +3 -0
- package/dist/commands/quests/types.js.map +1 -0
- package/dist/commands/quests/utils.d.ts +20 -0
- package/dist/commands/quests/utils.js +253 -0
- package/dist/commands/quests/utils.js.map +1 -0
- package/dist/commands/start/data-layer/fs.d.ts +8 -0
- package/dist/commands/start/data-layer/fs.js +73 -0
- package/dist/commands/start/data-layer/fs.js.map +1 -0
- package/dist/commands/start/data-layer/rpc.d.ts +8 -0
- package/dist/commands/start/data-layer/rpc.js +54 -0
- package/dist/commands/start/data-layer/rpc.js.map +1 -0
- package/dist/commands/start/data-layer/ws.d.ts +4 -0
- package/dist/commands/start/data-layer/ws.js +17 -0
- package/dist/commands/start/data-layer/ws.js.map +1 -0
- package/dist/commands/start/explorer-alpha.d.ts +19 -0
- package/dist/commands/start/explorer-alpha.js +109 -0
- package/dist/commands/start/explorer-alpha.js.map +1 -0
- package/dist/commands/start/index.d.ts +46 -0
- package/dist/commands/start/index.js +300 -0
- package/dist/commands/start/index.js.map +1 -0
- package/dist/commands/start/server/endpoints.d.ts +5 -0
- package/dist/commands/start/server/endpoints.js +417 -0
- package/dist/commands/start/server/endpoints.js.map +1 -0
- package/dist/commands/start/server/file-watch-notifier.d.ts +12 -0
- package/dist/commands/start/server/file-watch-notifier.js +96 -0
- package/dist/commands/start/server/file-watch-notifier.js.map +1 -0
- package/dist/commands/start/server/realm.d.ts +7 -0
- package/dist/commands/start/server/realm.js +58 -0
- package/dist/commands/start/server/realm.js.map +1 -0
- package/dist/commands/start/server/routes.d.ts +6 -0
- package/dist/commands/start/server/routes.js +77 -0
- package/dist/commands/start/server/routes.js.map +1 -0
- package/dist/commands/start/server/ws.d.ts +11 -0
- package/dist/commands/start/server/ws.js +19 -0
- package/dist/commands/start/server/ws.js.map +1 -0
- package/dist/commands/start/types.d.ts +16 -0
- package/dist/commands/start/types.js +3 -0
- package/dist/commands/start/types.js.map +1 -0
- package/dist/commands/start/utils.d.ts +8 -0
- package/dist/commands/start/utils.js +57 -0
- package/dist/commands/start/utils.js.map +1 -0
- package/dist/components/analytics.d.ts +105 -0
- package/dist/components/analytics.js +76 -0
- package/dist/components/analytics.js.map +1 -0
- package/dist/components/config.d.ts +18 -0
- package/dist/components/config.js +58 -0
- package/dist/components/config.js.map +1 -0
- package/dist/components/eth.d.ts +2 -0
- package/dist/components/eth.js +6 -0
- package/dist/components/eth.js.map +1 -0
- package/dist/components/exit-signal.d.ts +5 -0
- package/dist/components/exit-signal.js +21 -0
- package/dist/components/exit-signal.js.map +1 -0
- package/dist/components/fetch.d.ts +6 -0
- package/dist/components/fetch.js +9 -0
- package/dist/components/fetch.js.map +1 -0
- package/dist/components/fs.d.ts +18 -0
- package/dist/components/fs.js +85 -0
- package/dist/components/fs.js.map +1 -0
- package/dist/components/index.d.ts +14 -0
- package/dist/components/index.js +25 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/log.d.ts +24 -0
- package/dist/components/log.js +67 -0
- package/dist/components/log.js.map +1 -0
- package/dist/generated/decentraland/common/border_rect.gen.d.ts +49 -0
- package/dist/generated/decentraland/common/border_rect.gen.js +199 -0
- package/dist/generated/decentraland/common/border_rect.gen.js.map +1 -0
- package/dist/generated/decentraland/common/vectors.gen.d.ts +71 -0
- package/dist/generated/decentraland/common/vectors.gen.js +334 -0
- package/dist/generated/decentraland/common/vectors.gen.js.map +1 -0
- package/dist/generated/decentraland/realm/about.gen.d.ts +229 -0
- package/dist/generated/decentraland/realm/about.gen.js +1175 -0
- package/dist/generated/decentraland/realm/about.gen.js.map +1 -0
- package/dist/generated/decentraland/sdk/development/local_development.gen.d.ts +70 -0
- package/dist/generated/decentraland/sdk/development/local_development.gen.js +278 -0
- package/dist/generated/decentraland/sdk/development/local_development.gen.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/linker-dapp/routes.d.ts +32 -0
- package/dist/linker-dapp/routes.js +140 -0
- package/dist/linker-dapp/routes.js.map +1 -0
- package/dist/locales/en.json +84 -0
- package/dist/locales/es.json +84 -0
- package/dist/locales/zh.json +84 -0
- package/dist/logic/account.d.ts +6 -0
- package/dist/logic/account.js +25 -0
- package/dist/logic/account.js.map +1 -0
- package/dist/logic/args.d.ts +6 -0
- package/dist/logic/args.js +25 -0
- package/dist/logic/args.js.map +1 -0
- package/dist/logic/beautiful-logs.d.ts +14 -0
- package/dist/logic/beautiful-logs.js +55 -0
- package/dist/logic/beautiful-logs.js.map +1 -0
- package/dist/logic/bundle.d.ts +47 -0
- package/dist/logic/bundle.js +573 -0
- package/dist/logic/bundle.js.map +1 -0
- package/dist/logic/catalyst-requests.d.ts +20 -0
- package/dist/logic/catalyst-requests.js +54 -0
- package/dist/logic/catalyst-requests.js.map +1 -0
- package/dist/logic/commands.d.ts +3 -0
- package/dist/logic/commands.js +30 -0
- package/dist/logic/commands.js.map +1 -0
- package/dist/logic/composite.d.ts +15 -0
- package/dist/logic/composite.js +105 -0
- package/dist/logic/composite.js.map +1 -0
- package/dist/logic/config.d.ts +24 -0
- package/dist/logic/config.js +88 -0
- package/dist/logic/config.js.map +1 -0
- package/dist/logic/coordinates.d.ts +14 -0
- package/dist/logic/coordinates.js +31 -0
- package/dist/logic/coordinates.js.map +1 -0
- package/dist/logic/dcl-ignore.d.ts +8 -0
- package/dist/logic/dcl-ignore.js +53 -0
- package/dist/logic/dcl-ignore.js.map +1 -0
- package/dist/logic/debounce.d.ts +1 -0
- package/dist/logic/debounce.js +11 -0
- package/dist/logic/debounce.js.map +1 -0
- package/dist/logic/error.d.ts +7 -0
- package/dist/logic/error.js +13 -0
- package/dist/logic/error.js.map +1 -0
- package/dist/logic/exec.d.ts +12 -0
- package/dist/logic/exec.js +40 -0
- package/dist/logic/exec.js.map +1 -0
- package/dist/logic/fetch.d.ts +25 -0
- package/dist/logic/fetch.js +42 -0
- package/dist/logic/fetch.js.map +1 -0
- package/dist/logic/fs.d.ts +33 -0
- package/dist/logic/fs.js +57 -0
- package/dist/logic/fs.js.map +1 -0
- package/dist/logic/future.d.ts +6 -0
- package/dist/logic/future.js +14 -0
- package/dist/logic/future.js.map +1 -0
- package/dist/logic/get-free-port.d.ts +1 -0
- package/dist/logic/get-free-port.js +70 -0
- package/dist/logic/get-free-port.js.map +1 -0
- package/dist/logic/lang.d.ts +7 -0
- package/dist/logic/lang.js +41 -0
- package/dist/logic/lang.js.map +1 -0
- package/dist/logic/open.d.ts +1 -0
- package/dist/logic/open.js +41 -0
- package/dist/logic/open.js.map +1 -0
- package/dist/logic/portable-experience-sw-validations.d.ts +18 -0
- package/dist/logic/portable-experience-sw-validations.js +48 -0
- package/dist/logic/portable-experience-sw-validations.js.map +1 -0
- package/dist/logic/project-files.d.ts +40 -0
- package/dist/logic/project-files.js +158 -0
- package/dist/logic/project-files.js.map +1 -0
- package/dist/logic/project-validations.d.ts +45 -0
- package/dist/logic/project-validations.js +143 -0
- package/dist/logic/project-validations.js.map +1 -0
- package/dist/logic/promise-utils.d.ts +1 -0
- package/dist/logic/promise-utils.js +20 -0
- package/dist/logic/promise-utils.js.map +1 -0
- package/dist/logic/prompts.d.ts +23 -0
- package/dist/logic/prompts.js +74 -0
- package/dist/logic/prompts.js.map +1 -0
- package/dist/logic/realm.d.ts +3 -0
- package/dist/logic/realm.js +32 -0
- package/dist/logic/realm.js.map +1 -0
- package/dist/logic/runtime-script.d.ts +42 -0
- package/dist/logic/runtime-script.js +217 -0
- package/dist/logic/runtime-script.js.map +1 -0
- package/dist/logic/runtime-script.ts +270 -0
- package/dist/logic/scene-validations.d.ts +35 -0
- package/dist/logic/scene-validations.js +135 -0
- package/dist/logic/scene-validations.js.map +1 -0
- package/dist/logic/script-module.d.ts.template +87 -0
- package/dist/logic/workspace-validations.d.ts +27 -0
- package/dist/logic/workspace-validations.js +136 -0
- package/dist/logic/workspace-validations.js.map +1 -0
- package/dist/run-command.d.ts +7 -0
- package/dist/run-command.js +95 -0
- package/dist/run-command.js.map +1 -0
- package/dist/run-dapp.d.ts +23 -0
- package/dist/run-dapp.js +66 -0
- package/dist/run-dapp.js.map +1 -0
- package/package.json +74 -3
- package/scripts/postinstall.js +17 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import type { IEngine, Entity, EntityState } from '@dcl/ecs'
|
|
3
|
+
import type { ActionRef } from '@dcl/inspector/node_modules/@dcl/asset-packs'
|
|
4
|
+
import { getActionEvents } from '@dcl/inspector/node_modules/@dcl/asset-packs/dist/events'
|
|
5
|
+
|
|
6
|
+
declare global {
|
|
7
|
+
// eslint-disable-next-line no-var
|
|
8
|
+
var __DCL_SCRIPT_INSTANCES__: Map<string, { instance: any; entity: Entity; path: string }>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (!globalThis.__DCL_SCRIPT_INSTANCES__) {
|
|
12
|
+
globalThis.__DCL_SCRIPT_INSTANCES__ = new Map()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type ScriptParam = {
|
|
16
|
+
type?: string
|
|
17
|
+
value: unknown
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ScriptLayout = {
|
|
21
|
+
params?: Record<string, ScriptParam>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type Script = {
|
|
25
|
+
entity: Entity
|
|
26
|
+
path: string
|
|
27
|
+
priority: number
|
|
28
|
+
layout?: string
|
|
29
|
+
module: FunctionalScriptModule | Record<string, unknown>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type ScriptWithKey = Script & {
|
|
33
|
+
key: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type FunctionalScriptModule = {
|
|
37
|
+
start?: (src: string, entity: Entity, ...params: unknown[]) => void
|
|
38
|
+
update?: (src: string, entity: Entity, dt: number, ...params: unknown[]) => void
|
|
39
|
+
[key: string]: unknown
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type ScriptClassInstance = {
|
|
43
|
+
start?: () => void
|
|
44
|
+
update?: (dt: number) => void
|
|
45
|
+
[key: string]: unknown
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type ScriptClass = new (src: string, entity: Entity, ...params: unknown[]) => ScriptClassInstance
|
|
49
|
+
type ScriptsByPriority = Record<number, ScriptWithKey[]>
|
|
50
|
+
|
|
51
|
+
// compiler-checked literal: the @dcl/ecs d.ts pins EntityState.Removed = 2, so drift fails this build with TS2322; a value import would embed ecs runtime code into every scene bundle
|
|
52
|
+
const ENTITY_STATE_REMOVED: EntityState.Removed = 2
|
|
53
|
+
|
|
54
|
+
function entityIsRemoved(engine: IEngine, entity: Entity) {
|
|
55
|
+
return engine.getEntityState(entity) === ENTITY_STATE_REMOVED
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get a specific script instance by entity and script path.
|
|
60
|
+
* @param entity - The entity ID
|
|
61
|
+
* @param scriptPath - The script file path
|
|
62
|
+
* @returns The script instance or null if not found
|
|
63
|
+
*/
|
|
64
|
+
export function getScriptInstance(entity: Entity, scriptPath: string): any {
|
|
65
|
+
const key = `${entity}:${scriptPath}`
|
|
66
|
+
const entry = globalThis.__DCL_SCRIPT_INSTANCES__.get(key)
|
|
67
|
+
return entry?.instance || null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get all instances of a specific script (across all entities).
|
|
72
|
+
* @param scriptPath - The script file path
|
|
73
|
+
* @returns Array of { entity, instance } objects
|
|
74
|
+
*/
|
|
75
|
+
export function getScriptInstancesByPath(scriptPath: string): Array<{ entity: Entity; instance: any }> {
|
|
76
|
+
const results: Array<{ entity: Entity; instance: any }> = []
|
|
77
|
+
for (const [_, value] of globalThis.__DCL_SCRIPT_INSTANCES__) {
|
|
78
|
+
if (value.path === scriptPath) {
|
|
79
|
+
results.push({ entity: value.entity, instance: value.instance })
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return results
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get all script instances attached to a specific entity
|
|
87
|
+
* @param entity - The entity ID
|
|
88
|
+
* @returns Array of { path, instance } objects
|
|
89
|
+
*/
|
|
90
|
+
export function getAllScriptInstances(entity: Entity): Array<{ path: string; instance: any }> {
|
|
91
|
+
const results: Array<{ path: string; instance: any }> = []
|
|
92
|
+
for (const [_, value] of globalThis.__DCL_SCRIPT_INSTANCES__) {
|
|
93
|
+
if (value.entity === entity) {
|
|
94
|
+
results.push({ path: value.path, instance: value.instance })
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return results
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Call a method on a script instance (with safety checks).
|
|
102
|
+
* @param entity - The entity ID
|
|
103
|
+
* @param scriptPath - The script file path
|
|
104
|
+
* @param methodName - The method name to call
|
|
105
|
+
* @param args - Arguments to pass to the method
|
|
106
|
+
* @returns The method's return value or undefined if method not found
|
|
107
|
+
*/
|
|
108
|
+
export function callScriptMethod(entity: Entity, scriptPath: string, methodName: string, ...args: any[]): any {
|
|
109
|
+
const instance = getScriptInstance(entity, scriptPath)
|
|
110
|
+
if (instance && typeof instance[methodName] === 'function') {
|
|
111
|
+
return instance[methodName](...args)
|
|
112
|
+
}
|
|
113
|
+
console.error(`Method ${methodName} not found on script ${scriptPath} for entity ${entity}`)
|
|
114
|
+
return undefined
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Creates an ActionCallback function from an ActionRef.
|
|
119
|
+
* The returned function, when called, will trigger the specified action on the entity.
|
|
120
|
+
*
|
|
121
|
+
* Validation happens here, at resolution time, not inside the returned closure: an
|
|
122
|
+
* unassigned optional action param is stored by the editor as a truthy placeholder
|
|
123
|
+
* ({ entity: RootEntity (0), action: '' }), so validating at call time would still hand
|
|
124
|
+
* the script a callable and make its `if (this.onAction)` guard always pass. Returning
|
|
125
|
+
* undefined for an unwired ref lets that guard work as intended.
|
|
126
|
+
*
|
|
127
|
+
* @param actionRef - The action reference containing entity and action name
|
|
128
|
+
* @returns A function that triggers the action when called, or undefined if the ref is unwired
|
|
129
|
+
*/
|
|
130
|
+
function createActionCallback(actionRef: ActionRef): (() => void) | undefined {
|
|
131
|
+
if (!actionRef.entity || !actionRef.action) return undefined
|
|
132
|
+
return () => {
|
|
133
|
+
const actionEvents = getActionEvents(actionRef.entity)
|
|
134
|
+
actionEvents.emit(actionRef.action, {})
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolves script parameters, converting ActionRef values to ActionCallback functions.
|
|
140
|
+
*
|
|
141
|
+
* @param params - The raw parameters from the script layout
|
|
142
|
+
* @returns Array of resolved parameter values
|
|
143
|
+
*/
|
|
144
|
+
function resolveScriptParams(params: Record<string, ScriptParam>): unknown[] {
|
|
145
|
+
return Object.values(params).map((param) => {
|
|
146
|
+
if (param.type === 'action' && param.value && typeof param.value === 'object') {
|
|
147
|
+
const actionRef = param.value as ActionRef
|
|
148
|
+
return createActionCallback(actionRef)
|
|
149
|
+
}
|
|
150
|
+
return param.value
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Initializes and runs all scripts organized by priority.
|
|
156
|
+
* Supports both functional-style scripts (with start/update functions) and class-based scripts.
|
|
157
|
+
* Scripts are extracted at build time from composites.
|
|
158
|
+
*
|
|
159
|
+
* @internal This function is called automatically by the SDK entry point.
|
|
160
|
+
* Users should not call this function directly.
|
|
161
|
+
*
|
|
162
|
+
* @param engine - The ECS engine instance
|
|
163
|
+
* @param scripts - Scripts with their modules, extracted at build time
|
|
164
|
+
*/
|
|
165
|
+
export function runScripts(engine: IEngine, scripts: Script[]) {
|
|
166
|
+
const scriptsByPriority = groupScriptsByPriority(scripts)
|
|
167
|
+
const classInstances = new Map<string, { instance: ScriptClassInstance; entity: Entity }>()
|
|
168
|
+
const functionScripts = new Map<
|
|
169
|
+
string,
|
|
170
|
+
{ src: string; module: FunctionalScriptModule; entity: Entity; params: unknown[] }
|
|
171
|
+
>()
|
|
172
|
+
|
|
173
|
+
for (const [priority, instances] of Object.entries(scriptsByPriority)) {
|
|
174
|
+
for (const script of instances) {
|
|
175
|
+
if (entityIsRemoved(engine, script.entity)) continue
|
|
176
|
+
|
|
177
|
+
const module = script.module
|
|
178
|
+
if (!module) {
|
|
179
|
+
console.error('[Script] Unknown module:', script.path)
|
|
180
|
+
continue
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const src = script.path.split('/').slice(0, -1).join('/')
|
|
184
|
+
const layout: ScriptLayout = script.layout ? JSON.parse(script.layout) : {}
|
|
185
|
+
const params = resolveScriptParams(layout.params || {})
|
|
186
|
+
const registryKey = `${script.entity}:${script.path}`
|
|
187
|
+
|
|
188
|
+
if (typeof module.start === 'function') {
|
|
189
|
+
try {
|
|
190
|
+
module.start(src, script.entity, ...params)
|
|
191
|
+
} catch (e: unknown) {
|
|
192
|
+
console.error('[Script Error] ' + script.path + ' start() failed:', e)
|
|
193
|
+
throw e
|
|
194
|
+
}
|
|
195
|
+
functionScripts.set(script.key, {
|
|
196
|
+
src,
|
|
197
|
+
module: module as FunctionalScriptModule,
|
|
198
|
+
entity: script.entity,
|
|
199
|
+
params
|
|
200
|
+
})
|
|
201
|
+
globalThis.__DCL_SCRIPT_INSTANCES__.set(registryKey, {
|
|
202
|
+
instance: module,
|
|
203
|
+
entity: script.entity,
|
|
204
|
+
path: script.path
|
|
205
|
+
})
|
|
206
|
+
} else {
|
|
207
|
+
const ScriptClass = Object.values(module).find((exp) => typeof exp === 'function') as ScriptClass | undefined
|
|
208
|
+
if (!ScriptClass) {
|
|
209
|
+
console.error('[Script] No class found in module:', script.path)
|
|
210
|
+
continue
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
const instance = new ScriptClass(src, script.entity, ...params)
|
|
215
|
+
if (typeof instance.start === 'function') {
|
|
216
|
+
instance.start()
|
|
217
|
+
}
|
|
218
|
+
classInstances.set(script.key, { instance, entity: script.entity })
|
|
219
|
+
globalThis.__DCL_SCRIPT_INSTANCES__.set(registryKey, {
|
|
220
|
+
instance: instance,
|
|
221
|
+
entity: script.entity,
|
|
222
|
+
path: script.path
|
|
223
|
+
})
|
|
224
|
+
} catch (e: unknown) {
|
|
225
|
+
console.error('[Script Error] ' + script.path + ' class initialization failed:', e)
|
|
226
|
+
throw e
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
engine.addSystem((dt: number) => {
|
|
232
|
+
for (const scriptData of instances) {
|
|
233
|
+
try {
|
|
234
|
+
const classInstance = classInstances.get(scriptData.key)
|
|
235
|
+
if (classInstance && !entityIsRemoved(engine, classInstance.entity)) {
|
|
236
|
+
if (typeof classInstance.instance.update === 'function') {
|
|
237
|
+
classInstance.instance.update(dt)
|
|
238
|
+
}
|
|
239
|
+
} else {
|
|
240
|
+
const functionScript = functionScripts.get(scriptData.key)
|
|
241
|
+
if (functionScript && !entityIsRemoved(engine, functionScript.entity)) {
|
|
242
|
+
if (typeof functionScript.module.update === 'function') {
|
|
243
|
+
functionScript.module.update(functionScript.src, functionScript.entity, dt, ...functionScript.params)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} catch (e: unknown) {
|
|
248
|
+
console.error('[Script Error] update() failed:', e)
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}, Number(priority))
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function groupScriptsByPriority(scripts: Script[]): ScriptsByPriority {
|
|
256
|
+
const scriptsByPriority: ScriptsByPriority = {}
|
|
257
|
+
|
|
258
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
259
|
+
const script = scripts[i]
|
|
260
|
+
const key = `${script.entity}:${script.path}:${i}`
|
|
261
|
+
|
|
262
|
+
if (!scriptsByPriority[script.priority]) {
|
|
263
|
+
scriptsByPriority[script.priority] = []
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
scriptsByPriority[script.priority].push({ ...script, key })
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return scriptsByPriority
|
|
270
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Scene } from '@dcl/schemas';
|
|
2
|
+
import { CliComponents } from '../components';
|
|
3
|
+
export interface IFile {
|
|
4
|
+
path: string;
|
|
5
|
+
content: Buffer;
|
|
6
|
+
size: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const SCENE_FILE = "scene.json";
|
|
9
|
+
export declare const MAX_FILE_SIZE_BYTES: number;
|
|
10
|
+
/**
|
|
11
|
+
* Composes the path to the `scene.json` file based on the provided path.
|
|
12
|
+
* @param projectRoot The path to the directory containing the scene file.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getSceneFilePath(projectRoot: string): string;
|
|
15
|
+
export declare function assertValidScene(components: Pick<CliComponents, 'logger'>, scene: Scene, opts?: {
|
|
16
|
+
log?: boolean;
|
|
17
|
+
}): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get valid Scene JSON
|
|
20
|
+
*/
|
|
21
|
+
export declare function getValidSceneJson(components: Pick<CliComponents, 'fs' | 'logger'>, projectRoot: string, opts?: {
|
|
22
|
+
log?: boolean;
|
|
23
|
+
}): Promise<Scene>;
|
|
24
|
+
export declare function getBaseCoords(scene: Scene): {
|
|
25
|
+
x: number;
|
|
26
|
+
y: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Returns a promise of an array of objects containing the path and the content for all the files in the project.
|
|
30
|
+
* All the paths added to the `.dclignore` file will be excluded from the results.
|
|
31
|
+
* Windows directory separators are replaced for POSIX separators.
|
|
32
|
+
* @param ignoreFile The contents of the .dclignore file
|
|
33
|
+
*/
|
|
34
|
+
export declare function getFiles(components: Pick<CliComponents, 'fs' | 'logger'>, dir: string): Promise<IFile[]>;
|
|
35
|
+
export declare function validateFilesSizes(files: IFile[]): void;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MAX_FILE_SIZE_BYTES = exports.SCENE_FILE = void 0;
|
|
7
|
+
exports.getSceneFilePath = getSceneFilePath;
|
|
8
|
+
exports.assertValidScene = assertValidScene;
|
|
9
|
+
exports.getValidSceneJson = getValidSceneJson;
|
|
10
|
+
exports.getBaseCoords = getBaseCoords;
|
|
11
|
+
exports.getFiles = getFiles;
|
|
12
|
+
exports.validateFilesSizes = validateFilesSizes;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const schemas_1 = require("@dcl/schemas");
|
|
15
|
+
const dist_cjs_1 = require("@dcl/ecs/dist-cjs");
|
|
16
|
+
const i18next_1 = __importDefault(require("i18next"));
|
|
17
|
+
const project_1 = require("../commands/init/project");
|
|
18
|
+
const error_1 = require("./error");
|
|
19
|
+
const coordinates_1 = require("./coordinates");
|
|
20
|
+
const project_files_1 = require("./project-files");
|
|
21
|
+
const beautiful_logs_1 = require("./beautiful-logs");
|
|
22
|
+
const promise_utils_1 = require("./promise-utils");
|
|
23
|
+
exports.SCENE_FILE = 'scene.json';
|
|
24
|
+
exports.MAX_FILE_SIZE_BYTES = 50 * 1e6; // 50mb
|
|
25
|
+
/**
|
|
26
|
+
* Composes the path to the `scene.json` file based on the provided path.
|
|
27
|
+
* @param projectRoot The path to the directory containing the scene file.
|
|
28
|
+
*/
|
|
29
|
+
function getSceneFilePath(projectRoot) {
|
|
30
|
+
return (0, path_1.resolve)(projectRoot, exports.SCENE_FILE);
|
|
31
|
+
}
|
|
32
|
+
function getWorldRangesConstraintsMessage() {
|
|
33
|
+
const ranges = (0, schemas_1.getWorld)().validWorldRanges;
|
|
34
|
+
let str = '';
|
|
35
|
+
for (const range of ranges) {
|
|
36
|
+
str += `"x" from ${range.xMin} to ${range.xMax} and "y" from ${range.yMin} to ${range.yMax}\n`;
|
|
37
|
+
}
|
|
38
|
+
return str;
|
|
39
|
+
}
|
|
40
|
+
function checkMissingOrDefault(obj, defaults) {
|
|
41
|
+
const missingKeys = Object.entries(defaults).reduce((acc, [key, value]) => {
|
|
42
|
+
return obj[key] && obj[key] !== value ? acc : acc.concat(key);
|
|
43
|
+
}, []);
|
|
44
|
+
return missingKeys;
|
|
45
|
+
}
|
|
46
|
+
function assertValidScene(components, scene, opts = { log: false }) {
|
|
47
|
+
if (!schemas_1.Scene.validate(scene)) {
|
|
48
|
+
const errors = [];
|
|
49
|
+
if (schemas_1.Scene.validate.errors) {
|
|
50
|
+
for (const error of schemas_1.Scene.validate.errors) {
|
|
51
|
+
const errorPath = error.instancePath.slice(1).replace(/\//g, ' => ');
|
|
52
|
+
errors.push(`Error validating scene.json: ${errorPath} ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_INVALID_SCENE_JSON', i18next_1.default.t('errors.scene_validations.invalid_scene_json', { errors: errors.join('\n') }));
|
|
56
|
+
}
|
|
57
|
+
const parcelSet = new Set(scene.scene?.parcels);
|
|
58
|
+
if (parcelSet.size < scene.scene?.parcels?.length) {
|
|
59
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_DUPLICATE_PARCELS', i18next_1.default.t('errors.scene_validations.duplicate_parcels'));
|
|
60
|
+
}
|
|
61
|
+
if (!parcelSet.has(scene.scene?.base)) {
|
|
62
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_BASE_PARCEL_REQUIRED', i18next_1.default.t('errors.scene_validations.base_parcel_required', { base: scene.scene?.base }), scene.scene?.base);
|
|
63
|
+
}
|
|
64
|
+
const objParcels = scene.scene?.parcels?.map(coordinates_1.getObject);
|
|
65
|
+
objParcels.forEach(({ x, y }) => {
|
|
66
|
+
if ((0, schemas_1.isInsideWorldLimits)(x, y)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const constraints = getWorldRangesConstraintsMessage();
|
|
70
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_COORDINATES_OUTSIDE_LIMITS', i18next_1.default.t('errors.scene_validations.coordinates_outside_limits', { x, y, constraints }));
|
|
71
|
+
});
|
|
72
|
+
if (!(0, dist_cjs_1.areConnected)(objParcels)) {
|
|
73
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_PARCELS_NOT_CONNECTED', i18next_1.default.t('errors.scene_validations.parcels_not_connected'));
|
|
74
|
+
}
|
|
75
|
+
if (!scene.main?.endsWith('.js')) {
|
|
76
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_INVALID_MAIN_FORMAT', i18next_1.default.t('errors.scene_validations.invalid_main_format', { main: scene.main }), scene.main);
|
|
77
|
+
}
|
|
78
|
+
const minimalScene = (0, project_1.getMinimalSceneJson)();
|
|
79
|
+
const defaults = { ...minimalScene.display, navmapThumbnail: 'images/scene-thumbnail.png' };
|
|
80
|
+
const missingKeys = checkMissingOrDefault(scene.display ?? {}, defaults);
|
|
81
|
+
if (missingKeys.length && opts.log) {
|
|
82
|
+
const missingKeysMsg = missingKeys.join(', ');
|
|
83
|
+
(0, beautiful_logs_1.printWarning)(components.logger, `Don't forget to update your scene.json metadata: [${missingKeysMsg}]
|
|
84
|
+
https://docs.decentraland.org/creator/development-guide/scene-metadata/#scene-title-description-and-image`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get valid Scene JSON
|
|
89
|
+
*/
|
|
90
|
+
async function getValidSceneJson(components, projectRoot, opts) {
|
|
91
|
+
try {
|
|
92
|
+
const sceneJsonRaw = await components.fs.readFile(getSceneFilePath(projectRoot), 'utf8');
|
|
93
|
+
const sceneJson = JSON.parse(sceneJsonRaw);
|
|
94
|
+
assertValidScene(components, sceneJson, opts);
|
|
95
|
+
return sceneJson;
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_INVALID_SCENE_JSON', i18next_1.default.t('errors.scene_validations.invalid_scene_json', { errors: err.message }));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function getBaseCoords(scene) {
|
|
102
|
+
const [x, y] = scene.scene.base
|
|
103
|
+
.replace(/\ /g, '')
|
|
104
|
+
.split(',')
|
|
105
|
+
.map((a) => parseInt(a));
|
|
106
|
+
return { x, y };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns a promise of an array of objects containing the path and the content for all the files in the project.
|
|
110
|
+
* All the paths added to the `.dclignore` file will be excluded from the results.
|
|
111
|
+
* Windows directory separators are replaced for POSIX separators.
|
|
112
|
+
* @param ignoreFile The contents of the .dclignore file
|
|
113
|
+
*/
|
|
114
|
+
async function getFiles(components, dir) {
|
|
115
|
+
const files = await (0, project_files_1.getPublishableFiles)(components, dir);
|
|
116
|
+
return (0, promise_utils_1.concurrentMap)(files, async (file) => {
|
|
117
|
+
const filePath = (0, path_1.resolve)(dir, file);
|
|
118
|
+
const stat = await components.fs.stat(filePath);
|
|
119
|
+
const content = await components.fs.readFile(filePath);
|
|
120
|
+
return {
|
|
121
|
+
path: file.replace(/\\/g, '/'),
|
|
122
|
+
content: Buffer.from(content),
|
|
123
|
+
size: stat.size
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
function validateFilesSizes(files) {
|
|
128
|
+
for (const { path, size } of files) {
|
|
129
|
+
if (size > exports.MAX_FILE_SIZE_BYTES) {
|
|
130
|
+
const maxSizeInMb = exports.MAX_FILE_SIZE_BYTES / 1e6;
|
|
131
|
+
throw new error_1.CliError('SCENE_VALIDATIONS_MAX_FILE_SIZE_EXCEEDED', i18next_1.default.t('errors.scene_validations.max_file_size_exceeded', { path, maxSizeInMb }));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=scene-validations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scene-validations.js","sourceRoot":"","sources":["../../src/logic/scene-validations.ts"],"names":[],"mappings":";;;;;;AA0BA,4CAEC;AAkBD,4CAwEC;AAKD,8CAgBC;AAED,sCAMC;AAQD,4BAaC;AAED,gDAUC;AApLD,+BAA8B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AAE,IAAI,EAAkB,EAAE;QACzD,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACnC,MAAM,IAAI,GAAG,MAAM,UAAU,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QAC/C,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QAEtD,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;YAC9B,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;YAC7B,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,EAAE,CAAC;QACnC,IAAI,IAAI,GAAG,2BAAmB,EAAE,CAAC;YAC/B,MAAM,WAAW,GAAG,2BAAmB,GAAG,GAAG,CAAA;YAC7C,MAAM,IAAI,gBAAQ,CAChB,0CAA0C,EAC1C,iBAAO,CAAC,CAAC,CAAC,iDAAiD,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CACpF,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// @internal
|
|
2
|
+
declare module '~sdk/script-utils' {
|
|
3
|
+
import type { Entity } from '@dcl/ecs/dist-cjs'
|
|
4
|
+
|
|
5
|
+
__TYPE_IMPORTS__
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Type utility to extract the instance type from a script module.
|
|
9
|
+
* For class-based scripts, extracts the class instance type.
|
|
10
|
+
* For functional scripts, returns the module type itself.
|
|
11
|
+
*/
|
|
12
|
+
export type ExtractScriptType<T> = T extends Record<string, any>
|
|
13
|
+
? { [K in keyof T]: T[K] extends new (...args: any[]) => infer Instance ? Instance : never }[keyof T] extends never
|
|
14
|
+
? T
|
|
15
|
+
: { [K in keyof T]: T[K] extends new (...args: any[]) => infer Instance ? Instance : never }[keyof T]
|
|
16
|
+
: never
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A callback function that triggers an action on an entity.
|
|
20
|
+
* Use this type for script parameters that should trigger actions configured in the editor.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import type { ActionCallback } from '~sdk/script-utils'
|
|
25
|
+
*
|
|
26
|
+
* export class Padlock {
|
|
27
|
+
* constructor(
|
|
28
|
+
* public src: string,
|
|
29
|
+
* public entity: Entity,
|
|
30
|
+
* public onUnlock: ActionCallback
|
|
31
|
+
* ) {}
|
|
32
|
+
*
|
|
33
|
+
* solve() {
|
|
34
|
+
* this.onUnlock() // Triggers the action selected in the editor
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export type ActionCallback = () => void
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Registry interface that maps script paths to their types.
|
|
43
|
+
* This interface is populated at build time with actual script paths.
|
|
44
|
+
*/
|
|
45
|
+
export __SCRIPT_TYPES__
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated
|
|
49
|
+
* @internal This function is called automatically by the SDK entry point.
|
|
50
|
+
* Users should not call this function directly.
|
|
51
|
+
*/
|
|
52
|
+
export function _initializeScripts(engine: any): void
|
|
53
|
+
export function _initializeAssetPacks(): void
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get a specific script instance by entity and script path.
|
|
57
|
+
* TypeScript will automatically infer the return type based on the script path.
|
|
58
|
+
*/
|
|
59
|
+
export function getScriptInstance<K extends keyof ScriptRegistry>(entity: Entity, scriptPath: K): ScriptRegistry[K] | null
|
|
60
|
+
export function getScriptInstance<T = any>(entity: Entity, scriptPath: string): T | null
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Get all instances of a specific script (across all entities).
|
|
64
|
+
* TypeScript will automatically infer the instance type based on the script path.
|
|
65
|
+
*/
|
|
66
|
+
export function getScriptInstancesByPath<K extends keyof ScriptRegistry>(scriptPath: K): Array<{ entity: Entity; instance: ScriptRegistry[K] }>
|
|
67
|
+
export function getScriptInstancesByPath<T = any>(scriptPath: string): Array<{ entity: Entity; instance: T }>
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get all script instances attached to a specific entity
|
|
71
|
+
*/
|
|
72
|
+
export function getAllScriptInstances(entity: Entity): Array<{ path: string; instance: any }>
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Call a method on a script instance (with safety checks).
|
|
76
|
+
* TypeScript will automatically infer method names, parameter types, and return types.
|
|
77
|
+
*/
|
|
78
|
+
export function callScriptMethod<
|
|
79
|
+
K extends keyof ScriptRegistry,
|
|
80
|
+
M extends keyof ScriptRegistry[K]
|
|
81
|
+
>(
|
|
82
|
+
entity: Entity,
|
|
83
|
+
scriptPath: K,
|
|
84
|
+
methodName: M,
|
|
85
|
+
...args: ScriptRegistry[K][M] extends (...args: infer P) => any ? P : never
|
|
86
|
+
): ScriptRegistry[K][M] extends (...args: any[]) => infer R ? R : never
|
|
87
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { JSONSchema, ValidateFunction } from '@dcl/schemas';
|
|
2
|
+
import { CliComponents } from '../components';
|
|
3
|
+
import { ProjectUnion } from './project-validations';
|
|
4
|
+
export type WorkspaceJson = {
|
|
5
|
+
folders: Array<{
|
|
6
|
+
path: string;
|
|
7
|
+
}>;
|
|
8
|
+
};
|
|
9
|
+
export declare namespace WorkspaceJson {
|
|
10
|
+
const schema: JSONSchema<WorkspaceJson>;
|
|
11
|
+
const validate: ValidateFunction<WorkspaceJson>;
|
|
12
|
+
}
|
|
13
|
+
export type Workspace = {
|
|
14
|
+
rootWorkingDirectory: string;
|
|
15
|
+
projects: Array<ProjectUnion>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Composes the path to the `dcl-workspace.json` file based on the provided path.
|
|
19
|
+
* @param projectRoot The path to the directory containing the file.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getWorkspaceFilePath(projectRoot: string): string;
|
|
22
|
+
export declare function assertValidWorkspace(workspace: WorkspaceJson): void;
|
|
23
|
+
export declare function workspaceFromFolders(components: Pick<CliComponents, 'fs' | 'logger'>, workingDirectory: string, folders: string[]): Promise<Workspace>;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a workspace by loading the workspace file or generating a single-folder workspace on the fly.
|
|
26
|
+
*/
|
|
27
|
+
export declare function getValidWorkspace(components: Pick<CliComponents, 'fs' | 'logger'>, projectRoot: string): Promise<Workspace>;
|