@yaakapp/cli 0.0.19 → 0.0.37

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 ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+
3
+ const path = require("path");
4
+ const childProcess = require("child_process");
5
+
6
+ // Lookup table for all platforms and binary distribution packages
7
+ const BINARY_DISTRIBUTION_PACKAGES = {
8
+ darwin: "npm-binary-example-darwin",
9
+ linux: "npm-binary-example-linux",
10
+ freebsd: "npm-binary-example-linux",
11
+ win32: "npm-binary-example-win32",
12
+ };
13
+
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
+ // Determine package name for this platform
18
+ const platformSpecificPackageName =
19
+ BINARY_DISTRIBUTION_PACKAGES[process.platform];
20
+
21
+ function getBinaryPath() {
22
+ try {
23
+ // Resolving will fail if the optionalDependency was not installed
24
+ return require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`);
25
+ } catch (e) {
26
+ return path.join(__dirname, "..", binaryName);
27
+ }
28
+ }
29
+
30
+ childProcess.execFileSync(getBinaryPath(), process.argv.slice(2), {
31
+ stdio: "inherit",
32
+ });
package/common.js ADDED
@@ -0,0 +1,12 @@
1
+ // Lookup table for all platforms and binary distribution packages
2
+ const BINARY_DISTRIBUTION_PACKAGES = {
3
+ darwin_arm64: "@yaakapp/cli-darwin-arm64",
4
+ darwin_x64: "@yaakapp/cli-darwin-x64",
5
+ linux_x64: "@yaakapp/cli-linux-x64",
6
+ win32_x64: "@yaakapp/cli-win32-x64",
7
+ };
8
+
9
+ // Adjust the version you want to install. You can also make this dynamic.
10
+ const BINARY_DISTRIBUTION_VERSION = require('./package.json').version;
11
+
12
+ module.exports = {BINARY_DISTRIBUTION_PACKAGES, BINARY_DISTRIBUTION_VERSION};
package/index.js ADDED
@@ -0,0 +1,25 @@
1
+ const path = require("path");
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];
11
+
12
+ function getBinaryPath() {
13
+ try {
14
+ // Resolving will fail if the optionalDependency was not installed
15
+ return require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`);
16
+ } catch (e) {
17
+ return path.join(__dirname, "..", binaryName);
18
+ }
19
+ }
20
+
21
+ module.exports.runBinary = function (...args) {
22
+ childProcess.execFileSync(getBinaryPath(), args, {
23
+ stdio: "inherit",
24
+ });
25
+ };
@@ -2,17 +2,17 @@ const fs = require("fs");
2
2
  const path = require("path");
3
3
  const zlib = require("zlib");
4
4
  const https = require("https");
5
- const {getBinaryPath, getBinaryName} = require("./util");
5
+ const {BINARY_DISTRIBUTION_PACKAGES, BINARY_DISTRIBUTION_VERSION} = require("./common");
6
6
 
7
- // Adjust the version you want to install. You can also make this dynamic.
8
- const VERSION = "0.0.10";
7
+ // Windows binaries end with .exe so we need to special case them.
8
+ const binaryName = process.platform === "win32" ? "yaakcli.exe" : "yaakcli";
9
9
 
10
- // Windows binaries end with .exe so we need to special-case them.
11
- const binaryName = getBinaryName();
10
+ // Determine package name for this platform
11
+ const platformSpecificPackageName =
12
+ BINARY_DISTRIBUTION_PACKAGES[process.platform];
12
13
 
13
- // Compute the path we want to emit the binary to
14
- const binaryInstallationPath = getBinaryPath()
15
- fs.mkdirSync(path.dirname(binaryInstallationPath), {recursive: true});
14
+ // Compute the path we want to emit the fallback binary to
15
+ const fallbackBinaryPath = path.join(__dirname, binaryName);
16
16
 
