@yaakapp/cli 0.0.38 → 0.0.40

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/bin/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const path = require("path");
4
4
  const childProcess = require("child_process");
5
+ const {BINARY_NAME} = require("../common");
5
6
 
6
7
  // Lookup table for all platforms and binary distribution packages
7
8
  const BINARY_DISTRIBUTION_PACKAGES = {
@@ -11,9 +12,6 @@ const BINARY_DISTRIBUTION_PACKAGES = {
11
12
  win32: "npm-binary-example-win32",
12
13
  };
13
14
 
14
- // Windows binaries end with .exe so we need to special case them.
15
- const binaryName = process.platform === "win32" ? "my-binary.exe" : "my-binary";
16
-
17
15
  // Determine package name for this platform
18
16
  const platformSpecificPackageName =
19
17
  BINARY_DISTRIBUTION_PACKAGES[process.platform];
@@ -21,9 +19,9 @@ const platformSpecificPackageName =
21
19
  function getBinaryPath() {
22
20
  try {
23
21
  // Resolving will fail if the optionalDependency was not installed
24
- return require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`);
22
+ return require.resolve(`${platformSpecificPackageName}/bin/${BINARY_NAME}`);
25
23
  } catch (e) {
26
- return path.join(__dirname, "..", binaryName);
24
+ return path.join(__dirname, "..", BINARY_NAME);
27
25
  }
28
26
  }
29
27
 
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
- module.exports = {BINARY_DISTRIBUTION_PACKAGES, BINARY_DISTRIBUTION_VERSION};
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 {BINARY_DISTRIBUTION_PACKAGES} = require("./common");
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(`${platformSpecificPackageName}/bin/${binaryName}`);
8
+ return require.resolve(`${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`);
16
9
  } catch (e) {
17
- return path.join(__dirname, "..", binaryName);
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 {BINARY_DISTRIBUTION_PACKAGES, BINARY_DISTRIBUTION_VERSION} = require("./common");
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, binaryName);
8
+ const fallbackBinaryPath = path.join(__dirname, BINARY_NAME);
16
9
 
17
10
  function makeRequest(url) {
18
11
  return new Promise((resolve, reject) => {
@@ -73,7 +66,7 @@ function extractFileFromTarball(tarballBuffer, filepath) {
73
66
 
74
67
  async function downloadBinaryFromNpm() {
75
68
  // Download the tarball of the right binary distribution package
76
- const platformSpecificPackageNameWithoutOrg = platformSpecificPackageName.split('/')[1];
69
+ const platformSpecificPackageNameWithoutOrg = PLATFORM_SPECIFIC_PACKAGE_NAME.split('/')[1];
77
70
  const tarballDownloadBuffer = await makeRequest(
78
71
  `https://registry.npmjs.org/${platformSpecificPackageName}/-/${platformSpecificPackageNameWithoutOrg}-${BINARY_DISTRIBUTION_VERSION}.tgz`,
79
72
  );
@@ -83,7 +76,7 @@ async function downloadBinaryFromNpm() {
83
76
  // Extract binary from package and write to disk
84
77
  fs.writeFileSync(
85
78
  fallbackBinaryPath,
86
- extractFileFromTarball(tarballBuffer, `package/bin/${binaryName}`)
79
+ extractFileFromTarball(tarballBuffer, `package/bin/${BINARY_NAME}`)
87
80
  );
88
81
 
89
82
  // Make binary executable
@@ -93,7 +86,9 @@ async function downloadBinaryFromNpm() {
93
86
  function isPlatformSpecificPackageInstalled() {
94
87
  try {
95
88
  // Resolving will fail if the optionalDependency was not installed
96
- require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`);
89
+ const binPath = `${PLATFORM_SPECIFIC_PACKAGE_NAME}/bin/${BINARY_NAME}`;
90
+ console.log('Checking if binary is installed', binPath);
91
+ require.resolve(binPath);
97
92
  return true;
98
93
  } catch (e) {
99
94
  return false;
@@ -105,7 +100,7 @@ if (!isPlatformSpecificPackageInstalled()) {
105
100
  console.log(
106
101
  "Platform specific package not found. Will manually download binary."
107
102
  );
108
- downloadBinaryFromNpm();
103
+ downloadBinaryFromNpm().catch(console.error);
109
104
  } else {
110
105
  console.log(
111
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.38",
3
+ "version": "v0.0.40",
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.38",
17
- "@yaakapp/cli-darwin-arm64": "v0.0.38",
18
- "@yaakapp/cli-linux-x64": "v0.0.38",
19
- "@yaakapp/cli-win32-x64": "v0.0.38"
16
+ "@yaakapp/cli-darwin-x64": "v0.0.40",
17
+ "@yaakapp/cli-darwin-arm64": "v0.0.40",
18
+ "@yaakapp/cli-linux-x64": "v0.0.40",
19
+ "@yaakapp/cli-win32-x64": "v0.0.40"
20
20
  }
21
21
  }