My project is structured as follows:
myapp
-server.js
-test
--testcontent
---package.json
-package.json
I have two package.json
files and I want to run npm install
on the package.json
inside the testcontent
folder.
If in the command line I go to myapp/test/testcontent
and run npm install
it works and it creates a new folder node_modules
with the dependencies from the correct package.json
. How can that be done from within gulp?
I tried the following but it uses the package.json
in myapp
not the one in the testcontent
sub folder:
gulp.task('default', function () {
var options = {
continueOnError: true, // default = false, true means don't emit error event
pipeStdout: true, // default = false, true means stdout is written to file.contents
customTemplatingThing: "test" // content passed to gutil.template()
};
var reportOptions = {
err: true, // default = true, false means don't write err
stderr: true, // default = true, false means don't write stderr
stdout: true // default = true, false means don't write stdout
}
gulp.src('test/testcontent/')
.pipe(exec('npm install' , options))
.pipe(exec.reporter(reportOptions));
});
gulp-exec
is the wrong tool for this job. In fact the authors of thegulp-exec
plugin explicitly advise against using it the way you are doing:Instead you use the node.js built-in
child_process.spawn()
. You can pass the directory where the command should be executed using thecwd
option: