cpx icon indicating copy to clipboard operation
cpx copied to clipboard

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

Open yaooluu opened this issue 9 years ago • 3 comments

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 avatar Nov 16 '16 20:11 yaooluu

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

yaooluu avatar Nov 16 '16 21:11 yaooluu

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 avatar Nov 17 '16 09:11 mysticatea

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:

  • If --clean option was given, cpx removes all matched files with the given pattern in the destination directory. This option intends to clean old files which are removed from the source directory.
    E.g.: In cpx aaa/**/*.js bbb --clean case, cpx removes bbb/**/*.js files then it does copy all source files.
  • If --no-initial option was given, cpx does not copy all files. It copies only changed files on each change. This option intends to not do useless copies on the assumption that someone has not changed the source files since the previous copy.

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.

mysticatea avatar Nov 23 '16 02:11 mysticatea