Skip to content

Commit

Permalink
Set ignoreJunk by default; Update test, readme and ts definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Andrei committed Jul 7, 2019
1 parent cdf57cb commit 5208695
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions index.d.ts
Expand Up @@ -32,6 +32,13 @@ declare namespace cpy {
```
*/
readonly rename?: string | ((basename: string) => string);

/**
Ignore junk files.
@default true
*/
readonly ignoreJunk?: boolean;
}

interface ProgressData {
Expand Down
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -7,6 +7,10 @@ const cpFile = require('cp-file');
const junk = require('junk');
const CpyError = require('./cpy-error');

const defaultOptions = {
ignoreJunk: true
};

const preprocessSourcePath = (source, options) => options.cwd ? path.resolve(options.cwd, source) : source;

const preprocessDestinationPath = (source, destination, options) => {
Expand All @@ -32,6 +36,7 @@ const preprocessDestinationPath = (source, destination, options) => {

module.exports = (source, destination, options = {}) => {
const progressEmitter = new EventEmitter();
options = {...defaultOptions, ...options};

const promise = (async () => {
source = arrify(source);
Expand All @@ -49,7 +54,7 @@ module.exports = (source, destination, options = {}) => {
files = await globby(source, options);

if (options.ignoreJunk) {
files = files.filter(file => junk.not(file.substring(file.lastIndexOf('/') + 1, file.length)));
files = files.filter(file => junk.not(path.basename(file)));
}
} catch (error) {
throw new CpyError(`Cannot glob \`${source}\`: ${error.message}`, error);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -97,7 +97,7 @@ const cpy = require('cpy');
##### ignoreJunk

Type: `boolean`<br>
Default: `false`
Default: `true`

Ignores [junk](https://github.com/sindresorhus/junk) files.

Expand Down
2 changes: 1 addition & 1 deletion test.js
Expand Up @@ -180,7 +180,7 @@ test('junk files are copied', async t => {

let report;

await cpy('*', t.context.tmp, {cwd: path.join(t.context.tmp, 'cwd')})
await cpy('*', t.context.tmp, {cwd: path.join(t.context.tmp, 'cwd'), ignoreJunk: false})
.on('progress', event => {
report = event;
});
Expand Down

0 comments on commit 5208695

Please sign in to comment.