How to run `nuxt generate` in the foreground - vue.js

In my package.json, I have:
...
"scripts": {
"generate": "nuxt generate & npm run css",
...
And run the command via npm run generate, with only one issue -- it seems to run in the background, so if I run it in a bash script with additional commands following the generation, they actually run during the generation. Is there an option to make nuxt generate run in the foreground?

That‘s because you only have one & in script which means the command before will be sent to the background. Try using && between the commands.

Related

How to run Vue.js app locally & run Cypress tests against it sequentially using npm script

I am trying to run a Vue.js app locally (localhost:3000) & then run Cypress tests against it.
Below are some npm scripts in my package.json:
"dev": "nuxt",
"cypress": "npx cypress open",
"localCypress": "npm run dev && npm run cypress"
When I run the above dev & cypress commands on their own, they work as expected.
But when I try to run them both sequentially using localCypress, only the app is starting, & the Cypress Explorer isn't opening (npm run cypress part doesn't seem to be working).
Can someone please point out why this is occurring & how I can resolve it?
The problem is that the npm run dev spins a server and that's a long running process, that won't close until you manually stop it (or if it crashes). In both cases, it will return an exit code different than 0, so the second command after && won't run.
Take a look to this question to see how to run two npm process in parallel:
How can I run multiple npm scripts in parallel?

How to execute nested "npm run commands" inside an npm#^7.0.0 monorepo set up within the context of the current workspace?

I have a monorepo with several workspaces within it. It has been very common for me to use chained npm scripts for simple tasks instead of using a task runner. So for example, the following configuration (pseudo code) is very common for me and usefull as well, specially for pre and post build scripts
"scripts": {
"prebuild:task1":"task1 --task1-arguments",
"prebuild:task2":"task2 --task2-arguments",
"prebuild": "npm run prebuild:task1 && npm run prebuild:task2",
"build":"build-script --build-arguments",
}
So the above is the package.json for the child worskpace itself and then in the master package.json I have the call to the script that triggers the build for that workspace.
build:packageA: "npm run build -w packageA"
All seems working well but the chained "npm run script" inside the workspace is actually execute in the context of the master monorepo and not inside that particular workspace.
So, in summary, the first call is to run the build script in the workscape and then triggers the prebuild script of that workspace BUT as that script execute chained npm run scripts those are run in the context of the master repo which happens that they don't exist in there. So the callstack might be ...
(master) build:packageA
(packageA) prebuild
(master) npm run prebuild:task1 >>>> EXIT ERROR
The only way I found, up to now, to bypass this issue was to make my child workspace a monorepo itself holding zero woskpaces. Essentially I have a "workspaces" key in its package.json pointing to the root directory. This enables me to use the -w flag in the scripts section so to refer all scripts to itself. So my current workaround looks like this ...
"workspaces": ["."],
"scripts": {
"prebuild:task1":"task1 --task1-arguments",
"prebuild:task2":"task2 --task2-arguments",
"prebuild": "npm run prebuild:task1 -w packageA && npm run prebuild:task2 -w packageA",
"build":"build-script --build-arguments -w packageA"
}
Isn't there already a better way to solve this?
Thanks in advance to everyone!
Following this post https://stackoverflow.com/a/67060676 I found out that npm changed the way it calls nested scripts in workspaces.
I ran into similar issues like you while running npm#7.5, but the feature was introduced in npm#7.7. Updating node to v17 and npm to 8.3 resulted in everything is running as intended.
In my case I wanted to execute nested npm run build commands in workspaces.

How can I run my live server & compile sass using node-sass simultaneously using a single command?

I want to run my app.js using "dev" : "nodemon app.js"
and I have also added "node-sass": "node-sass public/sass/main.scss public/css/style.css -w"
My goal is to run live server using nodemon app.js only once.
And compile sass to css everytime I edit my sass file and press ctrl + S without restarting my server.
I have tried it by adding "dev": " nodemon app.js && node-sass public/sass/main.scss public/css/style.css -w" .This command is running server successfully but its not compiling my sass to css whenever im trying Ctrl + s on sass file.
Use both commands on seperate terminals.
Click the plus sign to open the terminal in the same directory or use git bash.
You can also make another script merging both commands in your package.json.
"scripts": {
"dev":"nodemon app.js",
"node-sass":"node-sass public/sass/main.scss public/css/style.css -w",
"dev:sass":"npm-run-all --parallel node-sass dev"
}
By executing dev:sass, you will run both commands in parallel (note the --parallel flag).
Note: You have to install the "npm-run-all" devDependency to make the script work.

How to conditionally run npm script

I am looking for a cross-platform way of conditionally running a step in my build script.
I have a build step that is expensive, however checking to see if it is necessary is relatively quick. I have created a script that returns a non-zero error code if it is not necessary to do the build step. How can I write my npm script to only run the build if the check passes but provide errors if the build step fails?
Example package.json:
"scripts": {
"schema:build": "npm run schema:rebuild-check && npm run schema:force-build",
"schema:rebuild-check": "node tools/schema is-rebuild-necessary",
"schema:force-build": "npm run schema:validate && npm run schema:generate-index && npm run schema:bundle"
}
The problem with the above is that if the rebuild is not necessary my entire build fails. I can't just swallow the exit code with something like exitzero because I want to know if any of the commands fail in the schema:force-build script.
The problem arises from two things:
1) If an npm script exits with a non-zero code npm will always complain
2) Need to provide an "else" that returns non zero using the || operator
Working solution:
"schema:build": "node tools/schema is-rebuild-necessary && npm run schema:force-build || echo Skipping schema build",
"schema:force-build": "npm run schema:validate && npm run schema:generate-index && npm run schema:bundle"

IntelliJ stuck after running npm scripts

I have created a Scala, Play project. I am trying to add Angular2 in it. I added two npm commands through edit configuration. They are suppose to install the required packages and use webpack to bundle final JS. I notice that nothing happens after 2nd script is executed (I do not know if that script is hung or there is some other issue (see pic). It seems that the 2nd npm script is stuck because on stopping the run command, I see exit code 1 - Process finished with exit code 1
Is there a way to find out if Intelli build/run process is still running?
The issue was with the 2nd script (npm start). I had to remove --profile --watch flag from the webpack command. This works - "scripts": {
"start": "webpack --config webpack.config.dev.js --progress"
}