aboutsummaryrefslogtreecommitdiff
path: root/hooks
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-03-27 17:56:40 +0200
committerMinteck <contact@minteck.org>2022-03-27 17:56:40 +0200
commit44b4222bc02f102480d1afe05d940612ff6cb983 (patch)
tree936e6baf8039e065324cd1c2e453c33ec4cf4122 /hooks
parent1d8cbd4b6a7b654c77d8cd3793bc67811a39725d (diff)
downloadtwilight-44b4222bc02f102480d1afe05d940612ff6cb983.tar.gz
twilight-44b4222bc02f102480d1afe05d940612ff6cb983.tar.bz2
twilight-44b4222bc02f102480d1afe05d940612ff6cb983.zip
WIP Alicorn port (abandonned, To be removed)
Diffstat (limited to 'hooks')
-rw-r--r--hooks/apply_update.js8
-rw-r--r--hooks/clone.js2
-rw-r--r--hooks/files.js3
-rw-r--r--hooks/size.js4
-rw-r--r--hooks/update.js13
5 files changed, 19 insertions, 11 deletions
diff --git a/hooks/apply_update.js b/hooks/apply_update.js
index aa7496c..4258ee0 100644
--- a/hooks/apply_update.js
+++ b/hooks/apply_update.js
@@ -24,6 +24,8 @@
*/
module.exports = (pkg, tempDir) => {
+ let pkg2 = (twiplatform === "alicorn" ? pkg.replaceAll("_", "-").replaceAll(".", "-").split("-").map((i) => { return i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase() }).join("") : pkg)
+
const getAllDirs = function(dirPath, arrayOfFiles) {
files = fs.readdirSync(dirPath)
@@ -43,15 +45,15 @@ module.exports = (pkg, tempDir) => {
dirs = getAllDirs((home + "/packages/" + tempDir).replaceAll("\\", "/")).map(i => i.replaceAll("\\", "/").replaceAll((home + "/packages/" + tempDir).replaceAll("\\", "/") + "/", ""));
for (let dir of dirs) {
- if (!fs.existsSync(home + "/packages/" + pkg + "/" + dir)) {
- fs.mkdirSync(home + "/packages/" + pkg + "/" + dir);
+ if (!fs.existsSync(home + "/packages/" + pkg2 + "/" + dir)) {
+ fs.mkdirSync(home + "/packages/" + pkg2 + "/" + dir);
}
}
files = require('./files')(tempDir);
for (let file of files) {
if (file.trim() !== "") {
- fs.copyFileSync(home + "/packages/" + tempDir + "/" + file, home + "/packages/" + pkg + "/" + file);
+ fs.copyFileSync(home + "/packages/" + tempDir + "/" + file, home + "/packages/" + pkg2 + "/" + file);
}
}
} \ No newline at end of file
diff --git a/hooks/clone.js b/hooks/clone.js
index 315a6e5..239d09a 100644
--- a/hooks/clone.js
+++ b/hooks/clone.js
@@ -26,7 +26,7 @@
module.exports = (repo, branch, callback) => {
const spinner = ora("Downloading package...").start();
- if (os.platform() === "win32") {
+ if (twiplatform === "win32") {
git = require('child_process').execSync("where git").toString().trim();
} else {
git = require('child_process').execSync("which git").toString().trim();
diff --git a/hooks/files.js b/hooks/files.js
index 8e26dee..36a7894 100644
--- a/hooks/files.js
+++ b/hooks/files.js
@@ -42,5 +42,6 @@ const getAllFiles = function(dirPath, arrayOfFiles) {
}
module.exports = (pkg) => {
- return getAllFiles((home + "/packages/" + pkg).replaceAll("\\", "/")).map(i => i.replaceAll("\\", "/").replaceAll((home + "/packages/" + pkg).replaceAll("\\", "/") + "/", ""));
+ let pkg2 = (twiplatform === "alicorn" ? pkg.replaceAll("_", "-").replaceAll(".", "-").split("-").map((i) => { return i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase() }).join("") : pkg)
+ return getAllFiles((home + "/packages/" + pkg2).replaceAll("\\", "/")).map(i => i.replaceAll("\\", "/").replaceAll((home + "/packages/" + pkg2).replaceAll("\\", "/") + "/", ""));
} \ No newline at end of file
diff --git a/hooks/size.js b/hooks/size.js
index 84d9d3e..7c8ed44 100644
--- a/hooks/size.js
+++ b/hooks/size.js
@@ -42,7 +42,9 @@ const getAllFiles = function(dirPath, arrayOfFiles) {
}
module.exports = (pkg) => {
- asize = getAllFiles((home + "/packages/" + pkg).replaceAll("\\", "/")).map(i => i.replaceAll("\\", "/").replaceAll((home + "/packages/" + pkg).replaceAll("\\", "/") + "/", "")).map(i => fs.readFileSync(home + "/packages/" + pkg + "/" + i).length).reduce((a, b) => a + b);
+ let pkg2 = (twiplatform === "alicorn" ? pkg.replaceAll("_", "-").replaceAll(".", "-").split("-").map((i) => { return i.substring(0, 1).toUpperCase() + i.substring(1).toLowerCase() }).join("") : pkg);
+
+ asize = getAllFiles((home + "/packages/" + pkg2).replaceAll("\\", "/")).map(i => i.replaceAll("\\", "/").replaceAll((home + "/packages/" + pkg2).replaceAll("\\", "/") + "/", "")).map(i => fs.readFileSync(home + "/packages/" + pkg2 + "/" + i).length).reduce((a, b) => a + b);
if (asize > 1024) {
if (asize > 1048576) {
diff --git a/hooks/update.js b/hooks/update.js
index e2d4b8a..f89f5c1 100644
--- a/hooks/update.js
+++ b/hooks/update.js
@@ -34,9 +34,12 @@ module.exports = async () => {
let list = (await axios.get("https://twipkg.cdn.minteck.org/packages.json")).data;
if (fs.existsSync(home + "/repository")) {
- fs.rmSync(home + "/repository", { recursive: true });
+ for (let item of fs.readdirSync(home + "/repository")) {
+ fs.rmSync(home + "/repository/" + item, { recursive: true });
+ }
+ } else {
+ fs.mkdirSync(home + "/repository");
}
- fs.mkdirSync(home + "/repository");
fs.writeFileSync(home + "/repository/list.json", JSON.stringify(list));
@@ -50,12 +53,12 @@ module.exports = async () => {
}
if (eta > 1) {
if (eta > 60) {
- spinner.text = "Fetching package lists... " + Math.round((index / list.length) * 100) + "%, " + Math.round(eta / 60) + " minute" + (Math.round(eta / 60) > 1 ? "s" : "");
+ spinner.text = "Fetching package lists...\n " + Math.round((index / list.length) * 100) + "% completed\n about " + Math.round(eta / 60) + " minute" + (Math.round(eta / 60) > 1 ? "s" : "") + " remaining";
} else {
- spinner.text = "Fetching package lists... " + Math.round((index / list.length) * 100) + "%, " + Math.round(eta) + " second" + (Math.round(eta) > 1 ? "s" : "");
+ spinner.text = "Fetching package lists...\n " + Math.round((index / list.length) * 100) + "% completed\n about " + Math.round(eta) + " second" + (Math.round(eta) > 1 ? "s" : "") + " remaining";
}
} else {
- spinner.text = "Fetching package lists... " + Math.round((index / list.length) * 100) + "%";
+ spinner.text = "Fetching package lists...\n " + Math.round((index / list.length) * 100) + "% completed\n calculating remaining time...";
}
let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#");
try {