-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileAssetsToConfig.esm.js
More file actions
39 lines (39 loc) · 1.93 KB
/
fileAssetsToConfig.esm.js
File metadata and controls
39 lines (39 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.*/
import { join } from "https://deno.land/std@0.224.0/path/mod.ts";
const root = "~\\Light Bridge\\Source", configPath = "~\\Light Bridge\\Source\\Engine\\config.json";
let config = JSON.parse(await Deno.readTextFile(configPath)), assets = config?.["assets"];
if (typeof assets == "object" && assets != null) {
for await (const {
isFile,
name
} of Deno.readDir(root)) {
if (isFile == true && name.endsWith(".json") == true) {
try {
const path = join(root, name);
let data = JSON.parse(await Deno.readTextFile(path)), asset = data?.["asset"];
if (typeof asset == "object" && asset != null) {
let file = asset?.["file"];
if (typeof file == "object" && file != null) {
const fileName = file?.["filename"];
if ((typeof fileName == "string" ? fileName.length > 0 : false) == true) {
if (name.slice(0, name.lastIndexOf(".json")) == fileName) {
const fileURL = (new URL(file?.["url"], "file://"))?.pathname;
if ((typeof fileURL == "string" ? fileURL.length > 0 : false) == true) {
assets[fileURL] = asset;
await Deno.remove(path)
}
}
}
}
}
} catch (error) {
undefined
}
}
};
await Deno.writeTextFile(configPath, JSON.stringify(config, null, 4))
}