@yaakapp/cli 0.0.37 → 0.0.39
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/common.js +13 -1
- package/index.js +3 -10
- package/install.js +10 -14
- package/package.json +5 -5
package/common.js
CHANGED
@@ -9,4 +9,16 @@ const BINARY_DISTRIBUTION_PACKAGES = {
|
|
9
9
|
// Adjust the version you want to install. You can also make this dynamic.
|
10
10
|
const BINARY_DISTRIBUTION_VERSION = require('./package.json').version;
|
11
11
|
|
12
|
-
|
12
|
+
// Windows binaries end with .exe so we need to special case them.
|
13
|
+
const BINARY_NAME = process.platform === "win32" ? "yaakcli.exe" : "yaakcli";
|
14
|
+
|
15
|
+
// Determine package name for this platform
|
16
|
+
const PLATFORM_SPECIFIC_PACKAGE_NAME =
|
17
|
+
BINARY_DISTRIBUTION_PACKAGES[process.platform + '_' + process.arch];
|
18
|
+
|
19
|
+
module.exports = {
|
20
|
+
BINARY_DISTRIBUTION_PACKAGES,
|
21
|
+
BINARY_DISTRIBUTION_VERSION,
|
22
|
+
BINARY_NAME,
|
23
|
+
PLATFORM_SPECIFIC_PACKAGE_NAME
|
24
|
+
};
|
package/index.js
CHANGED
@@ -1,20 +1,13 @@
|
|
1
1
|
const path = require("path");
|
2
2
|
const childProcess = require("child_process");
|
3
|
-
const {
|
4
|
-
|
5
|
-
// Windows binaries end with .exe so we need to special case them.
|
6
|
-
const binaryName = process.platform === "win32" ? "my-binary.exe" : "my-binary";
|
7
|
-
|
8
|
-
// Determine package name for this platform
|
9
|
-
const platformSpecificPackageName =
|
10
|
-
BINARY_DISTRIBUTION_PACKAGES[process.platform];
|
3
|
+
const {PLATFORM_SPECIFIC_PACKAGE_NAME, BINARY_NAME} = require("./common");
|
11
4
|
|
12
5
|
function getBinaryPath() {
|
13
6
|
try {
|
14
7
|
// Resolving will fail if the optionalDependency was not installed
|
15
|
-
return require.resolve(`${
|
8
|
+
return require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`);
|
16
9
|
} catch (e) {
|
17
|
-
return path.join(__dirname, "..",
|
10
|
+
return path.join(__dirname, "..", BINARY_NAME);
|
18
11
|
}
|
19
12
|
}
|
20
13
|
|
package/install.js
CHANGED
@@ -2,17 +2,10 @@ const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
3
3
|
const zlib = require("zlib");
|
4
4
|
const https = require("https");
|
5
|
-
const {
|
6
|
-
|
7
|
-
// Windows binaries end with .exe so we need to special case them.
|
8
|
-
const binaryName = process.platform === "win32" ? "yaakcli.exe" : "yaakcli";
|
9
|
-
|
10
|
-
// Determine package name for this platform
|
11
|
-
const platformSpecificPackageName =
|
12
|
-
BINARY_DISTRIBUTION_PACKAGES[process.platform];
|
5
|
+
const {BINARY_DISTRIBUTION_VERSION, BINARY_NAME, PLATFORM_SPECIFIC_PACKAGE_NAME} = require("./common");
|
13
6
|
|
14
7
|
// Compute the path we want to emit the fallback binary to
|
15
|
-
const fallbackBinaryPath = path.join(__dirname,
|
8
|
+
const fallbackBinaryPath = path.join(__dirname, BINARY_NAME);
|
16
9
|
|
17
10
|
function makeRequest(url) {
|
18
11
|
return new Promise((resolve, reject) => {
|
@@ -34,7 +27,7 @@ function makeRequest(url) {
|
|
34
27
|
} else {
|
35
28
|
reject(
|
36
29
|
new Error(
|
37
|
-
`npm responded with status code ${response.statusCode} when downloading the package
|
30
|
+
`npm responded with status code ${response.statusCode} when downloading the package! ${url}`
|
38
31
|
)
|
39
32
|
);
|
40
33
|
}
|
@@ -73,8 +66,9 @@ function extractFileFromTarball(tarballBuffer, filepath) {
|
|
73
66
|
|
74
67
|
async function downloadBinaryFromNpm() {
|
75
68
|
// Download the tarball of the right binary distribution package
|
69
|
+
const platformSpecificPackageNameWithoutOrg = PLATFORM_SPECIFIC_PACKAGE_NAME.split('/')[1];
|
76
70
|
const tarballDownloadBuffer = await makeRequest(
|
77
|
-
`https://registry.npmjs.org/${platformSpecificPackageName}/-/${
|
71
|
+
`https://registry.npmjs.org/${platformSpecificPackageName}/-/${platformSpecificPackageNameWithoutOrg}-${BINARY_DISTRIBUTION_VERSION}.tgz`,
|
78
72
|
);
|
79
73
|
|
80
74
|
const tarballBuffer = zlib.unzipSync(tarballDownloadBuffer);
|
@@ -82,7 +76,7 @@ async function downloadBinaryFromNpm() {
|
|
82
76
|
// Extract binary from package and write to disk
|
83
77
|
fs.writeFileSync(
|
84
78
|
fallbackBinaryPath,
|
85
|
-
extractFileFromTarball(tarballBuffer, `package/bin/${
|
79
|
+
extractFileFromTarball(tarballBuffer, `package/bin/${BINARY_NAME}`)
|
86
80
|
);
|
87
81
|
|
88
82
|
// Make binary executable
|
@@ -92,7 +86,9 @@ async function downloadBinaryFromNpm() {
|
|
92
86
|
function isPlatformSpecificPackageInstalled() {
|
93
87
|
try {
|
94
88
|
// Resolving will fail if the optionalDependency was not installed
|
95
|
-
|
89
|
+
const binPath = `${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`;
|
90
|
+
console.log('Checking if binary is installed', binPath);
|
91
|
+
require.resolve(binPath);
|
96
92
|
return true;
|
97
93
|
} catch (e) {
|
98
94
|
return false;
|
@@ -104,7 +100,7 @@ if (!isPlatformSpecificPackageInstalled()) {
|
|
104
100
|
console.log(
|
105
101
|
"Platform specific package not found. Will manually download binary."
|
106
102
|
);
|
107
|
-
downloadBinaryFromNpm();
|
103
|
+
downloadBinaryFromNpm().catch(console.error);
|
108
104
|
} else {
|
109
105
|
console.log(
|
110
106
|
"Platform specific package already installed. Will fall back to manually downloading binary."
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@yaakapp/cli",
|
3
|
-
"version": "v0.0.
|
3
|
+
"version": "v0.0.39",
|
4
4
|
"main": "./index.js",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -13,9 +13,9 @@
|
|
13
13
|
"yaakcli": "bin/cli.js"
|
14
14
|
},
|
15
15
|
"optionalDependencies": {
|
16
|
-
"@yaakapp/cli-darwin-x64": "v0.0.
|
17
|
-
"@yaakapp/cli-darwin-arm64": "v0.0.
|
18
|
-
"@yaakapp/cli-linux-x64": "v0.0.
|
19
|
-
"@yaakapp/cli-win32-x64": "v0.0.
|
16
|
+
"@yaakapp/cli-darwin-x64": "v0.0.39",
|
17
|
+
"@yaakapp/cli-darwin-arm64": "v0.0.39",
|
18
|
+
"@yaakapp/cli-linux-x64": "v0.0.39",
|
19
|
+
"@yaakapp/cli-win32-x64": "v0.0.39"
|
20
20
|
}
|
21
21
|
}
|