weside-cli 0.2.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/bin/.gitkeep ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "weside-cli",
3
+ "version": "0.2.1",
4
+ "description": "CLI for the weside.ai AI Companion Platform",
5
+ "homepage": "https://github.com/weside-ai/weside-cli",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/weside-ai/weside-cli.git"
9
+ },
10
+ "license": "Apache-2.0",
11
+ "bin": {
12
+ "weside": "bin/weside"
13
+ },
14
+ "scripts": {
15
+ "postinstall": "node postinstall.js"
16
+ },
17
+ "files": [
18
+ "bin/",
19
+ "postinstall.js"
20
+ ],
21
+ "keywords": [
22
+ "weside",
23
+ "ai",
24
+ "companion",
25
+ "cli",
26
+ "chat"
27
+ ],
28
+ "engines": {
29
+ "node": ">=16"
30
+ }
31
+ }
package/postinstall.js ADDED
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require("child_process");
4
+ const fs = require("fs");
5
+ const https = require("https");
6
+ const path = require("path");
7
+ const os = require("os");
8
+
9
+ const REPO = "weside-ai/weside-cli";
10
+ const BIN_DIR = path.join(__dirname, "bin");
11
+ const BIN_NAME = process.platform === "win32" ? "weside.exe" : "weside";
12
+
13
+ const PLATFORM_MAP = {
14
+ darwin: "darwin",
15
+ linux: "linux",
16
+ win32: "windows",
17
+ };
18
+
19
+ const ARCH_MAP = {
20
+ x64: "amd64",
21
+ arm64: "arm64",
22
+ };
23
+
24
+ async function main() {
25
+ const platform = PLATFORM_MAP[process.platform];
26
+ const arch = ARCH_MAP[process.arch];
27
+
28
+ if (!platform || !arch) {
29
+ console.error(
30
+ `Unsupported platform: ${process.platform}/${process.arch}`
31
+ );
32
+ process.exit(1);
33
+ }
34
+
35
+ const pkg = require("./package.json");
36
+ const version = pkg.version;
37
+
38
+ const ext = platform === "windows" ? "zip" : "tar.gz";
39
+ const archiveName = `weside-cli_${version}_${platform}_${arch}.${ext}`;
40
+ const url = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
41
+
42
+ console.log(`Downloading weside CLI v${version} (${platform}/${arch})...`);
43
+
44
+ fs.mkdirSync(BIN_DIR, { recursive: true });
45
+
46
+ const tmpFile = path.join(os.tmpdir(), archiveName);
47
+
48
+ try {
49
+ await download(url, tmpFile);
50
+
51
+ if (ext === "tar.gz") {
52
+ execSync(`tar -xzf "${tmpFile}" -C "${BIN_DIR}" weside`, {
53
+ stdio: "pipe",
54
+ });
55
+ } else {
56
+ execSync(
57
+ `powershell -Command "Expand-Archive -Path '${tmpFile}' -DestinationPath '${BIN_DIR}' -Force"`,
58
+ { stdio: "pipe" }
59
+ );
60
+ }
61
+
62
+ const binPath = path.join(BIN_DIR, BIN_NAME);
63
+ if (process.platform !== "win32") {
64
+ fs.chmodSync(binPath, 0o755);
65
+ }
66
+
67
+ console.log(`weside CLI v${version} installed successfully.`);
68
+ } catch (err) {
69
+ console.error(`Failed to install weside CLI: ${err.message}`);
70
+ console.error(
71
+ `You can manually download from: https://github.com/${REPO}/releases`
72
+ );
73
+ process.exit(1);
74
+ } finally {
75
+ try {
76
+ fs.unlinkSync(tmpFile);
77
+ } catch {}
78
+ }
79
+ }
80
+
81
+ function download(url, dest) {
82
+ return new Promise((resolve, reject) => {
83
+ const follow = (currentUrl) => {
84
+ https
85
+ .get(currentUrl, (res) => {
86
+ if (
87
+ res.statusCode >= 300 &&
88
+ res.statusCode < 400 &&
89
+ res.headers.location
90
+ ) {
91
+ follow(res.headers.location);
92
+ return;
93
+ }
94
+ if (res.statusCode !== 200) {
95
+ reject(new Error(`HTTP ${res.statusCode} downloading ${currentUrl}`));
96
+ return;
97
+ }
98
+ const file = fs.createWriteStream(dest);
99
+ res.pipe(file);
100
+ file.on("finish", () => {
101
+ file.close(resolve);
102
+ });
103
+ })
104
+ .on("error", reject);
105
+ };
106
+ follow(url);
107
+ });
108
+ }
109
+
110
+ main();