3.2.0 • Published 3 years ago
@bent10/codep v3.2.0
CoDep
Copy node_modules dependencies directly into your assets.
Features
- Fast
- CLI support
- Creating non-existent output directories
- User-friendly error messages
- Customable reporting
Install
npm install @bent10/codep -D
Usage
import Codep from "@bent10/codep"
await new Codep("assets/vendor", {
exclude: ["jquery", "modernizr"]
}).paste()
It is ready to use on the CLI
as well, with zero configuration.
$ codep --help
Usage
$ codep <outDir>
Examples
Copy dependencies with default options
$ codep public/assets
Copy dependencies to public/assets folder except jquery and modernizr
$ codep public/assets --exclude jquery,modernizr
Options
-s, --source Specify the node modules directory
-p, --pkg Specify the package.json location
-k, --keepDist Keep the dist folder to exist
-e, --exclude Specify the name of the dependencies you don\'t want to copy, e.g. "bootstrap,modernizr"
-d, --devDependencies Should you need to grab devDependencies as well?
--ext Only copied files with the specified extension, e.g. "js,ts"
--overwrite Do you want to overwrite existing dependencies in <outDir>?
<outDir> Specify an output folder for all copied files
For local installation usage:
npx codep --help
Or via package.json
scripts:
{
"scripts": {
"vendor": "codep assets/vendor"
}
}
Then run npm run vendor
through your CLI.
API
new Codep(outDir, options?)
const codep = new Codep("assets/vendor")
outDir
Type : string
Specify an output folder for all copied files
options
Type: object
Property | Type | Default | Description |
---|---|---|---|
source | string | node_modules | Specify the node modules directory |
pkg | string | package.json | Specify the json file location |
flattenDist | boolean | true | Keep the dist folder or flatten in the root folder from each dependency |
exclude | string\|array | [] | Specify the name of the dependencies you don't want to copy, e.g. ['jquery', 'modernizr'] |
ext | string\|array | Only copied files with the specified extension. Use * to grab all files from dependencies | |
overwrite | boolean | false | Do you want to overwrite existing dependencies in the outdir ? |
devDependencies | boolean | false | Should you need to grab devDependencies as well? |
ext
Default: js,jsx,ts,tsx,css,scss,less,stylus,map,eot,woff,woff2,ttf,svg,png,jpg,jpeg
codep.paste()
Write source files to outDir
asynchronously.
;(async () => {
await codep.paste()
})()
Optimizations
Handle progress reports the way you want.
import Codep from "@bent10/codep"
// initialize Codep
const codep = new Codep("assets/vendor", {
exclude: ["jquery", "modernizr"]
})
// handle reports or just ignore this block
codep.on("progress", data => {
// doing things on progress
})
// copying
;(async () => {
try {
await codep.paste()
} catch (error) {
throw error
}
})()
codep.on('progress', handler)
handler(data)
Type: Function
data
Type: Manifest
Manifest is an object with properties below:
Property | Type |
---|---|
success | number |
failed | number |
processed | number |
percent | string |
vendors | string[] |
totalFiles | number |
log | Log |
Contributing
Please contribute! We welcome issues and pull requests.
When committing, please conform to the semantic-release commit standards.
License
MIT License 2021 © Stilearning and contributors