Skip to content

Commit 89f560b

Browse files
committed
feat(cli): install necessary packages for default gulpfile
After downloading the default gulpfile, install the necessary packages for it to work.
1 parent 86fbce6 commit 89f560b

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

lib/cli.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,28 @@ function runWithGulp(argv, taskInstance){
198198
});
199199
var downloadGulp = false;
200200
return deferred.promise.then(
201-
function(){
201+
function() {
202202
downloadGulp = true;
203-
return downloadDefaultGulpfile();
203+
return downloadDefaultGulpfile(cmdName).then(
204+
installGulpfilePackages,
205+
function(err) {
206+
console.error('There was an error downloading the default gulpfile: ' + err);
207+
process.exit(1);
208+
}
209+
).then(
210+
function(){
211+
console.success('Npm packages installed successfully. Try running \'' + cmdName + '\' again.');
212+
},
213+
function(){
214+
console.warn('There was an error installing the packages required by the gulpfile.');
215+
console.warn('You\'ll need to install the following packages manually: ');
216+
console.warn(' ' + requires.join(' '));
217+
}
218+
);
204219
},
205-
function(){
220+
function() {
206221
return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
207222
}
208-
).then(
209-
function(){
210-
if (downloadGulp) {
211-
console.success('Successfully downloaded gulpfile. Try running \'' + cmdName + '\' again.');
212-
}
213-
},
214-
function(err) {
215-
console.error('There was an error downloading the default gulpfile: ' + err);
216-
process.exit(1);
217-
}
218223
);
219224
}
220225
}
@@ -254,7 +259,7 @@ function downloadDefaultGulpfile(){
254259
var branch = project.get('typescript') ? 'typescript' : 'master';
255260
var url = 'https://raw.githubusercontent.com/driftyco/ionic2-app-base/' + branch + '/gulpfile.js';
256261

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

259264
fileStream.on('open', function () {
260265
https.get(url, function (res) {
@@ -273,6 +278,26 @@ function downloadDefaultGulpfile(){
273278
return deferred.promise;
274279
}
275280

281+
function installGulpfilePackages(cmdName){
282+
var detective = require('detective');
283+
var requires = detective(fs.readFileSync('gulpfile.js'));
284+
var deferred = Q.defer();
285+
286+
console.success('Successfully downloaded gulpfile.\n');
287+
console.info('Now installing npm packages used by the gulpfile: ');
288+
console.info(' ' + requires.join(' ') + '\n');
289+
290+
var npmInstall = require('child_process').spawn('npm', ['install', '--save-dev'].concat(requires));
291+
npmInstall.stdout.on('data', function(data){ logging.logger.debug(data) });
292+
npmInstall.stderr.on('data', function(data){ logging.logger.debug(data) });
293+
npmInstall.on('error', function(err) { console.error(err) });
294+
npmInstall.on('exit', function(code) {
295+
code !== 0 ? deferred.reject() : deferred.resolve();
296+
});
297+
298+
return deferred.promise;
299+
}
300+
276301

277302
function logEvents(gulpInst, finalTaskNames) {
278303
gulpInst.on('task_start', function(e) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"connect-livereload": "0.5.2",
6868
"crc": "3.2.1",
6969
"cross-spawn": "0.2.3",
70+
"detective": "4.3.1",
7071
"event-stream": "3.0.20",
7172
"expand-tilde": "1.2.0",
7273
"finalhandler": "0.2.0",

0 commit comments

Comments
 (0)