1 | const semver = require("semver");
|
2 |
|
3 | const webpackPackageName = "@nativescript/webpack";
|
4 |
|
5 | module.exports = function ($staticConfig, hookArgs) {
|
6 | const cliVersion = semver.parse($staticConfig.version);
|
7 | const platfrom = hookArgs.prepareData.platform;
|
8 | const projectData = hookArgs.projectData;
|
9 |
|
10 |
|
11 | if (platfrom.toLowerCase() === "ios" &&
|
12 | !satisfiesRequriredVersion(cliVersion, 6, 2)) {
|
13 | throw new Error(`Building @nativescript/core for iOS requires NativeScript CLI with version at least 6.2.0. Please upgrade your NativeScript CLI version (npm i -g nativescript).`);
|
14 | }
|
15 |
|
16 |
|
17 | if (projectData.projectType === "Angular") {
|
18 | const webpackMinVer = getMinWebpackVersion(projectData);
|
19 |
|
20 | if (webpackMinVer && !satisfiesRequriredVersion(webpackMinVer, 1, 3)) {
|
21 | throw new Error(`Building @nativescript/core for Angular requires ${webpackPackageName} with version at least 1.3.0. Please upgrade: npm i ${webpackPackageName} --save-dev.`);
|
22 | }
|
23 | }
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | function satisfiesRequriredVersion(actualVersion, requiredMajor, requiredMinor) {
|
30 |
|
31 | if (!actualVersion) {
|
32 | return true;
|
33 | }
|
34 |
|
35 | if (actualVersion.major < requiredMajor) {
|
36 | return false;
|
37 | }
|
38 |
|
39 | if (actualVersion.major === requiredMajor && actualVersion.minor < requiredMinor) {
|
40 | return false;
|
41 | }
|
42 |
|
43 | return true;
|
44 | }
|
45 |
|
46 | function getMinWebpackVersion(projectData) {
|
47 | const devDependencies = projectData.devDependencies || {};
|
48 | const dependencies = projectData.dependencies || {};
|
49 | const webpackVer = dependencies[webpackPackageName] || devDependencies[webpackPackageName];
|
50 |
|
51 | let webpackMinVer = null;
|
52 |
|
53 | if (semver.valid(webpackVer)) {
|
54 | webpackMinVer = semver.parse(webpackVer);
|
55 | } else if (semver.validRange(webpackVer)) {
|
56 | webpackMinVer = semver.minVersion(webpackVer);
|
57 | }
|
58 |
|
59 | return webpackMinVer;
|
60 | } |
\ | No newline at end of file |