@infisical/cli 0.41.89 → 0.41.91

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.
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infisical/cli",
3
3
  "private": false,
4
- "version": "0.41.89",
4
+ "version": "0.41.91",
5
5
  "keywords": [
6
6
  "infisical",
7
7
  "cli",
package/src/index.cjs CHANGED
@@ -12,155 +12,165 @@ const supportedPlatforms = ["linux", "darwin", "win32", "freebsd", "windows"];
12
12
  const outputDir = "bin";
13
13
 
14
14
  const getPlatform = () => {
15
- let platform = process.platform;
16
-
17
- if (platform === "win32") {
18
- platform = "windows";
19
- }
20
-
21
- if (!supportedPlatforms.includes(platform)) {
22
- console.error("Your platform doesn't seem to be of type darwin, linux or windows");
23
- process.exit(1);
24
- }
25
- return platform;
15
+ let platform = process.platform;
16
+
17
+ if (platform === "win32") {
18
+ platform = "windows";
19
+ }
20
+
21
+ if (!supportedPlatforms.includes(platform)) {
22
+ console.error(
23
+ "Your platform doesn't seem to be of type darwin, linux or windows"
24
+ );
25
+ process.exit(1);
26
+ }
27
+ return platform;
26
28
  };
27
29
 
28
30
  const getArchitecture = () => {
29
- const architecture = process.arch;
30
- let arch = "";
31
-
32
- if (architecture === "x64" || architecture === "amd64") {
33
- arch = "amd64";
34
- } else if (architecture === "arm64") {
35
- arch = "arm64";
36
- } else if (architecture === "arm") {
37
- // If the platform is Linux, we should find the exact ARM version, otherwise we default to armv7 which is the most common
38
- if (process.platform === "linux" || process.platform === "freebsd") {
39
- const output = childProcess.execSync("uname -m").toString().trim();
40
-
41
- const armVersions = ["armv5", "armv6", "armv7"];
42
-
43
- const armVersion = armVersions.find(version => output.startsWith(version));
44
-
45
- if (armVersion) {
46
- arch = armVersion;
47
- } else {
48
- arch = "armv7";
49
- }
50
- } else {
51
- arch = "armv7";
52
- }
53
- } else if (architecture === "ia32") {
54
- arch = "i386";
55
- } else {
56
- console.error("Your architecture doesn't seem to be supported. Your architecture is", architecture);
57
- process.exit(1);
58
- }
59
-
60
- return arch;
31
+ const architecture = process.arch;
32
+ let arch = "";
33
+
34
+ if (architecture === "x64" || architecture === "amd64") {
35
+ arch = "amd64";
36
+ } else if (architecture === "arm64") {
37
+ arch = "arm64";
38
+ } else if (architecture === "arm") {
39
+ // If the platform is Linux, we should find the exact ARM version, otherwise we default to armv7 which is the most common
40
+ if (process.platform === "linux" || process.platform === "freebsd") {
41
+ const output = childProcess.execSync("uname -m").toString().trim();
42
+
43
+ const armVersions = ["armv5", "armv6", "armv7"];
44
+
45
+ const armVersion = armVersions.find((version) =>
46
+ output.startsWith(version)
47
+ );
48
+
49
+ if (armVersion) {
50
+ arch = armVersion;
51
+ } else {
52
+ arch = "armv7";
53
+ }
54
+ } else {
55
+ arch = "armv7";
56
+ }
57
+ } else if (architecture === "ia32") {
58
+ arch = "i386";
59
+ } else {
60
+ console.error(
61
+ "Your architecture doesn't seem to be supported. Your architecture is",
62
+ architecture
63
+ );
64
+ process.exit(1);
65
+ }
66
+
67
+ return arch;
61
68
  };
62
69
 
63
70
  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
- let fileName = entry.fileName;
81
-
82
- if (entry.fileName.endsWith(".exe")) {
83
- fileName = "infisical.exe";
84
- } else if (entry.fileName.includes("infisical")) {
85
- fileName = "infisical";
86
- }
87
-
88
- const outputPath = path.join(targetPath, fileName);
89
- const writeStream = fs.createWriteStream(outputPath);
90
-
91
- readStream.pipe(writeStream);
92
- writeStream.on("close", () => {
93
- zipfile.readEntry();
94
- });
95
- });
96
- }
97
- });
98
-
99
- zipfile.on("end", resolve);
100
- zipfile.on("error", reject);
101
- });
102
- });
71
+ return new Promise((resolve, reject) => {
72
+ yauzl.fromBuffer(buffer, { lazyEntries: true }, (err, zipfile) => {
73
+ if (err) return reject(err);
74
+
75
+ zipfile.readEntry();
76
+ zipfile.on("entry", (entry) => {
77
+ const isExecutable =
78
+ entry.fileName === "infisical" || entry.fileName === "infisical.exe";
79
+
80
+ if (/\/$/.test(entry.fileName) || !isExecutable) {
81
+ // Directory entry
82
+ zipfile.readEntry();
83
+ } else {
84
+ // File entry
85
+ zipfile.openReadStream(entry, (err, readStream) => {
86
+ if (err) return reject(err);
87
+
88
+ let fileName = entry.fileName;
89
+
90
+ if (entry.fileName.endsWith(".exe")) {
91
+ fileName = "infisical.exe";
92
+ } else if (entry.fileName.includes("infisical")) {
93
+ fileName = "infisical";
94
+ }
95
+
96
+ const outputPath = path.join(targetPath, fileName);
97
+ const writeStream = fs.createWriteStream(outputPath);
98
+
99
+ readStream.pipe(writeStream);
100
+ writeStream.on("close", () => {
101
+ zipfile.readEntry();
102
+ });
103
+ });
104
+ }
105
+ });
106
+
107
+ zipfile.on("end", resolve);
108
+ zipfile.on("error", reject);
109
+ });
110
+ });
103
111
  }
