I can't make a commit and push - javascript

I can't commit and push my code in git.
What i do:
git add .
git commit -m "init commit"
What i get:
after that nothing works for me, I can't click anything.
My package.json
"devDependencies": {
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"prettier": "^2.8.1",
}
scripts": {
"start": "cross-env PORT=3006 react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-scripts test --watchAll",
"test:ci": "cross-env CI=true react-scripts test",
"eslint": "eslint -c .eslintrc.js --ext .ts src/ --max-warnings=0",
"eslint:fix": "npm run eslint -- --fix",
"prepare": "husky install"
},
My .lintstagedrc
{
"*.{ts,tsx}": "npm run eslint",
"*.test.{ts,tsx}": "npm run test:ci"
}
npm install does not help(

You tests are being run in watch mode, as people have said in the comments.
The test:ci command you have is intended to disable watching by creating the CI environment variable, but you're probably not running on the platform that command was written for.
The simplest solution is to add the --watchAll=false command line option in the test:ci script:
"test:ci": "cross-env CI=true react-scripts --watchAll=false test",
Ref: https://create-react-app.dev/docs/running-tests/#on-your-own-environment
PS: I'm not familiar with cross-env, but that reference shows ways you might configure test:ci on various platforms.

Related

Failed to migrate: buildpacks from Heroku to Nixpacks

Failed to migrate: buildpacks from Heroku to Nixpacks
I need help I can't do the migration of my front end projects it doesn't compile and gives an error.
My Heroku buildpacks:
This script works correctly to generate the application on Heroku and Vercel, but I can't install it with the Nixpacks package. Can someone tell me what is wrong with the scripts?
"scripts": {
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build",
"install:clean": "rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm start",
"compile:scss": "node-sass src/assets/scss/light-bootstrap-dashboard-react.scss src/assets/css/light-bootstrap-dashboard-react.css",
"minify:scss": "node-sass src/assets/scss/light-bootstrap-dashboard-react.scss src/assets/css/light-bootstrap-dashboard-react.min.css --output-style compressed",
"map:scss": "node-sass src/assets/scss/light-bootstrap-dashboard-react.scss src/assets/css/light-bootstrap-dashboard-react.css --source-map true",
"build:scss": "npm run compile:scss && npm run minify:scss && npm run map:scss"
},
Error:
Using Nixpacks
Nixpacks build failed
If someone could help me, so as not to leave the railway.
The Heroku buildpacks are finally leaving Railway forever on Novermber 14th.
Moving From Heroku to Railway
I really appreciate any help, I'm new to this type of development
In railway settings>general>root directory> name of the directory where you do mpn start
&&
package.json>"scripts">"start": "nodemon src/app.js"

How to set cross env variables to start tests before commit?

I have configured to run tests before commit. But it only works in Ubuntu.
Here what I have now:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"test:all": "CI=true react-scripts test"
},
"husky": {
"hooks": {
"pre-commit": "npm run test:all"
}
},
How to set cross env variables to run them in any operating system?
Use the cross-env package:
"test:all": "cross-env CI=true react-scripts test"
have you tried with a .env.test file? See React docs for info on .env in create-react-app create-react-app adding custom variables

How do I setup live code reload with featherjs?

How do I setup live code reload, kind of like meteor, with featherjs?
Nodemon installs automatically via CLI. To run it just type npm run dev.
Step 1. Install nodemon in your app directory:
npm install --save-dev nodemon
Step 2. Add the following to your package.json file, in the scripts section:
...
},
"scripts": {
"test": "npm run eslint && npm run mocha",
"dev": "./node_modules/nodemon/bin/nodemon.js src/",
"eslint": "eslint src/. test/. --config .eslintrc.json",
"start": "node src/",
"mocha": "mocha test/ --recursive"
}
...
Step 3. Run the script using:
npm run dev

How to use nodemon in npm scripts to build and start scripts?

