问题描述:

I'm trying to write a small helper CLI for a project I'm working on, and I would like to make it so that the first time the command is run it will automatically install the requirements to save a step. I have that much working,

try {

require.resolve('fs-extra');

require.resolve('mustache')

require.resolve('chokidar')

require.resolve('path')

} catch (e) {

console.log("Installing requirements...");

require('child_process').execSync('npm install', {cwd: __dirname, stdio: [1,2]});

console.log("Requirements installed, please run the command again.")

return

}

But I would like it to not have to be run a second time, if possible. Currently, if it isn't run again, it gives a standard "module can't be found" error, even though the module is now there.

Thanks,

-tlf

相关阅读:
Top