diff --git a/platform/nativescript/hooks/before-checkForChanges.js b/platform/nativescript/hooks/before-checkForChanges.js index 2d2b5307..c047d66f 100644 --- a/platform/nativescript/hooks/before-checkForChanges.js +++ b/platform/nativescript/hooks/before-checkForChanges.js @@ -1,12 +1,19 @@ -module.exports = function(hookArgs, $errors) { - const bundle = - hookArgs && - hookArgs.checkForChangesOpts && - hookArgs.checkForChangesOpts.projectChangesOptions && - hookArgs.checkForChangesOpts.projectChangesOptions.bundle - if (!bundle) { - $errors.failWithoutHelp( - "Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again." - ) +const { isBundleCheckRequired } = require('./helpers') + +module.exports = function(hookArgs, $errors, $injector) { + const shouldCheckBundleOption = isBundleCheckRequired($injector) + + if (shouldCheckBundleOption) { + const bundle = + hookArgs && + hookArgs.checkForChangesOpts && + hookArgs.checkForChangesOpts.projectChangesOptions && + hookArgs.checkForChangesOpts.projectChangesOptions.bundle + + if (!bundle) { + $errors.failWithoutHelp( + "Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again." + ) + } } } diff --git a/platform/nativescript/hooks/before-watch.js b/platform/nativescript/hooks/before-watch.js index 46b4b618..aad240a1 100644 --- a/platform/nativescript/hooks/before-watch.js +++ b/platform/nativescript/hooks/before-watch.js @@ -1,12 +1,18 @@ -module.exports = function(hookArgs, $errors) { - const bundle = - hookArgs && - hookArgs.config && - hookArgs.config.appFilesUpdaterOptions && - hookArgs.config.appFilesUpdaterOptions.bundle - if (!bundle) { - $errors.failWithoutHelp( - "Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again." - ) +const { isBundleCheckRequired } = require('./helpers') + +module.exports = function(hookArgs, $errors, $injector) { + const shouldCheckBundleOption = isBundleCheckRequired($injector) + + if (shouldCheckBundleOption) { + const bundle = + hookArgs && + hookArgs.config && + hookArgs.config.appFilesUpdaterOptions && + hookArgs.config.appFilesUpdaterOptions.bundle + if (!bundle) { + $errors.failWithoutHelp( + "Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again." + ) + } } } diff --git a/platform/nativescript/hooks/helpers.js b/platform/nativescript/hooks/helpers.js new file mode 100644 index 00000000..b5b4a2d1 --- /dev/null +++ b/platform/nativescript/hooks/helpers.js @@ -0,0 +1,14 @@ +function isBundleCheckRequired($injector) { + try { + const $staticConfig = $injector.resolve('$staticConfig') + const version = $staticConfig && $staticConfig.version + const majorVersion = (version || '').split('.')[0] + // If the major version is not available, probably we are in some new version of CLI, where the staticConfig is not available + // So it definitely should work with bundle; + return !majorVersion || +majorVersion < 6 + } catch (err) { + return false + } +} + +module.exports.isBundleCheckRequired = isBundleCheckRequired