Skip to content

Instantly share code, notes, and snippets.

@ByIvo
Last active February 8, 2018 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ByIvo/ec75b920750ef2aa53e907623bfd9fc6 to your computer and use it in GitHub Desktop.
Save ByIvo/ec75b920750ef2aa53e907623bfd9fc6 to your computer and use it in GitHub Desktop.
NPM project-info-scanner package utilization example
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: []
}
*/
/* /tmp/my-project/.project-info.json */
{
"name": "My Project",
"root": true,
"libsPath": "custom/libs"
}
/* tmp/my-project/owner-dependecy/.project-info.json */
{
"name": "Owner Dependency",
"root": true,
"isModule": false,
"owner": "http://github.com/ByIvo"
}
/* 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