From 93f68936c658eeb77dcc5091db29c4c27fb0d41a Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Tue, 18 Jun 2019 13:04:19 +0300 Subject: [PATCH 01/15] add filter option, fixes #63 --- index.d.ts | 16 ++++++++++++++++ index.js | 15 +++++++++++++++ index.test-d.ts | 6 ++++++ package.json | 3 ++- readme.md | 15 +++++++++++++++ test.js | 14 ++++++++++++++ 6 files changed, 68 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index a1ecdc6..4e43944 100644 --- a/index.d.ts +++ b/index.d.ts @@ -46,6 +46,22 @@ declare namespace cpy { @default true */ readonly ignoreJunk?: boolean; + + /** + Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false. + + @example + ``` + import cpy = require('cpy'); + + (async () => { + await cpy('foo', 'destination', { + filter: name => !name.includes('NOCOPY') + }); + })(); + ``` + */ + readonly filter?: (basename: string) => (boolean | Promise); } interface ProgressData { diff --git a/index.js b/index.js index 398cbe0..9b8f256 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const globby = require('globby'); const hasGlob = require('has-glob'); const cpFile = require('cp-file'); const junk = require('junk'); +const pFilter = require('p-filter'); const CpyError = require('./cpy-error'); const defaultOptions = { @@ -74,6 +75,20 @@ module.exports = (source, destination, { throw new CpyError(`Cannot copy \`${source}\`: the file doesn't exist`); } + if (options.filter !== undefined) { + const filteredFiles = await pFilter(files, options.filter, {concurrency: 1024}); + files = filteredFiles; + } + + if (files.length === 0) { + progressEmitter.emit('progress', { + totalFiles: 0, + percent: 1, + completedFiles: 0, + completedSize: 0 + }); + } + const fileProgressHandler = event => { const fileStatus = copyStatus.get(event.src) || {written: 0, percent: 0}; diff --git a/index.test-d.ts b/index.test-d.ts index 39fec27..31a0993 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -27,6 +27,12 @@ expectType & ProgressEmitter>( cpy('foo.js', 'destination', {concurrency: 2}) ); +expectType & ProgressEmitter>( + cpy('foo.js', 'destination', {filter: () => true}) +); +expectType & ProgressEmitter>( + cpy('foo.js', 'destination', {filter: async () => true}) +); expectType>( cpy('foo.js', 'destination').on('progress', progress => { diff --git a/package.json b/package.json index ba95cb0..622a74a 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,8 @@ "has-glob": "^1.0.0", "junk": "^3.1.0", "nested-error-stacks": "^2.1.0", - "p-all": "^2.1.0" + "p-all": "^2.1.0", + "p-filter": "^2.1.0" }, "devDependencies": { "ava": "^2.1.0", diff --git a/readme.md b/readme.md index d358d1c..6492b81 100644 --- a/readme.md +++ b/readme.md @@ -106,6 +106,21 @@ Default: `true` Ignores [junk](https://github.com/sindresorhus/junk) files. +#### filter + +Type: `string | Function` + +Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false. + +```js +const cpy = require('cpy'); + +(async () => { + await cpy('foo.js', 'destination', { + filter: name => !name.includes('NOCOPY') + }); +})(); +``` ## Progress reporting ### cpy.on('progress', handler) diff --git a/test.js b/test.js index 4d440af..2259e8a 100644 --- a/test.js +++ b/test.js @@ -54,6 +54,20 @@ test('throws on invalid concurrency value', async t => { await t.throwsAsync(cpy(['license', 'package.json'], t.context.tmp, {concurrency: 'foo'})); }); +test('copy array of files with filter', async t => { + await cpy(['license', 'package.json'], t.context.tmp, {filter: name => name !== 'license'}); + + t.false(fs.existsSync(path.join(t.context.tmp, 'license'))); + t.is(read('package.json'), read(t.context.tmp, 'package.json')); +}); + +test('copy array of files with async filter', async t => { + await cpy(['license', 'package.json'], t.context.tmp, {filter: async name => name !== 'license'}); + + t.false(fs.existsSync(path.join(t.context.tmp, 'license'))); + t.is(read('package.json'), read(t.context.tmp, 'package.json')); +}); + test('cwd', async t => { fs.mkdirSync(t.context.tmp); fs.mkdirSync(path.join(t.context.tmp, 'cwd')); From bbe803d5702c7859ab09bc5af925acd04ec5d451 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 23 Jun 2019 19:51:18 +0700 Subject: [PATCH 02/15] Update readme.md --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 6492b81..32165b7 100644 --- a/readme.md +++ b/readme.md @@ -121,6 +121,8 @@ const cpy = require('cpy'); }); })(); ``` + + ## Progress reporting ### cpy.on('progress', handler) From ec0b4f9f3d64ea1ec83e00315011863b5e410760 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Fri, 28 Jun 2019 14:25:48 +0300 Subject: [PATCH 03/15] Typo in readme.md Co-Authored-By: Sindre Sorhus --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 32165b7..c10a505 100644 --- a/readme.md +++ b/readme.md @@ -108,7 +108,7 @@ Ignores [junk](https://github.com/sindresorhus/junk) files. #### filter -Type: `string | Function` +Type: `Function` Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false. From 3379b3a93c66a370cde437d7b12f6d0a3714a0ad Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Fri, 28 Jun 2019 15:44:37 +0300 Subject: [PATCH 04/15] more complex filtering --- index.d.ts | 34 ++++++++++++++++++++++++++++++--- index.js | 50 +++++++++++++++++++++++++++++++++---------------- index.test-d.ts | 4 ++-- readme.md | 40 +++++++++++++++++++++++++++++++++++---- test.js | 22 ++++++++++++++++++++-- 5 files changed, 123 insertions(+), 27 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4e43944..d0a342b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,6 +2,33 @@ import {GlobbyOptions} from 'globby'; import {Options as CpFileOptions} from 'cp-file'; declare namespace cpy { + interface SourceFile { + /** + Path to file. + */ + readonly path: string, + + /** + Resolved path to file. + */ + readonly resolvedPath: string, + + /** + File name. + */ + readonly name: string, + + /** + File name without extension. + */ + readonly nameWithoutExtension: string, + + /** + File extension. + */ + readonly extension: string, + } + interface Options extends Readonly, CpFileOptions { /** Working directory to find source files. @@ -48,7 +75,8 @@ declare namespace cpy { readonly ignoreJunk?: boolean; /** - Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false. + Function to filter files to copy. Should accept source file object as argument. + Return true to include, false to exclude. Can also return a Promise that resolves to true or false. @example ``` @@ -56,12 +84,12 @@ declare namespace cpy { (async () => { await cpy('foo', 'destination', { - filter: name => !name.includes('NOCOPY') + filter: file => file.extension !== '.nocopy' }); })(); ``` */ - readonly filter?: (basename: string) => (boolean | Promise); + readonly filter?: (file: SourceFile) => (boolean | Promise); } interface ProgressData { diff --git a/index.js b/index.js index 9b8f256..d03d91f 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const EventEmitter = require('events'); const path = require('path'); const os = require('os'); -const pAll = require('p-all'); +const pMap = require('p-map'); const arrify = require('arrify'); const globby = require('globby'); const hasGlob = require('has-glob'); @@ -15,6 +15,25 @@ const defaultOptions = { ignoreJunk: true }; +class SourceFile { + constructor(path, resolvedPath) { + this.path = path; + this.resolvedPath = resolvedPath; + } + + get name() { + return path.basename(this.path); + } + + get nameWithoutExtension() { + return path.basename(this.path, this.extension); + } + + get extension() { + return path.extname(this.path); + } +} + const preprocessSourcePath = (source, options) => options.cwd ? path.resolve(options.cwd, source) : source; const preprocessDestinationPath = (source, destination, options) => { @@ -75,12 +94,14 @@ module.exports = (source, destination, { throw new CpyError(`Cannot copy \`${source}\`: the file doesn't exist`); } + let sources = files.map(sourcePath => new SourceFile(sourcePath, preprocessSourcePath(sourcePath, options))); + if (options.filter !== undefined) { - const filteredFiles = await pFilter(files, options.filter, {concurrency: 1024}); - files = filteredFiles; + const filteredSources = await pFilter(sources, options.filter, {concurrency: 1024}); + sources = filteredSources; } - if (files.length === 0) { + if (sources.length === 0) { progressEmitter.emit('progress', { totalFiles: 0, percent: 1, @@ -114,20 +135,17 @@ module.exports = (source, destination, { } }; - return pAll(files.map(sourcePath => { - return async () => { - const from = preprocessSourcePath(sourcePath, options); - const to = preprocessDestinationPath(sourcePath, destination, options); + return pMap(sources, async source => { + const to = preprocessDestinationPath(source.path, destination, options); - try { - await cpFile(from, to, options).on('progress', fileProgressHandler); - } catch (error) { - throw new CpyError(`Cannot copy from \`${from}\` to \`${to}\`: ${error.message}`, error); - } + try { + await cpFile(source.resolvedPath, to, options).on('progress', fileProgressHandler); + } catch (error) { + throw new CpyError(`Cannot copy from \`${source.path}\` to \`${to}\`: ${error.message}`, error); + } - return to; - }; - }), {concurrency}); + return to; + }, {concurrency}); })(); promise.on = (...arguments_) => { diff --git a/index.test-d.ts b/index.test-d.ts index 31a0993..5c16541 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -28,10 +28,10 @@ expectType & ProgressEmitter>( ); expectType & ProgressEmitter>( - cpy('foo.js', 'destination', {filter: () => true}) + cpy('foo.js', 'destination', {filter: (file: cpy.SourceFile) => true}) ); expectType & ProgressEmitter>( - cpy('foo.js', 'destination', {filter: async () => true}) + cpy('foo.js', 'destination', {filter: async (file: cpy.SourceFile) => true}) ); expectType>( diff --git a/readme.md b/readme.md index c10a505..cbd6979 100644 --- a/readme.md +++ b/readme.md @@ -106,22 +106,54 @@ Default: `true` Ignores [junk](https://github.com/sindresorhus/junk) files. -#### filter +##### filter Type: `Function` -Function to filter copied files. Return true to include, false to exclude. Can also return a Promise that resolves to true or false. +Function to filter files to copy. Should accept source file object as argument. +Return true to include, false to exclude. Can also return a Promise that resolves to true or false. ```js const cpy = require('cpy'); (async () => { - await cpy('foo.js', 'destination', { - filter: name => !name.includes('NOCOPY') + await cpy('foo', 'destination', { + filter: file => file.extension !== '.nocopy' }); })(); ``` +##### Source file object + +###### path + +Type: `string` + +Path to file. + +###### resolvedPath + +Type: `string` + +Resolved path to file. + +###### name + +Type: `string` + +File name. + +###### nameWithoutExtension + +Type: `string` + +File name without extension. + +###### extension + +Type: `string` + +File extension. ## Progress reporting diff --git a/test.js b/test.js index 2259e8a..53b9ce7 100644 --- a/test.js +++ b/test.js @@ -55,14 +55,32 @@ test('throws on invalid concurrency value', async t => { }); test('copy array of files with filter', async t => { - await cpy(['license', 'package.json'], t.context.tmp, {filter: name => name !== 'license'}); + await cpy(['license', 'package.json'], t.context.tmp, { + filter: file => { + t.is(typeof file.path, 'string'); + t.is(typeof file.resolvedPath, 'string'); + t.is(typeof file.name, 'string'); + t.is(typeof file.nameWithoutExtension, 'string'); + t.is(typeof file.extension, 'string'); + return file.path !== 'license'; + } + }); t.false(fs.existsSync(path.join(t.context.tmp, 'license'))); t.is(read('package.json'), read(t.context.tmp, 'package.json')); }); test('copy array of files with async filter', async t => { - await cpy(['license', 'package.json'], t.context.tmp, {filter: async name => name !== 'license'}); + await cpy(['license', 'package.json'], t.context.tmp, { + filter: async file => { + t.is(typeof file.path, 'string'); + t.is(typeof file.resolvedPath, 'string'); + t.is(typeof file.name, 'string'); + t.is(typeof file.nameWithoutExtension, 'string'); + t.is(typeof file.extension, 'string'); + return file.path !== 'license'; + } + }); t.false(fs.existsSync(path.join(t.context.tmp, 'license'))); t.is(read('package.json'), read(t.context.tmp, 'package.json')); From 571fd9d1257212735a92aa0a06ed44b331e79038 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Fri, 28 Jun 2019 15:47:23 +0300 Subject: [PATCH 05/15] ws --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index cbd6979..4054c89 100644 --- a/readme.md +++ b/readme.md @@ -155,6 +155,7 @@ Type: `string` File extension. + ## Progress reporting ### cpy.on('progress', handler) From 3cb3c531b693588d04b11efad9a3494267586df9 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Thu, 25 Jul 2019 12:05:56 +0300 Subject: [PATCH 06/15] frozen source files --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index d03d91f..896a6ec 100644 --- a/index.js +++ b/index.js @@ -19,6 +19,7 @@ class SourceFile { constructor(path, resolvedPath) { this.path = path; this.resolvedPath = resolvedPath; + Object.freeze(this); } get name() { From 0f090d91346dd42c9d0af1bfa8733a1e4a6078e0 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Fri, 20 Sep 2019 18:02:12 +0300 Subject: [PATCH 07/15] changed path type, file name => filename --- index.d.ts | 11 +++-------- index.js | 18 +++++++++--------- package.json | 3 ++- test.js | 39 +++++++++++++++++++++++++++------------ 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/index.d.ts b/index.d.ts index d0a342b..062eb03 100644 --- a/index.d.ts +++ b/index.d.ts @@ -3,23 +3,18 @@ import {Options as CpFileOptions} from 'cp-file'; declare namespace cpy { interface SourceFile { - /** - Path to file. - */ - readonly path: string, - /** Resolved path to file. */ - readonly resolvedPath: string, + readonly path: string, /** - File name. + Filename. */ readonly name: string, /** - File name without extension. + Filename without extension. */ readonly nameWithoutExtension: string, diff --git a/index.js b/index.js index 896a6ec..883ce74 100644 --- a/index.js +++ b/index.js @@ -16,26 +16,26 @@ const defaultOptions = { }; class SourceFile { - constructor(path, resolvedPath) { + constructor(relativePath, path) { this.path = path; - this.resolvedPath = resolvedPath; + Object.defineProperty(this, 'relativePath', {enumerable: false, value: relativePath}); Object.freeze(this); } get name() { - return path.basename(this.path); + return path.basename(this.relativePath); } get nameWithoutExtension() { - return path.basename(this.path, this.extension); + return path.basename(this.relativePath, this.extension); } get extension() { - return path.extname(this.path); + return path.extname(this.relativePath); } } -const preprocessSourcePath = (source, options) => options.cwd ? path.resolve(options.cwd, source) : source; +const preprocessSourcePath = (source, options) => path.resolve(options.cwd ? options.cwd : process.cwd(), source); const preprocessDestinationPath = (source, destination, options) => { let basename = path.basename(source); @@ -137,12 +137,12 @@ module.exports = (source, destination, { }; return pMap(sources, async source => { - const to = preprocessDestinationPath(source.path, destination, options); + const to = preprocessDestinationPath(source.relativePath, destination, options); try { - await cpFile(source.resolvedPath, to, options).on('progress', fileProgressHandler); + await cpFile(source.path, to, options).on('progress', fileProgressHandler); } catch (error) { - throw new CpyError(`Cannot copy from \`${source.path}\` to \`${to}\`: ${error.message}`, error); + throw new CpyError(`Cannot copy from \`${source.relativePath}\` to \`${to}\`: ${error.message}`, error); } return to; diff --git a/package.json b/package.json index 622a74a..1f605a5 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "junk": "^3.1.0", "nested-error-stacks": "^2.1.0", "p-all": "^2.1.0", - "p-filter": "^2.1.0" + "p-filter": "^2.1.0", + "p-map": "^3.0.0" }, "devDependencies": { "ava": "^2.1.0", diff --git a/test.js b/test.js index 53b9ce7..e374539 100644 --- a/test.js +++ b/test.js @@ -57,12 +57,20 @@ test('throws on invalid concurrency value', async t => { test('copy array of files with filter', async t => { await cpy(['license', 'package.json'], t.context.tmp, { filter: file => { - t.is(typeof file.path, 'string'); - t.is(typeof file.resolvedPath, 'string'); - t.is(typeof file.name, 'string'); - t.is(typeof file.nameWithoutExtension, 'string'); - t.is(typeof file.extension, 'string'); - return file.path !== 'license'; + console.log(file); + if (file.path.endsWith('/license')) { + t.is(file.path, path.join(process.cwd(), 'license')); + t.is(file.name, 'license'); + t.is(file.nameWithoutExtension, 'license'); + t.is(file.extension, ''); + } else if (file.path.endsWith('/package.json')) { + t.is(file.path, path.join(process.cwd(), 'package.json')); + t.is(file.name, 'package.json'); + t.is(file.nameWithoutExtension, 'package'); + t.is(file.extension, '.json'); + } + + return !file.path.endsWith('/license'); } }); @@ -73,12 +81,19 @@ test('copy array of files with filter', async t => { test('copy array of files with async filter', async t => { await cpy(['license', 'package.json'], t.context.tmp, { filter: async file => { - t.is(typeof file.path, 'string'); - t.is(typeof file.resolvedPath, 'string'); - t.is(typeof file.name, 'string'); - t.is(typeof file.nameWithoutExtension, 'string'); - t.is(typeof file.extension, 'string'); - return file.path !== 'license'; + if (file.path.endsWith('/license')) { + t.is(file.path, path.join(process.cwd(), 'license')); + t.is(file.name, 'license'); + t.is(file.nameWithoutExtension, 'license'); + t.is(file.extension, ''); + } else if (file.path.endsWith('/package.json')) { + t.is(file.path, path.join(process.cwd(), 'package.json')); + t.is(file.name, 'package.json'); + t.is(file.nameWithoutExtension, 'package'); + t.is(file.extension, '.json'); + } + + return !file.path.endsWith('/license'); } }); From 27177d500e5ea4502438892d11bff5f4deb9b433 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Fri, 20 Sep 2019 18:24:29 +0300 Subject: [PATCH 08/15] readme and examples --- index.d.ts | 4 ++++ readme.md | 14 ++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index 062eb03..6466572 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,21 +5,25 @@ declare namespace cpy { interface SourceFile { /** Resolved path to file. + @example `/tmp/foo.bar` */ readonly path: string, /** Filename. + @example `foo.bar` */ readonly name: string, /** Filename without extension. + @example `foo` */ readonly nameWithoutExtension: string, /** File extension. + @example `.bar` */ readonly extension: string, } diff --git a/readme.md b/readme.md index 4054c89..e0ce8e0 100644 --- a/readme.md +++ b/readme.md @@ -129,31 +129,25 @@ const cpy = require('cpy'); Type: `string` -Path to file. - -###### resolvedPath - -Type: `string` - -Resolved path to file. +Resolved path to file. Example: `/tmp/foo.bar`. ###### name Type: `string` -File name. +Filename. Example: `foo.bar`. ###### nameWithoutExtension Type: `string` -File name without extension. +File name without extension. Example: `foo`. ###### extension Type: `string` -File extension. +File extension. Example: `.bar`. ## Progress reporting From 8149a5e6567e04c644c8b8079d4bda899d428224 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Sun, 1 Mar 2020 13:43:21 +0300 Subject: [PATCH 09/15] add relativePath --- index.d.ts | 8 +++++++- index.js | 6 +++--- test.js | 9 ++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6466572..3b056aa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,10 +5,16 @@ declare namespace cpy { interface SourceFile { /** Resolved path to file. - @example `/tmp/foo.bar` + @example `/tmp/dir/foo.bar` */ readonly path: string, + /** + Relative path to file from `cwd`. + @example 'dir/foo.bar' if `cwd` was '/tmp' + */ + readonly relativePath: string, + /** Filename. @example `foo.bar` diff --git a/index.js b/index.js index 883ce74..80817ff 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ const defaultOptions = { class SourceFile { constructor(relativePath, path) { this.path = path; - Object.defineProperty(this, 'relativePath', {enumerable: false, value: relativePath}); + this.relativePath = relativePath; Object.freeze(this); } @@ -27,11 +27,11 @@ class SourceFile { } get nameWithoutExtension() { - return path.basename(this.relativePath, this.extension); + return path.basename(this.relativePath, path.extname(this.relativePath)); } get extension() { - return path.extname(this.relativePath); + return path.extname(this.relativePath).slice(1); } } diff --git a/test.js b/test.js index e374539..de7ca74 100644 --- a/test.js +++ b/test.js @@ -57,17 +57,18 @@ test('throws on invalid concurrency value', async t => { test('copy array of files with filter', async t => { await cpy(['license', 'package.json'], t.context.tmp, { filter: file => { - console.log(file); if (file.path.endsWith('/license')) { t.is(file.path, path.join(process.cwd(), 'license')); + t.is(file.relativePath, 'license'); t.is(file.name, 'license'); t.is(file.nameWithoutExtension, 'license'); t.is(file.extension, ''); } else if (file.path.endsWith('/package.json')) { t.is(file.path, path.join(process.cwd(), 'package.json')); + t.is(file.relativePath, 'package.json'); t.is(file.name, 'package.json'); t.is(file.nameWithoutExtension, 'package'); - t.is(file.extension, '.json'); + t.is(file.extension, 'json'); } return !file.path.endsWith('/license'); @@ -83,14 +84,16 @@ test('copy array of files with async filter', async t => { filter: async file => { if (file.path.endsWith('/license')) { t.is(file.path, path.join(process.cwd(), 'license')); + t.is(file.relativePath, 'license'); t.is(file.name, 'license'); t.is(file.nameWithoutExtension, 'license'); t.is(file.extension, ''); } else if (file.path.endsWith('/package.json')) { t.is(file.path, path.join(process.cwd(), 'package.json')); + t.is(file.relativePath, 'package.json'); t.is(file.name, 'package.json'); t.is(file.nameWithoutExtension, 'package'); - t.is(file.extension, '.json'); + t.is(file.extension, 'json'); } return !file.path.endsWith('/license'); From b78410df26a3eeaa47d3530414562c1809234081 Mon Sep 17 00:00:00 2001 From: Yanis Benson Date: Wed, 4 Mar 2020 01:51:53 +0300 Subject: [PATCH 10/15] docs --- index.d.ts | 2 +- readme.md | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3b056aa..a9f6cbe 100644 --- a/index.d.ts +++ b/index.d.ts @@ -29,7 +29,7 @@ declare namespace cpy { /** File extension. - @example `.bar` + @example `bar` */ readonly extension: string, } diff --git a/readme.md b/readme.md index e0ce8e0..ad7237c 100644 --- a/readme.md +++ b/readme.md @@ -127,27 +127,38 @@ const cpy = require('cpy'); ###### path -Type: `string` +Type: `string`\ +Example: `/tmp/dir/foo.bar` + +Resolved path to file. + +###### relativePath + +Type: `string`\ +Example: `dir/foo.bar` if `cwd` was `/tmp` -Resolved path to file. Example: `/tmp/foo.bar`. +Relative path to file from `cwd`. ###### name -Type: `string` +Type: `string`\ +Example: `foo.bar` -Filename. Example: `foo.bar`. +Filename. ###### nameWithoutExtension -Type: `string` +Type: `string`\ +Example: `foo`. -File name without extension. Example: `foo`. +File name without extension. ###### extension -Type: `string` +Type: `string`\ +Example: `bar`. -File extension. Example: `.bar`. +File extension. ## Progress reporting From 4bb79b5690e860a3bdbc23a581654b29b45d6246 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 7 Mar 2020 13:00:31 +0800 Subject: [PATCH 11/15] Update index.d.ts --- index.d.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index a9f6cbe..4597da4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,31 +5,36 @@ declare namespace cpy { interface SourceFile { /** Resolved path to file. - @example `/tmp/dir/foo.bar` + + @example '/tmp/dir/foo.js' */ readonly path: string, /** Relative path to file from `cwd`. - @example 'dir/foo.bar' if `cwd` was '/tmp' + + @example 'dir/foo.js' if `cwd` was '/tmp' */ readonly relativePath: string, /** Filename. - @example `foo.bar` + + @example 'foo.js' */ readonly name: string, /** Filename without extension. - @example `foo` + + @example 'foo' */ readonly nameWithoutExtension: string, /** File extension. - @example `bar` + + @example 'js' */ readonly extension: string, } From 0b322b69b612309b315068f885e3e5b769fdb1c2 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 7 Mar 2020 13:01:25 +0800 Subject: [PATCH 12/15] Update index.d.ts --- index.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.d.ts b/index.d.ts index 4597da4..fb6c21c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,39 +4,39 @@ import {Options as CpFileOptions} from 'cp-file'; declare namespace cpy { interface SourceFile { /** - Resolved path to file. + Resolved path to the file. @example '/tmp/dir/foo.js' */ - readonly path: string, + readonly path: string; /** - Relative path to file from `cwd`. + Relative path to the file from `cwd`. @example 'dir/foo.js' if `cwd` was '/tmp' */ - readonly relativePath: string, + readonly relativePath: string; /** - Filename. + Filename with extension. @example 'foo.js' */ - readonly name: string, + readonly name: string; /** Filename without extension. @example 'foo' */ - readonly nameWithoutExtension: string, + readonly nameWithoutExtension: string; /** File extension. @example 'js' */ - readonly extension: string, + readonly extension: string; } interface Options extends Readonly, CpFileOptions { From 2ed0e3fac04f10557ff7fe7bfc8e505db01e23cf Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 7 Mar 2020 13:03:05 +0800 Subject: [PATCH 13/15] Update index.d.ts --- index.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.d.ts b/index.d.ts index fb6c21c..f004571 100644 --- a/index.d.ts +++ b/index.d.ts @@ -85,8 +85,11 @@ declare namespace cpy { readonly ignoreJunk?: boolean; /** - Function to filter files to copy. Should accept source file object as argument. - Return true to include, false to exclude. Can also return a Promise that resolves to true or false. + Function to filter files to copy. + + Receives a source file object as the first argument. + + Return true to include, false to exclude. You can also return a Promise that resolves to true or false. @example ``` From 36e0f8b3dcc1e6e421c4896d0454add2b11ea7b1 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 7 Mar 2020 13:04:42 +0800 Subject: [PATCH 14/15] Update readme.md --- readme.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index ad7237c..296eacc 100644 --- a/readme.md +++ b/readme.md @@ -110,8 +110,11 @@ Ignores [junk](https://github.com/sindresorhus/junk) files. Type: `Function` -Function to filter files to copy. Should accept source file object as argument. -Return true to include, false to exclude. Can also return a Promise that resolves to true or false. +Function to filter files to copy. + +Receives a source file object as the first argument. + +Return true to include, false to exclude. You can also return a Promise that resolves to true or false. ```js const cpy = require('cpy'); @@ -128,39 +131,38 @@ const cpy = require('cpy'); ###### path Type: `string`\ -Example: `/tmp/dir/foo.bar` +Example: `/tmp/dir/foo.js` -Resolved path to file. +Resolved path to the file. ###### relativePath Type: `string`\ -Example: `dir/foo.bar` if `cwd` was `/tmp` +Example: `dir/foo.js` if `cwd` was `/tmp` -Relative path to file from `cwd`. +Relative path to the file from `cwd`. ###### name Type: `string`\ -Example: `foo.bar` +Example: `foo.js` -Filename. +Filename with extension. ###### nameWithoutExtension Type: `string`\ Example: `foo`. -File name without extension. +Filename without extension. ###### extension Type: `string`\ -Example: `bar`. +Example: `js`. File extension. - ## Progress reporting ### cpy.on('progress', handler) From b9ca416b59937480282f2fc7221a0d6a1f8b34ed Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 7 Mar 2020 13:05:58 +0800 Subject: [PATCH 15/15] Update readme.md --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 296eacc..3b5aa96 100644 --- a/readme.md +++ b/readme.md @@ -131,35 +131,35 @@ const cpy = require('cpy'); ###### path Type: `string`\ -Example: `/tmp/dir/foo.js` +Example: `'/tmp/dir/foo.js'` Resolved path to the file. ###### relativePath Type: `string`\ -Example: `dir/foo.js` if `cwd` was `/tmp` +Example: `'dir/foo.js'` if `cwd` was `'/tmp'` Relative path to the file from `cwd`. ###### name Type: `string`\ -Example: `foo.js` +Example: `'foo.js'` Filename with extension. ###### nameWithoutExtension Type: `string`\ -Example: `foo`. +Example: `'foo'` Filename without extension. ###### extension Type: `string`\ -Example: `js`. +Example: `'js'` File extension.