@kepoai/cli 0.0.5 → 0.0.8
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/README.md +2 -2
- package/bin/kp +29 -4
- package/bin/kp.bat +80 -0
- package/bin/kp.js +185 -0
- package/package.json +24 -21
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@ npx @kepo/cli [command] [options]
|
|
|
25
25
|
## System Requirements
|
|
26
26
|
|
|
27
27
|
- Node.js >= 14.0.0
|
|
28
|
-
- Supported OS: macOS, Linux
|
|
29
|
-
- Supported architectures: x86_64, arm64 (Apple Silicon)
|
|
28
|
+
- Supported OS: macOS, Windows, Linux
|
|
29
|
+
- Supported architectures: x86_64 (Intel/AMD), arm64 (Apple Silicon/ARM)
|
|
30
30
|
|
|
31
31
|
## Auto-Download
|
|
32
32
|
|
package/bin/kp
CHANGED
|
@@ -24,10 +24,10 @@ fi
|
|
|
24
24
|
|
|
25
25
|
# Determine system architecture
|
|
26
26
|
os="$(uname)"
|
|
27
|
-
os_lower="darwin" # Currently only support macOS
|
|
28
27
|
architecture="$(uname -m)"
|
|
29
28
|
|
|
30
29
|
if [[ "${os}" = "Darwin" ]]; then
|
|
30
|
+
os_lower="darwin"
|
|
31
31
|
if [[ "${architecture}" = "arm64" ]]; then
|
|
32
32
|
architecture_dir="arm64"
|
|
33
33
|
download_arch="arm64"
|
|
@@ -35,15 +35,40 @@ if [[ "${os}" = "Darwin" ]]; then
|
|
|
35
35
|
architecture_dir="x86"
|
|
36
36
|
download_arch="amd64"
|
|
37
37
|
fi
|
|
38
|
+
elif [[ "${os}" = "Linux" ]]; then
|
|
39
|
+
os_lower="linux"
|
|
40
|
+
if [[ "${architecture}" = "aarch64" ]] || [[ "${architecture}" = "arm64" ]]; then
|
|
41
|
+
architecture_dir="linux-arm64"
|
|
42
|
+
download_arch="arm64"
|
|
43
|
+
else
|
|
44
|
+
architecture_dir="linux-x86"
|
|
45
|
+
download_arch="amd64"
|
|
46
|
+
fi
|
|
47
|
+
elif [[ "${os}" =~ ^MINGW.*|^MSYS.*|^CYGWIN.* ]] || [[ "${OS}" = "Windows_NT" ]]; then
|
|
48
|
+
os_lower="windows"
|
|
49
|
+
# Windows 架构检测
|
|
50
|
+
if [[ "${PROCESSOR_ARCHITECTURE}" = "ARM64" ]] || [[ "${architecture}" = "arm64" ]]; then
|
|
51
|
+
architecture_dir="windows-arm64"
|
|
52
|
+
download_arch="arm64"
|
|
53
|
+
else
|
|
54
|
+
architecture_dir="windows-x86"
|
|
55
|
+
download_arch="amd64"
|
|
56
|
+
fi
|
|
38
57
|
else
|
|
39
|
-
echo "Error:
|
|
58
|
+
echo "Error: Unsupported operating system: ${os}"
|
|
59
|
+
echo "Supported systems: macOS, Linux, Windows"
|
|
40
60
|
exit 1
|
|
41
61
|
fi
|
|
42
62
|
|
|
43
63
|
# Define CLI paths
|
|
44
|
-
|
|
64
|
+
if [[ "${os_lower}" = "windows" ]]; then
|
|
65
|
+
kp_path="$bin_dir/$architecture_dir/kp.exe"
|
|
66
|
+
download_url="https://r2.kepo.ai/kepo-cli/$kp_version/kepo-cli-$os_lower-$download_arch.exe"
|
|
67
|
+
else
|
|
68
|
+
kp_path="$bin_dir/$architecture_dir/kp"
|
|
69
|
+
download_url="https://r2.kepo.ai/kepo-cli/$kp_version/kepo-cli-$os_lower-$download_arch"
|
|
70
|
+
fi
|
|
45
71
|
kp_version_file="$bin_dir/$architecture_dir/version"
|
|
46
|
-
download_url="https://r2.kepo.ai/kepo-cli/$kp_version/kepo-cli-$os_lower-$download_arch"
|
|
47
72
|
|
|
48
73
|
# Function to download CLI binary
|
|
49
74
|
function download_cli {
|
package/bin/kp.bat
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
REM Determine script path
|
|
5
|
+
set "bin_dir=%~dp0"
|
|
6
|
+
set "bin_dir=%bin_dir:~0,-1%"
|
|
7
|
+
for %%i in ("%bin_dir%") do set "dist_dir=%%~dpi"
|
|
8
|
+
set "dist_dir=%dist_dir:~0,-1%"
|
|
9
|
+
|
|
10
|
+
if "%bin_dir%"=="" (
|
|
11
|
+
echo Error: Unable to determine CLI path
|
|
12
|
+
exit /b 1
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
REM Read version from package.json
|
|
16
|
+
for /f "tokens=2 delims=:, " %%a in ('findstr /r "\"version\":" "%dist_dir%\package.json"') do (
|
|
17
|
+
set "kp_version=%%~a"
|
|
18
|
+
set "kp_version=!kp_version:"=!"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
if "%kp_version%"=="" (
|
|
22
|
+
echo Error: Failed to parse version
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
REM Determine system architecture
|
|
27
|
+
set "os_lower=windows"
|
|
28
|
+
|
|
29
|
+
REM Check processor architecture
|
|
30
|
+
if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
|
|
31
|
+
set "architecture_dir=windows-arm64"
|
|
32
|
+
set "download_arch=arm64"
|
|
33
|
+
) else (
|
|
34
|
+
set "architecture_dir=windows-x86"
|
|
35
|
+
set "download_arch=amd64"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
REM Define CLI paths
|
|
39
|
+
set "kp_path=%bin_dir%\%architecture_dir%\kp.exe"
|
|
40
|
+
set "kp_version_file=%bin_dir%\%architecture_dir%\version"
|
|
41
|
+
set "download_url=https://r2.kepo.ai/kepo-cli/%kp_version%/kepo-cli-%os_lower%-%download_arch%.exe"
|
|
42
|
+
|
|
43
|
+
REM Function to download CLI binary
|
|
44
|
+
if "%1"=="npm-post-install" (
|
|
45
|
+
call :download_cli
|
|
46
|
+
exit /b 0
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
REM If CLI doesn't exist or version file is missing, download it
|
|
50
|
+
if not exist "%kp_path%" (
|
|
51
|
+
call :download_cli
|
|
52
|
+
) else if not exist "%kp_version_file%" (
|
|
53
|
+
call :download_cli
|
|
54
|
+
) else (
|
|
55
|
+
REM Check if version is outdated using version file
|
|
56
|
+
set /p current_version=<"%kp_version_file%"
|
|
57
|
+
if not "!current_version!"=="%kp_version%" (
|
|
58
|
+
echo Updating Kepo CLI from v!current_version! to v%kp_version%...
|
|
59
|
+
call :download_cli
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
REM Execute CLI command
|
|
64
|
+
"%kp_path%" %*
|
|
65
|
+
exit /b %errorlevel%
|
|
66
|
+
|
|
67
|
+
:download_cli
|
|
68
|
+
echo Downloading Kepo CLI v%kp_version% for Windows/%download_arch%...
|
|
69
|
+
if not exist "%bin_dir%\%architecture_dir%" mkdir "%bin_dir%\%architecture_dir%"
|
|
70
|
+
|
|
71
|
+
REM Use PowerShell to download the file (more reliable than curl on Windows)
|
|
72
|
+
powershell -Command "try { Invoke-WebRequest -Uri '%download_url%' -OutFile '%kp_path%' -UseBasicParsing } catch { Write-Host 'Error: Failed to download CLI from %download_url%'; exit 1 }"
|
|
73
|
+
if %errorlevel% neq 0 (
|
|
74
|
+
echo Error: Failed to download CLI from %download_url%
|
|
75
|
+
exit /b 1
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
echo %kp_version% > "%kp_version_file%"
|
|
79
|
+
echo Successfully downloaded CLI to %kp_path%
|
|
80
|
+
goto :eof
|
package/bin/kp.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const { execSync, spawn } = require('child_process');
|
|
7
|
+
const https = require('https');
|
|
8
|
+
|
|
9
|
+
// 获取脚本路径和版本信息
|
|
10
|
+
const binDir = __dirname;
|
|
11
|
+
const distDir = path.dirname(binDir);
|
|
12
|
+
const packageJsonPath = path.join(distDir, 'package.json');
|
|
13
|
+
|
|
14
|
+
// 读取版本信息
|
|
15
|
+
let kpVersion;
|
|
16
|
+
try {
|
|
17
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
18
|
+
kpVersion = packageJson.version;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error('Error: Failed to parse version from package.json');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 检测操作系统和架构
|
|
25
|
+
function detectPlatform() {
|
|
26
|
+
const platform = os.platform();
|
|
27
|
+
const arch = os.arch();
|
|
28
|
+
|
|
29
|
+
let osLower, architectureDir, downloadArch, executableName;
|
|
30
|
+
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case 'darwin':
|
|
33
|
+
osLower = 'darwin';
|
|
34
|
+
executableName = 'kp';
|
|
35
|
+
if (arch === 'arm64') {
|
|
36
|
+
architectureDir = 'arm64';
|
|
37
|
+
downloadArch = 'arm64';
|
|
38
|
+
} else {
|
|
39
|
+
architectureDir = 'x86';
|
|
40
|
+
downloadArch = 'amd64';
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case 'linux':
|
|
45
|
+
osLower = 'linux';
|
|
46
|
+
executableName = 'kp';
|
|
47
|
+
if (arch === 'arm64' || arch === 'aarch64') {
|
|
48
|
+
architectureDir = 'linux-arm64';
|
|
49
|
+
downloadArch = 'arm64';
|
|
50
|
+
} else {
|
|
51
|
+
architectureDir = 'linux-x86';
|
|
52
|
+
downloadArch = 'amd64';
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
|
|
56
|
+
case 'win32':
|
|
57
|
+
osLower = 'windows';
|
|
58
|
+
executableName = 'kp.exe';
|
|
59
|
+
if (arch === 'arm64') {
|
|
60
|
+
architectureDir = 'windows-arm64';
|
|
61
|
+
downloadArch = 'arm64';
|
|
62
|
+
} else {
|
|
63
|
+
architectureDir = 'windows-x86';
|
|
64
|
+
downloadArch = 'amd64';
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
default:
|
|
69
|
+
console.error(`Error: Unsupported operating system: ${platform}`);
|
|
70
|
+
console.error('Supported systems: macOS, Linux, Windows');
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { osLower, architectureDir, downloadArch, executableName };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 下载文件
|
|
78
|
+
function downloadFile(url, filePath) {
|
|
79
|
+
return new Promise((resolve, reject) => {
|
|
80
|
+
const file = fs.createWriteStream(filePath);
|
|
81
|
+
|
|
82
|
+
https.get(url, (response) => {
|
|
83
|
+
if (response.statusCode === 200) {
|
|
84
|
+
response.pipe(file);
|
|
85
|
+
file.on('finish', () => {
|
|
86
|
+
file.close();
|
|
87
|
+
resolve();
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
91
|
+
}
|
|
92
|
+
}).on('error', (error) => {
|
|
93
|
+
fs.unlink(filePath, () => {}); // 删除部分下载的文件
|
|
94
|
+
reject(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 下载 CLI 二进制文件
|
|
100
|
+
async function downloadCli(kpPath, downloadUrl, versionFile) {
|
|
101
|
+
console.log(`Downloading Kepo CLI v${kpVersion} for ${os.platform()}/${os.arch()}...`);
|
|
102
|
+
|
|
103
|
+
// 确保目录存在
|
|
104
|
+
const dir = path.dirname(kpPath);
|
|
105
|
+
if (!fs.existsSync(dir)) {
|
|
106
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
await downloadFile(downloadUrl, kpPath);
|
|
111
|
+
|
|
112
|
+
// 设置执行权限(Unix 系统)
|
|
113
|
+
if (os.platform() !== 'win32') {
|
|
114
|
+
fs.chmodSync(kpPath, 0o755);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 写入版本文件
|
|
118
|
+
fs.writeFileSync(versionFile, kpVersion);
|
|
119
|
+
console.log(`Successfully downloaded CLI to ${kpPath}`);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(`Error: Failed to download CLI from ${downloadUrl}`);
|
|
122
|
+
console.error(error.message);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 检查版本是否需要更新
|
|
128
|
+
function needsUpdate(versionFile) {
|
|
129
|
+
if (!fs.existsSync(versionFile)) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
const currentVersion = fs.readFileSync(versionFile, 'utf8').trim();
|
|
135
|
+
return currentVersion !== kpVersion;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 主函数
|
|
142
|
+
async function main() {
|
|
143
|
+
const { osLower, architectureDir, downloadArch, executableName } = detectPlatform();
|
|
144
|
+
|
|
145
|
+
const kpPath = path.join(binDir, architectureDir, executableName);
|
|
146
|
+
const versionFile = path.join(binDir, architectureDir, 'version');
|
|
147
|
+
const downloadUrl = `https://r2.kepo.ai/kepo-cli/${kpVersion}/kepo-cli-${osLower}-${downloadArch}${osLower === 'windows' ? '.exe' : ''}`;
|
|
148
|
+
|
|
149
|
+
// 处理 npm post-install
|
|
150
|
+
if (process.argv[2] === 'npm-post-install') {
|
|
151
|
+
await downloadCli(kpPath, downloadUrl, versionFile);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 检查是否需要下载或更新
|
|
156
|
+
if (!fs.existsSync(kpPath) || needsUpdate(versionFile)) {
|
|
157
|
+
if (fs.existsSync(versionFile)) {
|
|
158
|
+
const currentVersion = fs.readFileSync(versionFile, 'utf8').trim();
|
|
159
|
+
console.log(`Updating Kepo CLI from v${currentVersion} to v${kpVersion}...`);
|
|
160
|
+
}
|
|
161
|
+
await downloadCli(kpPath, downloadUrl, versionFile);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// 执行 CLI 命令
|
|
165
|
+
const args = process.argv.slice(2);
|
|
166
|
+
const child = spawn(kpPath, args, {
|
|
167
|
+
stdio: 'inherit',
|
|
168
|
+
shell: os.platform() === 'win32' // Windows 需要 shell
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
child.on('exit', (code) => {
|
|
172
|
+
process.exit(code || 0);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
child.on('error', (error) => {
|
|
176
|
+
console.error(`Error executing CLI: ${error.message}`);
|
|
177
|
+
process.exit(1);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 运行主函数
|
|
182
|
+
main().catch((error) => {
|
|
183
|
+
console.error(`Unexpected error: ${error.message}`);
|
|
184
|
+
process.exit(1);
|
|
185
|
+
});
|
package/package.json
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"version": "0.0.5",
|
|
4
|
-
"description": "Kepo CLI - A tool for building TypeScript code into platform-specific plugins",
|
|
2
|
+
"author": "Kepo Team",
|
|
5
3
|
"bin": {
|
|
6
|
-
"kp": "./bin/kp"
|
|
4
|
+
"kp": "./bin/kp.js"
|
|
5
|
+
},
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/kepo-io/cli/issues"
|
|
8
|
+
},
|
|
9
|
+
"description": "Kepo CLI - A tool for building TypeScript code into platform-specific plugins",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": "\u003e=14.0.0"
|
|
7
12
|
},
|
|
8
13
|
"files": [
|
|
9
14
|
"bin",
|
|
10
15
|
"README.md"
|
|
11
16
|
],
|
|
12
|
-
"
|
|
13
|
-
"node": ">=14.0.0"
|
|
14
|
-
},
|
|
15
|
-
"os": [
|
|
16
|
-
"darwin"
|
|
17
|
-
],
|
|
18
|
-
"author": "Kepo Team",
|
|
19
|
-
"license": "MIT",
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "https://github.com/kepo-io/cli"
|
|
23
|
-
},
|
|
17
|
+
"homepage": "https://kepo.ai",
|
|
24
18
|
"keywords": [
|
|
25
19
|
"kepo",
|
|
26
20
|
"cli",
|
|
@@ -28,14 +22,23 @@
|
|
|
28
22
|
"plugin",
|
|
29
23
|
"build"
|
|
30
24
|
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"name": "@kepoai/cli",
|
|
27
|
+
"os": [
|
|
28
|
+
"darwin",
|
|
29
|
+
"win32",
|
|
30
|
+
"linux"
|
|
31
|
+
],
|
|
32
|
+
"pluginId": "ffb20575-3af1-48a1-bccf-46958fe61b01",
|
|
31
33
|
"publishConfig": {
|
|
32
34
|
"access": "public"
|
|
33
35
|
},
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/kepo-io/cli"
|
|
36
39
|
},
|
|
37
|
-
"homepage": "https://kepo.ai",
|
|
38
40
|
"scripts": {
|
|
39
|
-
"postinstall": "./bin/kp npm-post-install"
|
|
40
|
-
}
|
|
41
|
+
"postinstall": "node ./bin/kp.js npm-post-install"
|
|
42
|
+
},
|
|
43
|
+
"version": "0.0.8"
|
|
41
44
|
}
|