@mark3labs/kit 0.0.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/kit +100 -0
- package/install.js +153 -0
- package/package.json +41 -0
package/bin/kit
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
|
|
8
|
+
const REPO = "mark3labs/kit";
|
|
9
|
+
const BINARY = "kit";
|
|
10
|
+
|
|
11
|
+
const binDir = __dirname;
|
|
12
|
+
const isWindows = process.platform === "win32";
|
|
13
|
+
const binaryName = isWindows ? "kit.exe" : "kit-bin";
|
|
14
|
+
const binaryPath = path.join(binDir, binaryName);
|
|
15
|
+
|
|
16
|
+
// Platform/arch mapping
|
|
17
|
+
const PLATFORM_MAP = { darwin: "darwin", linux: "linux", win32: "windows" };
|
|
18
|
+
const ARCH_MAP = { x64: "amd64", arm64: "arm64" };
|
|
19
|
+
|
|
20
|
+
function download(url, dest) {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
const follow = (url, redirects = 0) => {
|
|
23
|
+
if (redirects > 10) return reject(new Error("Too many redirects"));
|
|
24
|
+
https.get(url, (res) => {
|
|
25
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
26
|
+
return follow(res.headers.location, redirects + 1);
|
|
27
|
+
}
|
|
28
|
+
if (res.statusCode !== 200) return reject(new Error(`HTTP ${res.statusCode}`));
|
|
29
|
+
const file = fs.createWriteStream(dest);
|
|
30
|
+
res.pipe(file);
|
|
31
|
+
file.on("finish", () => { file.close(); resolve(); });
|
|
32
|
+
file.on("error", (err) => { fs.unlinkSync(dest); reject(err); });
|
|
33
|
+
}).on("error", reject);
|
|
34
|
+
};
|
|
35
|
+
follow(url);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function install() {
|
|
40
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
41
|
+
const arch = ARCH_MAP[process.arch];
|
|
42
|
+
if (!platform || !arch) {
|
|
43
|
+
console.error(`Unsupported platform: ${process.platform}/${process.arch}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const packageJson = require("../package.json");
|
|
48
|
+
const version = packageJson.version;
|
|
49
|
+
const ext = platform === "windows" ? "zip" : "tar.gz";
|
|
50
|
+
const filename = `${BINARY}_${version}_${platform}_${arch}.${ext}`;
|
|
51
|
+
const url = `https://github.com/${REPO}/releases/download/v${version}/${filename}`;
|
|
52
|
+
const archivePath = path.join(binDir, filename);
|
|
53
|
+
// Extract to temp dir to avoid overwriting this JS wrapper script
|
|
54
|
+
const tempDir = path.join(binDir, ".tmp-extract");
|
|
55
|
+
|
|
56
|
+
console.log(`Installing ${BINARY} v${version} (${platform}/${arch})...`);
|
|
57
|
+
|
|
58
|
+
await download(url, archivePath);
|
|
59
|
+
|
|
60
|
+
// Create temp extraction directory
|
|
61
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
62
|
+
|
|
63
|
+
if (platform === "windows") {
|
|
64
|
+
spawnSync("powershell", ["-Command", `Expand-Archive -Path "${archivePath}" -DestinationPath "${tempDir}" -Force`]);
|
|
65
|
+
} else {
|
|
66
|
+
spawnSync("tar", ["-xzf", archivePath, "-C", tempDir]);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Move extracted binary to final location (from temp dir to avoid overwriting wrapper)
|
|
70
|
+
const extractedPath = path.join(tempDir, platform === "windows" ? `${BINARY}.exe` : BINARY);
|
|
71
|
+
if (fs.existsSync(extractedPath)) {
|
|
72
|
+
fs.renameSync(extractedPath, binaryPath);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (platform !== "windows") fs.chmodSync(binaryPath, 0o755);
|
|
76
|
+
fs.unlinkSync(archivePath);
|
|
77
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
78
|
+
console.log(`Installed ${BINARY} successfully`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function main() {
|
|
82
|
+
// Install binary if missing
|
|
83
|
+
if (!fs.existsSync(binaryPath)) {
|
|
84
|
+
await install();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
88
|
+
stdio: "inherit",
|
|
89
|
+
shell: false,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (result.error) {
|
|
93
|
+
console.error(`Failed to run kit: ${result.error.message}`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
process.exit(result.status ?? 1);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
main();
|
package/install.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execSync, spawnSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const https = require("https");
|
|
7
|
+
const { createWriteStream, mkdirSync, chmodSync, unlinkSync } = fs;
|
|
8
|
+
|
|
9
|
+
const REPO = "mark3labs/kit";
|
|
10
|
+
const BINARY = "kit";
|
|
11
|
+
|
|
12
|
+
// Get version from package.json
|
|
13
|
+
const packageJson = require("./package.json");
|
|
14
|
+
const VERSION = packageJson.version;
|
|
15
|
+
|
|
16
|
+
// Platform mapping
|
|
17
|
+
const PLATFORM_MAP = {
|
|
18
|
+
darwin: "darwin",
|
|
19
|
+
linux: "linux",
|
|
20
|
+
win32: "windows",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Arch mapping
|
|
24
|
+
const ARCH_MAP = {
|
|
25
|
+
x64: "amd64",
|
|
26
|
+
arm64: "arm64",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function getPlatform() {
|
|
30
|
+
const platform = PLATFORM_MAP[process.platform];
|
|
31
|
+
if (!platform) {
|
|
32
|
+
throw new Error(`Unsupported platform: ${process.platform}`);
|
|
33
|
+
}
|
|
34
|
+
return platform;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getArch() {
|
|
38
|
+
const arch = ARCH_MAP[process.arch];
|
|
39
|
+
if (!arch) {
|
|
40
|
+
throw new Error(`Unsupported architecture: ${process.arch}`);
|
|
41
|
+
}
|
|
42
|
+
return arch;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getExtension(platform) {
|
|
46
|
+
return platform === "windows" ? "zip" : "tar.gz";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getBinaryName(platform) {
|
|
50
|
+
// Use different name to avoid conflict with JS wrapper on Unix
|
|
51
|
+
return platform === "windows" ? `${BINARY}.exe` : `${BINARY}-bin`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function download(url, dest) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
const follow = (url, redirects = 0) => {
|
|
57
|
+
if (redirects > 10) {
|
|
58
|
+
reject(new Error("Too many redirects"));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
https
|
|
63
|
+
.get(url, (response) => {
|
|
64
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
65
|
+
follow(response.headers.location, redirects + 1);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (response.statusCode !== 200) {
|
|
70
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const file = createWriteStream(dest);
|
|
75
|
+
response.pipe(file);
|
|
76
|
+
file.on("finish", () => {
|
|
77
|
+
file.close();
|
|
78
|
+
resolve();
|
|
79
|
+
});
|
|
80
|
+
file.on("error", (err) => {
|
|
81
|
+
unlinkSync(dest);
|
|
82
|
+
reject(err);
|
|
83
|
+
});
|
|
84
|
+
})
|
|
85
|
+
.on("error", reject);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
follow(url);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function extract(archivePath, destDir, platform) {
|
|
93
|
+
if (platform === "windows") {
|
|
94
|
+
// Use PowerShell to extract zip on Windows
|
|
95
|
+
spawnSync("powershell", [
|
|
96
|
+
"-Command",
|
|
97
|
+
`Expand-Archive -Path "${archivePath}" -DestinationPath "${destDir}" -Force`,
|
|
98
|
+
]);
|
|
99
|
+
} else {
|
|
100
|
+
// Use tar for Unix systems
|
|
101
|
+
spawnSync("tar", ["-xzf", archivePath, "-C", destDir]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function main() {
|
|
106
|
+
const platform = getPlatform();
|
|
107
|
+
const arch = getArch();
|
|
108
|
+
const ext = getExtension(platform);
|
|
109
|
+
const binaryName = getBinaryName(platform);
|
|
110
|
+
|
|
111
|
+
const filename = `${BINARY}_${VERSION}_${platform}_${arch}.${ext}`;
|
|
112
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${filename}`;
|
|
113
|
+
|
|
114
|
+
const binDir = path.join(__dirname, "bin");
|
|
115
|
+
const archivePath = path.join(__dirname, filename);
|
|
116
|
+
const binaryPath = path.join(binDir, binaryName);
|
|
117
|
+
|
|
118
|
+
console.log(`Installing ${BINARY} v${VERSION} (${platform}/${arch})...`);
|
|
119
|
+
console.log(`Downloading from ${url}...`);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
// Ensure bin directory exists
|
|
123
|
+
mkdirSync(binDir, { recursive: true });
|
|
124
|
+
|
|
125
|
+
// Download archive
|
|
126
|
+
await download(url, archivePath);
|
|
127
|
+
|
|
128
|
+
// Extract
|
|
129
|
+
extract(archivePath, binDir, platform);
|
|
130
|
+
|
|
131
|
+
// Rename binary (archive contains "kit", we want "kit-bin" on Unix)
|
|
132
|
+
const extractedName = platform === "windows" ? `${BINARY}.exe` : BINARY;
|
|
133
|
+
const extractedPath = path.join(binDir, extractedName);
|
|
134
|
+
if (extractedPath !== binaryPath && fs.existsSync(extractedPath)) {
|
|
135
|
+
fs.renameSync(extractedPath, binaryPath);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Make executable on Unix
|
|
139
|
+
if (platform !== "windows") {
|
|
140
|
+
chmodSync(binaryPath, 0o755);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Clean up archive
|
|
144
|
+
unlinkSync(archivePath);
|
|
145
|
+
|
|
146
|
+
console.log(`Successfully installed ${BINARY} to ${binaryPath}`);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
console.error(`Failed to install ${BINARY}: ${err.message}`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mark3labs/kit",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "AI-powered CLI tool",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/mark3labs/kit.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/mark3labs/kit",
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/mark3labs/kit/issues"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"bin": {
|
|
15
|
+
"kit": "bin/kit"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"postinstall": "node install.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin",
|
|
22
|
+
"install.js"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=16"
|
|
26
|
+
},
|
|
27
|
+
"os": [
|
|
28
|
+
"darwin",
|
|
29
|
+
"linux",
|
|
30
|
+
"win32"
|
|
31
|
+
],
|
|
32
|
+
"cpu": [
|
|
33
|
+
"x64",
|
|
34
|
+
"arm64"
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"cli",
|
|
38
|
+
"kit",
|
|
39
|
+
"ai"
|
|
40
|
+
]
|
|
41
|
+
}
|