@criticalmanufacturing/cli 5.1.0 → 5.2.0-1

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 (3) hide show
  1. package/package.json +3 -5
  2. package/postinstall.js +25 -29
  3. package/run.js +5 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@criticalmanufacturing/cli",
3
- "version": "5.1.0",
3
+ "version": "5.2.0-1",
4
4
  "description": "Critical Manufacturing command line client",
5
5
  "bin": {
6
6
  "cmf": "./run.js"
@@ -29,12 +29,10 @@
29
29
  ],
30
30
  "dependencies": {
31
31
  "adm-zip": "^0.5.12",
32
- "axios": "^1.6.8",
32
+ "axios": "^1.7.9",
33
+ "proxy-agent": "^5.0.0",
33
34
  "debug": "^4.3.4",
34
- "env-paths": "^2.2.1",
35
35
  "global-dirs": "3.0.0",
36
- "is-installed-globally": "^0.4.0",
37
- "is-path-inside": "^3.0.3",
38
36
  "mkdirp": "^2.1.6",
39
37
  "node_modules-path": "^2.0.7",
40
38
  "rimraf": "^3.0.2",
package/postinstall.js CHANGED
@@ -4,42 +4,28 @@
4
4
 
5
5
  const path = require('path'),
6
6
  mkdirp = require('mkdirp'),
7
- envPaths = require('env-paths'),
8
7
  rimraf = require('rimraf'),
9
8
  fs = require('fs'),
10
9
  axios = require('axios'),
10
+ httpsProxyAgent = require('https-proxy-agent'),
11
+ httpProxyAgent = require('http-proxy-agent'),
12
+ proxyFromEnv = require('proxy-from-env'),
11
13
  AdmZip = require("adm-zip"),
12
14
  tmp = require('tmp'),
13
- dbg= require('debug'),
15
+ dbg = require('debug'),
14
16
  node_modules = require('node_modules-path'),
15
17
  { parsePackageJson, PLATFORM_MAPPING, ARCH_MAPPING } = require('./utils');
16
18
 
17
-
18
19
  const debug = dbg("cmf:debug");
19
20
  const error = dbg("cmf:debug:error");
20
21
 
21
22
  async function getInstallationPath() {
22
23
  debug("Getting installation path...");
23
- if (!!process.env.npm_config_global) {
24
- debug("Install is global, so targeting home directory for binaries");
25
- // install into home:
26
- // win: /AppData/Local/CMF/cmf-cli
27
- // linux: ~/.local/share/cmf-cli
28
- // osx: ~/Library/Application Support/cmf-cli
29
- const paths = envPaths("cmf-cli", {suffix: ""});
30
- debug(`Install at ${paths.data}. Making sure path exists...`);
31
- await mkdirp(paths.data);
32
- debug(`Install path exists!`);
33
- return paths.data;
34
- } else {
35
- debug("Install is local, so targeting node_modules/.bin/cmf-cli. Making sure path exists...");
36
- // install into node_modules/.bin/cmf-cli
37
- const value = path.join(node_modules(), ".bin");
38
- const dir = path.join(value, "cmf-cli");
39
- await mkdirp(dir);
40
- debug(`Install path exists!`);
41
- return dir;
42
- }
24
+ debug("Targeting node_modules/.bin/cmf-cli. Making sure path exists...");
25
+ const dir = path.join(node_modules(), ".bin", "cmf-cli");
26
+ await mkdirp(dir);
27
+ debug(`Install path exists!`);
28
+ return dir;
43
29
  }
44
30
 
45
31
  async function verifyAndPlaceBinary(binName, binPath, callback) {
@@ -57,7 +43,6 @@ async function verifyAndPlaceBinary(binName, binPath, callback) {
57
43
  */
58
44
  var INVALID_INPUT = "Invalid inputs";
59
45
  async function install(callback) {
60
-
61
46
  var opts = parsePackageJson(".");
62
47
  if (!opts) return callback(INVALID_INPUT);
63
48
  console.info(`Copying the relevant binary for your platform ${process.platform}`);
@@ -68,9 +53,21 @@ async function install(callback) {
68
53
  const pkgUrl = opts.binUrl.replace("{{version}}", opts.version).replace("{{platform}}", PLATFORM_MAPPING[process.platform]).replace("{{arch}}", ARCH_MAPPING[process.arch]);
69
54
  console.info(`Getting release archive from ${pkgUrl} into ${path.resolve(src)}`);
70
55
  try {
56
+ // support for http/s proxies through env vars
57
+ const proxy = proxyFromEnv.getProxyForUrl(pkgUrl);
58
+ let httpAgent, httpsAgent;
59
+ if (proxy) {
60
+ httpAgent = new httpProxyAgent.HttpProxyAgent(proxy);
61
+ httpsAgent = new httpsProxyAgent.HttpsProxyAgent(proxy);
62
+ }
63
+
64
+ // make req (override axios automatic proxy since it is not working properly)
71
65
  const response = await axios({
72
66
  url: pkgUrl,
73
67
  method: 'GET',
68
+ proxy: false,
69
+ httpAgent: httpAgent,
70
+ httpsAgent: httpsAgent,
74
71
  responseType: 'arraybuffer', // to do this with streaming we must deal with chunking
75
72
  });
76
73
  const zip = tmp.tmpNameSync();
@@ -94,16 +91,14 @@ async function install(callback) {
94
91
  await execShellCommand(`cp -r ${src}/** "${installPath}"`);
95
92
  await execShellCommand(`chmod +x "${installPath}/cmf"`);
96
93
  }
97
-
98
94
  await verifyAndPlaceBinary(opts.binName, installPath, callback);
99
95
  }
100
96
 
101
97
  async function uninstall(callback) {
102
- var opts = parsePackageJson(".");
103
98
  try {
104
- const installationPath = await getInstallationPath();
105
- debug("Deleting binaries from " + installationPath);
106
- rimraf.sync(installationPath);
99
+ const installPath = await getInstallationPath();
100
+ debug("Deleting binaries from " + installPath);
101
+ rimraf.sync(installPath);
107
102
  } catch (ex) {
108
103
  console.log(ex);
109
104
  callback(ex);
@@ -118,6 +113,7 @@ var actions = {
118
113
  "install": install,
119
114
  "uninstall": uninstall
120
115
  };
116
+
121
117
  /**
122
118
  * Executes a shell command and return it as a Promise.
123
119
  * @param cmd {string}
package/run.js CHANGED
@@ -1,10 +1,9 @@
1
1
  #! /usr/bin/env node
2
+
2
3
  "use strict";
4
+
3
5
  const { spawn } = require('child_process');
4
- const envPaths = require('env-paths');
5
6
  const path = require('path');
6
- const isInstalledGlobally = require('is-installed-globally');
7
- const isPathInside = require('is-path-inside');
8
7
  const node_modules = require('node_modules-path');
9
8
  const dbg = require('debug');
10
9
  const { parsePackageJson } = require('./utils');
@@ -13,21 +12,8 @@ const opts = parsePackageJson(__dirname);
13
12
  const debug = dbg("cmf:debug");
14
13
 
15
14
  debug("Executing cmf-cli");
16
- let exePath = null;
17
- debug("Determining if cli is installed globally or locally...");
18
- /**
19
- * we need to check if we are installed globally.
20
- * However, this does not cover some cases, depending on how Node was installed, that we need to check manually:
21
- * - in windows, Node was installed in Program Files but NPM is installed in the user profile (AppData/Roaming)
22
- */
23
- if (isInstalledGlobally || isPathInside(__dirname, process.env.APPDATA || "dummy") || isPathInside(__dirname, "/usr/local")) {
24
- debug("cli is installed globally. Getting binary location from user profile...");
25
- const paths = envPaths("cmf-cli", {suffix: ""});
26
- exePath = path.join(paths.data, opts.binName);
27
- } else {
28
- debug("cli is installed locally. Getting binary from node_modules/.bin/cmf-cli...");
29
- exePath = path.join(node_modules(), ".bin", "cmf-cli", opts.binName);
30
- }
15
+ debug("Getting binary from node_modules/.bin/cmf-cli...");
16
+ const exePath = path.join(node_modules(), ".bin", "cmf-cli", opts.binName);
31
17
  debug("Obtained binary path: " + exePath);
32
18
 
33
19
  debug(`Spawning cmf-cli from ${exePath} with args ${process.argv.slice(2)} and piping.`);
@@ -35,4 +21,4 @@ const child = spawn(exePath, process.argv.slice(2), {stdio: "inherit"});
35
21
  child.on('close', (code) => {
36
22
  debug("Process exited with code " + code);
37
23
  process.exitCode = code;
38
- });
24
+ });