104
112
 
105
113
  async function main() {
106
- const PLATFORM = getPlatform();
107
- const ARCH = getArchitecture();
108
- const NUMERIC_RELEASE_VERSION = packageJSON.version;
109
- const LATEST_RELEASE_VERSION = `v${NUMERIC_RELEASE_VERSION}`;
110
- const EXTENSION = PLATFORM === "windows" ? "zip" : "tar.gz";
111
- const downloadLink = `https://github.com/Infisical/infisical/releases/download/infisical-cli/${LATEST_RELEASE_VERSION}/infisical_${NUMERIC_RELEASE_VERSION}_${PLATFORM}_${ARCH}.${EXTENSION}`;
112
-
113
- // Ensure the output directory exists
114
- if (!fs.existsSync(outputDir)) {
115
- fs.mkdirSync(outputDir);
116
- }
117
-
118
- // Download the latest CLI binary
119
- try {
120
- const response = await fetch(downloadLink, {
121
- headers: {
122
- Accept: "application/octet-stream"
123
- }
124
- });
125
-
126
- if (!response.ok) {
127
- throw new Error(`Failed to fetch: ${response.status} - ${response.statusText}`);
128
- }
129
-
130
- if (EXTENSION === "zip") {
131
- // For ZIP files, we need to buffer the whole thing first
132
- const buffer = await response.arrayBuffer();
133
- await extractZip(Buffer.from(buffer), outputDir);
134
- } else {
135
- // For tar.gz files, we stream
136
- await new Promise((resolve, reject) => {
137
- const outStream = stream.Readable.fromWeb(response.body)
138
- .pipe(zlib.createGunzip())
139
- .pipe(
140
- tar.x({
141
- C: path.join(outputDir),
142
- filter: path => path === "infisical"
143
- })
144
- );
145
-
146
- outStream.on("error", reject);
147
- outStream.on("close", resolve);
148
- });
149
- }
150
-
151
- // Platform-specific tasks
152
- if (PLATFORM === "windows") {
153
- // We create an empty file called 'infisical'. This file has no functionality, except allowing NPM to correctly create the symlink.
154
- // Reason why this doesn't work without the empty file, is because the files downloaded are a .ps1, .exe, and .cmd file. None of these match the binary name from the package.json['bin'] field.
155
- // This is a bit hacky, but it assures that the symlink is correctly created.
156
- fs.closeSync(fs.openSync(path.join(outputDir, "infisical"), "w"));
157
- } else {
158
- // Unix systems only need chmod
159
- fs.chmodSync(path.join(outputDir, "infisical"), "755");
160
- }
161
- } catch (error) {
162
- console.error("Error downloading or extracting Infisical CLI:", error);
163
- process.exit(1);
164
- }
114
+ const PLATFORM = getPlatform();
115
+ const ARCH = getArchitecture();
116
+ const NUMERIC_RELEASE_VERSION = packageJSON.version;
117
+ const LATEST_RELEASE_VERSION = `v${NUMERIC_RELEASE_VERSION}`;
118
+ const EXTENSION = PLATFORM === "windows" ? "zip" : "tar.gz";
119
+ const downloadLink = `https://github.com/Infisical/cli/releases/download/${LATEST_RELEASE_VERSION}/cli_${NUMERIC_RELEASE_VERSION}_${PLATFORM}_${ARCH}.${EXTENSION}`;
120
+
121
+ // Ensure the output directory exists
122
+ if (!fs.existsSync(outputDir)) {
123
+ fs.mkdirSync(outputDir);
124
+ }
125
+
126
+ // Download the latest CLI binary
127
+ try {
128
+ const response = await fetch(downloadLink, {
129
+ headers: {
130
+ Accept: "application/octet-stream",
131
+ },
132
+ });
133
+
134
+ if (!response.ok) {
135
+ throw new Error(
136
+ `Failed to fetch: ${response.status} - ${response.statusText}`
137
+ );
138
+ }
139
+
140
+ if (EXTENSION === "zip") {
141
+ // For ZIP files, we need to buffer the whole thing first
142
+ const buffer = await response.arrayBuffer();
143
+ await extractZip(Buffer.from(buffer), outputDir);
144
+ } else {
145
+ // For tar.gz files, we stream
146
+ await new Promise((resolve, reject) => {
147
+ const outStream = stream.Readable.fromWeb(response.body)
148
+ .pipe(zlib.createGunzip())
149
+ .pipe(
150
+ tar.x({
151
+ C: path.join(outputDir),
152
+ filter: (path) => path === "infisical",
153
+ })
154
+ );
155
+
156
+ outStream.on("error", reject);
157
+ outStream.on("close", resolve);
158
+ });
159
+ }
160
+
161
+ // Platform-specific tasks
162
+ if (PLATFORM === "windows") {
163
+ // We create an empty file called 'infisical'. This file has no functionality, except allowing NPM to correctly create the symlink.
164
+ // Reason why this doesn't work without the empty file, is because the files downloaded are a .ps1, .exe, and .cmd file. None of these match the binary name from the package.json['bin'] field.
165
+ // This is a bit hacky, but it assures that the symlink is correctly created.
166
+ fs.closeSync(fs.openSync(path.join(outputDir, "infisical"), "w"));
167
+ } else {
168
+ // Unix systems only need chmod
169
+ fs.chmodSync(path.join(outputDir, "infisical"), "755");
170
+ }
171
+ } catch (error) {
172
+ console.error("Error downloading or extracting Infisical CLI:", error);
173
+ process.exit(1);
174
+ }
165
175
  }
166
176
  main();
Binary file