-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathinit_app.js
112 lines (100 loc) · 3.34 KB
/
init_app.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const fs = require("fs");
const { resolve } = require("path");
const { $ } = require("./js/shell");
const { displayError, displayMessage } = require("./js/displayMessage.js");
const { processExit } = require("./js/processExit.js");
const checkConda = async () => {
try {
displayMessage("Checking conda installation...");
await $("conda --version");
displayMessage("");
} catch (error) {
displayError(
"Please install conda from https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html"
);
processExit(1);
}
};
const updateConda = async () => {
await $("conda update -y -n base -c defaults conda");
};
const FORCE_REINSTALL = process.env.FORCE_REINSTALL ? true : false;
const DEBUG_ALWAYS_RETURN_UPDATED =
FORCE_REINSTALL || process.env.DEBUG_ALWAYS_RETURN_UPDATED ? true : false;
const getGitCommitHash = () =>
fs.readFileSync("./.git/refs/heads/main", "utf8");
const AppliedGitVersion = {
file: resolve(__dirname, ".git_version"),
get: () =>
fs.existsSync(AppliedGitVersion.file)
? fs.readFileSync(AppliedGitVersion.file, "utf8")
: null,
save: () => fs.writeFileSync(AppliedGitVersion.file, getGitCommitHash()),
};
const syncRepo = async () => {
if (!fs.existsSync(".git")) {
displayMessage("Linking to tts-generation-webui repository");
// this is a clone over the files from https://github.com/rsxdalv/tts-generation-webui
await $("git init -b main");
await $(
"git remote add origin https://github.com/rsxdalv/tts-generation-webui"
);
await $("git fetch");
await $("git reset --hard origin/main"); // Required when the versioned files existed in path before "git init" of this repo.
await $("git branch --set-upstream-to=origin/main");
return true;
} else {
displayMessage("Pulling updates from tts-generation-webui");
try {
await $("git pull");
const newHash = getGitCommitHash();
if (AppliedGitVersion.get() === newHash) {
displayMessage("Current git version: " + newHash);
displayMessage("No updates found, skipping...");
return false || DEBUG_ALWAYS_RETURN_UPDATED;
}
return true;
} catch (error) {
displayMessage("There was a problem while pulling updates. Aborting...");
throw error;
}
}
};
async function main() {
// http
// .createServer(function (req, res) {
// // res.writeHead(200, { "Content-Type": "text/html" });
// res.writeHead(200, { "Content-Type": "text/plain" });
// process.stdout.on("data", (data) => {
// res.write(data);
// });
// })
// .listen(8080);
const version = "0.0.6";
displayMessage("\n\nStarting init app (version: " + version + ")...\n\n");
if (process.env.DEBUG_ALWAYS_RETURN_UPDATED) {
displayMessage("Forcing update");
}
try {
await checkConda();
// await updateConda();
// check if there are any packages actually installed inside of conda
const isUpdated = await syncRepo();
if (!isUpdated) return;
const {
initializeApp,
setupReactUI,
repairTorch,
} = require("./js/initializeApp.js");
await initializeApp();
await setupReactUI();
await repairTorch();
AppliedGitVersion.save();
} catch (error) {
displayError(error.message);
processExit(1);
}
displayMessage("\n\nFinished init app.\n");
processExit(0);
}
main();