@kairainy/ck 0.1.20 → 0.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kairainy/ck",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "npm wrapper for the Code Knowledge Graph CLI (ck)",
5
5
  "license": "UNLICENSED",
6
6
  "bin": {
@@ -84,28 +84,55 @@ function download(url, outFile) {
84
84
 
85
85
  async function downloadRelease() {
86
86
  const target = rustTarget();
87
+ const archive = isWin ? `ck-${target}.zip` : `ck-${target}.tar.gz`;
88
+
89
+ const candidates = [];
90
+ if (process.env.CK_CLI_BINARY_URL) {
91
+ candidates.push(process.env.CK_CLI_BINARY_URL);
92
+ }
87
93
  const base =
88
94
  process.env.CK_RELEASE_BASE ||
89
95
  "https://github.com/kairainyomni/code-knowledge/releases";
90
- const archive = isWin
91
- ? `ck-${target}.zip`
92
- : `ck-${target}.tar.gz`;
93
- const url =
94
- process.env.CK_CLI_BINARY_URL ||
95
- `${base}/download/v${version}/${archive}`;
96
+ // 1. Versioned GitHub Release
97
+ candidates.push(`${base}/download/v${version}/${archive}`);
98
+ // 2. Latest GitHub Release
99
+ candidates.push(`${base}/latest/download/${archive}`);
100
+ // 3. Fallback: CodeKnowledge Live Portal CDN/API
101
+ candidates.push(`https://codeknowledge.io.vn/downloads/${archive}`);
96
102
 
97
103
  const tmpDir = fs.mkdtempSync(path.join(require("node:os").tmpdir(), "ck-npm-"));
98
104
  const archivePath = path.join(tmpDir, archive);
99
105
 
100
- console.log(`[ck] Downloading ${url}`);
101
- try {
102
- await download(url, archivePath);
103
- } catch (e) {
106
+ let success = false;
107
+ let lastError = null;
108
+
109
+ for (const url of candidates) {
110
+ console.log(`[ck] Attempting download: ${url}`);
111
+ try {
112
+ await download(url, archivePath);
113
+ success = true;
114
+ break;
115
+ } catch (e) {
116
+ lastError = e;
117
+ // Try next candidate
118
+ }
119
+ }
120
+
121
+ if (!success) {
104
122
  fs.rmSync(tmpDir, { recursive: true, force: true });
123
+ // Check if local target/release/ck.exe is available (workspace developer machine)
124
+ const local = path.join(findRepoRoot(), "target", "release", binName);
125
+ if (fs.existsSync(local)) {
126
+ console.log(`[ck] Fallback to locally built binary: ${local}`);
127
+ copyLocal();
128
+ return;
129
+ }
130
+
105
131
  throw new Error(
106
- `${e.message}\n` +
107
- `No release asset yet? Use local: CK_CLI_USE_LOCAL=1 npm i -g ./packaging/npm/@codeknowledge/cli\n` +
108
- `Or: cargo install --path apps/cli --force`
132
+ `All download sources failed (${lastError ? lastError.message : "404"}).\n` +
133
+ `Options to install:\n` +
134
+ ` 1. Local copy: CK_CLI_USE_LOCAL=1 npm i -g ./packaging/npm/@codeknowledge/cli\n` +
135
+ ` 2. Cargo: cargo install --path apps/cli --force`
109
136
  );
110
137
  }
111
138