From f1bb613c81dc4e322c0225b550dcf1cc0bef623c Mon Sep 17 00:00:00 2001 From: James Macmillan Date: Thu, 6 May 2021 13:29:30 +0100 Subject: [PATCH] fixes issue in prepare script --- src/scripts/prepare.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/scripts/prepare.js b/src/scripts/prepare.js index 67b67a2..dd837af 100644 --- a/src/scripts/prepare.js +++ b/src/scripts/prepare.js @@ -1,6 +1,27 @@ const { exec } = require('child_process'); const semver = require('semver'); +function getTnsVersion() { + + try { + return semver.major(stdout); + } catch(error) { + try { + const regex = /(^\d\.\d\.\d$)/gm; + const match = regex.exec(stdout); + + if (match && match[0]) { + return semver.major(match[0]); + } + } catch(error) { + // noop + } + } + + console.warn('Could not get Nativescript version from nativescript cli. Assuming version 7+'); + return 7; +} + exec('tns --version', (err, stdout, stderr) => { if (err) { // node couldn't execute the command @@ -8,11 +29,11 @@ exec('tns --version', (err, stdout, stderr) => { return; } - const tnsVersion = semver.major(stdout); + const tnsVersion = getTnsVersion(); // execute 'tns plugin build' for {N} version > 4. This command builds .aar in platforms/android folder. if (tnsVersion >= 4) { console.log(`executing 'tns plugin build'`); exec('tns plugin build'); } -}); \ No newline at end of file +});