I'm trying to build a more interactive and user-friendly command to run scripts on my package-json. For example, I'd like to set a script for start running tests where the user could select by cli which "test mode" it would run.
My approach was to create a js file:(Very simplified version, so its easier to get the idea)
testConfig.js:
const prompt = require('prompt-sync')();(function () { const type = prompt('Run tests on "dev" or "prod" mode ?'); console.log(`Running testing scripts with ${type} config`); return type === 'dev' ? 'jest --silent=false --watch' : 'jest --verbose --coverage';})();
And I wanted to be able to use its return value to define the command line to be executed; something like this (pseudocode):
"scripts": {"test": "run return of 'node testConfig.js'"}
I know I could just create "test:dev" and "test:pro" scripts, for example. But my idea here is just trying to go beyond that and explore the posibilities of triggering different scripts based on an user selection started by a single simple script.
I've tried looots of different ways, but I'm unable to do such a thing.How could I do it? :/ Is it even possible?Thanks!