@ghyper9023/oy 0.1.2
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/install.js +64 -0
- package/bin/native/oy +0 -0
- package/bin/oy-wrapper.js +11 -0
- package/package.json +30 -0
package/bin/install.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const { https } = require('follow-redirects');
|
|
7
|
+
|
|
8
|
+
const pkgJson = require('../package.json');
|
|
9
|
+
const version = pkgJson.version;
|
|
10
|
+
|
|
11
|
+
// 从 repository.url 中提取 "owner/repo"
|
|
12
|
+
const repoUrl = pkgJson.repository && pkgJson.repository.url;
|
|
13
|
+
if (!repoUrl) {
|
|
14
|
+
console.error('package.json repository.url ');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const match = repoUrl.match(/github\.com[\/:]([^\/]+\/[^\/]+)(\.git)?$/);
|
|
19
|
+
if (!match) {
|
|
20
|
+
console.error(` repository.url owner/repo: ${repoUrl}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
const repo = match[1];
|
|
24
|
+
const tag = `v${version}`;
|
|
25
|
+
|
|
26
|
+
function getPlatformAsset() {
|
|
27
|
+
const platform = os.platform();
|
|
28
|
+
const arch = os.arch();
|
|
29
|
+
if (platform === 'linux' && arch === 'x64') {
|
|
30
|
+
return 'oy-x86_64-unknown-linux-gnu';
|
|
31
|
+
} else if (platform === 'darwin' && arch === 'arm64') {
|
|
32
|
+
return 'oy-aarch64-apple-darwin';
|
|
33
|
+
} else if (platform === 'win32' && arch === 'x64') {
|
|
34
|
+
return 'oy-x86_64-pc-windows-msvc.exe';
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error(`Unsupported platform: ${platform} ${arch}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const assetName = getPlatformAsset();
|
|
41
|
+
const destDir = path.join(__dirname, 'native');
|
|
42
|
+
const destFile = path.join(destDir, os.platform() === 'win32' ? 'oy.exe' : 'oy');
|
|
43
|
+
const url = `https://github.com/${repo}/releases/download/${tag}/${assetName}`;
|
|
44
|
+
|
|
45
|
+
console.log(`Downloading from ${url} ...`);
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });
|
|
48
|
+
|
|
49
|
+
const file = fs.createWriteStream(destFile);
|
|
50
|
+
https.get(url, (response) => {
|
|
51
|
+
if (response.statusCode !== 200) {
|
|
52
|
+
console.error(`Failed to download ${url}: HTTP ${response.statusCode}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
response.pipe(file);
|
|
56
|
+
file.on('finish', () => {
|
|
57
|
+
file.close();
|
|
58
|
+
fs.chmodSync(destFile, 0o755);
|
|
59
|
+
console.log(`Binary saved to ${destFile}`);
|
|
60
|
+
});
|
|
61
|
+
}).on('error', (err) => {
|
|
62
|
+
console.error(err);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
});
|
package/bin/native/oy
ADDED
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const exePath = path.join(__dirname, 'native', os.platform() === 'win32' ? 'oy.exe' : 'oy');
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
|
|
10
|
+
const child = spawn(exePath, args, { stdio: 'inherit' });
|
|
11
|
+
child.on('exit', (code) => process.exit(code));
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ghyper9023/oy",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Ai-Agent CLI tool named oy",
|
|
5
|
+
"bin": {
|
|
6
|
+
"oy": "bin/oy-wrapper.js"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"follow-redirects": "^1.16.0"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"postinstall": "node bin/install.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"cli",
|
|
22
|
+
"oy"
|
|
23
|
+
],
|
|
24
|
+
"author": "Your Name",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/cherish-ltt/oy"
|
|
29
|
+
}
|
|
30
|
+
}
|