@liorian/cli 0.12.0-alpha.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.
@@ -0,0 +1,4 @@
1
+ @ECHO OFF
2
+ SETLOCAL
3
+ SET SCRIPT_DIR=%~dp0
4
+ "%SCRIPT_DIR%liorian.exe" %*
package/lib/install.js ADDED
@@ -0,0 +1,170 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const { execSync } = require("child_process");
6
+ const fs = require("fs");
7
+ const os = require("os");
8
+ const path = require("path");
9
+ const https = require("https");
10
+ const http = require("http");
11
+
12
+ const REPO = "protorians/liorian-cli";
13
+ const BINARY_NAME = "liorian";
14
+
15
+ function getOsToken() {
16
+ const platform = os.platform();
17
+ const arch = os.arch();
18
+ switch (platform) {
19
+ case "darwin":
20
+ return `Macintosh; ${arch === "arm64" ? "" : "Intel "}Mac OS X ${execSync("sw_vers -productVersion").toString().trim()}`;
21
+ case "linux":
22
+ return `X11; Linux ${arch === "x64" ? "x86_64" : arch === "arm64" ? "aarch64" : arch}`;
23
+ case "win32":
24
+ return `Windows NT 10.0; Win64; ${arch === "arm64" ? "ARM64" : "x64"}`;
25
+ default:
26
+ return `${platform}; ${arch}`;
27
+ }
28
+ }
29
+
30
+ function getUserAgent() {
31
+ const pkg = require("../package.json");
32
+ // `Node/<version>` is the engine token of Node's core `http`/`https`
33
+ // package; `Senteints/<version>` is the CLI.
34
+ return `Protorians/5.0 (${getOsToken()}) Node/${process.version.slice(1)} Senteints/${pkg.version}`;
35
+ }
36
+
37
+ const PLATFORM_MAP = {
38
+ darwin: { amd64: "darwin_amd64", arm64: "darwin_arm64" },
39
+ linux: { amd64: "linux_amd64", arm64: "linux_arm64" },
40
+ win32: { amd64: "windows_amd64" },
41
+ };
42
+
43
+ const ARCHIVE_EXT = {
44
+ darwin: "tar.gz",
45
+ linux: "tar.gz",
46
+ win32: "zip",
47
+ };
48
+
49
+ function getVersion() {
50
+ const pkg = require("../package.json");
51
+ return `v${pkg.version}`;
52
+ }
53
+
54
+ function getPlatform() {
55
+ const platform = os.platform();
56
+ const arch = os.arch();
57
+
58
+ if (!PLATFORM_MAP[platform]) {
59
+ throw new Error(`Unsupported platform: ${platform}`);
60
+ }
61
+ if (!PLATFORM_MAP[platform][arch]) {
62
+ throw new Error(`Unsupported architecture: ${platform}/${arch}`);
63
+ }
64
+
65
+ return {
66
+ platform,
67
+ arch,
68
+ triple: PLATFORM_MAP[platform][arch],
69
+ ext: ARCHIVE_EXT[platform],
70
+ };
71
+ }
72
+
73
+ function getDownloadUrl(version, platform) {
74
+ const archiveVersion = version.replace(/^v/, "");
75
+ const archiveName = `${BINARY_NAME}-cli_${archiveVersion}_${platform.triple}.${platform.ext}`;
76
+ return `https://github.com/${REPO}/releases/download/${version}/${archiveName}`;
77
+ }
78
+
79
+ function download(url) {
80
+ return new Promise((resolve, reject) => {
81
+ const mod = url.startsWith("https") ? https : http;
82
+ mod
83
+ .get(url, { headers: { "User-Agent": getUserAgent() } }, (res) => {
84
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
85
+ return download(res.headers.location).then(resolve, reject);
86
+ }
87
+ if (res.statusCode !== 200) {
88
+ reject(new Error(`Download failed with status ${res.statusCode}: ${url}`));
89
+ return;
90
+ }
91
+ const chunks = [];
92
+ res.on("data", (chunk) => chunks.push(chunk));
93
+ res.on("end", () => resolve(Buffer.concat(chunks)));
94
+ res.on("error", reject);
95
+ })
96
+ .on("error", reject);
97
+ });
98
+ }
99
+
100
+ async function extractArchive(archivePath, destDir, platform) {
101
+ if (platform.ext === "zip") {
102
+ execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force"`, {
103
+ stdio: "inherit",
104
+ });
105
+ } else {
106
+ execSync(`tar -xzf "${archivePath}" -C "${destDir}"`, { stdio: "inherit" });
107
+ }
108
+ }
109
+
110
+ async function main() {
111
+ const version = getVersion();
112
+ const platform = getPlatform();
113
+ const binDir = path.join(__dirname, "..", "bin");
114
+ const tmpDir = path.join(os.tmpdir(), `liorian-install-${Date.now()}`);
115
+
116
+ console.log(`Installing @liorian/cli ${version} for ${platform.triple}...`);
117
+
118
+ try {
119
+ fs.mkdirSync(tmpDir, { recursive: true });
120
+ fs.mkdirSync(binDir, { recursive: true });
121
+
122
+ const url = getDownloadUrl(version, platform);
123
+ console.log(`Downloading from ${url}...`);
124
+
125
+ const data = await download(url);
126
+ const archivePath = path.join(tmpDir, `release.${platform.ext}`);
127
+ fs.writeFileSync(archivePath, data);
128
+
129
+ console.log("Extracting...");
130
+ await extractArchive(archivePath, tmpDir, platform);
131
+
132
+ const binaryExt = platform.platform === "win32" ? ".exe" : "";
133
+ const extractedBinary = path.join(tmpDir, `${BINARY_NAME}${binaryExt}`);
134
+ const targetBinary = path.join(binDir, `${BINARY_NAME}${binaryExt}`);
135
+
136
+ if (fs.existsSync(extractedBinary)) {
137
+ fs.copyFileSync(extractedBinary, targetBinary);
138
+ } else {
139
+ // Try to find the binary in subdirectories
140
+ const files = fs.readdirSync(tmpDir, { recursive: true });
141
+ const found = files.find(
142
+ (f) => f.toString().endsWith(`${BINARY_NAME}${binaryExt}`) || f.toString().endsWith(`${BINARY_NAME}.exe`)
143
+ );
144
+ if (found) {
145
+ fs.copyFileSync(path.join(tmpDir, found.toString()), targetBinary);
146
+ } else {
147
+ throw new Error(`Binary ${BINARY_NAME} not found in archive`);
148
+ }
149
+ }
150
+
151
+ if (platform.platform !== "win32") {
152
+ fs.chmodSync(targetBinary, 0o755);
153
+ }
154
+
155
+ console.log(`@liorian/cli ${version} installed successfully.`);
156
+ } catch (err) {
157
+ console.error(`Failed to install @liorian/cli: ${err.message}`);
158
+ console.error("");
159
+ console.error("You can install the binary manually from:");
160
+ console.error(` https://github.com/${REPO}/releases`);
161
+ process.exit(1);
162
+ } finally {
163
+ // Cleanup
164
+ try {
165
+ fs.rmSync(tmpDir, { recursive: true, force: true });
166
+ } catch {}
167
+ }
168
+ }
169
+
170
+ main();
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@liorian/cli",
3
+ "version": "0.12.0-alpha.1",
4
+ "description": "Liorian CLI - Create, maintain, and publish modules in the Liorian ecosystem",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/protorians/liorian-cli.git",
9
+ "directory": "npm/liorian-cli"
10
+ },
11
+ "homepage": "https://github.com/protorians/liorian-cli#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/protorians/liorian-cli/issues"
14
+ },
15
+ "bin": {
16
+ "liorian": "bin/liorian"
17
+ },
18
+ "scripts": {
19
+ "postinstall": "node lib/install.js"
20
+ },
21
+ "files": [
22
+ "bin",
23
+ "lib"
24
+ ],
25
+ "keywords": [
26
+ "liorian",
27
+ "cli",
28
+ "module",
29
+ "package-manager",
30
+ "blockchain",
31
+ "web3"
32
+ ],
33
+ "engines": {
34
+ "node": ">=16"
35
+ }
36
+ }