I have a metadata.json file which includes some values:
{"build":{"major":0,"minor":88}}
In my create-react-app project, I need to run the script to upload sentry map files:
"sentry" : "sentry-cli releases files 0.88 upload-sourcemaps --validate ./build"
where the 0.88 should be pulled from the metadata.json file. I can then run it with:
npm run sentry
How can I pull the value 0.88 from the metadata.json file with build major/ minor and insert it into the sentry command?
I am not sure if there is a solution to do this via package.json
.
Below are the steps I would have taken to solve this problem:
js
file. Let's say the name is run-command.js
.node ./run-command.js
under the script
object in package.json
.metadata.json
file in this newly created file and extract the necessary dataExample:
package.json
scripts: {
"sentry": "node ./run-command.js"
}
run-command.js
const metadata = require('./metadata.json');
const { exec } = require('child_process');
exec(`echo ${metadata.build.major}`, (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return;
}
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
Replace echo with your command. It would look something like ./node_modules/.bin/sentry ...
You can use a bash script like ./sentry.sh
if you are comfortable with shell scripts.