Skip to content

Commit

Permalink
feat(hooks): download default gulpfile
Browse files Browse the repository at this point in the history
If user has ionic.config.js and no gulpfile, prompt to download the
default gulpfile so they can still build.
  • Loading branch information
tlancina committed Mar 28, 2016
1 parent 0bd5b6f commit 408a660
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,48 @@ function runWithGulp(argv, taskInstance){
});
}

//No gulpfile
if (/serve|build|run|emulate|upload/.test(cmdName) && argv.v2) {
console.warn('WARN: No gulpfile found!');
console.warn('If your app requires a build step, you may want to ensure it runs before ' + cmdName + '.\n');

if (fs.existsSync('ionic.config.js')) {
var inquirer = require('inquirer');
var deferred = Q.defer();

console.info('Looks like you are using the deprecated ionic.config.js and have no gulpfile!');
console.info('As of beta.21 the Ionic CLI relies on gulp hooks to build your web assets\n');
inquirer.prompt([{
type: 'confirm',
name: 'downloadGulp',
message: 'Would you like to download the default gulpfile?'.cyan,
}],
function(answers){
answers.downloadGulp ? deferred.resolve() : deferred.reject();
});
var downloadGulp = false;
return deferred.promise.then(
function(){
downloadGulp = true;
return downloadDefaultGulpfile();
},
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);
}
);
}
}

return Q.fcall(taskInstance.run.bind(taskInstance), Cli, argv);
}

Expand Down Expand Up @@ -207,6 +245,34 @@ function loadGulpfile(){
return false;
}

function downloadDefaultGulpfile(){
var https = require('https');
var fileStream = fs.createWriteStream('gulpfile.js');
var deferred = Q.defer();
var project = IonicProject.load();
var branch = project.get('typescript') ? 'typescript' : 'master';
var url = 'https://cdn.rawgit.com/driftyco/ionic2-app-base/' + branch + '/gulpfile.js';

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

fileStream.on('open', function () {
https.get(url, function (res) {
res.on('error', function (err) {
deferred.reject(err);
});

res.pipe(fileStream);
});
}).on('error', function (err) {
deferred.reject(err);
}).on('finish', function () {
deferred.resolve();
});

return deferred.promise;
}


function logEvents(gulpInst, finalTaskNames) {
gulpInst.on('task_start', function(e) {
// TODO: batch these
Expand Down

0 comments on commit 408a660

Please sign in to comment.