@eggplanty/mycli 0.1.23 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggplanty/mycli",
3
- "version": "0.1.23",
3
+ "version": "1.0.1",
4
4
  "description": "A simple CLI demo built with Go",
5
5
  "bin": {
6
6
  "mycli": "scripts/run.js"
@@ -1,12 +1,11 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
- const https = require("https");
4
3
  const { execSync } = require("child_process");
5
4
  const os = require("os");
6
5
 
7
- const VERSION = require("../package.json").version;
8
- const REPO = "eggplanty/test_npm";
9
- const NAME = "mycli";
6
+ const VERSION = "1.0.0";
7
+ const REPO = "larksuite/cli";
8
+ const NAME = "lark-cli";
10
9
 
11
10
  const PLATFORM_MAP = {
12
11
  darwin: "darwin",
@@ -32,111 +31,32 @@ if (!platform || !arch) {
32
31
  const isWindows = process.platform === "win32";
33
32
  const ext = isWindows ? ".zip" : ".tar.gz";
34
33
  const archiveName = `${NAME}-${VERSION}-${platform}-${arch}${ext}`;
35
- const token = process.env.MYCLI_TOKEN || "";
34
+ const GITHUB_URL = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
35
+ const MIRROR_URL = `https://registry.npmmirror.com/-/binary/lark-cli/v${VERSION}/${archiveName}`;
36
+
36
37
  const binDir = path.join(__dirname, "..", "bin");
37
38
  const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
38
39
 
39
40
  fs.mkdirSync(binDir, { recursive: true });
40
41
 
41
- function httpGet(url, headers = {}) {
42
- return new Promise((resolve, reject) => {
43
- const parsed = new URL(url);
44
- const client = parsed.protocol === "https:" ? https : require("http");
45
- client
46
- .get(
47
- {
48
- hostname: parsed.hostname,
49
- path: parsed.pathname + parsed.search,
50
- headers: { "User-Agent": "mycli-installer", ...headers },
51
- },
52
- (res) => resolve(res)
53
- )
54
- .on("error", reject);
55
- });
56
- }
57
-
58
- function downloadToFile(url, destPath, headers = {}) {
59
- return new Promise(async (resolve, reject) => {
60
- try {
61
- const res = await httpGet(url, headers);
62
- if (res.statusCode === 302 || res.statusCode === 301) {
63
- // Do not send auth token to redirected hosts (e.g. S3)
64
- return downloadToFile(res.headers.location, destPath).then(
65
- resolve,
66
- reject
67
- );
68
- }
69
- if (res.statusCode !== 200) {
70
- return reject(
71
- new Error(`Download failed with status ${res.statusCode}: ${url}`)
72
- );
73
- }
74
- const file = fs.createWriteStream(destPath);
75
- res.pipe(file);
76
- file.on("finish", () => {
77
- file.close();
78
- resolve();
79
- });
80
- } catch (err) {
81
- reject(err);
82
- }
83
- });
84
- }
85
-
86
- async function getAssetDownloadUrl() {
87
- if (!token) {
88
- // No token, use public download URL directly
89
- return `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
90
- }
91
-
92
- // For private repos, use GitHub API to find the asset and get its download URL
93
- const apiUrl = `https://api.github.com/repos/${REPO}/releases/tags/v${VERSION}`;
94
- const res = await httpGet(apiUrl, {
95
- Authorization: `token ${token}`,
96
- Accept: "application/vnd.github.v3+json",
97
- });
98
-
99
- if (res.statusCode !== 200) {
100
- throw new Error(
101
- `Failed to fetch release info (status ${res.statusCode}). Check that the token is valid and the release v${VERSION} exists.`
102
- );
103
- }
104
-
105
- const body = await new Promise((resolve, reject) => {
106
- let data = "";
107
- res.on("data", (chunk) => (data += chunk));
108
- res.on("end", () => resolve(data));
109
- res.on("error", reject);
110
- });
111
-
112
- const release = JSON.parse(body);
113
- const asset = release.assets.find((a) => a.name === archiveName);
114
- if (!asset) {
115
- const available = release.assets.map((a) => a.name).join(", ");
116
- throw new Error(
117
- `Asset "${archiveName}" not found in release v${VERSION}. Available assets: ${available || "(none)"}`
118
- );
119
- }
120
-
121
- // Return the API URL for downloading the asset
122
- return asset.url;
42
+ function download(url, destPath) {
43
+ execSync(
44
+ `curl --fail --location --silent --show-error --connect-timeout 10 --max-time 120 --output "${destPath}" "${url}"`,
45
+ { stdio: ["ignore", "ignore", "pipe"] }
46
+ );
123
47
  }
124
48
 
125
- async function install() {
126
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "mycli-"));
49
+ function install() {
50
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "lark-cli-"));
127
51
  const archivePath = path.join(tmpDir, archiveName);
128
52
 
129
53
  try {
130
- const downloadUrl = await getAssetDownloadUrl();
131
-
132
- const headers = {};
133
- if (token && downloadUrl.includes("api.github.com")) {
134
- headers["Authorization"] = `token ${token}`;
135
- headers["Accept"] = "application/octet-stream";
54
+ try {
55
+ download(GITHUB_URL, archivePath);
56
+ } catch (err) {
57
+ download(MIRROR_URL, archivePath);
136
58
  }
137
59
 
138
- await downloadToFile(downloadUrl, archivePath, headers);
139
-
140
60
  if (isWindows) {
141
61
  execSync(
142
62
  `powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${tmpDir}'"`,
@@ -159,7 +79,14 @@ async function install() {
159
79
  }
160
80
  }
161
81
 
162
- install().catch((err) => {
82
+ try {
83
+ install();
84
+ } catch (err) {
163
85
  console.error(`Failed to install ${NAME}:`, err.message);
86
+ console.error(
87
+ `\nIf you are behind a firewall or in a restricted network, try setting a proxy:\n` +
88
+ ` export https_proxy=http://your-proxy:port\n` +
89
+ ` npm install -g @eggplanty/mycli`
90
+ );
164
91
  process.exit(1);
165
- });
92
+ }
package/scripts/run.js CHANGED
@@ -3,7 +3,7 @@ const { execFileSync } = require("child_process");
3
3
  const path = require("path");
4
4
 
5
5
  const ext = process.platform === "win32" ? ".exe" : "";
6
- const bin = path.join(__dirname, "..", "bin", "mycli" + ext);
6
+ const bin = path.join(__dirname, "..", "bin", "lark-cli" + ext);
7
7
 
8
8
  try {
9
9
  execFileSync(bin, process.argv.slice(2), { stdio: "inherit" });