@yixinkj/cli 1.0.14 → 1.0.15-beta.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/index.js +52 -22
- package/package.json +2 -1
- package/skills.json +11 -0
package/index.js
CHANGED
|
@@ -9,6 +9,9 @@ import { createRequire } from 'node:module';
|
|
|
9
9
|
|
|
10
10
|
const require = createRequire(import.meta.url);
|
|
11
11
|
const packageJson = require('./package.json');
|
|
12
|
+
// skills.json 是新增 Skill 的单一事实源(skill 名 → flag → 二进制名)。
|
|
13
|
+
// launcher 在运行期读它来决定下载哪些二进制、按 flag 启动哪个;发布 workflow 读同一份来打包。
|
|
14
|
+
const registry = require('./skills.json');
|
|
12
15
|
|
|
13
16
|
const VERSION = packageJson.version;
|
|
14
17
|
const RELEASE_REPO = process.env.YIXIN_RELEASE_REPO || 'yixinkj/cli-releases';
|
|
@@ -16,37 +19,56 @@ const CACHE_ROOT = path.join(os.homedir(), '.yixin');
|
|
|
16
19
|
const BIN_DIR = path.join(CACHE_ROOT, 'bin');
|
|
17
20
|
const VERSION_FILE = path.join(CACHE_ROOT, 'version');
|
|
18
21
|
|
|
19
|
-
const PLATFORM_TARGETS = {
|
|
20
|
-
'darwin-arm64': {
|
|
21
|
-
id: 'mac-arm64',
|
|
22
|
-
archive: 'yixin-mac-arm64.tar.gz',
|
|
23
|
-
mainBinary: 'alibaba-cli-mac-arm64',
|
|
24
|
-
binaries: ['alibaba-cli-mac-arm64', 'browser-bridge-mac-arm64']
|
|
25
|
-
},
|
|
26
|
-
'win32-x64': {
|
|
27
|
-
id: 'win32-x64',
|
|
28
|
-
archive: 'yixin-win32-x64.zip',
|
|
29
|
-
mainBinary: 'alibaba-cli-win32-x64.exe',
|
|
30
|
-
binaries: ['alibaba-cli-win32-x64.exe', 'browser-bridge-win32-x64.exe']
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
22
|
function fail(message) {
|
|
35
23
|
console.error(`[yixin] ${message}`);
|
|
36
24
|
process.exit(1);
|
|
37
25
|
}
|
|
38
26
|
|
|
27
|
+
function binaryName(base, platform) {
|
|
28
|
+
return `${base}-${platform.id}${platform.exe || ''}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
39
31
|
function detectTarget() {
|
|
40
32
|
const platformKey = `${process.platform}-${process.arch}`;
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
43
|
-
|
|
33
|
+
const platform = registry.platforms[platformKey];
|
|
34
|
+
if (!platform) {
|
|
35
|
+
const supported = Object.values(registry.platforms)
|
|
36
|
+
.map((entry) => entry.id)
|
|
37
|
+
.join('、');
|
|
38
|
+
throw new Error(
|
|
39
|
+
`暂不支持当前平台:${process.platform}/${process.arch}。已支持:${supported}。`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
// 整包包含所有 Skill 二进制 + 一份共享浏览器桥接。
|
|
43
|
+
const binaries = registry.skills.map((skill) => binaryName(skill.bin, platform));
|
|
44
|
+
binaries.push(binaryName(registry.bridge, platform));
|
|
45
|
+
return { id: platform.id, archive: platform.archive, exe: platform.exe || '', binaries };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function selectSkill(argv) {
|
|
49
|
+
const byFlag = registry.skills.find((skill) => argv.includes(skill.flag));
|
|
50
|
+
if (byFlag) {
|
|
51
|
+
return byFlag;
|
|
44
52
|
}
|
|
45
|
-
|
|
53
|
+
// 只有一个 Skill 时缺省用它,保持单 Skill 时的旧用法可用。
|
|
54
|
+
if (registry.skills.length === 1) {
|
|
55
|
+
return registry.skills[0];
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function skillBinaryPath(skill, target) {
|
|
61
|
+
return path.join(BIN_DIR, `${skill.bin}-${target.id}${target.exe}`);
|
|
46
62
|
}
|
|
47
63
|
|
|
48
|
-
function
|
|
49
|
-
|
|
64
|
+
function printSkillHelp() {
|
|
65
|
+
const lines = registry.skills.map((skill) => ` ${skill.flag}\t${skill.name}`).join('\n');
|
|
66
|
+
console.error(
|
|
67
|
+
`译心 CLI v${VERSION}\n\n` +
|
|
68
|
+
`用法:\n npx -y @yixinkj/cli@latest <skill> [选项]\n\n` +
|
|
69
|
+
`可用 Skill:\n${lines}\n\n` +
|
|
70
|
+
`示例:\n npx -y @yixinkj/cli@latest --ads --period last-week`
|
|
71
|
+
);
|
|
50
72
|
}
|
|
51
73
|
|
|
52
74
|
function isInstalled(target) {
|
|
@@ -213,9 +235,17 @@ async function ensureInstalled(target) {
|
|
|
213
235
|
|
|
214
236
|
async function main() {
|
|
215
237
|
const target = detectTarget();
|
|
238
|
+
const argv = process.argv.slice(2);
|
|
239
|
+
|
|
240
|
+
const skill = selectSkill(argv);
|
|
241
|
+
if (!skill) {
|
|
242
|
+
printSkillHelp();
|
|
243
|
+
process.exit(argv.some((arg) => arg === '--help' || arg === '-h') ? 0 : 1);
|
|
244
|
+
}
|
|
245
|
+
|
|
216
246
|
await ensureInstalled(target);
|
|
217
247
|
|
|
218
|
-
const result = spawnSync(
|
|
248
|
+
const result = spawnSync(skillBinaryPath(skill, target), argv, {
|
|
219
249
|
stdio: 'inherit',
|
|
220
250
|
env: process.env
|
|
221
251
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yixinkj/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15-beta.0",
|
|
4
4
|
"description": "Yixin native CLI launcher.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"index.js",
|
|
11
|
+
"skills.json",
|
|
11
12
|
"README.md"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {},
|
package/skills.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"platforms": {
|
|
3
|
+
"darwin-arm64": { "id": "mac-arm64", "archive": "yixin-mac-arm64.tar.gz", "exe": "" },
|
|
4
|
+
"win32-x64": { "id": "win32-x64", "archive": "yixin-win32-x64.zip", "exe": ".exe" }
|
|
5
|
+
},
|
|
6
|
+
"bridge": "browser-bridge",
|
|
7
|
+
"skills": [
|
|
8
|
+
{ "name": "阿里国际站直通车广告分析", "flag": "--ads", "bin": "alibaba-cli" },
|
|
9
|
+
{ "name": "阿里国际站店铺数据参谋", "flag": "--shop", "bin": "shop-cli" }
|
|
10
|
+
]
|
|
11
|
+
}
|