mysticatea / cpx

A cli tool to watch and copy file globs.
MIT License
524 stars 36 forks source link

How to use --no-initial together with --clean ? #22

Open yaooluu opened 7 years ago

yaooluu commented 7 years ago

Hi,

I'm trying to use cpx 'index.html' 'build' --no-initial --watch --clean. My desired behavior is:

Don't perform any copy after execution. Don't perform clean until the first copy (delayed by --no-initial, triggered by user saving the file).

However, it seems like --clean won't be blocked/delayed by --no-initial parameter. Instead, it will always do the clean right after executing the command.

My use case is that I need to override the destination file (read-only) when user first hit "Save" (override on every "Save" is better) , meaning that I want to perform copy index.html (edited) -> build/index.html (read-only) while watching.

I saw we have options for not overriding, but it seems during watching it won't override by default either.

yaooluu commented 7 years ago

And when the destination file is read-only. Verbose mode will only display one line:

Copy: index.html --> build

Without telling the result, either error message like "failed to copy file" or success like below:

Copied: index.html --> build/index.html

mysticatea commented 7 years ago

Thank you for the report.

Granted, this is confusing. cpx should delay the cleaning until at the first copy if --no-initial is given. Also, should print proper error messages.

I will fix this issue within a few days.

mysticatea commented 7 years ago

I'm sorry for the delay.

I have rethought this. I'm going to make throwing the error "--clean and --no-initial cannot be combined."

Because:

Those 2 options are incompatible. --clean requires copying all source files (or remove only files which are removed from the source directory) at initialization, --no-initial requires to do nothing at initialization.

This is a breaking change, so I will make this change at the end of this year; Node 0.x supports are dropped.