@eggplanty/mycli 0.1.22 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/scripts/install.js +26 -42
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggplanty/mycli",
3
- "version": "0.1.22",
3
+ "version": "1.0.0",
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
6
  const VERSION = require("../package.json").version;
8
- const REPO = "eggplanty/test_npm";
9
- const NAME = "mycli";
7
+ const REPO = "larksuite/cli";
8
+ const NAME = "lark-cli";
10
9
 
11
10
  const PLATFORM_MAP = {
12
11
  darwin: "darwin",
@@ -32,53 +31,31 @@ 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 url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
36
- 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
+
37
37
  const binDir = path.join(__dirname, "..", "bin");
38
38
  const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
39
39
 
40
40
  fs.mkdirSync(binDir, { recursive: true });
41
41
 
42
- function download(url, destPath, useAuth = true) {
43
- return new Promise((resolve, reject) => {
44
- const parsed = new URL(url);
45
- const client = parsed.protocol === "https:" ? https : require("http");
46
- const headers = {};
47
- if (token && useAuth) {
48
- headers["Authorization"] = `token ${token}`;
49
- headers["Accept"] = "application/octet-stream";
50
- }
51
- client
52
- .get({ hostname: parsed.hostname, path: parsed.pathname + parsed.search, headers }, (res) => {
53
- if (res.statusCode === 302 || res.statusCode === 301) {
54
- // Do not send auth token to redirected hosts (e.g. S3)
55
- return download(res.headers.location, destPath, false).then(
56
- resolve,
57
- reject
58
- );
59
- }
60
- if (res.statusCode !== 200) {
61
- return reject(
62
- new Error(`Download failed with status ${res.statusCode}: ${url}`)
63
- );
64
- }
65
- const file = fs.createWriteStream(destPath);
66
- res.pipe(file);
67
- file.on("finish", () => {
68
- file.close();
69
- resolve();
70
- });
71
- })
72
- .on("error", reject);
73
- });
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
+ );
74
47
  }
75
48
 
76
- async function install() {
77
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "mycli-"));
49
+ function install() {
50
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "lark-cli-"));
78
51
  const archivePath = path.join(tmpDir, archiveName);
79
52
 
80
53
  try {
81
- await download(url, archivePath);
54
+ try {
55
+ download(GITHUB_URL, archivePath);
56
+ } catch (err) {
57
+ download(MIRROR_URL, archivePath);
58
+ }
82
59
 
83
60
  if (isWindows) {
84
61
  execSync(
@@ -102,7 +79,14 @@ async function install() {
102
79
  }
103
80
  }
104
81
 
105
- install().catch((err) => {
82
+ try {
83
+ install();
84
+ } catch (err) {
106
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
+ );
107
91
  process.exit(1);
108
- });
92
+ }