@delta-infra/cli 1.0.0 → 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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/scripts/install.js +15 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delta-infra/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Delta Sandbox CLI",
5
5
  "bin": {
6
6
  "delta-cli": "scripts/run.js"
@@ -19,6 +19,6 @@
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "https://github.com/yzailab/delta-infra-cli.git"
22
+ "url": "git+https://github.com/yzailab/delta-infra-cli.git"
23
23
  }
24
24
  }
@@ -9,6 +9,14 @@ const BINARY_NAME = 'delta-cli';
9
9
  const VERSION = require('../package.json').version;
10
10
  const RELEASE_BASE_URL = 'https://github.com/yzailab/delta-infra-cli/releases/download';
11
11
 
12
+ function releaseAssetUrl(version, assetName) {
13
+ const mirror = process.env.DELTA_CLI_MIRROR || '';
14
+ if (mirror) {
15
+ return `${mirror.replace(/\/$/, '')}/yzailab/delta-infra-cli/releases/download/v${version}/${assetName}`;
16
+ }
17
+ return `${RELEASE_BASE_URL}/v${version}/${assetName}`;
18
+ }
19
+
12
20
  const platformMap = {
13
21
  darwin: 'darwin',
14
22
  linux: 'linux',
@@ -38,7 +46,7 @@ function download(url, dest) {
38
46
  try { fs.unlinkSync(dest); } catch {}
39
47
  };
40
48
 
41
- https.get(url, (response) => {
49
+ https.get(url, { timeout: 60000 }, (response) => {
42
50
  if (response.statusCode >= 301 && response.statusCode <= 308 && response.headers.location) {
43
51
  file.destroy();
44
52
  cleanup();
@@ -90,14 +98,18 @@ async function main() {
90
98
 
91
99
  fs.mkdirSync(binDir, { recursive: true });
92
100
 
93
- const url = `${RELEASE_BASE_URL}/v${VERSION}/${assetName}`;
94
- console.log(`Downloading ${assetName} from GitHub...`);
101
+ const url = releaseAssetUrl(VERSION, assetName);
102
+ console.log(`Downloading ${assetName} from ${process.env.DELTA_CLI_MIRROR ? 'mirror' : 'GitHub'}...`);
95
103
 
96
104
  try {
97
105
  const checksum = await download(url, archivePath);
98
106
  console.log(`Downloaded archive, SHA256: ${checksum}`);
99
107
  console.log(`Extracting to ${binDir}...`);
100
108
  extract(archivePath, binDir, platform);
109
+ const extractedBinary = path.join(binDir, `${BINARY_NAME}-${platform}-${arch}${binaryExt}`);
110
+ if (fs.existsSync(extractedBinary) && extractedBinary !== binaryPath) {
111
+ fs.renameSync(extractedBinary, binaryPath);
112
+ }
101
113
  fs.chmodSync(binaryPath, 0o755);
102
114
  fs.unlinkSync(archivePath);
103
115
  console.log(`Installed to ${binaryPath}`);