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.
This commit is contained in:
Andrew Stewart 2013-12-02 17:11:56 -08:00
parent 0608e53991
commit 40434a0eb5
4 changed files with 42 additions and 1 deletions

13
bin/cylon Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env node
var program = require('commander'),
cylon = require('../package.json');
program.version(cylon.version);
program
.command("generate <name>")
.description("Generates a new adaptor")
.action(function(name) { require('../src/generators/adaptor')(name) });
program.parse(process.argv);

View File

@ -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",

26
src/generators/adaptor.js Normal file
View File

@ -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;

View File