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

Commit 3a687c0

Browse files
committed
feat: ensure valid CLI version when Windows snapshot is requested
1 parent f63d493 commit 3a687c0

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Diff for: lib/before-checkForChanges.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
const { shouldSnapshot, isWinOS } = require("./utils");
2+
const semver = require("semver");
3+
14
module.exports = function ($staticConfig, hookArgs) {
2-
const majorVersionMatch = ($staticConfig.version || '').match(/^(\d+)\./);
3-
const majorVersion = majorVersionMatch && majorVersionMatch[1] && +majorVersionMatch[1];
5+
const cliVersion = semver.parse($staticConfig.version);
6+
const majorVersion = cliVersion && cliVersion.major;
7+
const minorVersion = cliVersion && cliVersion.minor;
8+
49
if (majorVersion && majorVersion < 6) {
510
// check if we are using the bundle workflow or the legacy one.
611
const isUsingBundleWorkflow = hookArgs &&
@@ -12,5 +17,17 @@ module.exports = function ($staticConfig, hookArgs) {
1217
const packageJsonData = require("../package.json")
1318
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).`);
1419
}
20+
} else {
21+
const env = hookArgs.prepareData.env || {};
22+
const shouldSnapshotOptions = {
23+
platform: hookArgs.prepareData.platform,
24+
release: hookArgs.prepareData.release
25+
};
26+
27+
const shouldSnapshotOnWin = env.snapshot && shouldSnapshot(shouldSnapshotOptions) && isWinOS();
28+
const isCLIWithoutWinSnapshotsSupport = majorVersion && majorVersion == 6 && minorVersion && minorVersion < 2;
29+
if (shouldSnapshotOnWin && isCLIWithoutWinSnapshotsSupport) {
30+
throw new Error(`In order to generate Snapshots on Windows, please upgrade your NativeScript CLI version (npm i -g nativescript).`);
31+
}
1532
}
1633
}

Diff for: lib/utils.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ function convertToUnixPath(relativePath) {
1111
return relativePath.replace(/\\/g, "/");
1212
}
1313

14+
function isWinOS() {
15+
return os.type() === "Windows_NT";
16+
}
17+
1418
module.exports = {
1519
shouldSnapshot,
16-
convertToUnixPath
20+
convertToUnixPath,
21+
isWinOS
1722
};

0 commit comments

Comments
 (0)