st-registry-cli 1.4.0 → 1.4.1
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/index.js +45 -41
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import fetch from "node-fetch";
|
|
|
6
6
|
import fs from "fs";
|
|
7
7
|
import path from "path";
|
|
8
8
|
|
|
9
|
-
// --- INSTALL COMMAND
|
|
9
|
+
// --- INSTALL COMMAND ---
|
|
10
10
|
program
|
|
11
11
|
.command("install <name> [destination] [version]")
|
|
12
12
|
.description("Downloads package")
|
|
@@ -26,8 +26,7 @@ program
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const mjson = await (await fetch(module["url"])).json();
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
|
|
31
30
|
let selectedVersion;
|
|
32
31
|
if (Array.isArray(mjson["url"])) {
|
|
33
32
|
if (version) {
|
|
@@ -43,47 +42,49 @@ program
|
|
|
43
42
|
|
|
44
43
|
if (selectedVersion) {
|
|
45
44
|
const downloadUrl = selectedVersion.url;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
let extension = "";
|
|
46
|
+
|
|
47
|
+
// 1. Check if it's a GitHub API zipball
|
|
48
|
+
if (downloadUrl.includes("zipball") || downloadUrl.includes("/archive/")) {
|
|
49
|
+
extension = ".zip";
|
|
50
|
+
} else {
|
|
51
|
+
// 2. Extract extension from filename if it exists
|
|
52
|
+
const lastPart = downloadUrl.split('/').pop().split('?')[0];
|
|
53
|
+
if (lastPart.includes(".")) {
|
|
54
|
+
const ext = lastPart.split('.').pop();
|
|
55
|
+
if (isNaN(ext)) extension = "." + ext;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
49
58
|
|
|
50
59
|
const finalDestination = destination || (module["name"] + extension);
|
|
51
|
-
|
|
52
60
|
console.log(chalk.blue(`Downloading to ${finalDestination}...`));
|
|
53
61
|
await download(downloadUrl, finalDestination);
|
|
54
62
|
console.log(chalk.green("Download complete!"));
|
|
55
|
-
} else {
|
|
56
|
-
console.error(chalk.red(`Version "${version}" not found for this module.`));
|
|
57
63
|
}
|
|
58
|
-
|
|
59
64
|
} catch (error) {
|
|
60
65
|
console.error(chalk.red("An error occurred:"), error.message);
|
|
61
66
|
}
|
|
62
67
|
});
|
|
63
68
|
|
|
64
|
-
// --- CLONE COMMAND
|
|
69
|
+
// --- CLONE COMMAND ---
|
|
65
70
|
program
|
|
66
71
|
.command("clone")
|
|
67
72
|
.description("Clones the entire registry using defined paths and all versions")
|
|
68
73
|
.action(async function () {
|
|
69
74
|
try {
|
|
70
|
-
console.log(chalk.cyan("Fetching registry..."));
|
|
71
75
|
const response = await fetch("https://stoppedwumm-studios.github.io/st-registry/index.json");
|
|
72
76
|
const modulesData = await response.json();
|
|
73
77
|
const modules = modulesData.modules;
|
|
74
78
|
|
|
75
79
|
for (const module of modules) {
|
|
76
80
|
console.log(chalk.yellow(`\nProcessing module: ${module.name}`));
|
|
77
|
-
|
|
78
81
|
const mjson = await (await fetch(module.url)).json();
|
|
79
82
|
|
|
80
|
-
// Create the directory based on the "path" key (e.g., "m/minecraft")
|
|
81
83
|
const targetDir = module.path;
|
|
82
84
|
if (!fs.existsSync(targetDir)) {
|
|
83
85
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
84
86
|
}
|
|
85
87
|
|
|
86
|
-
// Handle modules that have multiple versions
|
|
87
88
|
const versions = Array.isArray(mjson.url)
|
|
88
89
|
? mjson.url
|
|
89
90
|
: [{ versionRule: "latest", url: mjson.url }];
|
|
@@ -92,52 +93,55 @@ program
|
|
|
92
93
|
const downloadUrl = v.url;
|
|
93
94
|
const versionName = v.versionRule || "default";
|
|
94
95
|
|
|
95
|
-
// --- SMART EXTENSION DETECTION ---
|
|
96
|
-
const urlObj = new URL(downloadUrl);
|
|
97
|
-
const lastSegment = urlObj.pathname.split('/').pop();
|
|
98
|
-
|
|
99
96
|
let extension = "";
|
|
100
|
-
|
|
97
|
+
|
|
98
|
+
// --- REFINED EXTENSION LOGIC (No guessing) ---
|
|
101
99
|
|
|
102
|
-
|
|
100
|
+
// 1. If it's a GitHub API Zipball, it's a .zip
|
|
101
|
+
if (downloadUrl.includes("zipball") || downloadUrl.includes("/archive/")) {
|
|
103
102
|
extension = ".zip";
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
}
|
|
104
|
+
// 2. If the URL filename has an extension (like .jar or .zip), use it
|
|
105
|
+
else {
|
|
106
|
+
try {
|
|
107
|
+
const urlPath = new URL(downloadUrl).pathname;
|
|
108
|
+
const lastSegment = urlPath.split('/').pop();
|
|
109
|
+
|
|
110
|
+
if (lastSegment.includes(".")) {
|
|
111
|
+
const potentialExt = lastSegment.split('.').pop();
|
|
112
|
+
// Ensure it's not a version number (like v1.2.1 ending in .1)
|
|
113
|
+
if (isNaN(potentialExt)) {
|
|
114
|
+
extension = "." + potentialExt;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
// Fallback if URL is malformed
|
|
111
119
|
}
|
|
112
120
|
}
|
|
113
121
|
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
if (!extension) {
|
|
117
|
-
if (downloadUrl.toLowerCase().includes("installer")) extension = ".exe";
|
|
118
|
-
else if (downloadUrl.toLowerCase().includes("mac") || downloadUrl.toLowerCase().includes("osx")) extension = ".dmg";
|
|
119
|
-
else if (downloadUrl.toLowerCase().includes("json")) extension = ".json";
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Sanitize version name (remove slashes) to keep files inside the module folder
|
|
122
|
+
// 3. Build filename
|
|
123
|
+
// Result: "hyperPatchClient-v1.2.1" (No .dmg added!)
|
|
123
124
|
const safeVersionName = versionName.replace(/[/\\?%*:|"<>]/g, '-');
|
|
124
125
|
const fileName = `${module.name}-${safeVersionName}${extension}`;
|
|
125
|
-
|
|
126
126
|
const finalDestination = path.join(targetDir, fileName);
|
|
127
127
|
|
|
128
|
-
console.log(chalk.blue(` -> Downloading
|
|
128
|
+
console.log(chalk.blue(` -> Downloading [${versionName}] to ${finalDestination}...`));
|
|
129
129
|
|
|
130
130
|
try {
|
|
131
131
|
await download(downloadUrl, finalDestination);
|
|
132
|
+
|
|
133
|
+
// Set execution permissions for raw binaries on Mac/Linux
|
|
134
|
+
if (extension === "" && process.platform !== "win32") {
|
|
135
|
+
fs.chmodSync(finalDestination, 0o755);
|
|
136
|
+
}
|
|
132
137
|
} catch (dlErr) {
|
|
133
138
|
console.error(chalk.red(` Failed to download ${versionName}:`), dlErr.message);
|
|
134
139
|
}
|
|
135
140
|
}
|
|
136
|
-
console.log(chalk.green(`Successfully processed all versions for ${module.name}`));
|
|
137
141
|
}
|
|
138
142
|
console.log(chalk.bold.green("\nRegistry cloning complete!"));
|
|
139
143
|
} catch (error) {
|
|
140
|
-
console.error(chalk.red("An error occurred
|
|
144
|
+
console.error(chalk.red("An error occurred:"), error.message);
|
|
141
145
|
}
|
|
142
146
|
});
|
|
143
147
|
|