"scripts": {
"build": "babel src -d lib",
"start": "node --use_strict ./lib/index.js",
"watch": "nodemon lib/index.js --exec npm run build"
}
Using the command npm run watch results in the following wrong command being run: [nodemon] starting "npm lib/index.js run build"
How would I write a nodemon command that, on reload, transpiles the code using babel and reloads the code?
"scripts": {
"build": "babel src -d lib",
"start": "node --use_strict ./lib/index.js",
"watch": "nodemon --exec \"npm run build && node lib/index.js\" -e js --ignore lib/"
}
Then run npm run watch. After this, nodemon will rebuild the project and then restart the server every time source code(.js files) is modified.
--exec specifies what non-node scripts (also works for node scripts as above node lib/index.js) you want nodemon to execute when there is a file change.
-e specifies what file extensions you want nodemon to watch.
--ignore specifies the files/directories you want nodemon to ignore. This option is essential to solve this problem because if you do not specify to ignore this lib/ folder, nodemon will restart infinitely as the compiled files in lib/ are also .js files.
You could simply run your code with babel-node to avoid explicit transpiling.
$ nodemon lib/index.js --exec babel-node --presets=es2015,stage-2
It seems like this is the recommended way to use nodemon with babel.
Please note, running --exec could have unintended side effects when running your development environment remotely of your localhost
You can have two nodemons, one to transpile and the other to run your code. In package.json you can do something like this:
"scripts": {
"serve": "nodemon --watch dist/ ./dist/index.js",
"build" : "nodemon --watch src/ --exec babel ./src --out-dir ./dist --source-maps --copy-files"
},
There is an option to build files with Babel in "watch" mode, let Nodemon monitor just the "build" folder and restart the app upon changes to the compiled output.
{
"name": "app",
"version": "1.0.0",
"private": true,
"dependencies": {},
"devDependencies": {
"#babel/cli": "^7.6.0",
"#babel/core": "^7.6.0",
"#babel/preset-env": "^7.6.0",
"nodemon": "^1.19.2"
},
"scripts": {
"build": "babel src --out-dir build --source-maps=inline --verbose",
"start": "yarn build --watch & sleep 1 && nodemon --watch build build/index.js"
}
}
This example is taken from GraphQL API Examples repository on GitHub.
"scripts": {
"build": "babel src -d lib",
"start": "nodemon --exec babel-node lib/index.js",
"serve": "npm run build && node lib/index.js"
}
Serve is for production, with npm start what you do is transpile first and then run nodemon.
A better option would be to not use a global install but instead use the package installed locally. This will also help for automation builds that might be setup the same as your local machine per 12 factor app design.
"scripts": {
"watch": "node ./node_modules/nodemon/bin/nodemon.js"
}

How do I add a custom script to my package.json file that runs a javascript file?

I want to be able to execute the command script1 in a project directory that will run node script1.js.
script1.js is a file in the same directory. The command needs to be specific to the project directory, meaning that if I send someone else the project folder, they will be able to run the same command.
So far I've tried adding:
"scripts": {
"script1": "node script1.js"
}
to my package.json file but when I try running script1 I get the following output:
zsh: command not found: script1
Does anyone know the steps necessary to add the script mentioned above to the project folder?
*Note: the command can not be added to the bash profile (cannot be a machine specific command)
Please let me know if you need any clarification.
Custom Scripts
npm run-script <custom_script_name>
or
npm run <custom_script_name>
In your example, you would want to run npm run-script script1 or npm run script1.
See https://docs.npmjs.com/cli/run-script
Lifecycle Scripts
Node also allows you to run custom scripts for certain lifecycle events, like after npm install is run. These can be found here.
For example:
"scripts": {
"postinstall": "electron-rebuild",
},
This would run electron-rebuild after a npm install command.
I have created the following, and it's working on my system. Please try this:
package.json:
{
"name": "test app",
"version": "1.0.0",
"scripts": {
"start": "node script1.js"
}
}
script1.js:
console.log('testing')
From your command line run the following command:
npm start
Additional use case
My package.json file has generally the following scripts, which enable me to watch my files for typescript, sass compilations and running a server as well.
"scripts": {
"start": "concurrently \"sass --watch ./style/sass:./style/css\" \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
}
Steps are below:
In package.json add:
"bin":{
"script1": "bin/script1.js"
}
Create a bin folder in the project directory and add file runScript1.js with the code:
#! /usr/bin/env node
var shell = require("shelljs");
shell.exec("node step1script.js");
Run npm install shelljs in terminal
Run npm link in terminal
From terminal you can now run script1 which will run node script1.js
Reference: http://blog.npmjs.org/post/118810260230/building-a-simple-command-line-tool-with-npm
Lets say in scripts you want to run 2 commands with a single command:
"scripts":{
"start":"any command",
"singleCommandToRunTwoCommand":"some command here && npm start"
}
Now go to your terminal and run there npm run singleCommandToRunTwoCommand.
Suppose I have this line of scripts in my "package.json"
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"export_advertisements": "node export.js advertisements",
"export_homedata": "node export.js homedata",
"export_customdata": "node export.js customdata",
"export_rooms": "node export.js rooms"
},
Now to run the script "export_advertisements", I will simply go to the terminal and type
npm run export_advertisements
Example:
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"build_c": "ng build --prod && del \"../../server/front-end/*.*\" /s /q & xcopy /s dist \"../../server/front-end\"",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
As you can see, the script "build_c" is building the angular application, then deletes all old files from a directory, then finally copies the result build files.

Categories

Resources