Skip to content

Commit

Permalink
Fix for undefined variable and for getting path on new product versio…
Browse files Browse the repository at this point in the history
…ns 2020.1+ (#127)

* Fixing problem with undefined variable

* New regexp to guess product binary

To be compatible with 2020.1+ products

* Changing check of regex match size and adjusting which capture group to use

* Improving condition to get capturing group.

* Extracting variable for regex match length
  • Loading branch information
pedro-stanaka authored Apr 24, 2020
1 parent 3f43d30 commit 80e0a3d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ const getApplicationPath = (product) => {
const binContent = fs.readFileSync(product.binPath, { encoding: "UTF-8" });

// Toolbox case
const pattern = new RegExp('open -a "(.*)" "\\$@"');
const pattern = new RegExp('open -(n)?a "(.*)" (--args)? "\\$@"');
const match = pattern.exec(binContent);
if (match && match.length === 2) {
let appPath = match[1];
const matchLength = match.length;

if (match && [2, 4].includes(matchLength)) {
let appPath = match[matchLength === 2 ? 1 : 2];
appPath = appPath.split("/");
appPath = appPath.slice(0, -3); // remove last three entries ('Contents', 'MacOS', ${bin})
appPath = appPath.join("/");
Expand All @@ -142,7 +144,7 @@ const getApplicationPath = (product) => {
return oldMatch[1];
}

throw new Error(`Can't find application path for ${bin}`);
throw new Error(`Can't find application path for ${product.key}.`);
};

const get = () => {
Expand Down

0 comments on commit 80e0a3d

Please sign in to comment.