Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
feat: ensure valid CLI version when Windows snapshot is requested
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitarTachev committed Sep 27, 2019
1 parent f63d493 commit 3a687c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/before-checkForChanges.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const { shouldSnapshot, isWinOS } = require("./utils");
const semver = require("semver");

module.exports = function ($staticConfig, hookArgs) {
const majorVersionMatch = ($staticConfig.version || '').match(/^(\d+)\./);
const majorVersion = majorVersionMatch && majorVersionMatch[1] && +majorVersionMatch[1];
const cliVersion = semver.parse($staticConfig.version);
const majorVersion = cliVersion && cliVersion.major;
const minorVersion = cliVersion && cliVersion.minor;

if (majorVersion && majorVersion < 6) {
// check if we are using the bundle workflow or the legacy one.
const isUsingBundleWorkflow = hookArgs &&
Expand All @@ -12,5 +17,17 @@ module.exports = function ($staticConfig, hookArgs) {
const packageJsonData = require("../package.json")
throw new Error(`The current version of ${packageJsonData.name} (${packageJsonData.version}) is not compatible with the used CLI: ${$staticConfig.version}. Please upgrade your NativeScript CLI version (npm i -g nativescript).`);
}
} else {
const env = hookArgs.prepareData.env || {};
const shouldSnapshotOptions = {
platform: hookArgs.prepareData.platform,
release: hookArgs.prepareData.release
};

const shouldSnapshotOnWin = env.snapshot && shouldSnapshot(shouldSnapshotOptions) && isWinOS();
const isCLIWithoutWinSnapshotsSupport = majorVersion && majorVersion == 6 && minorVersion && minorVersion < 2;
if (shouldSnapshotOnWin && isCLIWithoutWinSnapshotsSupport) {
throw new Error(`In order to generate Snapshots on Windows, please upgrade your NativeScript CLI version (npm i -g nativescript).`);
}
}
}
7 changes: 6 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ function convertToUnixPath(relativePath) {
return relativePath.replace(/\\/g, "/");
}

function isWinOS() {
return os.type() === "Windows_NT";
}

module.exports = {
shouldSnapshot,
convertToUnixPath
convertToUnixPath,
isWinOS
};

0 comments on commit 3a687c0

Please sign in to comment.