I have a brand new project created with:
$ npx create-react-app test-react-app && cd test-react-app && npm start
here the repo: https://github.com/tlg-265/test-react-app
I created a new script: /prepare-project.js
with the following content:
let project = 'ferrari' // replace this value with the one passed via: $ npm start [what to put here?]
console.log(`########################`);
console.log(`###### The current project is: ${project} ######`);
console.log(`########################`);
The content of file: /package.json
is:
{
"name": "test-react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "3.3.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"prestart": "node prepare-project.js"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
where you can see I configured the pre hook
:
"prestart": "node prepare-project.js"
My goal is to run:
$ npm start [what to put here?]
so inside the script: /prepare-project.js
I can read that value.
I tried with:
$ node prepare-project.js --project=mclaren
with no luck when trying to read that value from inside the script: prepare-project.js
.
Any idea on how to achieve this?
Thanks!