@getgauge/cli 1.5.0 → 1.5.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.
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "sinon": "^6.2.0"
30
30
  },
31
31
  "dependencies": {
32
- "unzipper": "^0.9.3"
32
+ "adm-zip": "^0.5.10"
33
33
  },
34
- "version": "1.5.0"
34
+ "version": "1.5.1"
35
35
  }
package/src/index.js CHANGED
@@ -4,19 +4,35 @@
4
4
 
5
5
  const install = require("./install"),
6
6
  path = require("path"),
7
- unzip = require('unzipper'),
7
+ AdmZip = require('adm-zip'),
8
8
  https = require('https'),
9
9
  packageJsonPath = path.join(__dirname, "..", "package.json"),
10
10
  binPath = "./bin";
11
11
 
12
+ var extractZipArchive = function(buffer) {
13
+ return new Promise(function(resolve, reject) {
14
+ try {
15
+ const zip = new AdmZip(buffer);
16
+ zip.extractAllTo(path.normalize(binPath), true, true);
17
+ resolve();
18
+ } catch (err) {
19
+ reject(new Error(`Failed to extract archive from buffer: ${err.message}`));
20
+ }
21
+ })
22
+ }
23
+
12
24
  var downloadFollowingRedirect = function(url, resolve, reject) {
13
25
  https.get(url, { headers: { 'accept-encoding': 'gzip,deflate' } }, res => {
14
26
  if (res.statusCode >= 300 && res.statusCode < 400) {
15
- downloadFollowingRedirect(res.headers.location, reject, resolve);
16
- } else if (res.statusCode > 400) {
17
- console.error(`Unable to download '${url}' : ${res.statusCode}-'${res.statusMessage}'`);
27
+ downloadFollowingRedirect(res.headers.location, resolve, reject);
28
+ } else if (res.statusCode >= 400) {
29
+ reject(new Error(`Unable to download '${url}' : ${res.statusCode}-'${res.statusMessage}'`));
18
30
  } else {
19
- res.pipe(unzip.Extract({ path: path.normalize(binPath) })).on('error', reject).on('end', resolve);
31
+ const chunks = [];
32
+ res
33
+ .on('data', chunk => chunks.push(chunk))
34
+ .on('end', () => resolve(Buffer.concat(chunks)))
35
+ .on('error', reject);
20
36
  }
21
37
  });
22
38
  };
@@ -32,6 +48,7 @@ var downloadAndExtract = function(version) {
32
48
  reject(error);
33
49
  }
34
50
  })
51
+ .then(extractZipArchive)
35
52
  };
36
53
 
37
54
  install.getVersion(packageJsonPath)
package/src/install.js CHANGED
@@ -25,7 +25,12 @@ var getVersion = function(p) {
25
25
  if(err) {
26
26
  reject(err);
27
27
  }
28
- resolve(JSON.parse(data).version);
28
+ const pkg = JSON.parse(data);
29
+ if (pkg.version) {
30
+ resolve(pkg.version);
31
+ } else {
32
+ reject(new Error("Unable to find version in package.json."));
33
+ }
29
34
  })
30
35
  });
31
36
  }