Extending ionic tool to have multiple task support.

This commit is contained in:
Max Lynch
2013-09-08 21:52:33 -05:00
parent 6c89a3d68e
commit 6ae11762f0
4 changed files with 73 additions and 21 deletions

View File

@ -3,32 +3,54 @@
| / \ |\ | | / ` | / \ |\ | | / `
| \__/ | \| | \__, | \__/ | \| | \__,
http://ionicframework.com/
A utility for starting and administering Ionic based mobile app projects.
Licensed under the Apache 2.0 license. See LICENSE For mroe. Licensed under the Apache 2.0 license. See LICENSE For mroe.
Copyright 2013 Drifty (http://drifty.com/) Copyright 2013 Drifty (http://drifty.com/)
*/ */
var fs = require('fs'), var argv = require('optimist').argv,
ncp = require('ncp').ncp, IonicStartTask = require('./lib/ionic/start.js');
path = require('path'),
argv = require('optimist')
.usage('Usage: ionic appname')
.argv;
Ionic = function() { var TASKS = [
}; {
title: 'New Project',
name: 'start',
usage: 'appname',
task: IonicStartTask
}
];
Ionic = function() {};
Ionic.prototype = { Ionic.prototype = {
_checkArgs: function() { _tryBuildingTask: function() {
if(argv._.length == 0) { if(argv._.length == 0) {
return false; return false;
} }
return true; var taskName = argv._[0];
var task = this._getTaskWithName(taskName);
return {
task: task
}
},
_getTaskWithName: function(name) {
for(var i = 0; i < TASKS.length; i++) {
var t = TASKS[i];
if(t.name === name) {
return t;
}
}
}, },
_printUsage: function() { _printUsage: function() {
this._printIonic(); this._printIonic();
process.stderr.write('Usage: ionic appname\n'); process.stderr.write('Usage: ionic task args\n');
process.exit(1); process.exit(1);
}, },
@ -37,11 +59,6 @@ Ionic.prototype = {
process.stdout.write('| / \\ |\\ | | / `\n' + '| \\__/ | \\| | \\__,\n\n'); process.stdout.write('| / \\ |\\ | | / `\n' + '| \\__/ | \\| | \\__,\n\n');
}, },
_fail: function(msg) {
process.stderr.write(msg + '\n');
process.exit(1);
},
_writeTemplateFolder: function() { _writeTemplateFolder: function() {
console.log('Copying template to', this.targetPath); console.log('Copying template to', this.targetPath);
ncp('template', this.appName, function(err) { ncp('template', this.appName, function(err) {
@ -52,7 +69,7 @@ Ionic.prototype = {
}, },
// Prompt the user for a response // Prompt the user for a response
_ask: function(question) { ask: function(question) {
var response; var response;
process.stdout.write(question + ' '); process.stdout.write(question + ' ');
@ -73,12 +90,19 @@ Ionic.prototype = {
return true; return true;
}, },
_loadTaskRunner: function(which) {
},
run: function() { run: function() {
if(this._checkArgs() === false) { var task = this._tryBuildingTask();
if(task === false) {
return this._printUsage(); return this._printUsage();
} }
this._printIonic(); console.log('Running', task.task.title, 'task...')
return
this.appName = argv._[0]; this.appName = argv._[0];
this.targetPath = path.resolve(this.appName); this.targetPath = path.resolve(this.appName);
@ -92,7 +116,13 @@ Ionic.prototype = {
console.log('Creating Ionic app in folder', this.targetPath); console.log('Creating Ionic app in folder', this.targetPath);
this._writeTemplateFolder(); this._writeTemplateFolder();
} },
fail: function(msg) {
process.stderr.write(msg + '\n');
process.exit(1);
},
}; };

View File

@ -0,0 +1,13 @@
var fs = require('fs'),
ncp = require('ncp').ncp,
path = require('path'),
IonicTask = require('./task').IonicTask;
var IonicStartTask = function() {
}
IonicStartTask.prototype = new IonicTask();
IonicStartTask.prototype.run = function(ionic) {
};

View File

@ -0,0 +1,9 @@
var IonicTask = function() {
};
IonicTask.prototype = {
run: function(ionic) {
}
};
exports.IonicTask = IonicTask;

View File

@ -3,7 +3,7 @@
"version": "0.0.1", "version": "0.0.1",
"description": "A utility for starting Ionic projects.", "description": "A utility for starting Ionic projects.",
"homepage": "http://ionicframework.com/", "homepage": "http://ionicframework.com/",
"main": "index.js", "main": "ionic.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },