How to use --no-initial together with --clean ?
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.
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
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.
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
--cleanoption 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.: Incpx aaa/**/*.js bbb --cleancase, cpx removesbbb/**/*.jsfiles then it does copy all source files. - If
--no-initialoption 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.