Windows 11, Yarn 3.2.4
My package.json has this
"scripts": {
"predist": "del /Q \"WWW\\*\"",
Trying to run it gives this:
PS C:\MyProject> yarn predist
Could Not Find C:\/Q
C:\MyProject\WWW\*, Are you sure (Y/N)?
If I omit the /Q files are deleted as expected once I answer the confirmation prompt
How to stop the /Q being interpreted as a filename?
rimraf solves this completely. https://www.npmjs.com/package/rimraf
> yarn add --dev rimraf
"predist": "rimraf WWW/*",
Related
I am trying to host a nuxtjs app on Firebase using cloud functions following this tutorial (around 12:30).
One of the required steps is copying a folder with batch commands in a predeploy hook of firebase deploy --only functions. The tutorial uses Linux (?) commands and I'm trying to replicate it on Windows.
I was able to create a command that works correctly (!) if I run it directly from terminal:
xcopy .\.nuxt\*.* '.\functions\nuxt\' /e /i /y /q
It also works if I put it to package.json as a test script and run it with npm run test (obviously additional \ characters are needed in package.json):
"scripts": {
"test": "xcopy .\\.nuxt\\*.* '.\\functions\\nuxt\\' /e /i /y /q"
}
But when I put the very string from above into firebase.json like this:
"functions": {
"source": "functions",
"predeploy": [
"xcopy .\\.nuxt\\*.* '.\\functions\\nuxt\\' /e /i /y /q"
]
},
and then run command firebase deploy --only functions, the CLI displays message:
Running command: xcopy .\.nuxt\*.* '.\functions\nuxt\' /e /i /y /q
and an error: Invalid number of parameters. The displayed command is identical to the command I successfully run manually in the terminal. I can copy it from that message paste into terminal and it will work. Yet when triggered by the firebase deploy mechanism it throws an error.
Usual answer for 'Invalid number of parameters' error is lack of quotation marks around the path. I have tried various combinations of '' or \" \", but neither works, although they fail in various ways (cannot find file: *.*' or Analysis error).
What can be the cause of this and how to solve it? What is the right way to write this command?
I managed to find a workaround - I 'outsourced' all file operations into a batch file and referred to that file in the firebase.json predeploy hook:
"functions": {
"source": "functions",
"predeploy": [
"npm run build && predeploy.bat"
]
}
Contents of predeploy.bat:
if exist functions\nuxt rmdir /S /Q functions\nuxt\
xcopy.exe .nuxt functions\nuxt /e /i /y /q /s
xcopy.exe nuxt.config.js functions\ /i /q /y
I had a problem also with rmdir not functioning properly if run from the Firebase's predeploy hook, but it works seamlessly if it is called from batch file that is called from predeploy hook (?!).
My folder structure is like this:
js:
folder1:
subfolder1
subfolder2
folder2:
...
...
folder3:
...
...
Now I want to create a batch file that sits in the js folder that when executed, navigates inside each folder (folder1, folder2, folder3) and not in their subfolders, open a command prompt and run the command npm i.
I have this command
for /D %%y in (*) do (
start cmd /k cd %%y & npm i
)
but it just opens up 3 command prompts, so navigating correctly but fails to run the npm command. I'm very new to batch programming so any help would be appreciated.
For those who stumble upon this question, here's the answer with the help of #aschipfl in the comments. The second command was being executed in the host cmd window and not in the new spawned prompts.
for /D %%y in (*) do (
start cmd /k cd %%y & npm run erp-dev
)
I have a requirement where I need to run a batch script which would compile a custom module and then come back to the project's root location and run the project.
For this, I have written something like below
SET curDir=%~dp0
PUSHD %curDir%
echo %curDir%
cd modules\custom-module
yarn build
POPD
echo %CD%
yarn start
but after the yarn build command, it stays in the modules\custom-module directory.
Before changing the directory call 'setlocal'. So your script will look like following
cd <- prints current dir
setlocal
cd modules\custom-module
yarn build <- if yarn is script, do 'call yarn build' instead
endlocal
cd
yarn start
Following on from an answer to this question
For the Windows command prompt I can define aliases as follows:
#echo off
DOSKEY ns=npm start
DOSKEY nsr=npm run serve
I want to define an alias that will combine these two commands. I tried the following:
#echo off
DOSKEY nss=npm start && npm run serve
When I try to open the command prompt the window will open but the > prompt does not appear.
I think that the inclusion of && is causing a problem.
The command separator for DOSKEY is $T
For your example:
DOSKEY nss=npm start $T npm run serve
I looked at an answer to a question on superuser. The following approach resolved my problem:
#echo off
DOSKEY nss=npm start ^&^& npm run serve
My approach is to load the macros from a text file:
a.bat:
#doskey /macrofile=C:\%HOMEPATH%\bin\aliases.txt
and in the macro file, && works:
aliases.txt:
cl=cd /d $* && dir
Then if I type "cl bin" from HOMEPATH, it does "cd /d bin" and then "dir":
C:\Users\mike> cl bin
09/17/2020 09:27 AM 1,303 a.bat
09/30/2020 03:17 PM 886 aliases.txt
Try writing it as a batch file and then calling the batch file use the DOSKEY command
REM do_npm.bat
npm start
npm run serve
Then, run the DOSKEY command
DOSKEY npm=do_npm.bat
See if that works for you
I made this batch file to execute certain commands for my kit for web dev, however, the bat file quits after line 59. Why is it quitting?
I noticed, however, that if I remove line 59 from the file and run it. It works fine. The only thing is, I have to physically type that line in after the bat file finishes.
You can try to reproduce the problem by downloading my kit from my GitHub and extracting the contents of the zip to a location that you prefer.
Just navigate to the Gulp/Starter Kit directory and run the setup.bat file.
Batch File:
#echo off
TITLE Starter Kit
runas /noprofile /user:Administrator cmd
goto :checkNodeVersion
:checkNodeVersion
cls
echo Current NodeJS version:
call npm -v
timeout 5
if errorlevel 1 goto :installNode
goto :updateNode
:installNode
cls
echo Installing NodeJS:
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://nodejs.org/dist/v5.3.0/node-v5.3.0-x64.msi', 'node-v5.3.0-x64.msi')"
echo downloading file, node-v5.3.0-x64.msi, from https://nodejs.org/dist/v5.3.0/node-v5.3.0-x64.msi....
set "fileName=node-v5.3.0-x64.msi"
%fileName%
echo NodeJS was successfully installed.
timeout 5
goto :updateNode
:updateNode
cls
echo Updating NodeJS:
call npm cache clean -f
call npm install -g n
call n stable
cls
echo NodeJS was successfully updated to version #:
node -v
timeout 5
goto :installBower
:installBower
cls
echo Installing Bower:
call npm install -g gulp bower
echo Bower was successfully installed.
goto :installGulp
:installGulp
cls
echo Installing GulpJS:
call npm install -g gulp
echo GulpJS was successfully installed.
timeout 5
goto :installDependencies
:installDependencies
cls
echo Installing Project Dependencies:
call npm install && bower install
::Quits unexpectedly after line 59
call npm install --save-dev gulp-rucksack
call npm install --save-dev gulp-imagemin
call npm install --save imagemin-pngquant
echo Project Dependencies were successfully installed.
timeout 5
goto :primaryFunction
:primaryFunction
cls
echo Starter Kit Log:
echo NodeJS is installed.
echo GulpJS is installed.
echo Gulp Dependencies are installed.
set /p response="Would you like to continue? <y/n>"
if /i "%response%"=="y" (
cls
set "filePath=%~dp0"
cd %filePath%
gulp help
cmd /k
)
if /i "%response%"=="n" goto :exitFunction
:exitFunction
cls
echo Starter Kit is Closing
exit
Based on the following quote from https://www.jetbrains.com/webstorm/help/bower.html, bower is a batch script (.cmd file).
In this field, specify the location of the Bower executable file
(bower.cmd or other depending on the operating system used).
So you need to change line 59 to read as follows:
call npm install && call bower install
Without CALL, you never return from bower.