Skip to content

Commit 693722f

Browse files
andy2mrqzsindresorhus
andauthoredMar 1, 2022
Update cpy to v9 (#34)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent b271612 commit 693722f

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed
 

‎cli.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,26 @@ const cli = meow(`
99
1010
Options
1111
--no-overwrite Don't overwrite the destination
12-
--parents Preserve path structure
1312
--cwd=<dir> Working directory for files
1413
--rename=<filename> Rename all <source> filenames to <filename>
1514
--dot Allow patterns to match entries that begin with a period (.)
15+
--flat Flatten directory structure. All copied files will be put in the same directory.
1616
1717
<source> can contain globs if quoted
1818
1919
Examples
2020
Copy all .png files in src folder into dist except src/goat.png
2121
$ cpy 'src/*.png' '!src/goat.png' dist
2222
23-
Copy all .html files inside src folder into dist and preserve path structure
24-
$ cpy '**/*.html' '../dist/' --cwd=src --parents
23+
Copy all files inside src folder into dist and preserve path structure
24+
$ cpy . '../dist/' --cwd=src
2525
`, {
2626
importMeta: import.meta,
2727
flags: {
2828
overwrite: {
2929
type: 'boolean',
3030
default: true,
3131
},
32-
parents: {
33-
type: 'boolean',
34-
default: false,
35-
},
3632
cwd: {
3733
type: 'string',
3834
default: process.cwd(),
@@ -44,6 +40,10 @@ const cli = meow(`
4440
type: 'boolean',
4541
default: false,
4642
},
43+
flat: {
44+
type: 'boolean',
45+
default: false,
Has conversations. Original line has conversations.
46+
},
4747
},
4848
});
4949

@@ -52,9 +52,9 @@ const cli = meow(`
5252
await cpy(cli.input, cli.input.pop(), {
5353
cwd: cli.flags.cwd,
5454
rename: cli.flags.rename,
55-
parents: cli.flags.parents,
5655
overwrite: cli.flags.overwrite,
5756
dot: cli.flags.dot,
57+
flat: cli.flags.flat,
5858
});
5959
} catch (error) {
6060
if (error.name === 'CpyError') {

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"contents"
5252
],
5353
"dependencies": {
54-
"cpy": "^8.1.2",
54+
"cpy": "^9.0.0",
5555
"meow": "^10.1.2"
5656
},
5757
"devDependencies": {

‎readme.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ $ cpy --help
2525
2626
Options
2727
--no-overwrite Don't overwrite the destination
28-
--parents Preserve path structure
2928
--cwd=<dir> Working directory for files
3029
--rename=<filename> Rename all <source> filenames to <filename>
3130
--dot Allow patterns to match entries that begin with a period (.)
31+
--flat Flatten directory structure. All copied files will be put in the same directory.
3232
3333
<source> can contain globs if quoted
3434
3535
Examples
3636
Copy all .png files in src folder into dist except src/goat.png
3737
$ cpy 'src/*.png' '!src/goat.png' dist
3838
39-
Copy all .html files inside src folder into dist and preserve path structure
40-
$ cpy '**/*.html' '../dist/' --cwd=src --parents
39+
Copy all files inside src folder into dist and preserve path structure
40+
$ cpy . '../dist/' --cwd=src
4141
```
4242

4343
## Related

‎test.js

+31-4
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ test('cwd', async t => {
2929
t.is(read(t.context.tmp, 'cwd/hello.js'), read(t.context.tmp, 'cwd/dest/hello.js'));
3030
});
3131

32-
test('keep path structure with flag `--parents`', async t => {
32+
test('path structure', async t => {
3333
fs.mkdirSync(t.context.tmp);
3434
fs.mkdirSync(path.join(t.context.tmp, 'cwd'));
35+
fs.mkdirSync(path.join(t.context.tmp, 'out'));
3536
fs.writeFileSync(path.join(t.context.tmp, 'cwd/hello.js'), 'console.log("hello");');
3637

37-
await execa('./cli.js', [path.join(t.context.tmp, 'cwd/hello.js'), t.context.tmp, '--parents']);
38+
await execa('./cli.js', [path.join(t.context.tmp, '**'), path.join(t.context.tmp, 'out')]);
3839

39-
t.is(read(t.context.tmp, 'cwd/hello.js'), read(t.context.tmp, t.context.tmp, 'cwd/hello.js'));
40+
t.is(
41+
read(t.context.tmp, 'cwd/hello.js'),
42+
read(t.context.tmp, 'out/cwd/hello.js'),
43+
);
4044
});
4145

4246
test('rename filenames but not filepaths', async t => {
@@ -68,9 +72,32 @@ test('do not copy files in the negated glob patterns', async t => {
6872
fs.writeFileSync(path.join(t.context.tmp, 'src/hello.jsx'), 'console.log("world");');
6973
fs.writeFileSync(path.join(t.context.tmp, 'src/hello.es2015'), 'console.log("world");');
7074

71-
await execa('./cli.js', ['src/*.*', '!src/*.jsx', '!src/*.es2015', 'dest', '--cwd', t.context.tmp]);
75+
await execa('./cli.js', ['src/*.*', '!src/*.jsx', '!src/*.es2015', path.join(t.context.tmp, 'dest'), '--cwd', t.context.tmp]);
7276

7377
t.is(read(t.context.tmp, 'dest/hello.js'), 'console.log("hello");');
7478
t.false(pathExistsSync(path.join(t.context.tmp, 'dest/hello.jsx')));
7579
t.false(pathExistsSync(path.join(t.context.tmp, 'dest/hello.es2015')));
7680
});
81+
82+
test('flatten directory tree', async t => {
83+
fs.mkdirSync(t.context.tmp);
84+
fs.mkdirSync(path.join(t.context.tmp, 'source'));
85+
fs.mkdirSync(path.join(t.context.tmp, 'source', 'nested'));
86+
fs.writeFileSync(path.join(t.context.tmp, 'foo.js'), 'console.log("foo");');
87+
fs.writeFileSync(path.join(t.context.tmp, 'source/bar.js'), 'console.log("bar");');
88+
fs.writeFileSync(path.join(t.context.tmp, 'source/nested/baz.ts'), 'console.log("baz");');
89+
90+
await execa('./cli.js', ['**/*.js', 'destination/subdir', '--cwd', t.context.tmp, '--flat']);
91+
92+
t.is(
93+
read(t.context.tmp, 'foo.js'),
94+
read(t.context.tmp, 'destination/subdir/foo.js'),
95+
);
96+
t.is(
97+
read(t.context.tmp, 'source/bar.js'),
98+
read(t.context.tmp, 'destination/subdir/bar.js'),
99+
);
100+
t.falsy(
101+
fs.existsSync(path.join(t.context.tmp, 'destination/subdir/baz.ts')),
102+
);
103+
});

0 commit comments

Comments
 (0)
Please sign in to comment.