Skip to content

Commit ce2a419

Browse files
committed
Add a property to check if the plugin is installing its own dev-dependencies on npm i, or is actually installed in a project
1 parent 088a20c commit ce2a419

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
module.exports = function (__dirname) {
22
return {
3+
/**
4+
* The `npm i` in `nativescript-dev-*` modules installs locally hooks.
5+
* This property can be used to check if the plugin is actually installed in a project.
6+
* - **true** - The plugin is installed in an app.
7+
* - **false** - The plugin is installing locally its own devDependencies.
8+
*
9+
* ```
10+
* const hooks = require("nativescript-hook");
11+
* const { isInstalledInProject, postinstall } = hooks(__dirname);
12+
*
13+
* if (isInstalledInProject) {
14+
* postinstall();
15+
* // Copy files, configure, etc.
16+
* }
17+
* ```
18+
*/
19+
get isInstalledInProject() {
20+
return findProjectDir(__dirname) != __dirname;
21+
},
322
findProjectDir: function () {
423
return findProjectDir(__dirname);
524
},

0 commit comments

Comments
 (0)