@dcl/sdk 7.0.6-4197739270.commit-db87ed8 → 7.0.6-4217957637.commit-a393ef7
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/package.json +6 -30
- package/cli/commands/build/helpers.d.ts +0 -21
- package/cli/commands/build/helpers.js +0 -50
- package/cli/commands/build/helpers.ts +0 -89
- package/cli/commands/build/index.d.ts +0 -19
- package/cli/commands/build/index.js +0 -69
- package/cli/commands/build/index.ts +0 -91
- package/cli/commands/init/index.d.ts +0 -17
- package/cli/commands/init/index.js +0 -51
- package/cli/commands/init/index.ts +0 -67
- package/cli/commands/init/repos.d.ts +0 -9
- package/cli/commands/init/repos.js +0 -12
- package/cli/commands/init/repos.ts +0 -17
- package/cli/commands/preview/bff.d.ts +0 -3
- package/cli/commands/preview/bff.js +0 -54
- package/cli/commands/preview/bff.ts +0 -63
- package/cli/commands/preview/catalyst.d.ts +0 -5
- package/cli/commands/preview/catalyst.js +0 -24
- package/cli/commands/preview/catalyst.ts +0 -31
- package/cli/commands/preview/coordinates.d.ts +0 -20
- package/cli/commands/preview/coordinates.js +0 -90
- package/cli/commands/preview/coordinates.ts +0 -146
- package/cli/commands/preview/endpoints.d.ts +0 -10
- package/cli/commands/preview/endpoints.js +0 -455
- package/cli/commands/preview/endpoints.ts +0 -568
- package/cli/commands/preview/eth.d.ts +0 -2
- package/cli/commands/preview/eth.js +0 -6
- package/cli/commands/preview/eth.ts +0 -3
- package/cli/commands/preview/index.d.ts +0 -20
- package/cli/commands/preview/index.js +0 -100
- package/cli/commands/preview/index.ts +0 -98
- package/cli/commands/preview/port.d.ts +0 -1
- package/cli/commands/preview/port.js +0 -21
- package/cli/commands/preview/port.ts +0 -15
- package/cli/commands/preview/project.d.ts +0 -14
- package/cli/commands/preview/project.js +0 -77
- package/cli/commands/preview/project.ts +0 -112
- package/cli/commands/preview/types.d.ts +0 -18
- package/cli/commands/preview/types.js +0 -3
- package/cli/commands/preview/types.ts +0 -26
- package/cli/commands/preview/wire.d.ts +0 -2
- package/cli/commands/preview/wire.js +0 -66
- package/cli/commands/preview/wire.ts +0 -70
- package/cli/commands/preview/ws.d.ts +0 -7
- package/cli/commands/preview/ws.js +0 -16
- package/cli/commands/preview/ws.ts +0 -24
- package/cli/commands/start/index.d.ts +0 -29
- package/cli/commands/start/index.js +0 -126
- package/cli/commands/start/index.ts +0 -145
- package/cli/components/fetch.d.ts +0 -5
- package/cli/components/fetch.js +0 -34
- package/cli/components/fetch.ts +0 -11
- package/cli/components/fs.d.ts +0 -12
- package/cli/components/fs.js +0 -69
- package/cli/components/fs.ts +0 -62
- package/cli/components/index.d.ts +0 -7
- package/cli/components/index.js +0 -13
- package/cli/components/index.ts +0 -14
- package/cli/index.d.ts +0 -7
- package/cli/index.js +0 -76
- package/cli/index.ts +0 -85
- package/cli/utils/args.d.ts +0 -10
- package/cli/utils/args.js +0 -16
- package/cli/utils/args.ts +0 -18
- package/cli/utils/commands.d.ts +0 -3
- package/cli/utils/commands.js +0 -24
- package/cli/utils/commands.ts +0 -28
- package/cli/utils/dcl-ignore.d.ts +0 -4
- package/cli/utils/dcl-ignore.js +0 -44
- package/cli/utils/dcl-ignore.ts +0 -45
- package/cli/utils/error.d.ts +0 -2
- package/cli/utils/error.js +0 -7
- package/cli/utils/error.ts +0 -1
- package/cli/utils/exec.d.ts +0 -8
- package/cli/utils/exec.js +0 -32
- package/cli/utils/exec.ts +0 -42
- package/cli/utils/fs.d.ts +0 -10
- package/cli/utils/fs.js +0 -26
- package/cli/utils/fs.ts +0 -41
- package/cli/utils/log.d.ts +0 -5
- package/cli/utils/log.js +0 -29
- package/cli/utils/log.ts +0 -39
- package/cli/utils/object.d.ts +0 -9
- package/cli/utils/object.js +0 -45
- package/cli/utils/object.ts +0 -62
- package/cli/utils/out-messages.d.ts +0 -1
- package/cli/utils/out-messages.js +0 -8
- package/cli/utils/out-messages.ts +0 -3
@@ -1,568 +0,0 @@
|
|
1
|
-
import { Router } from '@well-known-components/http-server'
|
2
|
-
import { PreviewComponents } from './types'
|
3
|
-
import * as path from 'path'
|
4
|
-
import { sync as globSync } from 'glob'
|
5
|
-
import { WearableJson } from '@dcl/schemas/dist/sdk'
|
6
|
-
import { ContentMapping, Entity, EntityType, Locale, Wearable } from '@dcl/schemas'
|
7
|
-
import ignore from 'ignore'
|
8
|
-
import fetch, { Headers } from 'node-fetch'
|
9
|
-
import { fetchEntityByPointer } from './catalyst'
|
10
|
-
import { CliComponents } from '../../components'
|
11
|
-
import { statSync } from 'fs'
|
12
|
-
import { getDCLIgnorePatterns } from '../../utils/dcl-ignore'
|
13
|
-
|
14
|
-
function getCatalystUrl(): URL {
|
15
|
-
return new URL('https://peer.decentraland.org')
|
16
|
-
}
|
17
|
-
|
18
|
-
function smartWearableNameToId(name: string) {
|
19
|
-
return name.toLocaleLowerCase().replace(/ /g, '-')
|
20
|
-
}
|
21
|
-
|
22
|
-
type LambdasWearable = Wearable & {
|
23
|
-
baseUrl: string
|
24
|
-
}
|
25
|
-
|
26
|
-
export function setupEcs6Endpoints(components: CliComponents, dir: string, router: Router<PreviewComponents>) {
|
27
|
-
const baseFolders = [dir]
|
28
|
-
// handle old preview scene.json
|
29
|
-
router.get('/scene.json', async () => {
|
30
|
-
return {
|
31
|
-
headers: { 'content-type': 'application/json' },
|
32
|
-
body: components.fs.createReadStream(path.join(dir, 'scene.json'))
|
33
|
-
}
|
34
|
-
})
|
35
|
-
|
36
|
-
router.get('/lambdas/explore/realms', async (ctx) => {
|
37
|
-
return {
|
38
|
-
body: [
|
39
|
-
{
|
40
|
-
serverName: 'localhost',
|
41
|
-
url: `http://${ctx.url.host}`,
|
42
|
-
layer: 'stub',
|
43
|
-
usersCount: 0,
|
44
|
-
maxUsers: 100,
|
45
|
-
userParcels: []
|
46
|
-
}
|
47
|
-
]
|
48
|
-
}
|
49
|
-
})
|
50
|
-
|
51
|
-
router.get('/lambdas/contracts/servers', async (ctx) => {
|
52
|
-
return {
|
53
|
-
body: [
|
54
|
-
{
|
55
|
-
address: `http://${ctx.url.host}`,
|
56
|
-
owner: '0x0000000000000000000000000000000000000000',
|
57
|
-
id: '0x0000000000000000000000000000000000000000000000000000000000000000'
|
58
|
-
}
|
59
|
-
]
|
60
|
-
}
|
61
|
-
})
|
62
|
-
|
63
|
-
router.get('/lambdas/profiles', async (ctx, next) => {
|
64
|
-
const baseUrl = `${ctx.url.protocol}//${ctx.url.host}/content/contents`
|
65
|
-
|
66
|
-
try {
|
67
|
-
const previewWearables = await getAllPreviewWearables(components, {
|
68
|
-
baseFolders,
|
69
|
-
baseUrl
|
70
|
-
})
|
71
|
-
|
72
|
-
if (previewWearables.length === 1) {
|
73
|
-
const catalystUrl = getCatalystUrl()
|
74
|
-
|
75
|
-
const u = new URL(ctx.url.toString())
|
76
|
-
u.host = catalystUrl.host
|
77
|
-
u.protocol = catalystUrl.protocol
|
78
|
-
u.port = catalystUrl.port
|
79
|
-
const req = await fetch(u.toString(), {
|
80
|
-
headers: {
|
81
|
-
connection: 'close'
|
82
|
-
},
|
83
|
-
method: ctx.request.method,
|
84
|
-
body: ctx.request.method === 'get' ? undefined : ctx.request.body
|
85
|
-
})
|
86
|
-
|
87
|
-
const deployedProfile = (await req.json()) as any[]
|
88
|
-
|
89
|
-
if (deployedProfile?.length === 1) {
|
90
|
-
deployedProfile[0].avatars[0].avatar.wearables.push(...previewWearables.map(($) => $.id))
|
91
|
-
return {
|
92
|
-
headers: {
|
93
|
-
'content-type': req.headers.get('content-type') || 'application/binary'
|
94
|
-
},
|
95
|
-
body: deployedProfile
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|
99
|
-
} catch (err) {
|
100
|
-
console.warn(`Failed to catch profile and fill with preview wearables.`, err)
|
101
|
-
}
|
102
|
-
|
103
|
-
return next()
|
104
|
-
})
|
105
|
-
|
106
|
-
router.all('/lambdas/:path+', async (ctx) => {
|
107
|
-
const catalystUrl = getCatalystUrl()
|
108
|
-
const u = new URL(ctx.url.toString())
|
109
|
-
u.host = catalystUrl.host
|
110
|
-
u.protocol = catalystUrl.protocol
|
111
|
-
u.port = catalystUrl.port
|
112
|
-
const req = await fetch(u.toString(), {
|
113
|
-
headers: {
|
114
|
-
connection: 'close'
|
115
|
-
},
|
116
|
-
method: ctx.request.method,
|
117
|
-
body: ctx.request.method === 'get' ? undefined : ctx.request.body
|
118
|
-
})
|
119
|
-
|
120
|
-
return {
|
121
|
-
headers: {
|
122
|
-
'content-type': req.headers.get('content-type') || 'application/binary'
|
123
|
-
},
|
124
|
-
body: req.body
|
125
|
-
}
|
126
|
-
})
|
127
|
-
|
128
|
-
router.post('/content/entities', async (ctx) => {
|
129
|
-
const catalystUrl = getCatalystUrl()
|
130
|
-
const headers = new Headers()
|
131
|
-
console.log(ctx.request.headers)
|
132
|
-
const res = await fetch(`${catalystUrl.toString()}/content/entities`, {
|
133
|
-
method: 'post',
|
134
|
-
headers,
|
135
|
-
body: ctx.request.body
|
136
|
-
})
|
137
|
-
|
138
|
-
return res
|
139
|
-
})
|
140
|
-
|
141
|
-
serveStatic(components, dir, router)
|
142
|
-
|
143
|
-
// TODO: get workspace scenes & wearables...
|
144
|
-
|
145
|
-
serveFolders(components, router, baseFolders)
|
146
|
-
}
|
147
|
-
|
148
|
-
function serveFolders(components: Pick<CliComponents, 'fs'>, router: Router<PreviewComponents>, baseFolders: string[]) {
|
149
|
-
router.get('/content/contents/:hash', async (ctx: any, next: any) => {
|
150
|
-
if (ctx.params.hash && ctx.params.hash.startsWith('b64-')) {
|
151
|
-
const fullPath = path.resolve(Buffer.from(ctx.params.hash.replace(/^b64-/, ''), 'base64').toString('utf8'))
|
152
|
-
|
153
|
-
// only return files IF the file is within a baseFolder
|
154
|
-
if (!baseFolders.find((folder: string) => fullPath.startsWith(folder))) {
|
155
|
-
return next()
|
156
|
-
}
|
157
|
-
|
158
|
-
return {
|
159
|
-
headers: {
|
160
|
-
'x-timestamp': Date.now(),
|
161
|
-
'x-sent': true,
|
162
|
-
'cache-control': 'no-cache,private,max-age=1'
|
163
|
-
},
|
164
|
-
body: components.fs.createReadStream(fullPath)
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
return next()
|
169
|
-
})
|
170
|
-
|
171
|
-
async function pointerRequestHandler(pointers: string[]) {
|
172
|
-
if (!pointers || pointers.length === 0) {
|
173
|
-
return []
|
174
|
-
}
|
175
|
-
|
176
|
-
const requestedPointers = new Set<string>(
|
177
|
-
pointers && typeof pointers === 'string' ? [pointers as string] : (pointers as string[])
|
178
|
-
)
|
179
|
-
|
180
|
-
const resultEntities = await getSceneJson(components, {
|
181
|
-
baseFolders,
|
182
|
-
pointers: Array.from(requestedPointers)
|
183
|
-
})
|
184
|
-
const catalystUrl = getCatalystUrl()
|
185
|
-
const remote = fetchEntityByPointer(
|
186
|
-
catalystUrl.toString(),
|
187
|
-
pointers.filter(($: string) => !$.match(/-?\d+,-?\d+/))
|
188
|
-
)
|
189
|
-
|
190
|
-
const serverEntities = Array.isArray(remote) ? remote : []
|
191
|
-
|
192
|
-
return [...resultEntities, ...serverEntities]
|
193
|
-
}
|
194
|
-
|
195
|
-
// REVIEW RESPONSE FORMAT
|
196
|
-
router.get('/content/entities/scene', async (ctx) => {
|
197
|
-
return {
|
198
|
-
body: await pointerRequestHandler(ctx.url.searchParams.getAll('pointer'))
|
199
|
-
}
|
200
|
-
})
|
201
|
-
|
202
|
-
// REVIEW RESPONSE FORMAT
|
203
|
-
router.post('/content/entities/active', async (ctx) => {
|
204
|
-
const body = await ctx.request.json()
|
205
|
-
return {
|
206
|
-
body: await pointerRequestHandler(body.pointers)
|
207
|
-
}
|
208
|
-
})
|
209
|
-
|
210
|
-
router.get('/preview-wearables/:id', async (ctx) => {
|
211
|
-
const baseUrl = `${ctx.url.protocol}//${ctx.url.host}/content/contents`
|
212
|
-
const wearables = await getAllPreviewWearables(components, {
|
213
|
-
baseUrl,
|
214
|
-
baseFolders
|
215
|
-
})
|
216
|
-
const wearableId = ctx.params.id
|
217
|
-
return {
|
218
|
-
body: {
|
219
|
-
ok: true,
|
220
|
-
data: wearables.filter((wearable) => smartWearableNameToId(wearable?.name) === wearableId)
|
221
|
-
}
|
222
|
-
}
|
223
|
-
})
|
224
|
-
|
225
|
-
router.get('/preview-wearables', async (ctx) => {
|
226
|
-
const baseUrl = `${ctx.url.protocol}//${ctx.url.host}/content/contents`
|
227
|
-
return {
|
228
|
-
body: {
|
229
|
-
ok: true,
|
230
|
-
data: await getAllPreviewWearables(components, { baseUrl, baseFolders })
|
231
|
-
}
|
232
|
-
}
|
233
|
-
})
|
234
|
-
}
|
235
|
-
|
236
|
-
const defaultHashMaker = (str: string) => 'b64-' + Buffer.from(str).toString('base64')
|
237
|
-
|
238
|
-
async function getAllPreviewWearables(
|
239
|
-
components: Pick<CliComponents, 'fs'>,
|
240
|
-
{ baseFolders, baseUrl }: { baseFolders: string[]; baseUrl: string }
|
241
|
-
) {
|
242
|
-
const wearablePathArray: string[] = []
|
243
|
-
for (const wearableDir of baseFolders) {
|
244
|
-
const wearableJsonPath = path.resolve(wearableDir, 'wearable.json')
|
245
|
-
if (await components.fs.fileExists(wearableJsonPath)) {
|
246
|
-
wearablePathArray.push(wearableJsonPath)
|
247
|
-
}
|
248
|
-
}
|
249
|
-
|
250
|
-
const ret: LambdasWearable[] = []
|
251
|
-
for (const wearableJsonPath of wearablePathArray) {
|
252
|
-
try {
|
253
|
-
ret.push(await serveWearable(components, { wearableJsonPath, baseUrl }))
|
254
|
-
} catch (err) {
|
255
|
-
console.error(`Couldn't mock the wearable ${wearableJsonPath}. Please verify the correct format and scheme.`, err)
|
256
|
-
}
|
257
|
-
}
|
258
|
-
return ret
|
259
|
-
}
|
260
|
-
|
261
|
-
async function serveWearable(
|
262
|
-
components: Pick<CliComponents, 'fs'>,
|
263
|
-
{ wearableJsonPath, baseUrl }: { wearableJsonPath: string; baseUrl: string }
|
264
|
-
): Promise<LambdasWearable> {
|
265
|
-
const wearableDir = path.dirname(wearableJsonPath)
|
266
|
-
const wearableJson = JSON.parse((await components.fs.readFile(wearableJsonPath)).toString())
|
267
|
-
|
268
|
-
if (!WearableJson.validate(wearableJson)) {
|
269
|
-
const errors = (WearableJson.validate.errors || []).map((a) => `${a.data} ${a.message}`).join('')
|
270
|
-
|
271
|
-
console.error(`Unable to validate wearable.json properly, please check it.`, errors)
|
272
|
-
throw new Error(`Invalid wearable.json (${wearableJsonPath})`)
|
273
|
-
}
|
274
|
-
|
275
|
-
const hashedFiles = await getFilesFromFolder(components, {
|
276
|
-
folder: wearableDir,
|
277
|
-
addOriginalPath: false
|
278
|
-
})
|
279
|
-
|
280
|
-
const thumbnailFiltered = hashedFiles.filter(($) => $?.file === 'thumbnail.png')
|
281
|
-
const thumbnail =
|
282
|
-
thumbnailFiltered.length > 0 && thumbnailFiltered[0]?.hash && `${baseUrl}/${thumbnailFiltered[0].hash}`
|
283
|
-
|
284
|
-
const wearableId = 'urn:8dc2d7ad-97e3-44d0-ba89-e8305d795a6a'
|
285
|
-
|
286
|
-
const representations = wearableJson.data.representations.map((representation) => ({
|
287
|
-
...representation,
|
288
|
-
mainFile: `male/${representation.mainFile}`,
|
289
|
-
contents: hashedFiles.map(($) => ({
|
290
|
-
key: `male/${$?.file}`,
|
291
|
-
url: `${baseUrl}/${$?.hash}`,
|
292
|
-
hash: $?.hash
|
293
|
-
}))
|
294
|
-
}))
|
295
|
-
|
296
|
-
return {
|
297
|
-
id: wearableId,
|
298
|
-
rarity: wearableJson.rarity,
|
299
|
-
i18n: [{ code: 'en' as Locale, text: wearableJson.name }],
|
300
|
-
description: wearableJson.description,
|
301
|
-
thumbnail: thumbnail || '',
|
302
|
-
image: thumbnail || '',
|
303
|
-
collectionAddress: '0x0',
|
304
|
-
baseUrl: `${baseUrl}/`,
|
305
|
-
name: wearableJson.name || '',
|
306
|
-
data: {
|
307
|
-
category: wearableJson.data.category,
|
308
|
-
replaces: [],
|
309
|
-
hides: [],
|
310
|
-
tags: [],
|
311
|
-
representations: representations as any
|
312
|
-
// scene: hashedFiles as any,
|
313
|
-
}
|
314
|
-
}
|
315
|
-
}
|
316
|
-
|
317
|
-
async function getSceneJson(
|
318
|
-
components: Pick<CliComponents, 'fs'>,
|
319
|
-
{
|
320
|
-
baseFolders,
|
321
|
-
pointers,
|
322
|
-
customHashMaker
|
323
|
-
}: {
|
324
|
-
baseFolders: string[]
|
325
|
-
pointers: string[]
|
326
|
-
customHashMaker?: (str: string) => string
|
327
|
-
}
|
328
|
-
): Promise<Entity[]> {
|
329
|
-
const requestedPointers = new Set<string>(pointers)
|
330
|
-
const resultEntities: Entity[] = []
|
331
|
-
|
332
|
-
const allDeployments = await Promise.all(
|
333
|
-
baseFolders.map(async (folder) => {
|
334
|
-
return entityV3FromFolder(components, {
|
335
|
-
folder,
|
336
|
-
addOriginalPath: false,
|
337
|
-
customHashMaker
|
338
|
-
})
|
339
|
-
})
|
340
|
-
)
|
341
|
-
|
342
|
-
for (const pointer of Array.from(requestedPointers)) {
|
343
|
-
// get deployment by pointer
|
344
|
-
const theDeployment = allDeployments.find(($) => $ && $.pointers.includes(pointer))
|
345
|
-
if (theDeployment) {
|
346
|
-
// remove all the required pointers from the requestedPointers set
|
347
|
-
// to prevent sending duplicated entities
|
348
|
-
theDeployment.pointers.forEach(($) => requestedPointers.delete($))
|
349
|
-
|
350
|
-
// add the deployment to the results
|
351
|
-
resultEntities.push(theDeployment)
|
352
|
-
}
|
353
|
-
}
|
354
|
-
|
355
|
-
return resultEntities
|
356
|
-
}
|
357
|
-
|
358
|
-
function serveStatic(components: Pick<CliComponents, 'fs'>, dir: string, router: Router<PreviewComponents>) {
|
359
|
-
const sdkPath = path.dirname(
|
360
|
-
require.resolve('@dcl/sdk/package.json', {
|
361
|
-
paths: [dir]
|
362
|
-
})
|
363
|
-
)
|
364
|
-
const dclExplorerJsonPath = path.dirname(
|
365
|
-
require.resolve('@dcl/explorer/package.json', {
|
366
|
-
paths: [dir, sdkPath]
|
367
|
-
})
|
368
|
-
)
|
369
|
-
|
370
|
-
const dclKernelDefaultProfilePath = path.resolve(dclExplorerJsonPath, 'default-profile')
|
371
|
-
const dclKernelImagesDecentralandConnect = path.resolve(dclExplorerJsonPath, 'images', 'decentraland-connect')
|
372
|
-
|
373
|
-
const routes = [
|
374
|
-
{
|
375
|
-
route: '/',
|
376
|
-
path: path.resolve(dclExplorerJsonPath, 'preview.html'),
|
377
|
-
type: 'text/html'
|
378
|
-
},
|
379
|
-
{
|
380
|
-
route: '/favicon.ico',
|
381
|
-
path: path.resolve(dclExplorerJsonPath, 'favicon.ico'),
|
382
|
-
type: 'text/html'
|
383
|
-
},
|
384
|
-
{
|
385
|
-
route: '/@/explorer/index.js',
|
386
|
-
path: path.resolve(dclExplorerJsonPath, 'index.js'),
|
387
|
-
type: 'text/javascript'
|
388
|
-
}
|
389
|
-
]
|
390
|
-
|
391
|
-
for (const route of routes) {
|
392
|
-
router.get(route.route, async (_ctx) => {
|
393
|
-
return {
|
394
|
-
headers: { 'Content-Type': route.type },
|
395
|
-
body: components.fs.createReadStream(route.path)
|
396
|
-
}
|
397
|
-
})
|
398
|
-
}
|
399
|
-
|
400
|
-
function createStaticRoutes(
|
401
|
-
components: Pick<CliComponents, 'fs'>,
|
402
|
-
route: string,
|
403
|
-
folder: string,
|
404
|
-
transform = (str: string) => str
|
405
|
-
) {
|
406
|
-
router.get(route, async (ctx, next) => {
|
407
|
-
const file = ctx.params.path
|
408
|
-
const fullPath = path.resolve(folder, transform(file))
|
409
|
-
|
410
|
-
// only return files IF the file is within a baseFolder
|
411
|
-
if (!(await components.fs.fileExists(fullPath))) {
|
412
|
-
return next()
|
413
|
-
}
|
414
|
-
|
415
|
-
const headers: Record<string, any> = {
|
416
|
-
'x-timestamp': Date.now(),
|
417
|
-
'x-sent': true,
|
418
|
-
'cache-control': 'no-cache,private,max-age=1'
|
419
|
-
}
|
420
|
-
|
421
|
-
if (fullPath.endsWith('.wasm')) {
|
422
|
-
headers['content-type'] = 'application/wasm'
|
423
|
-
}
|
424
|
-
|
425
|
-
return {
|
426
|
-
headers,
|
427
|
-
body: components.fs.createReadStream(fullPath)
|
428
|
-
}
|
429
|
-
})
|
430
|
-
}
|
431
|
-
|
432
|
-
createStaticRoutes(components, '/images/decentraland-connect/:path+', dclKernelImagesDecentralandConnect)
|
433
|
-
createStaticRoutes(components, '/default-profile/:path+', dclKernelDefaultProfilePath)
|
434
|
-
createStaticRoutes(components, '/@/explorer/:path+', dclExplorerJsonPath, (filePath) => filePath.replace(/.br+$/, ''))
|
435
|
-
|
436
|
-
router.get('/feature-flags/:file', async (ctx) => {
|
437
|
-
const res = await fetch(`https://feature-flags.decentraland.zone/${ctx.params.file}`, {
|
438
|
-
headers: {
|
439
|
-
connection: 'close'
|
440
|
-
}
|
441
|
-
})
|
442
|
-
return {
|
443
|
-
body: await res.arrayBuffer()
|
444
|
-
}
|
445
|
-
})
|
446
|
-
}
|
447
|
-
|
448
|
-
async function entityV3FromFolder(
|
449
|
-
components: Pick<CliComponents, 'fs'>,
|
450
|
-
{
|
451
|
-
folder,
|
452
|
-
addOriginalPath,
|
453
|
-
customHashMaker
|
454
|
-
}: {
|
455
|
-
folder: string
|
456
|
-
addOriginalPath?: boolean
|
457
|
-
customHashMaker?: (str: string) => string
|
458
|
-
}
|
459
|
-
): Promise<Entity | null> {
|
460
|
-
const sceneJsonPath = path.resolve(folder, './scene.json')
|
461
|
-
let isParcelScene = true
|
462
|
-
|
463
|
-
const wearableJsonPath = path.resolve(folder, './wearable.json')
|
464
|
-
if (await components.fs.fileExists(wearableJsonPath)) {
|
465
|
-
try {
|
466
|
-
const wearableJson = JSON.parse(await components.fs.readFile(wearableJsonPath, 'utf-8'))
|
467
|
-
if (!WearableJson.validate(wearableJson)) {
|
468
|
-
const errors = (WearableJson.validate.errors || []).map((a) => `${a.data} ${a.message}`).join('')
|
469
|
-
|
470
|
-
console.error(`Unable to validate wearable.json properly, please check it.`, errors)
|
471
|
-
console.error(`Invalid wearable.json (${wearableJsonPath})`)
|
472
|
-
} else {
|
473
|
-
isParcelScene = false
|
474
|
-
}
|
475
|
-
} catch (err) {
|
476
|
-
console.error(`Unable to load wearable.json properly`, err)
|
477
|
-
}
|
478
|
-
}
|
479
|
-
|
480
|
-
const hashMaker = customHashMaker ? customHashMaker : defaultHashMaker
|
481
|
-
|
482
|
-
if ((await components.fs.fileExists(sceneJsonPath)) && isParcelScene) {
|
483
|
-
const sceneJson = JSON.parse(await components.fs.readFile(sceneJsonPath, 'utf-8'))
|
484
|
-
const { base, parcels }: { base: string; parcels: string[] } = sceneJson.scene
|
485
|
-
const pointers = new Set<string>()
|
486
|
-
pointers.add(base)
|
487
|
-
parcels.forEach(($) => pointers.add($))
|
488
|
-
|
489
|
-
const mappedFiles = await getFilesFromFolder(components, {
|
490
|
-
folder,
|
491
|
-
addOriginalPath,
|
492
|
-
customHashMaker
|
493
|
-
})
|
494
|
-
|
495
|
-
return {
|
496
|
-
version: 'v3',
|
497
|
-
type: EntityType.SCENE,
|
498
|
-
id: hashMaker(folder),
|
499
|
-
pointers: Array.from(pointers),
|
500
|
-
timestamp: Date.now(),
|
501
|
-
metadata: sceneJson,
|
502
|
-
content: mappedFiles
|
503
|
-
}
|
504
|
-
}
|
505
|
-
|
506
|
-
return null
|
507
|
-
}
|
508
|
-
|
509
|
-
export async function getFilesFromFolder(
|
510
|
-
components: Pick<CliComponents, 'fs'>,
|
511
|
-
{
|
512
|
-
folder,
|
513
|
-
addOriginalPath,
|
514
|
-
customHashMaker
|
515
|
-
}: {
|
516
|
-
folder: string
|
517
|
-
addOriginalPath?: boolean
|
518
|
-
customHashMaker?: (str: string) => string
|
519
|
-
}
|
520
|
-
): Promise<ContentMapping[]> {
|
521
|
-
const hashMaker = customHashMaker ? customHashMaker : defaultHashMaker
|
522
|
-
const ignorePatterns = await getDCLIgnorePatterns(components, folder)
|
523
|
-
|
524
|
-
const allFiles = globSync('**/*', {
|
525
|
-
ignore: ignorePatterns,
|
526
|
-
cwd: folder,
|
527
|
-
dot: false,
|
528
|
-
absolute: true
|
529
|
-
})
|
530
|
-
.map((file) => {
|
531
|
-
try {
|
532
|
-
if (!statSync(file).isFile()) return
|
533
|
-
} catch (err) {
|
534
|
-
return
|
535
|
-
}
|
536
|
-
const _folder = folder.replace(/\\/gi, '/')
|
537
|
-
const key = file.replace(_folder, '').replace(/^\/+/, '')
|
538
|
-
return key
|
539
|
-
})
|
540
|
-
.filter(($) => !!$) as string[]
|
541
|
-
|
542
|
-
const ig = ignore().add(ignorePatterns)
|
543
|
-
const filteredFiles = ig.filter(allFiles)
|
544
|
-
|
545
|
-
const ret: (ContentMapping & { original_path: string | undefined })[] = []
|
546
|
-
|
547
|
-
for (const file of filteredFiles) {
|
548
|
-
const absolutePath = path.resolve(folder, file)
|
549
|
-
try {
|
550
|
-
if (!statSync(absolutePath).isFile()) continue
|
551
|
-
} catch (err) {
|
552
|
-
console.error(err)
|
553
|
-
continue
|
554
|
-
}
|
555
|
-
|
556
|
-
const absoluteFolder = folder.replace(/\\/gi, '/')
|
557
|
-
|
558
|
-
const relativeFilePathToFolder = file.replace(absoluteFolder, '').replace(/^\/+/, '')
|
559
|
-
|
560
|
-
ret.push({
|
561
|
-
file: relativeFilePathToFolder.toLowerCase(),
|
562
|
-
original_path: addOriginalPath ? absolutePath : undefined,
|
563
|
-
hash: hashMaker(absolutePath)
|
564
|
-
})
|
565
|
-
}
|
566
|
-
|
567
|
-
return ret
|
568
|
-
}
|
@@ -1,6 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.providerInstance = void 0;
|
4
|
-
const eth_connect_1 = require("eth-connect");
|
5
|
-
exports.providerInstance = new eth_connect_1.HTTPProvider('https://rpc.decentraland.org/mainnet?project=sdk-commands');
|
6
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXRoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiZXRoLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLDZDQUEwQztBQUU3QixRQUFBLGdCQUFnQixHQUFHLElBQUksMEJBQVksQ0FBQywyREFBMkQsQ0FBQyxDQUFBIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgSFRUUFByb3ZpZGVyIH0gZnJvbSAnZXRoLWNvbm5lY3QnXG5cbmV4cG9ydCBjb25zdCBwcm92aWRlckluc3RhbmNlID0gbmV3IEhUVFBQcm92aWRlcignaHR0cHM6Ly9ycGMuZGVjZW50cmFsYW5kLm9yZy9tYWlubmV0P3Byb2plY3Q9c2RrLWNvbW1hbmRzJylcbiJdfQ==
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { Lifecycle } from '@well-known-components/interfaces';
|
2
|
-
import { CliComponents } from '../../components';
|
3
|
-
import { PreviewComponents } from './types';
|
4
|
-
export declare function help(): string;
|
5
|
-
interface Options {
|
6
|
-
args: Omit<typeof args, '_'>;
|
7
|
-
components: Pick<CliComponents, 'fetch' | 'fs'>;
|
8
|
-
}
|
9
|
-
export declare const args: import("arg").Result<{
|
10
|
-
'--help': BooleanConstructor;
|
11
|
-
'-h': string;
|
12
|
-
} & {
|
13
|
-
'--watch': BooleanConstructor;
|
14
|
-
'-w': string;
|
15
|
-
'--dir': StringConstructor;
|
16
|
-
'--port': NumberConstructor;
|
17
|
-
'-p': string;
|
18
|
-
}>;
|
19
|
-
export declare function main(options: Options): Promise<Lifecycle.ComponentBasedProgram<PreviewComponents>>;
|
20
|
-
export {};
|