Skip to content

feat: show error when --bundle option is not provided when executing some commands from {N} CLI #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if (process.argv[2]) {
}

build(builds)
copyHooks()

function build(builds) {
let built = 0
Expand Down Expand Up @@ -60,4 +61,27 @@ function write(dest, code) {
}
function logError(e) {
console.log(e)
}

function copyHooks() {
Copy link
Author

@Fatme Fatme Oct 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this function in order to ensure the hooks directory will be copied to dist folder on build step. This way we'll ensure the hooks directory will be included in built package.
But I am not sure what is exactly the approach you use to pack/bundle the plugin's code.

We need this code only in case if we want to have all the code that will be bundled inside dist folder.
If you think this is unneeded, this function can be removed. If we decide to remove it, this line should be changed https://github.com/nativescript-vue/nativescript-vue/pull/361/files#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R9 as well.

Let me know about your opinion on this matter.

const sourceHooksDir = path.join(process.cwd(), "platform", "nativescript", "hooks");
if (!fs.existsSync(sourceHooksDir)) {
return;
}

const targetHooksDir = path.join(process.cwd(), "dist", "hooks");
if (!fs.existsSync(targetHooksDir)) {
fs.mkdirSync(targetHooksDir)
}

const sourceFiles = fs.readdirSync(sourceHooksDir);
sourceFiles.forEach(file => {
const sourcePath = path.join(sourceHooksDir, file);
const targetPath = path.join(targetHooksDir, file);
if (fs.existsSync(targetPath)) {
fs.unlinkSync(targetPath);
}

fs.copyFileSync(sourcePath, targetPath);
});
}
27 changes: 23 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"main": "dist/index.js",
"files": [
"dist/index.js",
"index.d.ts"
"index.d.ts",
"dist/hooks/**",
"postinstall.js",
"preuninstall.js"
],
"typings": "index.d.ts",
"scripts": {
Expand All @@ -20,7 +23,9 @@
"release": "node build/releaser.js",
"release:notes": "node build/gen-release-notes.js",
"changelog": "conventional-changelog --release-count 0 --outfile CHANGELOG.md --preset angular",
"commit": "git-cz"
"commit": "git-cz",
"postinstall": "node postinstall.js",
"preuninstall": "node preuninstall.js"
},
"repository": {
"type": "git",
Expand All @@ -47,9 +52,23 @@
"pan": "false",
"core3": "true",
"category": "Developer"
}
},
"hooks": [
{
"type": "before-checkForChanges",
"script": "dist/hooks/before-checkForChanges.js",
"inject": true
},
{
"type": "before-watch",
"script": "dist/hooks/before-watch.js",
"inject": true
}
]
},
"dependencies": {
"nativescript-hook": "0.2.4"
},
"dependencies": {},
"devDependencies": {
"@commitlint/cli": "^6.1.0",
"@commitlint/config-conventional": "^6.1.0",
Expand Down
11 changes: 11 additions & 0 deletions platform/nativescript/hooks/before-checkForChanges.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function(hookArgs, $errors) {
const bundle =
hookArgs &&
hookArgs.projectChangesOptions &&
hookArgs.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."
)
}
}
12 changes: 12 additions & 0 deletions platform/nativescript/hooks/before-watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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."
)
}
}
2 changes: 2 additions & 0 deletions postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var hook = require("nativescript-hook")(__dirname);
hook.postinstall();
2 changes: 2 additions & 0 deletions preuninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var hook = require("nativescript-hook")(__dirname);
hook.preuninstall();