Last active
February 8, 2018 00:14
-
-
Save ByIvo/ec75b920750ef2aa53e907623bfd9fc6 to your computer and use it in GitHub Desktop.
NPM project-info-scanner package utilization example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var projectInfoScanner = require('project-info-scanner'); | |
//Lets assume that you open your CLI tool at /tmp/my-project/sub-module and execute this index file with node | |
var completeProjectInfo = projectInfoScanner.from('/tmp/my-project/sub-module'); | |
console.log(completeProjectInfo); | |
/*The console.log will print exactly this: | |
* | |
{ | |
name: 'My Project', | |
root: true, | |
libsPath: 'custom/libs', | |
dir: '/tmp/my-project/.project-info.json' | |
branches: [ | |
{ | |
name: 'Sub module', | |
root: false, | |
isModule: true, | |
dependencies: [ | |
'node@8.9.1', | |
'npm@5.0.2' | |
], | |
dir: '/tmp/my-project/sub-module/.project-info.json', | |
branches: [] // IF THERE IS NO CHILD FOLDER WITH ANOTHER CONFIG FILE, THE BRANCHES PROPERTY WILL BE AN EMPTY ARRAY | |
}, { | |
name: 'Owner Dependency', | |
root: false, //THE ROOT PROPERTY WAS OVERWRITTEN WITH FALSE VALUE | |
isModule: false, | |
owner: 'http://github.com/ByIvo', | |
dir: '/tmp/my-project/owner-dependecy/.project-info.json', | |
branches: [] | |
} | |
] | |
} | |
*/ | |
// But lets assume you execute from Owner Dependecy path '/tmp/my-project/owner-dependecy' (or any of its folder children) | |
var ownerDependencyInfo = projectInfoScanner.from('/tmp/my-project/owner-dependecy'); | |
// The package starts to looking upwards for a config file with true root property (and will find it in first try) | |
console.log(ownerDependencyInfo); | |
/*So when we log this new project info, the result will be exactly like this: | |
{ | |
name: 'Owner Dependency', | |
root: true, //THE ROOT PROPERTY WAS NOT OVERWRITTEN BECAUSE IT WAS THE FIRST ROOT FILE FOUND | |
isModule: false, | |
owner: 'http://github.com/ByIvo', | |
dir: '/tmp/my-project/owner-dependecy/.project-info.json', | |
branches: [] | |
} | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* /tmp/my-project/.project-info.json */ | |
{ | |
"name": "My Project", | |
"root": true, | |
"libsPath": "custom/libs" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* tmp/my-project/owner-dependecy/.project-info.json */ | |
{ | |
"name": "Owner Dependency", | |
"root": true, | |
"isModule": false, | |
"owner": "http://github.com/ByIvo" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* tmp/my-project/sub-module/.project-info.json */ | |
{ | |
"name": "Sub module", | |
"root": false, | |
"isModule": true, | |
"dependencies": [ | |
"node@8.9.1", | |
"npm@5.0.2" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment