-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreateinfojson.js
92 lines (73 loc) · 2.45 KB
/
createinfojson.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { promises as fs } from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
//console.log("__dirname=" + __dirname);
//console.log("__filename=" + __filename);
async function start() {
const distFolder = path.join(__dirname, "dist");
const packageJsonPath = path.join(__dirname, "package.json");
const infoJsonPath = path.join(distFolder, "info.json");
let packageJson;
// load package.json so we can get data
try {
const packageData = await fs.readFile(packageJsonPath, {
encoding: "utf8",
});
packageJson = JSON.parse(packageData);
} catch (error) {
console.error(error);
}
// create vortex info.json object
const infoJson = {
name:
packageJson?.config?.extensionName == undefined
? packageJson.name
: packageJson?.config?.extensionName,
author: packageJson.author,
version: packageJson.version,
description: packageJson.description,
lastUpdated: Date.now()
};
// try to copy gameart.jpg
// const file = "gameart.jpg";
// const source = path.join(__dirname, file);
// const destination = path.join(distFolder, file);
// try {
// await fs.copyFile(source, destination);
// console.log(`${file} was copied to ${destination}`);
// } catch (error) {
// console.log(`The file could not be copied. ${error}`);
// }
/*
// try to load info.json if it exists
try {
await fs.access(infoJsonPath);
console.log(infoJsonPath + " exists");
const infoData = await fs.readFile(infoJsonPath, { encoding: "utf8" });
infoJson = JSON.parse(infoData); // try to parse into object
// exists, so only update the other stuff
infoJson.author = packageJson.author;
infoJson.version = packageJson.version;
infoJson.description = packageJson.description;
} catch (error) {
console.error(error);
// doesn't exist, update everything
infoJson.name = packageJson.name;
infoJson.author = packageJson.author;
infoJson.version = packageJson.version;
infoJson.description = packageJson.description;
}*/
// try to write created info.json to /dist folder
try {
const json = JSON.stringify(infoJson);
console.log(json);
console.log(new Date().toTimeString());
// write back to info.json
await fs.writeFile(infoJsonPath, json, { encoding: "utf8" });
} catch (err) {
console.error(err);
}
}
start();