@mistweaverco/kulala-cli 0.1.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,180 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let node_fs = require("node:fs");
24
+ let node_path = require("node:path");
25
+ let node_url = require("node:url");
26
+ let fs = require("fs");
27
+ fs = __toESM(fs, 1);
28
+ let path = require("path");
29
+ path = __toESM(path, 1);
30
+ let stream_promises = require("stream/promises");
31
+ //#region src/versions/backend.ts
32
+ var KULALA_CORE_VERSION = "0.17.0";
33
+ //#endregion
34
+ //#region src/lib/downloader/index.ts
35
+ var BINARY_NAME = "kulala-core";
36
+ var DOWNLOAD_URL = "https://github.com/mistweaverco/kulala-core/releases/download/v%s/%s";
37
+ function platform() {
38
+ const os = process.platform === "darwin" ? "darwin" : process.platform === "win32" ? "windows" : "linux";
39
+ const arch = process.arch;
40
+ let archName = arch;
41
+ if (arch === "x64") archName = "x86_64";
42
+ else if (arch === "arm64") archName = os === "darwin" ? "arm64" : "aarch64";
43
+ return `${os}-${archName}`;
44
+ }
45
+ function getBinDir() {
46
+ return path.default.join(__dirname, "bin");
47
+ }
48
+ function getReleaseBinName() {
49
+ const name = `${BINARY_NAME}-${platform()}`;
50
+ return process.platform === "win32" ? `${name}.exe` : name;
51
+ }
52
+ function getBinName() {
53
+ return process.platform === "win32" ? `${BINARY_NAME}.exe` : BINARY_NAME;
54
+ }
55
+ function getBinPath() {
56
+ return path.default.join(getBinDir(), getBinName());
57
+ }
58
+ function getVersionPath() {
59
+ return path.default.join(getBinDir(), "version.txt");
60
+ }
61
+ function binaryExists() {
62
+ return fs.default.existsSync(getBinPath());
63
+ }
64
+ function getInstalledVersion() {
65
+ const versionPath = getVersionPath();
66
+ if (!fs.default.existsSync(versionPath)) return null;
67
+ return fs.default.readFileSync(versionPath, "utf-8").trim();
68
+ }
69
+ function versionMatches() {
70
+ return getInstalledVersion() === KULALA_CORE_VERSION;
71
+ }
72
+ function makeExecutable(filePath) {
73
+ if (process.platform !== "win32") (0, fs.chmodSync)(filePath, 493);
74
+ }
75
+ var SPINNER_FRAMES = [
76
+ "⠋",
77
+ "⠙",
78
+ "⠹",
79
+ "⠸",
80
+ "⠼",
81
+ "⠴",
82
+ "⠦",
83
+ "⠧",
84
+ "⠇",
85
+ "⠏"
86
+ ];
87
+ function isInteractiveTerminal() {
88
+ return process.stderr.isTTY === true;
89
+ }
90
+ function createDownloadProgress() {
91
+ let timer;
92
+ let frame = 0;
93
+ let message = "";
94
+ const clearLine = () => {
95
+ if (timer) {
96
+ clearInterval(timer);
97
+ timer = void 0;
98
+ }
99
+ if (isInteractiveTerminal()) process.stderr.write("\r\x1B[K");
100
+ };
101
+ return {
102
+ start(msg) {
103
+ message = msg;
104
+ if (!isInteractiveTerminal()) {
105
+ console.error(message);
106
+ return;
107
+ }
108
+ const render = () => {
109
+ process.stderr.write(`\r${SPINNER_FRAMES[frame]} ${message}`);
110
+ frame = (frame + 1) % SPINNER_FRAMES.length;
111
+ };
112
+ render();
113
+ timer = setInterval(render, 80);
114
+ },
115
+ succeed(msg) {
116
+ clearLine();
117
+ console.error(msg);
118
+ },
119
+ fail() {
120
+ clearLine();
121
+ }
122
+ };
123
+ }
124
+ async function downloadFile(url, outputPath) {
125
+ const response = await fetch(url);
126
+ if (!response.ok || !response.body) throw new Error(`Failed to download kulala-core from ${url}: ${response.status} ${response.statusText}`);
127
+ await (0, stream_promises.pipeline)(response.body, (0, fs.createWriteStream)(outputPath));
128
+ }
129
+ function removeStaleBinary() {
130
+ if (!binaryExists()) return;
131
+ fs.default.unlinkSync(getBinPath());
132
+ const versionPath = getVersionPath();
133
+ if (fs.default.existsSync(versionPath)) fs.default.unlinkSync(versionPath);
134
+ }
135
+ async function installBackend() {
136
+ const binDir = getBinDir();
137
+ fs.default.mkdirSync(binDir, { recursive: true });
138
+ const releaseName = getReleaseBinName();
139
+ const url = DOWNLOAD_URL.replace("%s", KULALA_CORE_VERSION).replace("%s", releaseName);
140
+ const downloadPath = path.default.join(binDir, `${releaseName}.download`);
141
+ const binPath = getBinPath();
142
+ const progress = createDownloadProgress();
143
+ progress.start(`Downloading kulala-core v${KULALA_CORE_VERSION}...`);
144
+ try {
145
+ await downloadFile(url, downloadPath);
146
+ makeExecutable(downloadPath);
147
+ fs.default.renameSync(downloadPath, binPath);
148
+ fs.default.writeFileSync(getVersionPath(), KULALA_CORE_VERSION, "utf-8");
149
+ progress.succeed(`Installed kulala-core to ${binPath}`);
150
+ } catch (error) {
151
+ progress.fail();
152
+ throw error;
153
+ }
154
+ }
155
+ /**
156
+ * Best-effort install for lifecycle scripts (postinstall/prepare).
157
+ * Never throws; logs a warning when download fails so first-use fallback can run.
158
+ */
159
+ async function tryInstallBackend() {
160
+ const fromEnv = process.env.KULALA_CORE_PATH;
161
+ if (fromEnv && fromEnv.length > 0) return;
162
+ if (binaryExists() && versionMatches()) return;
163
+ if (binaryExists()) removeStaleBinary();
164
+ try {
165
+ await installBackend();
166
+ } catch (error) {
167
+ const message = error instanceof Error ? error.message : String(error);
168
+ console.error(`Warning: failed to download kulala-core during install: ${message}`);
169
+ console.error("kulala-cli will attempt to download it on first use instead.");
170
+ }
171
+ }
172
+ //#endregion
173
+ //#region src/postinstall.ts
174
+ if ((0, node_fs.existsSync)((0, node_path.join)((0, node_path.join)((0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href)), ".."), "scripts", "build.ts"))) process.exit(0);
175
+ tryInstallBackend().catch((error) => {
176
+ const message = error instanceof Error ? error.message : String(error);
177
+ process.stderr.write(`Warning: kulala-core postinstall failed: ${message}\n`);
178
+ process.stderr.write("kulala-cli will attempt to download it on first use instead.");
179
+ });
180
+ //#endregion
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@mistweaverco/kulala-cli",
3
+ "version": "0.1.0",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/mistweaverco/kulala-cli"
7
+ },
8
+ "bin": {
9
+ "kulala": "dist/cli.cjs"
10
+ },
11
+ "files": [
12
+ "dist/cli.cjs",
13
+ "dist/install-backend.cjs"
14
+ ],
15
+ "type": "module",
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "scripts": {
20
+ "build": "tsx ./scripts/build.ts",
21
+ "lint": "vp lint",
22
+ "prepare": "vp config && tsx ./scripts/build.ts || true",
23
+ "postinstall": "node dist/install-backend.cjs || true"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "25.9.1",
27
+ "chalk": "5.6.2",
28
+ "commander": "15.0.0",
29
+ "eslint-plugin-prettier": "5.5.6",
30
+ "globals": "17.6.0",
31
+ "picocolors": "1.1.1",
32
+ "prettier": "3.8.4",
33
+ "tsx": "4.22.4",
34
+ "typescript": "5.9.3",
35
+ "vite-plus": "catalog:"
36
+ },
37
+ "packageManager": "pnpm@11.5.2"
38
+ }