Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@flemist/copy-glob-flat

NikolayMakhonin52ISC0.0.5TypeScript support: included

Copy files to single directory with auto rename duplicates

copy, files, glob, globby, rename, auto rename, duplicates

readme

NPM Version NPM Downloads Build Status Test Coverage

Copy files to single directory with auto rename duplicates

Installation

npm i @flemist/copy-glob-flat

Usage CLI

cp-flat <SOURCE_GLOB1> <SOURCE_GLOB2> ... <DEST_DIR>
cp-flat src/**/*.txt !**/ignore.txt tmp/destDir

Usage module

import {copyGlobFlat} from '@flemist/copy-glob-flat'

/*
Initial:

/source
  /dir
    /dir1
      file.txt
      ignore.txt
    /dir2
      file.txt
      ignore.txt
    file.txt
    ignore.txt
  file.txt
  ignore.txt
/dest
  /file2.txt
    file.txt
  file1.txt
*/

await copyGlobFlat({
  destDir: 'tmp',
  globs: [
    '**/*.txt',
    '**/!ignore.txt',
  ],
})

/*
Result:

/source
  ...
/dest
  /file2.txt
    file.txt
  file.txt   - copied from source/file
  file0.txt  - copied from source/dir/file
  file1.txt
  file3.txt  - copied from source/dir/dir1/file
  file4.txt  - copied from source/dir/dir2/file
*/