st-registry-cli 1.3.2 → 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 +98 -23
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -2,69 +2,144 @@
|
|
|
2
2
|
import { program } from "commander";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
import { download } from "./download.js";
|
|
5
|
+
import fetch from "node-fetch";
|
|
6
|
+
import fs from "fs";
|
|
7
|
+
import path from "path";
|
|
5
8
|
|
|
9
|
+
// --- INSTALL COMMAND ---
|
|
6
10
|
program
|
|
7
11
|
.command("install <name> [destination] [version]")
|
|
8
12
|
.description("Downloads package")
|
|
9
13
|
.action(async function (name, destination, version) {
|
|
10
14
|
try {
|
|
11
|
-
// 1. Fetch the registry
|
|
12
15
|
const response = await fetch("https://stoppedwumm-studios.github.io/st-registry/index.json");
|
|
13
16
|
const modulesData = await response.json();
|
|
14
17
|
const modules = modulesData.modules;
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
modules[key].name.toLowerCase() === name.toLowerCase()
|
|
19
|
+
const module = modules.find(m =>
|
|
20
|
+
m.name.toLowerCase() === name.toLowerCase()
|
|
19
21
|
);
|
|
20
22
|
|
|
21
|
-
if (!
|
|
23
|
+
if (!module) {
|
|
22
24
|
console.error(chalk.red(`Module "${name}" not found in registry.`));
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
const module = modules[moduleKey];
|
|
27
28
|
const mjson = await (await fetch(module["url"])).json();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// 3. Determine which version to use
|
|
29
|
+
|
|
31
30
|
let selectedVersion;
|
|
32
|
-
|
|
33
31
|
if (Array.isArray(mjson["url"])) {
|
|
34
32
|
if (version) {
|
|
35
|
-
// Find specific version
|
|
36
33
|
selectedVersion = mjson["url"].find(v =>
|
|
37
34
|
v.versionRule.toLowerCase() === version.toLowerCase()
|
|
38
35
|
);
|
|
39
36
|
} else {
|
|
40
|
-
// Default to the first one if no version specified
|
|
41
37
|
selectedVersion = mjson["url"][0];
|
|
42
38
|
}
|
|
43
39
|
} else if (typeof mjson["url"] === "string") {
|
|
44
|
-
// Handle cases where "url" might just be a string instead of an array
|
|
45
40
|
selectedVersion = { url: mjson["url"] };
|
|
46
41
|
}
|
|
47
42
|
|
|
48
|
-
// 4. Execute download
|
|
49
43
|
if (selectedVersion) {
|
|
50
44
|
const downloadUrl = selectedVersion.url;
|
|
45
|
+
let extension = "";
|
|
51
46
|
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
}
|
|
56
58
|
|
|
57
59
|
const finalDestination = destination || (module["name"] + extension);
|
|
58
|
-
|
|
59
60
|
console.log(chalk.blue(`Downloading to ${finalDestination}...`));
|
|
60
|
-
|
|
61
|
-
// Note: If download is async, you should probably 'await' it
|
|
62
61
|
await download(downloadUrl, finalDestination);
|
|
63
62
|
console.log(chalk.green("Download complete!"));
|
|
64
|
-
} else {
|
|
65
|
-
console.error(chalk.red(`Version "${version}" not found for this module.`));
|
|
66
63
|
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error(chalk.red("An error occurred:"), error.message);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
67
68
|
|
|
69
|
+
// --- CLONE COMMAND ---
|
|
70
|
+
program
|
|
71
|
+
.command("clone")
|
|
72
|
+
.description("Clones the entire registry using defined paths and all versions")
|
|
73
|
+
.action(async function () {
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch("https://stoppedwumm-studios.github.io/st-registry/index.json");
|
|
76
|
+
const modulesData = await response.json();
|
|
77
|
+
const modules = modulesData.modules;
|
|
78
|
+
|
|
79
|
+
for (const module of modules) {
|
|
80
|
+
console.log(chalk.yellow(`\nProcessing module: ${module.name}`));
|
|
81
|
+
const mjson = await (await fetch(module.url)).json();
|
|
82
|
+
|
|
83
|
+
const targetDir = module.path;
|
|
84
|
+
if (!fs.existsSync(targetDir)) {
|
|
85
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const versions = Array.isArray(mjson.url)
|
|
89
|
+
? mjson.url
|
|
90
|
+
: [{ versionRule: "latest", url: mjson.url }];
|
|
91
|
+
|
|
92
|
+
for (const v of versions) {
|
|
93
|
+
const downloadUrl = v.url;
|
|
94
|
+
const versionName = v.versionRule || "default";
|
|
95
|
+
|
|
96
|
+
let extension = "";
|
|
97
|
+
|
|
98
|
+
// --- REFINED EXTENSION LOGIC (No guessing) ---
|
|
99
|
+
|
|
100
|
+
// 1. If it's a GitHub API Zipball, it's a .zip
|
|
101
|
+
if (downloadUrl.includes("zipball") || downloadUrl.includes("/archive/")) {
|
|
102
|
+
extension = ".zip";
|
|
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
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 3. Build filename
|
|
123
|
+
// Result: "hyperPatchClient-v1.2.1" (No .dmg added!)
|
|
124
|
+
const safeVersionName = versionName.replace(/[/\\?%*:|"<>]/g, '-');
|
|
125
|
+
const fileName = `${module.name}-${safeVersionName}${extension}`;
|
|
126
|
+
const finalDestination = path.join(targetDir, fileName);
|
|
127
|
+
|
|
128
|
+
console.log(chalk.blue(` -> Downloading [${versionName}] to ${finalDestination}...`));
|
|
129
|
+
|
|
130
|
+
try {
|
|
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
|
+
}
|
|
137
|
+
} catch (dlErr) {
|
|
138
|
+
console.error(chalk.red(` Failed to download ${versionName}:`), dlErr.message);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
console.log(chalk.bold.green("\nRegistry cloning complete!"));
|
|
68
143
|
} catch (error) {
|
|
69
144
|
console.error(chalk.red("An error occurred:"), error.message);
|
|
70
145
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "st-registry-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"chalk": "^5.6.2",
|
|
15
|
-
"commander": "^14.0.3"
|
|
15
|
+
"commander": "^14.0.3",
|
|
16
|
+
"node-fetch": "^3.3.2"
|
|
16
17
|
},
|
|
17
18
|
"bin": {
|
|
18
19
|
"spm": "index.js"
|