Skip to content

Commit 5f55de2

Browse files
authored
Merge pull request #39 from NativeScript/fatme/cli-6.0
fix: make the hooks compatible with CLI v6.0.0 release
2 parents 101d9eb + d492245 commit 5f55de2

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

lib/after-prepare.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
import * as path from "path";
22
import * as fs from "fs";
33

4-
module.exports = function (hookArgs, $platformsData, $testExecutionService) {
5-
const bundle = hookArgs && hookArgs.appFilesUpdaterOptions && hookArgs.appFilesUpdaterOptions.bundle;
6-
if($testExecutionService && $testExecutionService.platform && !bundle) {
7-
let platformData = $platformsData.getPlatformData($testExecutionService.platform),
8-
projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app"),
9-
packageJsonPath = path.join(projectFilesPath, 'package.json'),
10-
packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
4+
function isCLIVersionLowerThan6($injector) {
5+
try {
6+
const $staticConfig = $injector.resolve('$staticConfig');
7+
const version = $staticConfig && $staticConfig.version;
8+
const majorVersion = (version || '').split('.')[0];
9+
return !majorVersion || +majorVersion < 6;
10+
} catch (err) {
11+
return false;
12+
}
13+
}
14+
15+
module.exports = function (hookArgs, $injector, $testExecutionService) {
16+
if (isCLIVersionLowerThan6($injector)) {
17+
const bundle = hookArgs && hookArgs.appFilesUpdaterOptions && hookArgs.appFilesUpdaterOptions.bundle;
18+
if($testExecutionService && $testExecutionService.platform && !bundle) {
19+
const $platformsData = $injector.resolve("platformsData");
20+
let platformData = $platformsData.getPlatformData($testExecutionService.platform),
21+
projectFilesPath = path.join(platformData.appDestinationDirectoryPath, "app"),
22+
packageJsonPath = path.join(projectFilesPath, 'package.json'),
23+
packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
1124

12-
// When test command is used in ns-cli, we should change the entry point of the application
13-
packageJson.main = "./tns_modules/nativescript-unit-test-runner/app.js";
14-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
25+
// When test command is used in ns-cli, we should change the entry point of the application
26+
packageJson.main = "./tns_modules/nativescript-unit-test-runner/app.js";
27+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson));
28+
}
1529
}
16-
}
30+
}

0 commit comments

Comments
 (0)