Skip to content

Commit

Permalink
feat(cli): install necessary packages for default gulpfile
Browse files Browse the repository at this point in the history
After downloading the default gulpfile, install the necessary packages
for it to work.
  • Loading branch information
tlancina committed Mar 28, 2016
1 parent 86fbce6 commit 89f560b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
53 changes: 39 additions & 14 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,28 @@ function runWithGulp(argv, taskInstance){
});
var downloadGulp = false;
return deferred.promise.then(
function(){
function() {
downloadGulp = true;
return downloadDefaultGulpfile();
return downloadDefaultGulpfile(cmdName).then(
installGulpfilePackages,
function(err) {
console.error('There was an error downloading the default gulpfile: ' + err);
process.exit(1);
}
).then(
function(){
console.success('Npm packages installed successfully. Try running \'' + cmdName + '\' again.');
},
function(){
console.warn('There was an error installing the packages required by the gulpfile.');
console.warn('You\'ll need to install the following packages manually: ');
console.warn(' ' + requires.join(' '));
}
);
},
function(){
function() {
return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
}
).then(
function(){
if (downloadGulp) {
console.success('Successfully downloaded gulpfile. Try running \'' + cmdName + '\' again.');
}
},
function(err) {
console.error('There was an error downloading the default gulpfile: ' + err);
process.exit(1);
}
);
}
}
Expand Down Expand Up @@ -254,7 +259,7 @@ function downloadDefaultGulpfile(){
var branch = project.get('typescript') ? 'typescript' : 'master';
var url = 'https://raw.githubusercontent.com/driftyco/ionic2-app-base/' + branch + '/gulpfile.js';

console.info(('Downloading default gulpfile from: ' + url));
console.info('\nDownloading default gulpfile from: ' + url);

fileStream.on('open', function () {
https.get(url, function (res) {
Expand All @@ -273,6 +278,26 @@ function downloadDefaultGulpfile(){
return deferred.promise;
}

function installGulpfilePackages(cmdName){
var detective = require('detective');
var requires = detective(fs.readFileSync('gulpfile.js'));
var deferred = Q.defer();

console.success('Successfully downloaded gulpfile.\n');
console.info('Now installing npm packages used by the gulpfile: ');
console.info(' ' + requires.join(' ') + '\n');

var npmInstall = require('child_process').spawn('npm', ['install', '--save-dev'].concat(requires));
npmInstall.stdout.on('data', function(data){ logging.logger.debug(data) });
npmInstall.stderr.on('data', function(data){ logging.logger.debug(data) });
npmInstall.on('error', function(err) { console.error(err) });
npmInstall.on('exit', function(code) {
code !== 0 ? deferred.reject() : deferred.resolve();
});

return deferred.promise;
}


function logEvents(gulpInst, finalTaskNames) {
gulpInst.on('task_start', function(e) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"connect-livereload": "0.5.2",
"crc": "3.2.1",
"cross-spawn": "0.2.3",
"detective": "4.3.1",
"event-stream": "3.0.20",
"expand-tilde": "1.2.0",
"finalhandler": "0.2.0",
Expand Down

0 comments on commit 89f560b

Please sign in to comment.