mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
Task shit
This commit is contained in:
@ -11,12 +11,13 @@ Licensed under the Apache 2.0 license. See LICENSE For mroe.
|
||||
Copyright 2013 Drifty (http://drifty.com/)
|
||||
*/
|
||||
|
||||
var argv = require('optimist').argv,
|
||||
IonicStartTask = require('./lib/ionic/start.js');
|
||||
var IonicStartTask = require('./lib/ionic/start.js').IonicStartTask;
|
||||
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
var TASKS = [
|
||||
{
|
||||
title: 'New Project',
|
||||
title: 'start',
|
||||
name: 'start',
|
||||
usage: 'appname',
|
||||
task: IonicStartTask
|
||||
@ -48,9 +49,15 @@ Ionic.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
_printUsage: function() {
|
||||
_printGenericUsage: function() {
|
||||
this._printIonic();
|
||||
process.stderr.write('Usage: ionic task args\n');
|
||||
process.stderr.write('Usage: ionic task args\n\n===============\n\nAvailable tasks:\n\n');
|
||||
|
||||
for(var i = 0; i < TASKS.length; i++) {
|
||||
var task = TASKS[i];
|
||||
process.stderr.write(' ' + task.name + '\t\t' + task.task.HELP_LINE + '\n');
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
},
|
||||
|
||||
@ -59,15 +66,6 @@ Ionic.prototype = {
|
||||
process.stdout.write('| / \\ |\\ | | / `\n' + '| \\__/ | \\| | \\__,\n\n');
|
||||
},
|
||||
|
||||
_writeTemplateFolder: function() {
|
||||
console.log('Copying template to', this.targetPath);
|
||||
ncp('template', this.appName, function(err) {
|
||||
if(err) {
|
||||
this._fail('Unable to build starter folder', err);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Prompt the user for a response
|
||||
ask: function(question) {
|
||||
var response;
|
||||
@ -78,44 +76,17 @@ Ionic.prototype = {
|
||||
process.stdin.pause();
|
||||
return response[0].trim();
|
||||
},
|
||||
|
||||
_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;
|
||||
},
|
||||
|
||||
_loadTaskRunner: function(which) {
|
||||
|
||||
},
|
||||
|
||||
run: function() {
|
||||
var task = this._tryBuildingTask();
|
||||
if(task === false) {
|
||||
return this._printUsage();
|
||||
if(!task) {
|
||||
return this._printGenericUsage();
|
||||
}
|
||||
|
||||
console.log('Running', task.task.title, 'task...')
|
||||
|
||||
return
|
||||
|
||||
this.appName = argv._[0];
|
||||
this.targetPath = path.resolve(this.appName);
|
||||
|
||||
// Make sure to create this, or ask them if they want to override it
|
||||
if(this._checkTargetPath() === false) {
|
||||
process.stderr.write('Not continuing.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Creating Ionic app in folder', this.targetPath);
|
||||
|
||||
this._writeTemplateFolder();
|
||||
},
|
||||
|
||||
fail: function(msg) {
|
||||
|
||||
@ -3,11 +3,39 @@ var fs = require('fs'),
|
||||
path = require('path'),
|
||||
IonicTask = require('./task').IonicTask;
|
||||
|
||||
var argv = require('optimist').argv;
|
||||
|
||||
var IonicStartTask = function() {
|
||||
}
|
||||
|
||||
IonicStartTask.prototype = new IonicTask();
|
||||
IonicStartTask.prototype.run = function(ionic) {
|
||||
IonicStartTask.HELP_LINE = 'Start a new Ionic project with the given name.';
|
||||
|
||||
IonicStartTask.prototype = new IonicTask();
|
||||
|
||||
|
||||
IonicStartTask.prototype.run = function(ionic) {
|
||||
this.appName = argv._[0];
|
||||
this.targetPath = path.resolve(this.appName);
|
||||
|
||||
// Make sure to create this, or ask them if they want to override it
|
||||
if(this._checkTargetPath() === false) {
|
||||
process.stderr.write('Not continuing.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('Creating Ionic app in folder', this.targetPath);
|
||||
|
||||
this._writeTemplateFolder();
|
||||
};
|
||||
|
||||
IonicStartTask.prototype._writeTemplateFolder = function() {
|
||||
console.log('Copying template to', this.targetPath);
|
||||
ncp('template', this.appName, function(err) {
|
||||
if(err) {
|
||||
this._fail('Unable to build starter folder', err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
exports.IonicStartTask = IonicStartTask;
|
||||
Reference in New Issue
Block a user