8000 fix(hooks): make hooks compatible with CLI's 6.0.0 changes (#500) · rahulyhg/nativescript-vue@95aeab4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95aeab4

Browse files
rosen-vladimirovrigor789
authored andcommitted
fix(hooks): make hooks compatible with CLI's 6.0.0 changes (nativescript-vue#500)
In NativeScript CLI 6.0.0 release the bundle workflow will be the only one available. Currently, the nativescript-vue has some hooks that verify bundle is passed. There's no need of them for 6.0.0 release. Implement a check based on the CLI's version and skip the validation in case CLI is 6.x.x or newer.
1 parent 7204721 commit 95aeab4

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed
Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
module.exports = function(hookArgs, $errors) {
2-
const bundle =
3-
hookArgs &&
4-
hookArgs.checkForChangesOpts &&
5-
hookArgs.checkForChangesOpts.projectChangesOptions &&
6-
hookArgs.checkForChangesOpts.projectChangesOptions.bundle
7-
if (!bundle) {
8-
$errors.failWithoutHelp(
9-
"Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again."
10-
)
1+
const { isBundleCheckRequired } = require('./helpers')
2+
3+
module.exports = function(hookArgs, $errors, $injector) {
4+
const shouldCheckBundleOption = isBundleCheckRequired($injector)
5+
6+
if (shouldCheckBundleOption) {
7+
const bundle =
8+
hookArgs &&
9+
hookArgs.checkForChangesOpts &&
10+
hookArgs.checkForChangesOpts.projectChangesOptions &&
11+
hookArgs.checkForChangesOpts.projectChangesOptions.bundle
12+
13+
if (!bundle) {
14+
$errors.failWithoutHelp(
15+
"Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again."
16+
)
17+
}
1118
}
1219
}
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
module.exports = function(hookArgs, $errors) {
2-
const bundle =
3-
hookArgs &&
4-
hookArgs.config &&
5-
hookArgs.config.appFilesUpdaterOptions &&
6-
hookArgs.config.appFilesUpdaterOptions.bundle
7-
if (!bundle) {
8-
$errors.failWithoutHelp(
9-
"Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again."
10-
)
1+
const { isBundleCheckRequired } = require('./helpers')
2+
3+
module.exports = function(hookArgs, $errors, $injector) {
4+
const shouldCheckBundleOption = isBundleCheckRequired($injector)
5+
6+
if (shouldCheckBundleOption) {
7+
const bundle =
8+
hookArgs &&
9+
hookArgs.config &&
10+
hookArgs.config.appFilesUpdaterOptions &&
11+
hookArgs.config.appFilesUpdaterOptions.bundle
12+
if (!bundle) {
13+
$errors.failWithoutHelp(
14+
"Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again."
15+
)
16+
}
1117
}
1218
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function isBundleCheckRequired($injector) {
2+
try {
3+
const $staticConfig = $injector.resolve('$staticConfig')
4+
const version = $staticConfig && $staticConfig.version
5+
const majorVersion = (version || '').split('.')[0]
6+
// If the major version is not available, probably we are in some new version of CLI, where the staticConfig is not available
7+
// So it definitely should work with bundle;
8+
return !majorVersion || +majorVersion < 6
9+
} catch (err) {
10+
return false
11+
}
12+
}
13+
14+
module.exports.isBundleCheckRequired = isBundleCheckRequired

0 commit comments

Comments
 (0)
0