I have a node project which I build with concurrently with the following build pipe:
"scripts": {
"build": "concurrently -g npm:build:*",
"build:generate-db": "ts-node ./converter/main.ts",
"build:tailwind": "npx tailwindcss -i ./src/input.css -o ./static/css/build.css --minify",
"build:hugo": "hugo --minify",
},
build: Call's all commands with prefix build in synchron order.
build:generate-db: Create .md files for hugo application from a database.
build:tailwind: Generates tailwind file and puts it in correct folder
build:hugo: Creates hugo website with .md files and tailwind file.
When I run the script hugo is not finding the .md files. When I run the script a second time hugo finds the .md files and create the website correct.
What I tried:
First I thought the problem is the time the file write requires (so hugo is trying to find the files before they got written). This is not the case: Even when I sleep 10 seconds after build:generate-db hugo is not able to find the files as well.
When I run build:generate-db and than build:hugo it's working.
The tailwind file is created correctly. (it's also file write so why is this one working?)
When you run the following config it's working:
"build": "concurrently -g npm:build:* & hugo --minify",
"build:generate-db": "npm run converter",
"build:tailwind": "npx tailwindcss -i ./src/input.css -o ./static/css/build.css --minify",
The Converter writes like this:
writeFileSync(`${resultPath}/${data[titleKey]}.md`, JSON.stringify(resultDto, null, 2))
How can I fix this problem?
Related
First of all, I'm not after a technique to package my application into a single executable.
I'm curious to find out what is the approach to create a copy of the app within the current project that is ready to be moved to server-enabled location.
Right now my server app is a git repo and it has all the usual files in there, together with the source folder:
./src/server/index.js
Do we simply copy everything that is in the ./src/server folder to ./dist/ then also copy the package.json into ./dist?
Then we copy the contents of the ./dist folder to a location that will be able to serve the application, like /www/app2/ and inside that location, we make sure that we have NODE_ENV=production in the environment and run npm install to pull the production dependencies?
But then, our package.json file would still have the development related scripts and other things we don't need in production?
What is a best-practices way to deploy a NodeJs app?
--- UPDATE ---
This is what I have prototyped so far and it is working:
"scripts": {
"clean:dist": "./node_modules/.bin/rimraf dist",
"prep:dist": "./node_modules/.bin/mkdirp ./dist",
"copy:server": "./node_modules/.bin/ycopy ./src/server/ ./dist/ -r '^((?!tests$).)*$' -i",
"copy:package": "./node_modules/.bin/copyfiles package-production.json ./dist/",
"build": "npm run clean:dist && npm run prep:dist && npm run copy:server",
"start:dev": "nodemon src/server/index.js",
"start:server": "node dist/server/index.js",
"prompt": "echo 'No prompt functionality available'",
"greet": "echo 'Welcome to my project.'"
},
So the idea is to selectively move bits from the dev/src folder to a production ready dist folder. The idea behind having a simple package.json file is that we will not be needing the dev dependencies in there also we will not be needing most of the dev scripts as well. So probably something like the following will be enough:
"scripts": {
"setup:server": "NODE_ENV='production' && npm install"
"start:server": "pm2 start index.js"
}
... or maybe we would like to have some csh/bash scripts inside ./dist/bin that will streamline the start process.
"scripts": {
"start:server": "./bin/launcher"
}
I can definitely see a need for a custom project tree structure existing within the the ./dist folder and totally different to the ./src structure.
I am not sure why the "development" contents of your package.json are a problem, so perhaps I am not getting the crux of your problem. However, for our environment we deploy all of our node apps (primarily microservices) with ansible. The deployment package is just a tarball (could be a zip file). The ansible package includes templates for a config.js file and a pm2 startup.json file that are both customized based on the environment of the target (staging/test vs production).
Let me know if you want a few more details if you are interested in this approach.
What is the reason for running "rimraf dist" command in the build script in package.json file?
"scripts": {
"build": "rimraf dist ..."
},
The rimraf package which you will probably find in the devDependencies section of the package.json you have, is used to safely remove files and folders on all platforms (Unix and Windows).
When you have a build system, you want to also make sure you remove the output files before re-emitting the build output content (especially in case you have removed some files which are not needed anymore). You could go ahead and do:
"scripts": {
"clean": "rm ./dist/* -Recurse -Force"
}
But that will work on Windows only, and sometimes will also give you problems due to issues around the use of *. On Unix the command would be different. In order to make things better, rimraf does the removal for you so you can simply invoke it in your scripts/clean section:
"scripts": {
"clean": "rimraf dist"
}
This will ensure your package.json (your build system) to be cross-platform.
rimraf
A rm -rf util for nodejs
$ rimraf dist removes the dist file or folder.
I guess the build script puts stuff inside the dist directory and wants to remove the old stuff from the last time you build it.
To be sure that all old files are deleted from the folder before the script will compile the files.
What actually needs to be known is what the script rimraf dist is doing, and that's simple it's cleaning out the dist folder to give you a clean start on what is assumed to be a web app or TypeScript app that requires some level compilation.
But, it isn't limited to that alone. Rimraf is a package that allows you the power of rm -rf ./dist which is specific to Linux OS. As suggested in the above comment this command will give you problems on Windows, especially when there is a directory that isn't empty or the file path becomes too long (very common with nested npm dependencies). Rimraf will bypass those exceptions as if you're running on Linux and this becomes a very powerful tool.
I have the following directory structure for working with Cypress:
cypress-automation
cypress
fixtures
integration
apps
pulse
smhw-prod
smhw-qa
folder-a
sample-spec.js
examples
plugins
screenshots
support
videos
node_modules
cypress.json // this is where the file currently is
package-lock.json
package.json
Expectation
What I want to do is run all the tests inside the smhw-qa folder (there are a number of spec files in there) .. and be able to pass this using the --project command using CLI.
Currently if I just run `--run`` without any other arguments all the spec files, from all folders will start to run which is not desirable, since there are multiple applications "projects" (smhw-qa, smhw-prod etc) within this structure. This will allow me to only run the spec files from a single folder as desired.
I am also aware of using the --run command to "run" a specific folder, but I want to use "projects" instead to organise these tests so it's easier to identify them later.
I have had a look at the docs which show the use of the --project command however I need to help to understand what else I need to setup in order to make this work. By this, I am referring to the package.json file.
What I tried so far
I tried to follow the example provided for testing "nested folders" from here:
https://github.com/cypress-io/cypress-test-nested-projects
package.json: added the following script:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"smhw-qa": "cypress run --project ./cypress/integration/apps/smhw-qa"
},
When I run this via the terminal like so:
➜ cypress-automation npx cypress run --project ./cypress/integration/apps/smhw-qa
I get an error:
Can't run because no spec files were found.
We searched for any files inside of this folder:
/Users/jaswindersingh/Documents/cypress-automation/cypress/integration/apps/smhw-qa/cypress/integration
Am I missing something? Should my cypress.json file be located elsewhere?
I'd like to be able to set each of the folders inside "apps" to be projects, and then be able to run these projects using the cypress run --project command.
This will also make it easier to run specific folders of tests when I hookup our CI so that only specific projects (and their spec files) run when I choose.
I think you're looking for --spec path/to/folder/*.js
You can run all the tests in a folder, or even in all subfolders of a folder,
ex/ npx cypress run --spec cypress/integration/subsetA/**/*-spec.js
would run all .js specs in all folders under the "subsetA" folder in cypress/integration.
So in your case: npx cypress run --spec cypress/integration/apps/smhw-qa/**/*-spec.js should do the trick.
https://docs.cypress.io/guides/guides/command-line.html#How-to-run-commands
In my case I have angular workspace with multiple projects in it and I moved the cypress folder and cypress.json file in this sub project eg ./projects/app1.
Then add "integrationFolder": "e2e/cypress/integration", in the configuration file to specify tests directory.
Add these scripts to package.json
cypress open --project ./projects/app1
cypress run --project ./projects/app1
And only tests from e2e/cypress/integration directory are executed or opened.
I had a problem with running all tests files from one directory with
"cypress run --headed --no-exit --spec 'cypress/integration/sometests/*'"
Cypress was running only the first test file and stoppeded.
I've tried all combinations with *.js, *-spec.js etc and the problem was with the --no-exit flag. Removing --no-exit solved my problem.
Also, I've noticed that the path should be in quotes according to cypress docs https://docs.cypress.io/guides/guides/command-line#How-to-run-commands
I'm trying to create a Chrome extension.
However, once I've tried integrating Parcel I am in a bit of a pickle. I'd like to use Parcel for compatibility with old Chrome versions + for splitting my code into multiple files.
My folder structure:
When I try to make this command work:
//package.json
"scripts": {
"build": "parcel build src/js/script.js", }
I end up only with the 'script.js' inside the '/dist' folder, but I want to create a dist folder that I can package and publish. I basically want to get all my html, css, js (etc.) inside a dist folder. Can this be done?
How would you go about adding a whole framework, like Vue or React e.g. to make the popup or options page?
Parcel 2 has a first-party WebExtensions transformer. It will pick up every files mentioned in manifest.json plus some other files like what's under _locales and it works fairly well!
.parcelrc file:
{
"extends": "#parcel/config-webextension"
}
Install command:
npm install parcel #parcel/config-webextension
Build command:
parcel build manifest.json
✨ Built in 1.18s
Console output on npm run build failure:
'.' is not recognized as an internal or external command, operable
program or batch file.
And the relevant npm file:
"scripts": {
"postinstall": "jspm install && npm run build",
"start": "http-server",
"build": "./bin/build-code",
"build-home": "./bin/build-home -dw",
"build-common-deps": "./bin/build-common-deps -dw",
"build-navbar": "./bin/build-navbar -dw",
"build-root": "./bin/build-root -dw",
"build-angular1": "./bin/build-angular1 -dw",
"build-react": "./bin/build-react -w",
"build-preact": "./bin/build-preact -dw",
"build-vanilla": "./bin/build-vanillajs",
"build-angular2": "./bin/build-angular2 -dw"
}
Looks like it's not understanding the pathing to the ./bin/build-code script location. From what I understand, it looks for files from the package.json's location? So, if the app has a bin folder in the same dir as package.json, then this is the correct pathing to the build-code script, which is within the bin folder. What gives? Using PowerShell to run npm run build if it matters.
P.S. I tried with basic Command Prompt - no changes. Someone running the same build (both of us just pulled from repo) on Cygwin said they had to "Change dos endings to unix", which doesn't tell me much and doesn't seem to be the issue.
Looks to me like npm is invoking batch scripts. Batch files are run in CMD.exe (even when invoked from PowerShell), which doesn't recognize / as a path separator. That's where the error message comes from.
Replace the forward slashes with \ (or \\ if they require escaping).