From 40434a0eb54686113931669ed2dcc65f9759fc45 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Mon, 2 Dec 2013 17:11:56 -0800 Subject: [PATCH] Basic adaptor generation Adds a `cylon` script, build with Commander.js. Only functionality right now is to generate adaptors, still need to determine what files are necessary for new adaptors and to add templating. --- bin/cylon | 13 +++++++++++++ package.json | 4 +++- src/generators/adaptor.js | 26 ++++++++++++++++++++++++++ src/generators/adaptor/package.json | 0 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100755 bin/cylon create mode 100644 src/generators/adaptor.js create mode 100644 src/generators/adaptor/package.json diff --git a/bin/cylon b/bin/cylon new file mode 100755 index 0000000..1640c95 --- /dev/null +++ b/bin/cylon @@ -0,0 +1,13 @@ +#!/usr/bin/env node + +var program = require('commander'), + cylon = require('../package.json'); + +program.version(cylon.version); + +program + .command("generate ") + .description("Generates a new adaptor") + .action(function(name) { require('../src/generators/adaptor')(name) }); + +program.parse(process.argv); diff --git a/package.json b/package.json index 06cca11..d9d0671 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ "sinon-chai": "~2.4.0", "chai": "~1.7.2", "mocha": "~1.12.1", - "sinon": "~1.7.3" + "sinon": "~1.7.3", + "wrench": "~1.5.4", + "commander": "~2.1.0" }, "dependencies": { "async": "~0.2.9", diff --git a/src/generators/adaptor.js b/src/generators/adaptor.js new file mode 100644 index 0000000..6d58ab6 --- /dev/null +++ b/src/generators/adaptor.js @@ -0,0 +1,26 @@ +var wrench = require('wrench'); + +var adaptorName = ""; + +// Returns a cylon-namespaced adaptor name +var cylonAdaptorName = function() { + return "cylon-" + adaptorName; +}; + +// Converts the adaptor name to from camel_case to snake_case +var adaptorClassName = function() { + return String(adaptorName) + .replace(/[\W_]/g, ' ') + .toLowerCase() + .replace(/(?:^|\s|-)\S/g, function(c){ return c.toUpperCase(); }) + .replace(/\s/g, ''); +}; + +var generator = function(name) { + adaptorName = name; + console.log("Creating " + cylonAdaptorName() + " adaptor..."); + wrench.copyDirSyncRecursive(__dirname + "/adaptor", cylonAdaptorName()); + console.log("Done!"); +}; + +module.exports = generator; diff --git a/src/generators/adaptor/package.json b/src/generators/adaptor/package.json new file mode 100644 index 0000000..e69de29