I am trying to create a mini-script for make a folder empty as npm task.
It is the style folder, which is filled by lessc
.
In Linux shell it works:
me@work:~/path/to/my-app$ [ $(ls -A ./style/) ] && rm ./style/* # is is empty, nothing happens
me@work:~/path/to/my-app$ touch ./style/test
me@work:~/path/to/my-app$ ls -A ./style
test
me@work:~/path/to/my-app$ [ $(ls -A ./style/) ] && rm ./style/* # removing
me@work:~/path/to/my-app$ ls -A ./style # empty again
At this point the folder is empty and the task should run nonetheless. But it does not.
This is my line in the scripts object in package.json:
"clear:prod": "[ $(ls -A ./style/) ] && rm ./style/*"
me@work:~/path/to/my-app$ npm run dev
> hpc-app@0.9.2 dev
> run-s clear:* update:* compile:* eslint webpack:dev print-current-date
> hpc-app@0.9.2 clear:prod
> [ $(ls -A ./style/) ] && rm ./style/*
ERROR: "clear:prod" exited with 1.
The script works fine, when there is a file in the folder.
What am I doing wrong? Do I just not see the 1 when I run the shell command? Is there any way to do rm ./folder/*
if it is empty without getting an error?