diff --git a/cli.js b/cli.js
index a718470..481dda7 100755
--- a/cli.js
+++ b/cli.js
@@ -9,10 +9,10 @@ const cli = meow(`
Options
--no-overwrite Don't overwrite the destination
- --parents Preserve path structure
--cwd=
Working directory for files
--rename= Rename all filenames to
--dot Allow patterns to match entries that begin with a period (.)
+ --flat Flatten directory structure. All copied files will be put in the same directory.
can contain globs if quoted
@@ -20,8 +20,8 @@ const cli = meow(`
Copy all .png files in src folder into dist except src/goat.png
$ cpy 'src/*.png' '!src/goat.png' dist
- Copy all .html files inside src folder into dist and preserve path structure
- $ cpy '**/*.html' '../dist/' --cwd=src --parents
+ Copy all files inside src folder into dist and preserve path structure
+ $ cpy . '../dist/' --cwd=src
`, {
importMeta: import.meta,
flags: {
@@ -29,10 +29,6 @@ const cli = meow(`
type: 'boolean',
default: true,
},
- parents: {
- type: 'boolean',
- default: false,
- },
cwd: {
type: 'string',
default: process.cwd(),
@@ -44,6 +40,10 @@ const cli = meow(`
type: 'boolean',
default: false,
},
+ flat: {
+ type: 'boolean',
+ default: false,
+ },
},
});
@@ -52,9 +52,9 @@ const cli = meow(`
await cpy(cli.input, cli.input.pop(), {
cwd: cli.flags.cwd,
rename: cli.flags.rename,
- parents: cli.flags.parents,
overwrite: cli.flags.overwrite,
dot: cli.flags.dot,
+ flat: cli.flags.flat,
});
} catch (error) {
if (error.name === 'CpyError') {
diff --git a/package.json b/package.json
index 09baa5e..bbf1b4c 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,7 @@
"contents"
],
"dependencies": {
- "cpy": "^8.1.2",
+ "cpy": "^9.0.0",
"meow": "^10.1.2"
},
"devDependencies": {
diff --git a/readme.md b/readme.md
index 500aaaf..97acc51 100644
--- a/readme.md
+++ b/readme.md
@@ -25,10 +25,10 @@ $ cpy --help
Options
--no-overwrite Don't overwrite the destination
- --parents Preserve path structure
--cwd= Working directory for files
--rename= Rename all filenames to
--dot Allow patterns to match entries that begin with a period (.)
+ --flat Flatten directory structure. All copied files will be put in the same directory.
can contain globs if quoted
@@ -36,8 +36,8 @@ $ cpy --help
Copy all .png files in src folder into dist except src/goat.png
$ cpy 'src/*.png' '!src/goat.png' dist
- Copy all .html files inside src folder into dist and preserve path structure
- $ cpy '**/*.html' '../dist/' --cwd=src --parents
+ Copy all files inside src folder into dist and preserve path structure
+ $ cpy . '../dist/' --cwd=src
```
## Related
diff --git a/test.js b/test.js
index d8c8d19..6a30bf1 100644
--- a/test.js
+++ b/test.js
@@ -29,14 +29,18 @@ test('cwd', async t => {
t.is(read(t.context.tmp, 'cwd/hello.js'), read(t.context.tmp, 'cwd/dest/hello.js'));
});
-test('keep path structure with flag `--parents`', async t => {
+test('path structure', async t => {
fs.mkdirSync(t.context.tmp);
fs.mkdirSync(path.join(t.context.tmp, 'cwd'));
+ fs.mkdirSync(path.join(t.context.tmp, 'out'));
fs.writeFileSync(path.join(t.context.tmp, 'cwd/hello.js'), 'console.log("hello");');
- await execa('./cli.js', [path.join(t.context.tmp, 'cwd/hello.js'), t.context.tmp, '--parents']);
+ await execa('./cli.js', [path.join(t.context.tmp, '**'), path.join(t.context.tmp, 'out')]);
- t.is(read(t.context.tmp, 'cwd/hello.js'), read(t.context.tmp, t.context.tmp, 'cwd/hello.js'));
+ t.is(
+ read(t.context.tmp, 'cwd/hello.js'),
+ read(t.context.tmp, 'out/cwd/hello.js'),
+ );
});
test('rename filenames but not filepaths', async t => {
@@ -68,9 +72,32 @@ test('do not copy files in the negated glob patterns', async t => {
fs.writeFileSync(path.join(t.context.tmp, 'src/hello.jsx'), 'console.log("world");');
fs.writeFileSync(path.join(t.context.tmp, 'src/hello.es2015'), 'console.log("world");');
- await execa('./cli.js', ['src/*.*', '!src/*.jsx', '!src/*.es2015', 'dest', '--cwd', t.context.tmp]);
+ await execa('./cli.js', ['src/*.*', '!src/*.jsx', '!src/*.es2015', path.join(t.context.tmp, 'dest'), '--cwd', t.context.tmp]);
t.is(read(t.context.tmp, 'dest/hello.js'), 'console.log("hello");');
t.false(pathExistsSync(path.join(t.context.tmp, 'dest/hello.jsx')));
t.false(pathExistsSync(path.join(t.context.tmp, 'dest/hello.es2015')));
});
+
+test('flatten directory tree', async t => {
+ fs.mkdirSync(t.context.tmp);
+ fs.mkdirSync(path.join(t.context.tmp, 'source'));
+ fs.mkdirSync(path.join(t.context.tmp, 'source', 'nested'));
+ fs.writeFileSync(path.join(t.context.tmp, 'foo.js'), 'console.log("foo");');
+ fs.writeFileSync(path.join(t.context.tmp, 'source/bar.js'), 'console.log("bar");');
+ fs.writeFileSync(path.join(t.context.tmp, 'source/nested/baz.ts'), 'console.log("baz");');
+
+ await execa('./cli.js', ['**/*.js', 'destination/subdir', '--cwd', t.context.tmp, '--flat']);
+
+ t.is(
+ read(t.context.tmp, 'foo.js'),
+ read(t.context.tmp, 'destination/subdir/foo.js'),
+ );
+ t.is(
+ read(t.context.tmp, 'source/bar.js'),
+ read(t.context.tmp, 'destination/subdir/bar.js'),
+ );
+ t.falsy(
+ fs.existsSync(path.join(t.context.tmp, 'destination/subdir/baz.ts')),
+ );
+});