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

Copy separate file, with possible new name #6

Closed
tobiastom opened this issue Feb 25, 2015 · 11 comments
Closed

Copy separate file, with possible new name #6

tobiastom opened this issue Feb 25, 2015 · 11 comments
Assignees

Comments

@tobiastom
Copy link

I'd like to copy an existing file to a new path, with a possible new name. The idea would be something like

cpy package.json Build/$npm_package_name-$npm_package_version.json

I think we would need an option for that. Or we could check for a trailing slash, like cp does. I would prefer the later one, I'm not sure if that's a good idea because it might break existing use cases.

@schnittstabil
Copy link
Collaborator

About cp: as far as I know it's not the trailing slash, cp checks if the last argument is an existing directory - but I think that doesn't really matter.

@sindresorhus
Copy link
Owner

Sure, if cp does it. But I would prefer to rely on "cp checks if the last argument is an existing directory" and not trailing slash. @schnittstabil Do you think makes sense adding this?

@schnittstabil
Copy link
Collaborator

A nice-to-have feature, especially for npm scripts.

But a directory check reminds me of nonpreemptive batch processing and may cause unpredictable results in gulp or similar contexts, e.g.:

  1. compile *.less to assets/app.css and
  2. cpy('image.jpg', 'assets', …)
    This means, if the assets directory doesn't exists, the order of the two tasks become important.

Similar problems may arise in the following use cases:

  1. cpy(['image1.jpg', 'image2.jpg'], 'assets', …)
  2. cpy('image*.jpg', 'assets', …)
    In the first case I would expect that cpy will create the assets directory. But in the second case, especially if only image1.jpg exists?

I could imagine some more flexible solutions for this problem:

cpy package.json --replace $npm_package_name-$npm_package_version.json Build/ // or --rename
cpy package.json -r $npm_package_name-$npm_package_version.json Build/ // flag style

This may also allow us to provide the following in the future:

cpy --regex '/image\(.*\).jpg/' --replace '$1.jpg' 'images/image*.jpg' assets

@tobiastom
Copy link
Author

I would love this flexibility! Right now I have separate npm scripts for single files.

Rename might me a better name, as nothing is replaced.

@schnittstabil
Copy link
Collaborator

My first idea was --search and --replace, but --search is somewhat misleading…

@sindresorhus
Copy link
Owner

@kevva Thoughts on this?

@schnittstabil
Copy link
Collaborator

One use-case I've found is not very intuitive:

# this won't work:
$ cpy src -r dest

# but this:
$ cpy src -r dest .

@sindresorhus
Copy link
Owner

$ cpy src -r dest .

This doesn't look valid. ?

@schnittstabil
Copy link
Collaborator

@sindresorhus: that is handled by meow, or more precisely minimist.

$ cpy src -r dest . is the same as $ cpy -r src dest . $ cpy -r dest src .:

> meow({ argv:['src', '-r', 'dest', '.'] });
{ input: [ 'src', '.' ],
  flags: { r: 'dest' },}

@sindresorhus
Copy link
Owner

Good point. I'd say PR welcome on this. I prefer --rename over --replace.

@schnittstabil schnittstabil self-assigned this Jun 3, 2015
schnittstabil added a commit to schnittstabil/cpy that referenced this issue Jun 3, 2015
schnittstabil added a commit to schnittstabil/cpy that referenced this issue Jun 3, 2015
@tobiastom
Copy link
Author

Works like a charm. Thank you very much @schnittstabil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants