@dcode-dev/d-code 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.
- package/bin/d-code +20 -0
- package/install.js +145 -0
- package/package.json +36 -0
package/bin/d-code
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// This file is a placeholder. The real binary is downloaded by install.js during npm install.
|
|
3
|
+
// If you see this message, the postinstall script may have failed.
|
|
4
|
+
const { execFileSync } = require("child_process");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
|
|
8
|
+
const isWin = process.platform === "win32";
|
|
9
|
+
const bin = path.join(__dirname, isWin ? "d-code.exe" : "d-code-bin");
|
|
10
|
+
|
|
11
|
+
if (!fs.existsSync(bin)) {
|
|
12
|
+
console.error("[d-code] Binary not found. Try reinstalling: npm install -g @ddhanush1/d-code");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
18
|
+
} catch (e) {
|
|
19
|
+
process.exit(e.status ?? 1);
|
|
20
|
+
}
|
package/install.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* d-code installer
|
|
4
|
+
*
|
|
5
|
+
* Downloads the correct pre-built binary from GitHub Releases for the
|
|
6
|
+
* current platform and places it at npm/bin/d-code (or d-code.exe on Windows).
|
|
7
|
+
*
|
|
8
|
+
* Supported targets:
|
|
9
|
+
* linux x64 → x86_64-unknown-linux-musl
|
|
10
|
+
* linux arm64→ aarch64-unknown-linux-musl
|
|
11
|
+
* darwin x64 → x86_64-apple-darwin
|
|
12
|
+
* darwin arm64→ aarch64-apple-darwin
|
|
13
|
+
* win32 x64 → x86_64-pc-windows-msvc
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const https = require("https");
|
|
17
|
+
const fs = require("fs");
|
|
18
|
+
const path = require("path");
|
|
19
|
+
const os = require("os");
|
|
20
|
+
const { execSync } = require("child_process");
|
|
21
|
+
|
|
22
|
+
const VERSION = require("./package.json").version;
|
|
23
|
+
const REPO = "ddhanush1/d-code";
|
|
24
|
+
|
|
25
|
+
const TARGETS = {
|
|
26
|
+
"linux-x64": "x86_64-unknown-linux-musl",
|
|
27
|
+
"linux-arm64": "aarch64-unknown-linux-musl",
|
|
28
|
+
"darwin-x64": "x86_64-apple-darwin",
|
|
29
|
+
"darwin-arm64": "aarch64-apple-darwin",
|
|
30
|
+
"win32-x64": "x86_64-pc-windows-msvc",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const platform = os.platform();
|
|
34
|
+
const arch = os.arch();
|
|
35
|
+
const key = `${platform}-${arch}`;
|
|
36
|
+
const target = TARGETS[key];
|
|
37
|
+
|
|
38
|
+
if (!target) {
|
|
39
|
+
console.error(
|
|
40
|
+
`[d-code] Unsupported platform: ${platform}-${arch}.\n` +
|
|
41
|
+
`Supported: ${Object.keys(TARGETS).join(", ")}\n\n` +
|
|
42
|
+
`You can build from source:\n cargo install --git https://github.com/${REPO}`
|
|
43
|
+
);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const isWindows = platform === "win32";
|
|
48
|
+
// Use "d-code-bin" on unix so it doesn't conflict with the JS shim named "d-code".
|
|
49
|
+
const binaryName = isWindows ? "d-code.exe" : "d-code";
|
|
50
|
+
const installedName = isWindows ? "d-code.exe" : "d-code-bin";
|
|
51
|
+
const archiveName = isWindows
|
|
52
|
+
? `d-code-${target}.zip`
|
|
53
|
+
: `d-code-${target}.tar.gz`;
|
|
54
|
+
const downloadUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
|
|
55
|
+
const binDir = path.join(__dirname, "bin");
|
|
56
|
+
const binaryPath = path.join(binDir, installedName);
|
|
57
|
+
|
|
58
|
+
// If binary already exists (e.g. in CI or re-install), skip download.
|
|
59
|
+
if (fs.existsSync(binaryPath)) {
|
|
60
|
+
try {
|
|
61
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
62
|
+
} catch (_) {}
|
|
63
|
+
console.log(`[d-code] Binary already present at ${binaryPath}`);
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
68
|
+
|
|
69
|
+
console.log(`[d-code] Downloading ${archiveName} from GitHub Releases…`);
|
|
70
|
+
console.log(` ${downloadUrl}`);
|
|
71
|
+
|
|
72
|
+
downloadAndExtract(downloadUrl, archiveName, binaryName, binaryPath)
|
|
73
|
+
.then(() => {
|
|
74
|
+
// Rename extracted binary to installedName if different.
|
|
75
|
+
const extractedPath = path.join(binDir, binaryName);
|
|
76
|
+
if (extractedPath !== binaryPath && fs.existsSync(extractedPath)) {
|
|
77
|
+
fs.renameSync(extractedPath, binaryPath);
|
|
78
|
+
}
|
|
79
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
80
|
+
console.log(`[d-code] Installed to ${binaryPath}`);
|
|
81
|
+
})
|
|
82
|
+
.catch((err) => {
|
|
83
|
+
console.error(`[d-code] Installation failed: ${err.message}`);
|
|
84
|
+
console.error(
|
|
85
|
+
`\nYou can install manually:\n cargo install --git https://github.com/${REPO}`
|
|
86
|
+
);
|
|
87
|
+
// Don't exit 1 — allow npm install to succeed even if binary download fails
|
|
88
|
+
// (user may want to build from source or run in an unsupported env).
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
function downloadAndExtract(url, archiveName, binaryName, destPath) {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
const tmpFile = path.join(os.tmpdir(), archiveName);
|
|
94
|
+
const stream = fs.createWriteStream(tmpFile);
|
|
95
|
+
|
|
96
|
+
followRedirects(url, (res) => {
|
|
97
|
+
if (res.statusCode !== 200) {
|
|
98
|
+
reject(
|
|
99
|
+
new Error(`HTTP ${res.statusCode} downloading ${url}`)
|
|
100
|
+
);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
res.pipe(stream);
|
|
104
|
+
stream.on("finish", () => {
|
|
105
|
+
stream.close(() => {
|
|
106
|
+
extract(tmpFile, archiveName, binaryName, destPath)
|
|
107
|
+
.then(resolve)
|
|
108
|
+
.catch(reject);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
stream.on("error", reject);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function followRedirects(url, callback) {
|
|
117
|
+
https.get(url, (res) => {
|
|
118
|
+
if (res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 307 || res.statusCode === 308) {
|
|
119
|
+
followRedirects(res.headers.location, callback);
|
|
120
|
+
} else {
|
|
121
|
+
callback(res);
|
|
122
|
+
}
|
|
123
|
+
}).on("error", (err) => {
|
|
124
|
+
throw err;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function extract(archivePath, archiveName, binaryName, destPath) {
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
try {
|
|
131
|
+
if (archiveName.endsWith(".tar.gz")) {
|
|
132
|
+
execSync(`tar -xzf "${archivePath}" -C "${path.dirname(destPath)}" "${binaryName}"`, {
|
|
133
|
+
stdio: "pipe",
|
|
134
|
+
});
|
|
135
|
+
} else if (archiveName.endsWith(".zip")) {
|
|
136
|
+
execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${path.dirname(destPath)}' -Force"`, {
|
|
137
|
+
stdio: "pipe",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
resolve();
|
|
141
|
+
} catch (err) {
|
|
142
|
+
reject(new Error(`Extraction failed: ${err.message}`));
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dcode-dev/d-code",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lightweight AI coding agent for your terminal — powered by Claude, GPT-4, and GitHub Copilot",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ai",
|
|
7
|
+
"coding",
|
|
8
|
+
"agent",
|
|
9
|
+
"cli",
|
|
10
|
+
"llm",
|
|
11
|
+
"anthropic",
|
|
12
|
+
"claude",
|
|
13
|
+
"openai",
|
|
14
|
+
"copilot",
|
|
15
|
+
"developer-tools"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://github.com/ddhanush1/d-code",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/ddhanush1/d-code"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"bin": {
|
|
24
|
+
"d-code": "bin/d-code"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"postinstall": "node install.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"bin/",
|
|
31
|
+
"install.js"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=16"
|
|
35
|
+
}
|
|
36
|
+
}
|