@infisical/cli 0.0.0 → 0.31.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 +6 -4
  2. package/src/index.cjs +65 -16
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@infisical/cli",
3
3
  "private": false,
4
- "version": "0.0.0",
4
+ "version": "0.31.0",
5
5
  "keywords": [
6
6
  "infisical",
7
7
  "cli",
8
8
  "command-line"
9
9
  ],
10
10
  "bin": {
11
- "infisical": "bin/infisical"
11
+ "infisical": "./bin/infisical"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -16,9 +16,11 @@
16
16
  },
17
17
  "author": "Infisical Inc, <daniel@infisical.com>",
18
18
  "scripts": {
19
- "postinstall": "node src/index.cjs"
19
+ "preinstall": "node src/index.cjs"
20
20
  },
21
21
  "dependencies": {
22
- "tar": "^6.2.0"
22
+ "node-zip": "^1.1.1",
23
+ "tar": "^6.2.0",
24
+ "yauzl": "^3.2.0"
23
25
  }
24
26
  }
package/src/index.cjs CHANGED
@@ -4,13 +4,20 @@ const stream = require("node:stream");
4
4
  const tar = require("tar");
5
5
  const path = require("path");
6
6
  const zlib = require("zlib");
7
+ const yauzl = require("yauzl");
8
+
7
9
  const packageJSON = require("../package.json");
8
10
 
9
- const supportedPlatforms = ["linux", "darwin", "win32", "freebsd"];
11
+ const supportedPlatforms = ["linux", "darwin", "win32", "freebsd", "windows"];
10
12
  const outputDir = "bin";
11
13
 
12
14
  const getPlatform = () => {
13
- const platform = process.platform;
15
+ let platform = process.platform;
16
+
17
+ if (platform === "win32") {
18
+ platform = "windows";
19
+ }
20
+
14
21
  if (!supportedPlatforms.includes(platform)) {
15
22
  console.error("Your platform doesn't seem to be of type darwin, linux or windows");
16
23
  process.exit(1);
@@ -53,12 +60,47 @@ const getArchitecture = () => {
53
60
  return arch;
54
61
  };
55
62
 
63
+ async function extractZip(buffer, targetPath) {
64
+ return new Promise((resolve, reject) => {
65
+ yauzl.fromBuffer(buffer, { lazyEntries: true }, (err, zipfile) => {
66
+ if (err) return reject(err);
67
+
68
+ zipfile.readEntry();
69
+ zipfile.on("entry", entry => {
70
+ const isExecutable = entry.fileName === "infisical" || entry.fileName === "infisical.exe";
71
+
72
+ if (/\/$/.test(entry.fileName) || !isExecutable) {
73
+ // Directory entry
74
+ zipfile.readEntry();
75
+ } else {
76
+ // File entry
77
+ zipfile.openReadStream(entry, (err, readStream) => {
78
+ if (err) return reject(err);
79
+
80
+ const outputPath = path.join(targetPath, entry.fileName.includes("infisical") ? "infisical" : entry.fileName);
81
+ const writeStream = fs.createWriteStream(outputPath);
82
+
83
+ readStream.pipe(writeStream);
84
+ writeStream.on("close", () => {
85
+ zipfile.readEntry();
86
+ });
87
+ });
88
+ }
89
+ });
90
+
91
+ zipfile.on("end", resolve);
92
+ zipfile.on("error", reject);
93
+ });
94
+ });
95
+ }
96
+
56
97
  async function main() {
57
98
  const PLATFORM = getPlatform();
58
99
  const ARCH = getArchitecture();
59
100
  const NUMERIC_RELEASE_VERSION = packageJSON.version;
60
101
  const LATEST_RELEASE_VERSION = `v${NUMERIC_RELEASE_VERSION}`;
61
- const downloadLink = `https://github.com/Infisical/infisical/releases/download/infisical-cli/${LATEST_RELEASE_VERSION}/infisical_${NUMERIC_RELEASE_VERSION}_${PLATFORM}_${ARCH}.tar.gz`;
102
+ const EXTENSION = PLATFORM === "windows" ? "zip" : "tar.gz";
103
+ const downloadLink = `https://github.com/Infisical/infisical/releases/download/infisical-cli/${LATEST_RELEASE_VERSION}/infisical_${NUMERIC_RELEASE_VERSION}_${PLATFORM}_${ARCH}.${EXTENSION}`;
62
104
 
63
105
  // Ensure the output directory exists
64
106
  if (!fs.existsSync(outputDir)) {
@@ -77,19 +119,26 @@ async function main() {
77
119
  throw new Error(`Failed to fetch: ${response.status} - ${response.statusText}`);
78
120
  }
79
121
 
80
- await new Promise((resolve, reject) => {
81
- const outStream = stream.Readable.fromWeb(response.body)
82
- .pipe(zlib.createGunzip())
83
- .pipe(
84
- tar.x({
85
- C: path.join(outputDir),
86
- filter: path => path === "infisical"
87
- })
88
- );
89
-
90
- outStream.on("error", reject);
91
- outStream.on("close", resolve);
92
- });
122
+ if (EXTENSION === "zip") {
123
+ // For ZIP files, we need to buffer the whole thing first
124
+ const buffer = await response.arrayBuffer();
125
+ await extractZip(Buffer.from(buffer), outputDir);
126
+ } else {
127
+ // For tar.gz files, we stream
128
+ await new Promise((resolve, reject) => {
129
+ const outStream = stream.Readable.fromWeb(response.body)
130
+ .pipe(zlib.createGunzip())
131
+ .pipe(
132
+ tar.x({
133
+ C: path.join(outputDir),
134
+ filter: path => path === "infisical"
135
+ })
136
+ );
137
+
138
+ outStream.on("error", reject);
139
+ outStream.on("close", resolve);
140
+ });
141
+ }
93
142
 
94
143
  // Give the binary execute permissions if we're not on Windows
95
144
  if (PLATFORM !== "win32") {