@tangcent/apilot 0.1.3 → 0.1.4
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/CHANGELOG.md +201 -122
- package/LICENSE +661 -661
- package/README.md +563 -244
- package/package.json +34 -34
- package/scripts/install.js +124 -124
- package/scripts/run.js +27 -27
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tangcent/apilot",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Navigate your APIs. Scans source code and exports to Markdown, cURL, Postman, and more.",
|
|
5
|
-
"bin": {
|
|
6
|
-
"apilot": "scripts/run.js"
|
|
7
|
-
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"postinstall": "node scripts/install.js",
|
|
10
|
-
"test": "node --test scripts/install.test.js"
|
|
11
|
-
},
|
|
12
|
-
"os": [
|
|
13
|
-
"darwin",
|
|
14
|
-
"linux",
|
|
15
|
-
"win32"
|
|
16
|
-
],
|
|
17
|
-
"cpu": [
|
|
18
|
-
"x64",
|
|
19
|
-
"arm64"
|
|
20
|
-
],
|
|
21
|
-
"engines": {
|
|
22
|
-
"node": ">=16"
|
|
23
|
-
},
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/tangcent/apilot.git"
|
|
27
|
-
},
|
|
28
|
-
"license": "MIT",
|
|
29
|
-
"files": [
|
|
30
|
-
"scripts/install.js",
|
|
31
|
-
"scripts/run.js",
|
|
32
|
-
"CHANGELOG.md"
|
|
33
|
-
]
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@tangcent/apilot",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Navigate your APIs. Scans source code and exports to Markdown, cURL, Postman, and more.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"apilot": "scripts/run.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node scripts/install.js",
|
|
10
|
+
"test": "node --test scripts/install.test.js"
|
|
11
|
+
},
|
|
12
|
+
"os": [
|
|
13
|
+
"darwin",
|
|
14
|
+
"linux",
|
|
15
|
+
"win32"
|
|
16
|
+
],
|
|
17
|
+
"cpu": [
|
|
18
|
+
"x64",
|
|
19
|
+
"arm64"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=16"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/tangcent/apilot.git"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"files": [
|
|
30
|
+
"scripts/install.js",
|
|
31
|
+
"scripts/run.js",
|
|
32
|
+
"CHANGELOG.md"
|
|
33
|
+
]
|
|
34
|
+
}
|
package/scripts/install.js
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const { execSync } = require("child_process");
|
|
6
|
-
const os = require("os");
|
|
7
|
-
|
|
8
|
-
const VERSION = require("../package.json").version;
|
|
9
|
-
const REPO = "tangcent/apilot";
|
|
10
|
-
const NAME = "apilot";
|
|
11
|
-
|
|
12
|
-
const PLATFORM_MAP = {
|
|
13
|
-
darwin: "darwin",
|
|
14
|
-
linux: "linux",
|
|
15
|
-
win32: "windows",
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const ARCH_MAP = {
|
|
19
|
-
x64: "amd64",
|
|
20
|
-
arm64: "arm64",
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function getPlatformInfo(platform, arch, version) {
|
|
24
|
-
version = version || VERSION;
|
|
25
|
-
const mappedPlatform = PLATFORM_MAP[platform];
|
|
26
|
-
const mappedArch = ARCH_MAP[arch];
|
|
27
|
-
|
|
28
|
-
if (!mappedPlatform || !mappedArch) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const isWindows = platform === "win32";
|
|
33
|
-
const ext = isWindows ? ".zip" : ".tar.gz";
|
|
34
|
-
const archiveName = `${NAME}-${version}-${mappedPlatform}-${mappedArch}${ext}`;
|
|
35
|
-
const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
|
|
36
|
-
const binaryName = NAME + (isWindows ? ".exe" : "");
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
platform: mappedPlatform,
|
|
40
|
-
arch: mappedArch,
|
|
41
|
-
isWindows,
|
|
42
|
-
ext,
|
|
43
|
-
archiveName,
|
|
44
|
-
downloadUrl,
|
|
45
|
-
binaryName,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function download(url, destPath, isWindows) {
|
|
50
|
-
const sslFlag = isWindows ? "--ssl-revoke-best-effort " : "";
|
|
51
|
-
execSync(
|
|
52
|
-
`curl ${sslFlag}--fail --location --silent --show-error --connect-timeout 10 --max-time 120 --output "${destPath}" "${url}"`,
|
|
53
|
-
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function install(info, opts) {
|
|
58
|
-
opts = opts || {};
|
|
59
|
-
const _download = opts.download || download;
|
|
60
|
-
const _mkdirSync = opts.mkdirSync || fs.mkdirSync;
|
|
61
|
-
const _mkdtempSync = opts.mkdtempSync || fs.mkdtempSync;
|
|
62
|
-
const _copyFileSync = opts.copyFileSync || fs.copyFileSync;
|
|
63
|
-
const _chmodSync = opts.chmodSync || fs.chmodSync;
|
|
64
|
-
const _rmSync = opts.rmSync || fs.rmSync;
|
|
65
|
-
const _execSync = opts.execSync || execSync;
|
|
66
|
-
const _console = opts.console || console;
|
|
67
|
-
|
|
68
|
-
const binDir = path.join(__dirname, "..", "bin");
|
|
69
|
-
const dest = path.join(binDir, info.binaryName);
|
|
70
|
-
|
|
71
|
-
_mkdirSync(binDir, { recursive: true });
|
|
72
|
-
|
|
73
|
-
const tmpDir = _mkdtempSync(path.join(os.tmpdir(), "apilot-"));
|
|
74
|
-
const archivePath = path.join(tmpDir, info.archiveName);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
_console.log(`Downloading apilot v${VERSION} for ${info.platform}-${info.arch}...`);
|
|
78
|
-
_download(info.downloadUrl, archivePath, info.isWindows);
|
|
79
|
-
|
|
80
|
-
if (info.isWindows) {
|
|
81
|
-
_execSync(
|
|
82
|
-
`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`,
|
|
83
|
-
{ stdio: "ignore" }
|
|
84
|
-
);
|
|
85
|
-
} else {
|
|
86
|
-
_execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "ignore" });
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const extractedBinary = path.join(tmpDir, info.binaryName);
|
|
90
|
-
|
|
91
|
-
_copyFileSync(extractedBinary, dest);
|
|
92
|
-
_chmodSync(dest, 0o755);
|
|
93
|
-
_console.log(`apilot v${VERSION} installed successfully`);
|
|
94
|
-
} finally {
|
|
95
|
-
_rmSync(tmpDir, { recursive: true, force: true });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function runInstall() {
|
|
100
|
-
const info = getPlatformInfo(process.platform, process.arch);
|
|
101
|
-
|
|
102
|
-
if (!info) {
|
|
103
|
-
console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
|
|
104
|
-
process.exit(1);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
install(info);
|
|
109
|
-
} catch (err) {
|
|
110
|
-
console.error(`Failed to install apilot:`, err.message);
|
|
111
|
-
console.error(
|
|
112
|
-
`\nIf you are behind a firewall or in a restricted network, try setting a proxy:\n` +
|
|
113
|
-
` export https_proxy=http://your-proxy:port\n` +
|
|
114
|
-
` npm install -g @tangcent/apilot`
|
|
115
|
-
);
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
module.exports = { getPlatformInfo, download, install, PLATFORM_MAP, ARCH_MAP, NAME, REPO };
|
|
121
|
-
|
|
122
|
-
if (require.main === module) {
|
|
123
|
-
runInstall();
|
|
124
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { execSync } = require("child_process");
|
|
6
|
+
const os = require("os");
|
|
7
|
+
|
|
8
|
+
const VERSION = require("../package.json").version;
|
|
9
|
+
const REPO = "tangcent/apilot";
|
|
10
|
+
const NAME = "apilot";
|
|
11
|
+
|
|
12
|
+
const PLATFORM_MAP = {
|
|
13
|
+
darwin: "darwin",
|
|
14
|
+
linux: "linux",
|
|
15
|
+
win32: "windows",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ARCH_MAP = {
|
|
19
|
+
x64: "amd64",
|
|
20
|
+
arm64: "arm64",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function getPlatformInfo(platform, arch, version) {
|
|
24
|
+
version = version || VERSION;
|
|
25
|
+
const mappedPlatform = PLATFORM_MAP[platform];
|
|
26
|
+
const mappedArch = ARCH_MAP[arch];
|
|
27
|
+
|
|
28
|
+
if (!mappedPlatform || !mappedArch) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const isWindows = platform === "win32";
|
|
33
|
+
const ext = isWindows ? ".zip" : ".tar.gz";
|
|
34
|
+
const archiveName = `${NAME}-${version}-${mappedPlatform}-${mappedArch}${ext}`;
|
|
35
|
+
const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
|
|
36
|
+
const binaryName = NAME + (isWindows ? ".exe" : "");
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
platform: mappedPlatform,
|
|
40
|
+
arch: mappedArch,
|
|
41
|
+
isWindows,
|
|
42
|
+
ext,
|
|
43
|
+
archiveName,
|
|
44
|
+
downloadUrl,
|
|
45
|
+
binaryName,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function download(url, destPath, isWindows) {
|
|
50
|
+
const sslFlag = isWindows ? "--ssl-revoke-best-effort " : "";
|
|
51
|
+
execSync(
|
|
52
|
+
`curl ${sslFlag}--fail --location --silent --show-error --connect-timeout 10 --max-time 120 --output "${destPath}" "${url}"`,
|
|
53
|
+
{ stdio: ["ignore", "ignore", "pipe"] }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function install(info, opts) {
|
|
58
|
+
opts = opts || {};
|
|
59
|
+
const _download = opts.download || download;
|
|
60
|
+
const _mkdirSync = opts.mkdirSync || fs.mkdirSync;
|
|
61
|
+
const _mkdtempSync = opts.mkdtempSync || fs.mkdtempSync;
|
|
62
|
+
const _copyFileSync = opts.copyFileSync || fs.copyFileSync;
|
|
63
|
+
const _chmodSync = opts.chmodSync || fs.chmodSync;
|
|
64
|
+
const _rmSync = opts.rmSync || fs.rmSync;
|
|
65
|
+
const _execSync = opts.execSync || execSync;
|
|
66
|
+
const _console = opts.console || console;
|
|
67
|
+
|
|
68
|
+
const binDir = path.join(__dirname, "..", "bin");
|
|
69
|
+
const dest = path.join(binDir, info.binaryName);
|
|
70
|
+
|
|
71
|
+
_mkdirSync(binDir, { recursive: true });
|
|
72
|
+
|
|
73
|
+
const tmpDir = _mkdtempSync(path.join(os.tmpdir(), "apilot-"));
|
|
74
|
+
const archivePath = path.join(tmpDir, info.archiveName);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
_console.log(`Downloading apilot v${VERSION} for ${info.platform}-${info.arch}...`);
|
|
78
|
+
_download(info.downloadUrl, archivePath, info.isWindows);
|
|
79
|
+
|
|
80
|
+
if (info.isWindows) {
|
|
81
|
+
_execSync(
|
|
82
|
+
`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`,
|
|
83
|
+
{ stdio: "ignore" }
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
_execSync(`tar -xzf "${archivePath}" -C "${tmpDir}"`, { stdio: "ignore" });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const extractedBinary = path.join(tmpDir, info.binaryName);
|
|
90
|
+
|
|
91
|
+
_copyFileSync(extractedBinary, dest);
|
|
92
|
+
_chmodSync(dest, 0o755);
|
|
93
|
+
_console.log(`apilot v${VERSION} installed successfully`);
|
|
94
|
+
} finally {
|
|
95
|
+
_rmSync(tmpDir, { recursive: true, force: true });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function runInstall() {
|
|
100
|
+
const info = getPlatformInfo(process.platform, process.arch);
|
|
101
|
+
|
|
102
|
+
if (!info) {
|
|
103
|
+
console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
install(info);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
console.error(`Failed to install apilot:`, err.message);
|
|
111
|
+
console.error(
|
|
112
|
+
`\nIf you are behind a firewall or in a restricted network, try setting a proxy:\n` +
|
|
113
|
+
` export https_proxy=http://your-proxy:port\n` +
|
|
114
|
+
` npm install -g @tangcent/apilot`
|
|
115
|
+
);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
module.exports = { getPlatformInfo, download, install, PLATFORM_MAP, ARCH_MAP, NAME, REPO };
|
|
121
|
+
|
|
122
|
+
if (require.main === module) {
|
|
123
|
+
runInstall();
|
|
124
|
+
}
|
package/scripts/run.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { execFileSync } = require("child_process");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
|
|
7
|
-
const ext = process.platform === "win32" ? ".exe" : "";
|
|
8
|
-
const bin = path.join(__dirname, "..", "bin", "apilot" + ext);
|
|
9
|
-
|
|
10
|
-
if (!fs.existsSync(bin)) {
|
|
11
|
-
console.error(
|
|
12
|
-
`Error: apilot binary not found at ${bin}\n\n` +
|
|
13
|
-
`This usually means the postinstall script was skipped.\n` +
|
|
14
|
-
`Common causes:\n` +
|
|
15
|
-
` - npm is configured with ignore-scripts=true\n` +
|
|
16
|
-
` - The postinstall download failed\n\n` +
|
|
17
|
-
`To fix, run the install script manually:\n` +
|
|
18
|
-
` node "${path.join(__dirname, "install.js")}"\n`
|
|
19
|
-
);
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
25
|
-
} catch (e) {
|
|
26
|
-
process.exit(e.status || 1);
|
|
27
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
const ext = process.platform === "win32" ? ".exe" : "";
|
|
8
|
+
const bin = path.join(__dirname, "..", "bin", "apilot" + ext);
|
|
9
|
+
|
|
10
|
+
if (!fs.existsSync(bin)) {
|
|
11
|
+
console.error(
|
|
12
|
+
`Error: apilot binary not found at ${bin}\n\n` +
|
|
13
|
+
`This usually means the postinstall script was skipped.\n` +
|
|
14
|
+
`Common causes:\n` +
|
|
15
|
+
` - npm is configured with ignore-scripts=true\n` +
|
|
16
|
+
` - The postinstall download failed\n\n` +
|
|
17
|
+
`To fix, run the install script manually:\n` +
|
|
18
|
+
` node "${path.join(__dirname, "install.js")}"\n`
|
|
19
|
+
);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
25
|
+
} catch (e) {
|
|
26
|
+
process.exit(e.status || 1);
|
|
27
|
+
}
|