Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The --rename flag supports string templates. #40

Merged
merged 4 commits into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli.js
Expand Up @@ -55,6 +55,12 @@ const cli = meow(`

(async () => {
try {
const {rename} = cli.flags;
const renameReg = /{{(\s*)?basename(\s*)?}}/;
jaywcjlove marked this conversation as resolved.
Show resolved Hide resolved
jaywcjlove marked this conversation as resolved.
Show resolved Hide resolved
if (rename && renameReg.test(rename)) {
cli.flags.rename = basename => rename.replace(renameReg, basename);
}

await cpy(cli.input, cli.input.pop(), {
cwd: cli.flags.cwd,
rename: cli.flags.rename,
Expand Down
3 changes: 3 additions & 0 deletions test.js
Expand Up @@ -51,6 +51,9 @@ test('rename filenames but not filepaths', async t => {
await execa('./cli.js', [path.join(t.context.tmp, 'hello.js'), path.join(t.context.tmp, 'dest'), '--rename=hi.js']);

t.is(read(t.context.tmp, 'hello.js'), read(t.context.tmp, 'dest/hi.js'));

await execa('./cli.js', [path.join(t.context.tmp, 'hello.js'), path.join(t.context.tmp, 'dest'), '--rename=hi-{{basename}}-1']);
t.is(read(t.context.tmp, 'hello.js'), read(t.context.tmp, 'dest/hi-hello-1.js'));
});

test('overwrite files by default', async t => {
Expand Down