st-registry-cli 1.0.0

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.
@@ -0,0 +1,21 @@
1
+ name: Publish Package to npmjs
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+ steps:
12
+ - uses: actions/checkout@v5
13
+ # Setup .npmrc file to publish to npm
14
+ - uses: actions/setup-node@v4
15
+ with:
16
+ node-version: '20.x'
17
+ registry-url: 'https://registry.npmjs.org'
18
+ - run: npm ci
19
+ - run: npm publish --provenance --access public
20
+ env:
21
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/download.js ADDED
@@ -0,0 +1,7 @@
1
+ import { writeFile } from 'node:fs/promises'
2
+ import { Readable } from 'node:stream'
3
+
4
+ export async function download(url, path) {
5
+ const response = await fetch(url)
6
+ await writeFile(path, Readable.fromWeb(response.body))
7
+ }
package/index.js ADDED
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import chalk from "chalk";
4
+ import { download } from "./download.js";
5
+
6
+ program
7
+ .command("install <name> [destination] [version]")
8
+ .description("Downloads package")
9
+ .action(async function (name, destination, version) {
10
+ try {
11
+ // 1. Fetch the registry
12
+ const response = await fetch("https://stoppedwumm-studios.github.io/st-registry/index.json");
13
+ const modulesData = await response.json();
14
+ const modules = modulesData.modules;
15
+
16
+ // 2. Find the module (Case-insensitive)
17
+ const moduleKey = Object.keys(modules).find(key =>
18
+ modules[key].name.toLowerCase() === name.toLowerCase()
19
+ );
20
+
21
+ if (!moduleKey) {
22
+ console.error(chalk.red(`Module "${name}" not found in registry.`));
23
+ return;
24
+ }
25
+
26
+ const module = modules[moduleKey];
27
+ const mjson = await (await fetch(module["url"])).json();
28
+ console.log("Found module under path:", chalk.bold(module["path"]));
29
+
30
+ // 3. Determine which version to use
31
+ let selectedVersion;
32
+
33
+ if (Array.isArray(mjson["url"])) {
34
+ if (version) {
35
+ // Find specific version
36
+ selectedVersion = mjson["url"].find(v =>
37
+ v.versionRule.toLowerCase() === version.toLowerCase()
38
+ );
39
+ } else {
40
+ // Default to the first one if no version specified
41
+ selectedVersion = mjson["url"][0];
42
+ }
43
+ } else if (typeof mjson["url"] === "string") {
44
+ // Handle cases where "url" might just be a string instead of an array
45
+ selectedVersion = { url: mjson["url"] };
46
+ }
47
+
48
+ // 4. Execute download
49
+ if (selectedVersion) {
50
+ const downloadUrl = selectedVersion.url;
51
+
52
+ // Determine extension logic
53
+ const extension = downloadUrl.includes("zipball")
54
+ ? ".zip"
55
+ : "." + downloadUrl.split(".").at(-1);
56
+
57
+ const finalDestination = destination || (module["name"] + extension);
58
+
59
+ console.log(chalk.blue(`Downloading to ${finalDestination}...`));
60
+
61
+ // Note: If download is async, you should probably 'await' it
62
+ await download(downloadUrl, finalDestination);
63
+ console.log(chalk.green("Download complete!"));
64
+ } else {
65
+ console.error(chalk.red(`Version "${version}" not found for this module.`));
66
+ }
67
+
68
+ } catch (error) {
69
+ console.error(chalk.red("An error occurred:"), error.message);
70
+ }
71
+ });
72
+
73
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "st-registry-cli",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "module",
13
+ "dependencies": {
14
+ "chalk": "^5.6.2",
15
+ "commander": "^14.0.3"
16
+ },
17
+ "bin":{
18
+ "spm": "index.js"
19
+ }
20
+ }