-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbundle-validator-helper.ts
41 lines (33 loc) · 1.63 KB
/
bundle-validator-helper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as util from "util";
import { BundleValidatorMessages } from "../constants";
import { VersionValidatorHelper } from "./version-validator-helper";
export class BundleValidatorHelper extends VersionValidatorHelper implements IBundleValidatorHelper {
private bundlersMap: IStringDictionary = {
webpack: "nativescript-dev-webpack"
};
constructor(protected $errors: IErrors,
protected $options: IOptions) {
super();
}
public validate(projectData: IProjectData, minSupportedVersion?: string): void {
if (this.$options.bundle) {
const currentVersion = this.getBundlerDependencyVersion(projectData);
if (!currentVersion) {
this.$errors.failWithoutHelp(BundleValidatorMessages.MissingBundlePlugin);
}
const shouldThrowError = minSupportedVersion && this.isValidVersion(currentVersion) && this.isVersionLowerThan(currentVersion, minSupportedVersion);
if (shouldThrowError) {
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
}
}
}
public getBundlerDependencyVersion(projectData: IProjectData, bundlerName?: string): string {
let dependencyVersion = null;
const bundlePluginName = bundlerName || this.bundlersMap[this.$options.bundle];
const bundlerVersionInDependencies = projectData.dependencies && projectData.dependencies[bundlePluginName];
const bundlerVersionInDevDependencies = projectData.devDependencies && projectData.devDependencies[bundlePluginName];
dependencyVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
return dependencyVersion;
}
}
$injector.register("bundleValidatorHelper", BundleValidatorHelper);