Permalink
Browse files

Merge branch 'master' of github.com:IndigoUnited/automaton

  • Loading branch information...
2 parents 43dab1c + 089bacd commit 1b8d32b16db9aded26c7a28df7a2364dfc92183b @filipediasf filipediasf committed Dec 4, 2012
Showing with 40 additions and 24 deletions.
  1. +1 −1 .jshintrc
  2. +18 −3 bin/automaton.js
  3. +3 −2 index.js
  4. +1 −1 package.json
  5. +1 −1 tasks/scaffolding-append.js
  6. +7 −7 tasks/scaffolding-close.js
  7. +9 −9 tasks/scaffolding-replace.js
View
@@ -13,7 +13,7 @@
"eqeqeq": true,
"forin": false,
"immed": true,
- "latedef": true,
+ "latedef": false,
"newcap": true,
"noarg": true,
"noempty": false,
View
@@ -117,12 +117,13 @@ if (argv.help || argv.h) {
process.exit();
}
-
+console.log(argv);
// if a command was specified, run it
if (argv._.length) {
switch (argv._[0]) {
case 'init':
- initTask(argv._[1]);
+ var taskId = argv._[1] || 'autofile';
+ initTask(taskId);
break;
default:
@@ -149,6 +150,11 @@ if (argv._.length) {
else {
var task = getTaskFromFile();
+ if (!task) {
+ showUsage();
+ process.exit();
+ }
+
//runTask(task, getTaskOptFromArgv(task));
runTask(task, argv);
}
@@ -234,7 +240,16 @@ function showTaskUsage(task) {
}
function initTask(taskId) {
- console.log('initing', taskId);
+ runTask('task-init', {
+ 'name': taskId
+ }, function (err) {
+ if (err) {
+ console.error('Unable to create task');
+ process.exit(1);
+ }
+
+ console.log('Task initialized'.info);
+ });
}
function getTaskFromFile(file) {
View
@@ -6,7 +6,8 @@
colors = require('colors'),
fs = require('fs'),
util = require('util'),
- async = require('async')
+ async = require('async'),
+ path = require('path')
;
var inspect = function (v, levels) {
@@ -156,7 +157,7 @@
;
for (i = filenames.length - 1; i >= 0; --i) {
- this.addTask(require(folder + filenames[i].split(/\./)[0]));
+ this.addTask(require(folder + path.basename(filenames[i], '.js')));
}
return this;
View
@@ -1,6 +1,6 @@
{
"name": "automaton",
- "version": "0.0.10",
+ "version": "0.0.11",
"description": "Task automation tool",
"main": "index.js",
"scripts": {
@@ -41,7 +41,7 @@ var task = {
// append to placeholder
var tmp = opt.where.lastIndexOf(':');
var filename = opt.where.substr(0, tmp),
- placeholder = opt.where.substr(tmp),
+ placeholder = opt.where.substr(tmp + 1),
processedData,
placeholderData = {}
;
View
@@ -17,18 +17,18 @@ var task = {
{
'task' : function (opt, next) {
// check if a placeholder was specified
- var where = path.basename(opt.where);
- if (where.indexOf(':') > -1) {
- // append to placeholder
- var tmp = opt.where.lastIndexOf(':');
- var filename = opt.where.substr(0, tmp),
- placeholder = opt.where.substr(tmp),
+ var placeholder = path.basename(opt.placeholder);
+ if (placeholder.indexOf(':') > -1) {
+ // close placeholder
+ var tmp = opt.placeholder.lastIndexOf(':');
+ var filename = opt.placeholder.substr(0, tmp),
+ _placeholder = opt.placeholder.substr(tmp + 1),
processedData,
placeholderData = {}
;
// generate the placeholder data
- placeholderData[placeholder] = '';
+ placeholderData[_placeholder] = '';
processedData = utils.string.interpolate(fs.readFileSync(filename, 'utf8'), placeholderData);
@@ -24,7 +24,7 @@ var task = {
{
'task' : function (opt, next) {
var _with;
-
+console.log(opt);
// if type is file, then read its contents first
if (opt.type === 'file') {
// TODO: check if file exists
@@ -35,26 +35,26 @@ var task = {
}
// check if a placeholder was specified
- var where = path.basename(opt.where);
- if (where.indexOf(':') > -1) {
- // append to placeholder
- var tmp = opt.where.lastIndexOf(':');
- var filename = opt.where.substr(0, tmp),
- placeholder = opt.where.substr(tmp),
+ var what = path.basename(opt.what);
+ if (what.indexOf(':') > -1) {
+ // replace placeholder
+ var tmp = opt.what.lastIndexOf(':');
+ var filename = opt.what.substr(0, tmp),
+ placeholder = opt.what.substr(tmp + 1),
processedData,
placeholderData = {}
;
// generate the placeholder data
placeholderData[placeholder] = _with;
-
+console.log(filename, placeholder, placeholderData);
processedData = utils.string.interpolate(fs.readFileSync(filename, 'utf8'), placeholderData);
fs.writeFileSync(filename, processedData, 'utf8');
}
else {
// just replace the file, if it exists
- fs.writeFileSync(opt.where, _with, 'utf8');
+ fs.writeFileSync(opt.what, _with, 'utf8');
}
next();

0 comments on commit 1b8d32b

Please sign in to comment.