Functionality ( and README ) heavily inspired by ck86's main-bower-files
var mainNPMFiles = require('npmfiles');
var files = mainNPMFiles([options]);
This will read your package.json
, iterate through your dependencies and returns an array of files defined in the main property of the packages package.json
.
You can override the behavior if you add an overrides
property to your own package.json
.
var gulp = require('gulp');
var mainNPMFiles = require('npmfiles');
gulp.task('TASKNAME', function() {
return gulp.src(mainNPMFiles())
.pipe(/* what you want to do with the files */)
});
These options can be set directly in your package.json
file, e.g.:
{
"name": "your-package-name",
"dependencies": {
"NPM-PACKAGE": "*"
},
"overrides": {
"NPM-PACKAGE": {
"main": [
// Here you can override the main files or ignoring this package, for more info see options
]
}
}
}
Type: String
or Array
You can specify which files should be selected. e.g.:
You can also use glob pattern to select files, e.g.:
{
"overrides": {
"NPM-PACKAGE": {
"main": "**/*.js"
}
}
}
Type: Boolean
Default: false
Set to true
if you want to ignore this package.
These options can be passed to this plugin, e.g: mainNPMFiles(/* options*/)
Type: String
You can specify the node_modules
folder path where the modules are located.
For example:
mainNPMFiles({
nodeModulesPath: 'path/for/node_modules'
})
.pipe(gulp.dest('client/src/lib'));
Type: String
You can specify the package.json
file path.
For example:
mainNPMFiles({
packageJsonPath: 'path/for/package.json'
})
.pipe(gulp.dest('client/src/lib'));
Type: Boolean
Default: false
Set this option to true
to add the devDependencies to your dependencies
Type: Boolean
Default: false
Set this option to true
to show warnings for packages that don't have any files in the main entry or overrides
(MIT License)
Copyright (c) 2017 Cosmin Lupu
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.