- I'm using Shipit for deployment.
- On deploy, Shipit checks out the current Git Sha, to a tmp directory, then I run
npm install
followed bygulp build
, then proceed with the deploy. - Shipit uses Orchestrator for it's task flow, as Gulp does.
- Shipit has it's own CLI, so I can deploy with
shipit development deploy
.
Everything thing above works. What I'm trying to do is create a gulp deploy
task that will initialize Shipit directly, instead of using the CLI. Looks something like this:
gulp.task('shipit:deploy', function() {
var deployToEnv = argv['deploy-to'] || false;
var shipit;
return inquirer.prompt([{
type: 'list',
name: 'deployToEnv',
default: deployToEnv,
message: 'Deploy to environment:',
choices: envs
}]).then(function(answers) {
deployToEnv = answers.deployToEnv;
shipit = new Shipit({environment: deployToEnv});
shipit.initialize();
shipit.start('deploy');
});
});
Corresponding shipit config:
shipit.initConfig(config);
shipit.blTask('build', function() {
return shipit.local('npm install --silent', {
cwd: shipit.config.workspace
}).then(function() {
return shipit.local('gulp build', {
cwd: shipit.config.workspace
});
});
});
shipit.on('fetched', function() {
shipit.start('build');
});
Things appear to work with one problem: it doesn't actually perform the npm install
!
Running "npm install --silent" on local.
Running "gulp build" on local.
So, it would seem something in the npm install
command is prematurely resolving the promise, but I'm not sure how or why.
I had a similar problem (just using shipit cli) with npm warnings, which is when I discovered using the --silent arg solved that.
As a test, I left the code as is, but replaced npm install --silent
with sleep 10
. Sure enough, it waited for 10 seconds before executing gulp build
. So, it would seem it is something specific with the npm install
command.
Any help is appreciated!
Update #1:
shipit.local
uses child_process.exec
. I tried converting this to use child_process.spawn
, but had the same result.
Update #2:
If I change the command to sudo npm install
, things work as expected! So...what does this mean, and how can I avoid running it with sudo
?
Update #3:
Still unable to do this without sudo, but I tried adding the --verbose
flag with these results:
Without sudo
:
@ npm info it worked if it ends with ok
@ npm verb cli [ '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/node',
@ npm verb cli '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm',
@ npm verb cli 'install',
@ npm verb cli '--verbose' ]
@ npm info using [email protected]
@ npm info using [email protected]
@ npm verb install where, deps [ '/Users/timkelty/tmp/edwards-garment-website', [] ]
@ npm verb install where, peers [ '/Users/timkelty/tmp/edwards-garment-website', [] ]
@ npm info preinstall [email protected]
@ npm info build /Users/timkelty/tmp/edwards-garment-website
@ npm verb linkStuff [ false, false, false, '/Users/timkelty/tmp' ]
@ npm info linkStuff [email protected]
@ npm verb linkBins [email protected]
@ npm verb linkMans [email protected]
@ npm verb rebuildBundles [email protected]
@ npm info install [email protected]
@ npm info postinstall [email protected]
@ npm verb exit [ 0, true ]
@ npm info ok
Running "gulp build" on local.
@ [15:14:32] Local gulp not found in ~/tmp/edwards-garment-website
@ [15:14:32] Try running: npm install gulp
'build' errored after 755 ms
Error: Command failed: /bin/sh -c gulp build
With sudo
:
Running "sudo npm install --verbose" on local.
@ npm info it worked if it ends with ok
@ npm verb cli [ '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/node',
@ npm verb cli '/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm',
@ npm verb cli 'install',
@ npm verb cli '--verbose' ]
@ npm info using [email protected]
@ npm info using [email protected]
@ npm verb install where, deps [ '/Users/timkelty/tmp/edwards-garment-website',
@ npm verb install [ 'Select2',
@ npm verb install 'autoprefixer-core',
@ npm verb install 'babel',
...so for some reason, when running without sudo, the npm install command seems to think it doesn't have any dependencies to install, so it finishes without error and continues to my next task.
npm install
without--silent
and print in then console.log(res.stdout); and console.log(res.stderr)? – Soothfastchild_process.exec
callback, both stdout and stderr are empty strings: gist.github.com/4c0c905e2ab517806915 – Dichromaticismchmod -R 755
on the dir I'm running thenpm install
command from, same result. – Dichromaticismecho "$(which npm) test" >> test.file
instead ofsleep 10
. Why it is needed? First we know if gulp can create file, second we know if gulp can use npm and which one. – Soothfast/Users/timkelty/.nvm/versions/node/v0.12.0/bin/npm test
– Dichromaticismsudo
– Dichromaticism