Skip to content

Commit 265f416

Browse files
Fatmerigor789
Fatme
authored andcommitted
feat: show error when --bundle option is not provided (nativescript-vue#361)
1 parent 748d39a commit 265f416

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

build/build.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (process.argv[2]) {
1717
}
1818

1919
build(builds)
20+
copyHooks()
2021

2122
function build(builds) {
2223
let built = 0
@@ -60,4 +61,27 @@ function write(dest, code) {
6061
}
6162
function logError(e) {
6263
console.log(e)
64+
}
65+
66+
function copyHooks() {
67+
const sourceHooksDir = path.join(process.cwd(), "platform", "nativescript", "hooks");
68+
if (!fs.existsSync(sourceHooksDir)) {
69+
return;
70+
}
71+
72+
const targetHooksDir = path.join(process.cwd(), "dist", "hooks");
73+
if (!fs.existsSync(targetHooksDir)) {
74+
fs.mkdirSync(targetHooksDir)
75+
}
76+
77+
const sourceFiles = fs.readdirSync(sourceHooksDir);
78+
sourceFiles.forEach(file => {
79+
const sourcePath = path.join(sourceHooksDir, file);
80+
const targetPath = path.join(targetHooksDir, file);
81+
if (fs.existsSync(targetPath)) {
82+
fs.unlinkSync(targetPath);
83+
}
84+
85+
fs.copyFileSync(sourcePath, targetPath);
86+
});
6387
}

package.json

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"main": "dist/index.js",
66
"files": [
77
"dist/index.js",
8-
"index.d.ts"
8+
"index.d.ts",
9+
"dist/hooks/**",
10+
"postinstall.js",
11+
"preuninstall.js"
912
],
1013
"typings": "index.d.ts",
1114
"scripts": {
@@ -20,7 +23,9 @@
2023
"release": "node build/releaser.js",
2124
"release:notes": "node build/gen-release-notes.js",
2225
"changelog": "conventional-changelog --release-count 0 --outfile CHANGELOG.md --preset angular",
23-
"commit": "git-cz"
26+
"commit": "git-cz",
27+
"postinstall": "node postinstall.js",
28+
"preuninstall": "node preuninstall.js"
2429
},
2530
"repository": {
2631
"type": "git",
@@ -47,9 +52,23 @@
4752
"pan": "false",
4853
"core3": "true",
4954
"category": "Developer"
50-
}
55+
},
56+
"hooks": [
57+
{
58+
"type": "before-checkForChanges",
59+
"script": "dist/hooks/before-checkForChanges.js",
60+
"inject": true
61+
},
62+
{
63+
"type": "before-watch",
64+
"script": "dist/hooks/before-watch.js",
65+
"inject": true
66+
}
67+
]
68+
},
69+
"dependencies": {
70+
"nativescript-hook": "0.2.4"
5171
},
52-
"dependencies": {},
5372
"devDependencies": {
5473
"@commitlint/cli": "^6.1.0",
5574
"@commitlint/config-conventional": "^6.1.0",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = function(hookArgs, $errors) {
2+
const bundle =
3+
hookArgs &&
4+
hookArgs.projectChangesOptions &&
5+
hookArgs.projectChangesOptions.bundle
6+
if (!bundle) {
7+
$errors.failWithoutHelp(
8+
"Nativescript-vue doesn't work without --bundle option. Please specify --bundle option to the command and execute it again."
9+
)
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
)
11+
}
12+
}

postinstall.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var hook = require("nativescript-hook")(__dirname);
2+
hook.postinstall();

preuninstall.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var hook = require("nativescript-hook")(__dirname);
2+
hook.preuninstall();

0 commit comments

Comments
 (0)