17
17
  function makeRequest(url) {
18
18
  return new Promise((resolve, reject) => {
@@ -22,7 +22,6 @@ function makeRequest(url) {
22
22
  const chunks = [];
23
23
  response.on("data", (chunk) => chunks.push(chunk));
24
24
  response.on("end", () => {
25
- console.log("Finished downloading")
26
25
  resolve(Buffer.concat(chunks));
27
26
  });
28
27
  } else if (
@@ -35,8 +34,7 @@ function makeRequest(url) {
35
34
  } else {
36
35
  reject(
37
36
  new Error(
38
- `npm responded with status code ${response.statusCode}` +
39
- ` when downloading the package! ${url}`
37
+ `npm responded with status code ${response.statusCode} when downloading the package!`
40
38
  )
41
39
  );
42
40
  }
@@ -73,42 +71,42 @@ function extractFileFromTarball(tarballBuffer, filepath) {
73
71
  }
74
72
  }
75
73
 
76
- async function downloadBinary() {
74
+ async function downloadBinaryFromNpm() {
77
75
  // Download the tarball of the right binary distribution package
78
- const platform = process.platform === 'win32' ? 'windows' : process.platform;
79
- const arch = process.arch === 'x64' ? 'amd64' : process.arch;
80
- const url = `https://github.com/yaakapp/yaakcli/releases/download/v${VERSION}/yaakcli_${VERSION}_${platform}_${arch}.tar.gz`;
81
- console.log(`Downloading ${url}`);
82
- const tarballDownloadBuffer = await makeRequest(url);
76
+ const tarballDownloadBuffer = await makeRequest(
77
+ `https://registry.npmjs.org/${platformSpecificPackageName}/-/${platformSpecificPackageName}-${BINARY_DISTRIBUTION_VERSION}.tgz`
78
+ );
83
79
 
84
- console.log(`Extracting ${tarballDownloadBuffer.length}`);
85
80
  const tarballBuffer = zlib.unzipSync(tarballDownloadBuffer);
86
81
 
87
- const dir = path.dirname(binaryInstallationPath);
88
- console.log(`Creating dir ${dir}`);
89
- fs.mkdirSync(dir, {recursive: true});
90
-
91
82
  // Extract binary from package and write to disk
92
- console.log(`Writing tarball to ${binaryInstallationPath}`);
93
83
  fs.writeFileSync(
94
- binaryInstallationPath,
95
- extractFileFromTarball(tarballBuffer, binaryName)
84
+ fallbackBinaryPath,
85
+ extractFileFromTarball(tarballBuffer, `package/bin/${binaryName}`)
96
86
  );
97
87
 
98
- console.log(`Extracting tarball to ${binaryInstallationPath}`);
99
88
  // Make binary executable
100
- fs.chmodSync(binaryInstallationPath, "755");
101
-
102
- console.log("Done");
89
+ fs.chmodSync(fallbackBinaryPath, "755");
103
90
  }
104
91
 
105
92
  function isPlatformSpecificPackageInstalled() {
106
- return fs.existsSync(binaryInstallationPath)
93
+ try {
94
+ // Resolving will fail if the optionalDependency was not installed
95
+ require.resolve(`${platformSpecificPackageName}/bin/${binaryName}`);
96
+ return true;
97
+ } catch (e) {
98
+ return false;
99
+ }
107
100
  }
108
101
 
109
102
  // Skip downloading the binary if it was already installed via optionalDependencies
110
103
  if (!isPlatformSpecificPackageInstalled()) {
111
- downloadBinary().catch(console.error);
104
+ console.log(
105
+ "Platform specific package not found. Will manually download binary."
106
+ );
107
+ downloadBinaryFromNpm();
112
108
  } else {
113
- console.log(`yaakcli already exists at ${binaryInstallationPath}`);
109
+ console.log(
110
+ "Platform specific package already installed. Will fall back to manually downloading binary."
111
+ );
114
112
  }
package/package.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
2
  "name": "@yaakapp/cli",
3
- "version": "0.0.19",
3
+ "version": "v0.0.37",
4
+ "main": "./index.js",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "git+https://github.com/yaakapp/cli.git"
7
8
  },
8
- "files": [
9
- "scripts"
10
- ],
11
9
  "scripts": {
12
- "postinstall": "node scripts/install.js",
13
- "preuninstall": "node scripts/uninstall.js"
10
+ "postinstall": "node ./install.js"
11
+ },
12
+ "bin": {
13
+ "yaakcli": "bin/cli.js"
14
+ },
15
+ "optionalDependencies": {
16
+ "@yaakapp/cli-darwin-x64": "v0.0.37",
17
+ "@yaakapp/cli-darwin-arm64": "v0.0.37",
18
+ "@yaakapp/cli-linux-x64": "v0.0.37",
19
+ "@yaakapp/cli-win32-x64": "v0.0.37"
14
20
  }
15
- }
21
+ }
package/README.md DELETED
@@ -1,10 +0,0 @@
1
-
2
- # Yaak CLI (`yaakcli`)
3
-
4
- This is the CLI for developing [Yaak](https://yaak.app) plugins.
5
-
6
- ## Installation
7
-
8
- ```shell
9
- npm install -g @yaakapp/cli
10
- ```
File without changes
package/scripts/util.js DELETED
@@ -1,10 +0,0 @@
1
- const path = require("path");
2
- const {execSync} = require("child_process");
3
-
4
- module.exports.getBinaryName = function () {
5
- return process.platform === "win32" ? "yaakcli.exe" : "yaakcli";
6
- }
7
-
8
- module.exports.getBinaryPath = function () {
9
- return path.join(execSync("npm prefix -g").toString().trim(), "bin", module.exports.getBinaryName())
10
- }