@getgauge/cli 1.6.25 → 1.6.26

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
@@ -32,5 +32,5 @@
32
32
  "dependencies": {
33
33
  "adm-zip": "^0.5.16"
34
34
  },
35
- "version": "1.6.25"
35
+ "version": "1.6.26"
36
36
  }
package/src/index.js CHANGED
@@ -4,13 +4,14 @@
4
4
 
5
5
  const install = require("./install"),
6
6
  path = require("path"),
7
+ fs = require("fs"),
7
8
  AdmZip = require('adm-zip'),
8
9
  https = require('https'),
9
10
  packageJsonPath = path.join(__dirname, "..", "package.json"),
10
11
  binPath = "./bin";
11
12
 
12
- var extractZipArchive = function(buffer) {
13
- return new Promise(function(resolve, reject) {
13
+ const extractZipArchive = function (buffer) {
14
+ return new Promise(function (resolve, reject) {
14
15
  try {
15
16
  const zip = new AdmZip(buffer);
16
17
  zip.extractAllTo(path.normalize(binPath), true, true);
@@ -19,10 +20,10 @@ var extractZipArchive = function(buffer) {
19
20
  reject(new Error(`Failed to extract archive from buffer: ${err.message}`));
20
21
  }
21
22
  })
22
- }
23
+ };
23
24
 
24
- var downloadFollowingRedirect = function(url, resolve, reject) {
25
- https.get(url, { headers: { 'accept-encoding': 'gzip,deflate' } }, res => {
25
+ const downloadFollowingRedirect = function (url, resolve, reject) {
26
+ https.get(url, {headers: {'accept-encoding': 'gzip,deflate'}}, res => {
26
27
  if (res.statusCode >= 300 && res.statusCode < 400) {
27
28
  downloadFollowingRedirect(res.headers.location, resolve, reject);
28
29
  res.resume()
@@ -32,14 +33,14 @@ var downloadFollowingRedirect = function(url, resolve, reject) {
32
33
  } else {
33
34
  const chunks = [];
34
35
  res
35
- .on('data', chunk => chunks.push(chunk))
36
- .on('end', () => resolve(Buffer.concat(chunks)))
37
- .on('error', reject);
36
+ .on('data', chunk => chunks.push(chunk))
37
+ .on('end', () => resolve(Buffer.concat(chunks)))
38
+ .on('error', reject);
38
39
  }
39
40
  });
40
41
  };
41
42
 
42
- var downloadAndExtract = function(version) {
43
+ const downloadAndExtract = function (version) {
43
44
  console.log(`Fetching download url for Gauge version ${version}`);
44
45
  let url = install.getBinaryUrl(version);
45
46
  console.log(`Downloading ${url} to ${binPath}`);
@@ -50,9 +51,19 @@ var downloadAndExtract = function(version) {
50
51
  reject(error);
51
52
  }
52
53
  })
53
- .then(extractZipArchive)
54
+ .then(extractZipArchive)
55
+ };
56
+
57
+ const removeStubBinary = () => {
58
+ try {
59
+ fs.unlinkSync(path.normalize(`${binPath}/gauge`));
60
+ } catch (err) {
61
+ if (err.code !== 'ENOENT') {
62
+ console.error("Unable to clean up stub binary; ignoring...", err)
63
+ }
64
+ }
54
65
  };
55
66
 
56
67
  install.getVersion(packageJsonPath)
57
68
  .then((v) => downloadAndExtract(v.split('-')[0]))
58
- .catch((e) => console.error(e));
69
+ .catch((e) => { removeStubBinary(); throw e; });
package/src/install.js CHANGED
@@ -15,14 +15,14 @@ const BASE_URL="https://github.com/getgauge/gauge/releases/download/",
15
15
  "linux": "linux",
16
16
  "win32": "windows"
17
17
  };
18
-
19
- var getVersion = function(p) {
20
- return new Promise( (resolve, reject) => {
18
+
19
+ const getVersion = function (p) {
20
+ return new Promise((resolve, reject) => {
21
21
  if (!fs.existsSync(p)) {
22
22
  reject("Unable to find package.json.");
23
23
  }
24
24
  fs.readFile(p, (err, data) => {
25
- if(err) {
25
+ if (err) {
26
26
  reject(err);
27
27
  }
28
28
  const pkg = JSON.parse(data);
@@ -31,15 +31,16 @@ var getVersion = function(p) {
31
31
  } else {
32
32
  reject(new Error("Unable to find version in package.json."));
33
33
  }
34
- })
34
+ })
35
35
  });
36
- }
36
+ };
37
37
 
38
- var getBinaryUrl = function(version) {
39
- let os = PLATFORM_MAPPING[process.platform];
40
- let arch = ARCH_MAPPING[process.arch];
41
- return `${BASE_URL}v${version}/gauge-${version}-${os}.${arch}.zip`;
42
- }
38
+ const getBinaryUrl = function (version) {
39
+ // Use x64 on Windows for ARM64 as we don't publish ARM64 builds yet
40
+ const canonical_os = PLATFORM_MAPPING[process.platform];
41
+ const canonical_arch = ARCH_MAPPING[canonical_os === 'windows' && process.arch === 'arm64' ? 'x64' : process.arch];
42
+ return `${BASE_URL}v${version}/gauge-${version}-${canonical_os}.${canonical_arch}.zip`;
43
+ };
43
44
 
44
45
  module.exports = {
45
46
  getVersion: getVersion,
package/test/test.js CHANGED
@@ -18,8 +18,8 @@ describe("getVersion", () => {
18
18
 
19
19
  describe("getBinaryUrl", () => {
20
20
  it("should return platform specific URL", async () => {
21
- let originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');;
22
- let originalArch = Object.getOwnPropertyDescriptor(process, 'arch');;
21
+ let originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
22
+ let originalArch = Object.getOwnPropertyDescriptor(process, 'arch');
23
23
  Object.defineProperty(process, 'platform', { value: "win32" });
24
24
  Object.defineProperty(process, 'arch', { value: "ia32" });
25
25
 
@@ -29,6 +29,18 @@ describe("getBinaryUrl", () => {
29
29
  Object.defineProperty(process, 'arch', originalArch);
30
30
  });
31
31
 
32
+ it("should override platform specific URL for windows arm64", async () => {
33
+ let originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform');
34
+ let originalArch = Object.getOwnPropertyDescriptor(process, 'arch');
35
+ Object.defineProperty(process, 'platform', { value: "win32" });
36
+ Object.defineProperty(process, 'arch', { value: "arm64" });
37
+
38
+ expect(await subject.getBinaryUrl("1.0.0")).equals("https://github.com/getgauge/gauge/releases/download/v1.0.0/gauge-1.0.0-windows.x86_64.zip");
39
+
40
+ Object.defineProperty(process, 'platform', originalPlatform);
41
+ Object.defineProperty(process, 'arch', originalArch);
42
+ });
43
+
32
44
  });
33
45
 
34
46