Start task in own task

This commit is contained in:
Max Lynch
2013-09-08 22:47:18 -05:00
parent 46f4da7118
commit cf7cd9cb3a
3 changed files with 36 additions and 18 deletions

View File

@ -12,9 +12,16 @@ IonicStartTask.HELP_LINE = 'Start a new Ionic project with the given name.';
IonicStartTask.prototype = new IonicTask();
IonicStartTask.prototype._printUsage = function() {
process.stderr.write('ionic start appname\n');
}
IonicStartTask.prototype.run = function(ionic) {
this.appName = argv._[0];
if(argv._.length < 2) {
ionic.fail('No app name specified');
}
this.appName = argv._[1];
this.targetPath = path.resolve(this.appName);
// Make sure to create this, or ask them if they want to override it
@ -37,5 +44,15 @@ IonicStartTask.prototype._writeTemplateFolder = function() {
});
};
IonicStartTask.prototype._checkTargetPath = function() {
if(fs.existsSync(this.targetPath)) {
var resp = this.ask('The ' + this.targetPath + ' directory already exists. Overwrite files? (y/n)')
if(resp === 'y') {
return true;
}
return false;
}
return true;
};
exports.IonicStartTask = IonicStartTask;

View File

@ -1,7 +1,19 @@
var fs = require('fs');
var IonicTask = function() {
};
IonicTask.prototype = {
// Prompt the user for a response
ask: function(question) {
var response;
process.stdout.write(question + ' ');
process.stdin.resume();
response = fs.readSync(process.stdin.fd, 100, 0, "utf8");
process.stdin.pause();
return response[0].trim();
},
run: function(ionic) {
}
};