@dcl/sdk 7.0.0-3290193397.commit-3ca136b → 7.0.0-3313983919.commit-4ba44d2
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/dist/ecs7/index.d.ts +52 -8
- package/dist/ecs7/index.js +83 -79
- package/dist/ecs7/index.min.js +1 -1
- package/dist/ecs7/index.min.js.map +1 -1
- package/dist/playground/snippets/cube-spawner.ts +1 -1
- package/dist/playground/snippets/ui.tsx +1 -1
- package/package.json +6 -14
- package/types/ecs7/index.d.ts +52 -8
- package/src/cli/mock-catalyst/index.js +0 -175
- package/src/cli/setupUtils.js +0 -345
- package/src/cli/wearables.js +0 -145
- package/src/setupExport.js +0 -43
- package/src/setupProxy.js +0 -165
@@ -41,7 +41,7 @@ function circularSystem(dt: number) {
|
|
41
41
|
function spawnerSystem() {
|
42
42
|
const clickedCubes = engine.getEntitiesWith(PointerEvents)
|
43
43
|
for (const [entity] of clickedCubes) {
|
44
|
-
if (
|
44
|
+
if (Input.wasJustClicked(InputAction.IA_PRIMARY, entity)) {
|
45
45
|
createCube(
|
46
46
|
1 + Math.random() * 8,
|
47
47
|
Math.random() * 8,
|
@@ -114,7 +114,7 @@ function circularSystem(dt: number) {
|
|
114
114
|
function spawnerSystem() {
|
115
115
|
const clickedCubes = engine.getEntitiesWith(PointerEvents)
|
116
116
|
for (const [entity] of clickedCubes) {
|
117
|
-
if (
|
117
|
+
if (Input.wasJustClicked(InputAction.IA_PRIMARY, entity)) {
|
118
118
|
counter++
|
119
119
|
}
|
120
120
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dcl/sdk",
|
3
|
-
"version": "7.0.0-
|
3
|
+
"version": "7.0.0-3313983919.commit-4ba44d2",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/src/index.js",
|
6
6
|
"typings": "dist/index.d.ts",
|
@@ -20,23 +20,15 @@
|
|
20
20
|
"docs",
|
21
21
|
"LICENSE",
|
22
22
|
"docs-yaml",
|
23
|
-
"artifacts"
|
24
|
-
"src/setupProxy.js",
|
25
|
-
"src/setupExport.js",
|
26
|
-
"src/cli/*.js",
|
27
|
-
"src/cli/**/*.js"
|
23
|
+
"artifacts"
|
28
24
|
],
|
29
25
|
"dependencies": {
|
30
|
-
"@dcl/amd": "6.11.
|
31
|
-
"@dcl/build-ecs": "6.11.
|
26
|
+
"@dcl/amd": "6.11.10-3313983919.commit-4ba44d2",
|
27
|
+
"@dcl/build-ecs": "6.11.10-3313983919.commit-4ba44d2",
|
32
28
|
"@dcl/kernel": "1.0.0-2994874542.commit-c3ae489",
|
33
29
|
"@dcl/posix": "^1.0.4",
|
34
|
-
"@dcl/
|
35
|
-
"@dcl/unity-renderer": "^1.0.40531-20220621125654.commit-472137e",
|
36
|
-
"glob": "^7.1.7",
|
37
|
-
"http-proxy-middleware": "^2.0.3",
|
38
|
-
"ignore": "^5.1.8"
|
30
|
+
"@dcl/unity-renderer": "^1.0.40531-20220621125654.commit-472137e"
|
39
31
|
},
|
40
32
|
"minCliVersion": "3.10.2",
|
41
|
-
"commit": "
|
33
|
+
"commit": "4ba44d22e24f60ac5a491e5d883ab8212b70f9c7"
|
42
34
|
}
|
package/types/ecs7/index.d.ts
CHANGED
@@ -1333,6 +1333,53 @@ declare type IEngineParams = {
|
|
1333
1333
|
*/
|
1334
1334
|
declare function IEnum<T>(type: ISchema<any>): ISchema<T>;
|
1335
1335
|
|
1336
|
+
/**
|
1337
|
+
* @public
|
1338
|
+
*/
|
1339
|
+
declare type IInput = {
|
1340
|
+
/**
|
1341
|
+
* Check if a click was emmited in the current tick for the input action.
|
1342
|
+
* This is defined when an UP event is triggered with a previously DOWN state.
|
1343
|
+
* @param inputAction - the input action to query
|
1344
|
+
* @param entity - the entity to query, ignore for global events.
|
1345
|
+
* @returns true if the entity was clicked in the last tick-update
|
1346
|
+
*/
|
1347
|
+
wasJustClicked: (inputAction: InputAction, entity?: Entity) => boolean;
|
1348
|
+
/**
|
1349
|
+
* Check if a pointer event has been emited in the last tick-update.
|
1350
|
+
* @param inputAction - the input action to query
|
1351
|
+
* @param pointerEventType - the pointer event type to query
|
1352
|
+
* @param entity - the entity to query, ignore for global
|
1353
|
+
* @returns
|
1354
|
+
*/
|
1355
|
+
wasInputJustActive: (inputAction: InputAction, pointerEventType: PointerEventType, entity?: Entity) => boolean;
|
1356
|
+
/**
|
1357
|
+
* Check if an input action is in DOWN state.
|
1358
|
+
* @param inputAction - the input action to query
|
1359
|
+
* @returns true if the input action is being pressed
|
1360
|
+
*/
|
1361
|
+
isActionDown: (inputAction: InputAction) => boolean;
|
1362
|
+
/**
|
1363
|
+
* Get the click info if a click was emmited in the current tick for the input action.
|
1364
|
+
* This is defined when an UP event is triggered with a previously DOWN state.
|
1365
|
+
* @param inputAction - the input action to query
|
1366
|
+
* @param entity - the entity to query, ignore for global events.
|
1367
|
+
* @returns the click info or undefined if there is no command in the last tick-update
|
1368
|
+
*/
|
1369
|
+
getClick: (inputAction: InputAction, entity?: Entity) => {
|
1370
|
+
up: PBPointerEventsResult_PointerCommand;
|
1371
|
+
down: PBPointerEventsResult_PointerCommand;
|
1372
|
+
} | null;
|
1373
|
+
/**
|
1374
|
+
* Get the input command info if a pointer event has been emited in the last tick-update.
|
1375
|
+
* @param inputAction - the input action to query
|
1376
|
+
* @param pointerEventType - the pointer event type to query
|
1377
|
+
* @param entity - the entity to query, ignore for global
|
1378
|
+
* @returns the input command info or undefined if there is no command in the last tick-update
|
1379
|
+
*/
|
1380
|
+
getInputCommand: (inputAction: InputAction, pointerEventType: PointerEventType, entity?: Entity) => PBPointerEventsResult_PointerCommand | null;
|
1381
|
+
};
|
1382
|
+
|
1336
1383
|
/**
|
1337
1384
|
* @public
|
1338
1385
|
*/
|
@@ -1343,6 +1390,11 @@ declare type IncludeUndefined<T> = {
|
|
1343
1390
|
[P in keyof T]: undefined extends T[P] ? P : never;
|
1344
1391
|
}[keyof T];
|
1345
1392
|
|
1393
|
+
/**
|
1394
|
+
* @public
|
1395
|
+
*/
|
1396
|
+
declare const Input: IInput;
|
1397
|
+
|
1346
1398
|
declare const enum InputAction {
|
1347
1399
|
IA_POINTER = 0,
|
1348
1400
|
IA_PRIMARY = 1,
|
@@ -1374,10 +1426,6 @@ declare type ISchema<T = any> = {
|
|
1374
1426
|
create(): T;
|
1375
1427
|
};
|
1376
1428
|
|
1377
|
-
declare const isPointerEventActive: (entity: Entity, actionButton: InputAction, pointerEventType: PointerEventType) => boolean;
|
1378
|
-
|
1379
|
-
declare function isPointerEventActiveGenerator(engine: IEngine): (entity: Entity, actionButton: InputAction, pointerEventType: PointerEventType) => boolean;
|
1380
|
-
|
1381
1429
|
declare const log: (...a: any[]) => void;
|
1382
1430
|
|
1383
1431
|
/**
|
@@ -4245,10 +4293,6 @@ declare interface Vector3_2 {
|
|
4245
4293
|
/** @public */
|
4246
4294
|
declare const VisibilityComponent: ComponentDefinition<ISchema<PBVisibilityComponent>, PBVisibilityComponent>;
|
4247
4295
|
|
4248
|
-
declare const wasEntityClicked: (entity: Entity, actionButton: InputAction) => boolean;
|
4249
|
-
|
4250
|
-
declare function wasEntityClickedGenerator(engine: IEngine): (entity: Entity, actionButton: InputAction) => boolean;
|
4251
|
-
|
4252
4296
|
declare namespace WireMessage {
|
4253
4297
|
enum Enum {
|
4254
4298
|
RESERVED = 0,
|
@@ -1,175 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
-
function step(op) {
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
17
|
-
while (_) try {
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
-
switch (op[0]) {
|
21
|
-
case 0: case 1: t = op; break;
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
-
default:
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
-
if (t[2]) _.ops.pop();
|
31
|
-
_.trys.pop(); continue;
|
32
|
-
}
|
33
|
-
op = body.call(thisArg, _);
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
-
}
|
37
|
-
};
|
38
|
-
exports.__esModule = true;
|
39
|
-
exports.mockCatalyst = void 0;
|
40
|
-
var path = require("path");
|
41
|
-
var http_proxy_middleware_1 = require("http-proxy-middleware");
|
42
|
-
var setupUtils_1 = require("../setupUtils");
|
43
|
-
var wearables_1 = require("../wearables");
|
44
|
-
var mockCatalyst = function (app, baseFolders) {
|
45
|
-
serveFolders(app, baseFolders);
|
46
|
-
app.get('/lambdas/explore/realms', function (req, res) {
|
47
|
-
res.json([
|
48
|
-
{
|
49
|
-
serverName: 'localhost',
|
50
|
-
url: "http://".concat(req.get('host')),
|
51
|
-
layer: 'stub',
|
52
|
-
usersCount: 0,
|
53
|
-
maxUsers: 100,
|
54
|
-
userParcels: []
|
55
|
-
}
|
56
|
-
]);
|
57
|
-
});
|
58
|
-
app.get('/lambdas/contracts/servers', function (req, res) {
|
59
|
-
res.json([
|
60
|
-
{
|
61
|
-
address: "http://".concat(req.get('host')),
|
62
|
-
owner: '0x0000000000000000000000000000000000000000',
|
63
|
-
id: '0x0000000000000000000000000000000000000000000000000000000000000000'
|
64
|
-
}
|
65
|
-
]);
|
66
|
-
});
|
67
|
-
app.get('/lambdas/profiles', function (req, res, next) { return __awaiter(void 0, void 0, void 0, function () {
|
68
|
-
var baseUrl, previewWearables, deployedProfile, err_1;
|
69
|
-
var _a;
|
70
|
-
return __generator(this, function (_b) {
|
71
|
-
switch (_b.label) {
|
72
|
-
case 0:
|
73
|
-
baseUrl = "".concat(req.protocol, "://").concat(req.get('host'), "/content/contents");
|
74
|
-
_b.label = 1;
|
75
|
-
case 1:
|
76
|
-
_b.trys.push([1, 6, , 7]);
|
77
|
-
return [4 /*yield*/, (0, wearables_1.getAllPreviewWearables)({
|
78
|
-
baseFolders: baseFolders,
|
79
|
-
baseUrl: baseUrl
|
80
|
-
}).map(function (wearable) { return wearable.id; })];
|
81
|
-
case 2:
|
82
|
-
previewWearables = _b.sent();
|
83
|
-
if (!(previewWearables.length === 1)) return [3 /*break*/, 5];
|
84
|
-
return [4 /*yield*/, fetch("https://peer.decentraland.org".concat(req.originalUrl))];
|
85
|
-
case 3: return [4 /*yield*/, (_b.sent()).json()];
|
86
|
-
case 4:
|
87
|
-
deployedProfile = _b.sent();
|
88
|
-
if ((deployedProfile === null || deployedProfile === void 0 ? void 0 : deployedProfile.length) === 1) {
|
89
|
-
(_a = deployedProfile[0].avatars[0].avatar.wearables).push.apply(_a, previewWearables);
|
90
|
-
return [2 /*return*/, res.json(deployedProfile)];
|
91
|
-
}
|
92
|
-
_b.label = 5;
|
93
|
-
case 5: return [3 /*break*/, 7];
|
94
|
-
case 6:
|
95
|
-
err_1 = _b.sent();
|
96
|
-
console.warn("Failed to catch profile and fill with preview wearables.", err_1);
|
97
|
-
return [3 /*break*/, 7];
|
98
|
-
case 7: return [2 /*return*/, next()];
|
99
|
-
}
|
100
|
-
});
|
101
|
-
}); });
|
102
|
-
// fallback all lambdas to a real catalyst
|
103
|
-
app.use('/lambdas', (0, http_proxy_middleware_1.createProxyMiddleware)({
|
104
|
-
target: 'https://peer.decentraland.org/',
|
105
|
-
changeOrigin: true,
|
106
|
-
timeout: 25 * 1000,
|
107
|
-
proxyTimeout: 25 * 1000,
|
108
|
-
onError: function (err, req_, res) {
|
109
|
-
console.warn("Oops, it seems the catalyst isn't working well.");
|
110
|
-
res.writeHead(500);
|
111
|
-
res.end('');
|
112
|
-
}
|
113
|
-
}));
|
114
|
-
// fallback all lambdas to a real catalyst
|
115
|
-
app.use('/content', (0, http_proxy_middleware_1.createProxyMiddleware)({
|
116
|
-
target: 'https://peer.decentraland.org/',
|
117
|
-
changeOrigin: true,
|
118
|
-
timeout: 25 * 1000,
|
119
|
-
proxyTimeout: 25 * 1000,
|
120
|
-
onError: function (err, req_, res) {
|
121
|
-
console.warn("Oops, it seems the content server isn't working well.");
|
122
|
-
res.writeHead(500);
|
123
|
-
res.end('');
|
124
|
-
}
|
125
|
-
}));
|
126
|
-
};
|
127
|
-
exports.mockCatalyst = mockCatalyst;
|
128
|
-
var serveFolders = function (app, baseFolders) {
|
129
|
-
app.get('/content/contents/:hash', function (req, res, next) {
|
130
|
-
if (req.params.hash && req.params.hash.startsWith('b64-')) {
|
131
|
-
var fullPath_1 = path.resolve(Buffer.from(req.params.hash.replace(/^b64-/, ''), 'base64').toString('utf8'));
|
132
|
-
// only return files IF the file is within a baseFolder
|
133
|
-
if (!baseFolders.find(function (folder) { return fullPath_1.startsWith(folder); })) {
|
134
|
-
next();
|
135
|
-
return;
|
136
|
-
}
|
137
|
-
var options = {
|
138
|
-
dotfiles: 'deny',
|
139
|
-
maxAge: 1,
|
140
|
-
cacheControl: false,
|
141
|
-
lastModified: true,
|
142
|
-
headers: {
|
143
|
-
'x-timestamp': Date.now(),
|
144
|
-
'x-sent': true,
|
145
|
-
etag: JSON.stringify(Date.now().toString()),
|
146
|
-
'cache-control': 'no-cache,private,max-age=1'
|
147
|
-
}
|
148
|
-
};
|
149
|
-
res.sendFile(fullPath_1, options, function (err) {
|
150
|
-
if (err) {
|
151
|
-
next(err);
|
152
|
-
}
|
153
|
-
});
|
154
|
-
}
|
155
|
-
});
|
156
|
-
function pointerRequestHandler(pointers) {
|
157
|
-
if (!pointers) {
|
158
|
-
return [];
|
159
|
-
}
|
160
|
-
var requestedPointers = new Set(pointers && typeof pointers === 'string'
|
161
|
-
? [pointers]
|
162
|
-
: pointers);
|
163
|
-
var resultEntities = (0, setupUtils_1.getSceneJson)({
|
164
|
-
baseFolders: baseFolders,
|
165
|
-
pointers: Array.from(requestedPointers)
|
166
|
-
});
|
167
|
-
return resultEntities;
|
168
|
-
}
|
169
|
-
app.get('/content/entities/scene', function (req, res) {
|
170
|
-
return res.json(pointerRequestHandler(req.query.pointer)).end();
|
171
|
-
});
|
172
|
-
app.post('/content/entities/active', function (req, res) {
|
173
|
-
return res.json(pointerRequestHandler(req.body.pointers)).end();
|
174
|
-
});
|
175
|
-
};
|
package/src/cli/setupUtils.js
DELETED
@@ -1,345 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
15
|
-
function step(op) {
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
17
|
-
while (_) try {
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
20
|
-
switch (op[0]) {
|
21
|
-
case 0: case 1: t = op; break;
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
25
|
-
default:
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
30
|
-
if (t[2]) _.ops.pop();
|
31
|
-
_.trys.pop(); continue;
|
32
|
-
}
|
33
|
-
op = body.call(thisArg, _);
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
36
|
-
}
|
37
|
-
};
|
38
|
-
exports.__esModule = true;
|
39
|
-
exports.createStaticRoutes = exports.getDirectories = exports.defaultDclIgnore = exports.shaHashMaker = exports.downloadFile = exports.ensureCopyFile = exports.ensureWriteFile = exports.getSceneJson = exports.entityV3FromFolder = exports.getFilesFromFolder = exports.defaultHashMaker = exports.copyDir = void 0;
|
40
|
-
var fs = require("fs");
|
41
|
-
var glob_1 = require("glob");
|
42
|
-
var path = require("path");
|
43
|
-
var http = require("http");
|
44
|
-
var https = require("https");
|
45
|
-
var crypto = require("crypto");
|
46
|
-
var ignore_1 = require("ignore");
|
47
|
-
var wearables_1 = require("./wearables");
|
48
|
-
// instead of using fs-extra, create a custom function to no need to rollup
|
49
|
-
function copyDir(src, dest) {
|
50
|
-
return __awaiter(this, void 0, void 0, function () {
|
51
|
-
var entries, _i, entries_1, entry, srcPath, destPath, _a;
|
52
|
-
return __generator(this, function (_b) {
|
53
|
-
switch (_b.label) {
|
54
|
-
case 0: return [4 /*yield*/, fs.promises.mkdir(dest, { recursive: true })];
|
55
|
-
case 1:
|
56
|
-
_b.sent();
|
57
|
-
return [4 /*yield*/, fs.promises.readdir(src, { withFileTypes: true })];
|
58
|
-
case 2:
|
59
|
-
entries = _b.sent();
|
60
|
-
_i = 0, entries_1 = entries;
|
61
|
-
_b.label = 3;
|
62
|
-
case 3:
|
63
|
-
if (!(_i < entries_1.length)) return [3 /*break*/, 9];
|
64
|
-
entry = entries_1[_i];
|
65
|
-
srcPath = path.join(src, entry.name);
|
66
|
-
destPath = path.join(dest, entry.name);
|
67
|
-
if (!entry.isDirectory()) return [3 /*break*/, 5];
|
68
|
-
return [4 /*yield*/, copyDir(srcPath, destPath)];
|
69
|
-
case 4:
|
70
|
-
_a = _b.sent();
|
71
|
-
return [3 /*break*/, 7];
|
72
|
-
case 5: return [4 /*yield*/, fs.promises.copyFile(srcPath, destPath)];
|
73
|
-
case 6:
|
74
|
-
_a = _b.sent();
|
75
|
-
_b.label = 7;
|
76
|
-
case 7:
|
77
|
-
_a;
|
78
|
-
_b.label = 8;
|
79
|
-
case 8:
|
80
|
-
_i++;
|
81
|
-
return [3 /*break*/, 3];
|
82
|
-
case 9: return [2 /*return*/];
|
83
|
-
}
|
84
|
-
});
|
85
|
-
});
|
86
|
-
}
|
87
|
-
exports.copyDir = copyDir;
|
88
|
-
var defaultHashMaker = function (str) {
|
89
|
-
return 'b64-' + Buffer.from(str).toString('base64');
|
90
|
-
};
|
91
|
-
exports.defaultHashMaker = defaultHashMaker;
|
92
|
-
var getFilesFromFolder = function (_a) {
|
93
|
-
var folder = _a.folder, addOriginalPath = _a.addOriginalPath, ignorePattern = _a.ignorePattern, customHashMaker = _a.customHashMaker;
|
94
|
-
var hashMaker = customHashMaker ? customHashMaker : exports.defaultHashMaker;
|
95
|
-
var allFiles = (0, glob_1.sync)('**/*', {
|
96
|
-
cwd: folder,
|
97
|
-
dot: false,
|
98
|
-
absolute: true
|
99
|
-
})
|
100
|
-
.map(function (file) {
|
101
|
-
try {
|
102
|
-
if (!fs.statSync(file).isFile())
|
103
|
-
return;
|
104
|
-
}
|
105
|
-
catch (err) {
|
106
|
-
return;
|
107
|
-
}
|
108
|
-
var _folder = folder.replace(/\\/gi, '/');
|
109
|
-
var key = file.replace(_folder, '').replace(/^\/+/, '');
|
110
|
-
return key;
|
111
|
-
})
|
112
|
-
.filter(function ($) { return !!$; });
|
113
|
-
var ensureIgnorePattern = ignorePattern && ignorePattern !== '' ? ignorePattern : (0, exports.defaultDclIgnore)();
|
114
|
-
var ig = (0, ignore_1["default"])().add(ensureIgnorePattern);
|
115
|
-
var filteredFiles = ig.filter(allFiles);
|
116
|
-
return filteredFiles
|
117
|
-
.map(function (file) {
|
118
|
-
var absolutePath = path.resolve(folder, file);
|
119
|
-
try {
|
120
|
-
if (!fs.statSync(absolutePath).isFile())
|
121
|
-
return;
|
122
|
-
}
|
123
|
-
catch (err) {
|
124
|
-
console.log(err);
|
125
|
-
return;
|
126
|
-
}
|
127
|
-
var absoluteFolder = folder.replace(/\\/gi, '/');
|
128
|
-
var relativeFilePathToFolder = file
|
129
|
-
.replace(absoluteFolder, '')
|
130
|
-
.replace(/^\/+/, '');
|
131
|
-
return {
|
132
|
-
file: relativeFilePathToFolder.toLowerCase(),
|
133
|
-
original_path: addOriginalPath ? absolutePath : undefined,
|
134
|
-
hash: hashMaker(absolutePath)
|
135
|
-
};
|
136
|
-
})
|
137
|
-
.filter(function ($) { return !!$; });
|
138
|
-
};
|
139
|
-
exports.getFilesFromFolder = getFilesFromFolder;
|
140
|
-
function entityV3FromFolder(_a) {
|
141
|
-
var folder = _a.folder, addOriginalPath = _a.addOriginalPath, ignorePattern = _a.ignorePattern, customHashMaker = _a.customHashMaker;
|
142
|
-
var sceneJsonPath = path.resolve(folder, './scene.json');
|
143
|
-
var wearableJsonPath = path.resolve(folder, './wearable.json');
|
144
|
-
var wearableJson = fs.existsSync(wearableJsonPath) &&
|
145
|
-
JSON.parse(fs.readFileSync(wearableJsonPath).toString());
|
146
|
-
var isParcelScene = !wearableJson || !(0, wearables_1.wearableValidator)(wearableJson);
|
147
|
-
var hashMaker = customHashMaker ? customHashMaker : exports.defaultHashMaker;
|
148
|
-
if (fs.existsSync(sceneJsonPath) && isParcelScene) {
|
149
|
-
var sceneJson = JSON.parse(fs.readFileSync(sceneJsonPath).toString());
|
150
|
-
var _b = sceneJson.scene, base = _b.base, parcels = _b.parcels;
|
151
|
-
var pointers_1 = new Set();
|
152
|
-
pointers_1.add(base);
|
153
|
-
parcels.forEach(function ($) { return pointers_1.add($); });
|
154
|
-
var mappedFiles = (0, exports.getFilesFromFolder)({
|
155
|
-
folder: folder,
|
156
|
-
addOriginalPath: addOriginalPath,
|
157
|
-
ignorePattern: ignorePattern,
|
158
|
-
customHashMaker: customHashMaker
|
159
|
-
});
|
160
|
-
return {
|
161
|
-
version: 'v3',
|
162
|
-
type: 'scene',
|
163
|
-
id: hashMaker(folder),
|
164
|
-
pointers: Array.from(pointers_1),
|
165
|
-
timestamp: Date.now(),
|
166
|
-
metadata: sceneJson,
|
167
|
-
content: mappedFiles
|
168
|
-
};
|
169
|
-
}
|
170
|
-
return null;
|
171
|
-
}
|
172
|
-
exports.entityV3FromFolder = entityV3FromFolder;
|
173
|
-
function getSceneJson(_a) {
|
174
|
-
var baseFolders = _a.baseFolders, pointers = _a.pointers, customHashMaker = _a.customHashMaker;
|
175
|
-
var requestedPointers = new Set(pointers);
|
176
|
-
var resultEntities = [];
|
177
|
-
var allDeployments = baseFolders.map(function (folder) {
|
178
|
-
var dclIgnorePath = path.resolve(folder, '.dclignore');
|
179
|
-
var ignoreFileContent = '';
|
180
|
-
if (fs.existsSync(dclIgnorePath)) {
|
181
|
-
ignoreFileContent = fs.readFileSync(path.resolve(folder, '.dclignore'), 'utf-8');
|
182
|
-
}
|
183
|
-
return entityV3FromFolder({
|
184
|
-
folder: folder,
|
185
|
-
addOriginalPath: false,
|
186
|
-
ignorePattern: ignoreFileContent,
|
187
|
-
customHashMaker: customHashMaker
|
188
|
-
});
|
189
|
-
});
|
190
|
-
var _loop_1 = function (pointer) {
|
191
|
-
// get deployment by pointer
|
192
|
-
var theDeployment = allDeployments.find(function ($) { return $ && $.pointers.includes(pointer); });
|
193
|
-
if (theDeployment) {
|
194
|
-
// remove all the required pointers from the requestedPointers set
|
195
|
-
// to prevent sending duplicated entities
|
196
|
-
theDeployment.pointers.forEach(function ($) { return requestedPointers["delete"]($); });
|
197
|
-
// add the deployment to the results
|
198
|
-
resultEntities.push(theDeployment);
|
199
|
-
}
|
200
|
-
};
|
201
|
-
for (var _i = 0, _b = Array.from(requestedPointers); _i < _b.length; _i++) {
|
202
|
-
var pointer = _b[_i];
|
203
|
-
_loop_1(pointer);
|
204
|
-
}
|
205
|
-
return resultEntities;
|
206
|
-
}
|
207
|
-
exports.getSceneJson = getSceneJson;
|
208
|
-
function ensureWriteFile(filePath, data) {
|
209
|
-
return __awaiter(this, void 0, void 0, function () {
|
210
|
-
var directoryPath;
|
211
|
-
return __generator(this, function (_a) {
|
212
|
-
switch (_a.label) {
|
213
|
-
case 0:
|
214
|
-
directoryPath = path.dirname(filePath);
|
215
|
-
if (!!fs.existsSync(directoryPath)) return [3 /*break*/, 2];
|
216
|
-
return [4 /*yield*/, fs.promises.mkdir(directoryPath, { recursive: true })];
|
217
|
-
case 1:
|
218
|
-
_a.sent();
|
219
|
-
_a.label = 2;
|
220
|
-
case 2: return [4 /*yield*/, fs.promises.writeFile(filePath, data, 'utf-8')];
|
221
|
-
case 3:
|
222
|
-
_a.sent();
|
223
|
-
return [2 /*return*/];
|
224
|
-
}
|
225
|
-
});
|
226
|
-
});
|
227
|
-
}
|
228
|
-
exports.ensureWriteFile = ensureWriteFile;
|
229
|
-
function ensureCopyFile(fromFilePath, filePath) {
|
230
|
-
return __awaiter(this, void 0, void 0, function () {
|
231
|
-
var directoryPath;
|
232
|
-
return __generator(this, function (_a) {
|
233
|
-
switch (_a.label) {
|
234
|
-
case 0:
|
235
|
-
directoryPath = path.dirname(filePath);
|
236
|
-
if (!!fs.existsSync(directoryPath)) return [3 /*break*/, 2];
|
237
|
-
return [4 /*yield*/, fs.promises.mkdir(directoryPath, { recursive: true })];
|
238
|
-
case 1:
|
239
|
-
_a.sent();
|
240
|
-
_a.label = 2;
|
241
|
-
case 2: return [4 /*yield*/, fs.promises.copyFile(fromFilePath, filePath)];
|
242
|
-
case 3:
|
243
|
-
_a.sent();
|
244
|
-
return [2 /*return*/];
|
245
|
-
}
|
246
|
-
});
|
247
|
-
});
|
248
|
-
}
|
249
|
-
exports.ensureCopyFile = ensureCopyFile;
|
250
|
-
var downloadFile = function (url, path, timeout_seg) {
|
251
|
-
if (timeout_seg === void 0) { timeout_seg = 15; }
|
252
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
253
|
-
return __generator(this, function (_a) {
|
254
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
255
|
-
var file = fs.createWriteStream(path);
|
256
|
-
var schema = http;
|
257
|
-
if (url.toLowerCase().startsWith('https:')) {
|
258
|
-
schema = https;
|
259
|
-
}
|
260
|
-
var finished = false;
|
261
|
-
var request = schema
|
262
|
-
.get(url, function (response) {
|
263
|
-
response.pipe(file);
|
264
|
-
file.on('finish', function () {
|
265
|
-
file.close();
|
266
|
-
finished = true;
|
267
|
-
resolve(true);
|
268
|
-
});
|
269
|
-
})
|
270
|
-
.on('error', function (err) {
|
271
|
-
fs.unlinkSync(path);
|
272
|
-
finished = true;
|
273
|
-
reject(err);
|
274
|
-
});
|
275
|
-
setTimeout(function () {
|
276
|
-
if (!finished) {
|
277
|
-
request.destroy();
|
278
|
-
reject(new Error("Timeout ".concat(url)));
|
279
|
-
}
|
280
|
-
}, timeout_seg * 1000);
|
281
|
-
})];
|
282
|
-
});
|
283
|
-
});
|
284
|
-
};
|
285
|
-
exports.downloadFile = downloadFile;
|
286
|
-
var shaHashMaker = function (str) {
|
287
|
-
return crypto.createHash('sha1').update(str).digest('hex');
|
288
|
-
};
|
289
|
-
exports.shaHashMaker = shaHashMaker;
|
290
|
-
var defaultDclIgnore = function () {
|
291
|
-
return [
|
292
|
-
'.*',
|
293
|
-
'package.json',
|
294
|
-
'package-lock.json',
|
295
|
-
'yarn-lock.json',
|
296
|
-
'build.json',
|
297
|
-
'export',
|
298
|
-
'tsconfig.json',
|
299
|
-
'tslint.json',
|
300
|
-
'node_modules',
|
301
|
-
'*.ts',
|
302
|
-
'*.tsx',
|
303
|
-
'Dockerfile',
|
304
|
-
'dist',
|
305
|
-
'README.md',
|
306
|
-
'*.blend',
|
307
|
-
'*.fbx',
|
308
|
-
'*.zip',
|
309
|
-
'*.rar'
|
310
|
-
].join('\n');
|
311
|
-
};
|
312
|
-
exports.defaultDclIgnore = defaultDclIgnore;
|
313
|
-
var getDirectories = function (source) {
|
314
|
-
if (!fs.existsSync(source))
|
315
|
-
return [];
|
316
|
-
return fs
|
317
|
-
.readdirSync(source, { withFileTypes: true })
|
318
|
-
.filter(function (dirent) { return dirent.isDirectory(); })
|
319
|
-
.map(function (dirent) { return dirent.name; });
|
320
|
-
};
|
321
|
-
exports.getDirectories = getDirectories;
|
322
|
-
var createStaticRoutes = function (app, route, localFolder, mapFile) {
|
323
|
-
app.use(route, function (req, res, next) {
|
324
|
-
var options = {
|
325
|
-
root: localFolder,
|
326
|
-
dotfiles: 'deny',
|
327
|
-
maxAge: 1,
|
328
|
-
cacheControl: false,
|
329
|
-
lastModified: true,
|
330
|
-
headers: {
|
331
|
-
'x-timestamp': Date.now(),
|
332
|
-
'x-sent': true,
|
333
|
-
etag: JSON.stringify(Date.now().toString()),
|
334
|
-
'cache-control': 'no-cache,private,max-age=1'
|
335
|
-
}
|
336
|
-
};
|
337
|
-
var fileName = mapFile ? mapFile(req.params[0]) : req.params[0];
|
338
|
-
res.sendFile(fileName, options, function (err) {
|
339
|
-
if (err) {
|
340
|
-
next(err);
|
341
|
-
}
|
342
|
-
});
|
343
|
-
});
|
344
|
-
};
|
345
|
-
exports.createStaticRoutes = createStaticRoutes;
|