mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 06:57:02 +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/)
|
Copyright 2013 Drifty (http://drifty.com/)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var argv = require('optimist').argv,
|
var IonicStartTask = require('./lib/ionic/start.js').IonicStartTask;
|
||||||
IonicStartTask = require('./lib/ionic/start.js');
|
|
||||||
|
var argv = require('optimist').argv;
|
||||||
|
|
||||||
var TASKS = [
|
var TASKS = [
|
||||||
{
|
{
|
||||||
title: 'New Project',
|
title: 'start',
|
||||||
name: 'start',
|
name: 'start',
|
||||||
usage: 'appname',
|
usage: 'appname',
|
||||||
task: IonicStartTask
|
task: IonicStartTask
|
||||||
@ -48,9 +49,15 @@ Ionic.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_printUsage: function() {
|
_printGenericUsage: function() {
|
||||||
this._printIonic();
|
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);
|
process.exit(1);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -59,15 +66,6 @@ Ionic.prototype = {
|
|||||||
process.stdout.write('| / \\ |\\ | | / `\n' + '| \\__/ | \\| | \\__,\n\n');
|
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
|
// Prompt the user for a response
|
||||||
ask: function(question) {
|
ask: function(question) {
|
||||||
var response;
|
var response;
|
||||||
@ -78,44 +76,17 @@ Ionic.prototype = {
|
|||||||
process.stdin.pause();
|
process.stdin.pause();
|
||||||
return response[0].trim();
|
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) {
|
_loadTaskRunner: function(which) {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
run: function() {
|
run: function() {
|
||||||
var task = this._tryBuildingTask();
|
var task = this._tryBuildingTask();
|
||||||
if(task === false) {
|
if(!task) {
|
||||||
return this._printUsage();
|
return this._printGenericUsage();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Running', task.task.title, 'task...')
|
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) {
|
fail: function(msg) {
|
||||||
|
|||||||
@ -3,11 +3,39 @@ var fs = require('fs'),
|
|||||||
path = require('path'),
|
path = require('path'),
|
||||||
IonicTask = require('./task').IonicTask;
|
IonicTask = require('./task').IonicTask;
|
||||||
|
|
||||||
|
var argv = require('optimist').argv;
|
||||||
|
|
||||||
var IonicStartTask = function() {
|
var IonicStartTask = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
IonicStartTask.prototype = new IonicTask();
|
IonicStartTask.HELP_LINE = 'Start a new Ionic project with the given name.';
|
||||||
IonicStartTask.prototype.run = function(ionic) {
|
|
||||||
|
|
||||||
|
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