Templating for generating adaptors in place
This commit is contained in:
parent
40434a0eb5
commit
519ce65d01
|
@ -1,9 +1,11 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
var program = require('commander'),
|
var program = require('commander'),
|
||||||
cylon = require('../package.json');
|
pkg = require('../package.json');
|
||||||
|
|
||||||
program.version(cylon.version);
|
program
|
||||||
|
.version(pkg.version)
|
||||||
|
.usage('[command] [options]');
|
||||||
|
|
||||||
program
|
program
|
||||||
.command("generate <name>")
|
.command("generate <name>")
|
||||||
|
@ -11,3 +13,6 @@ program
|
||||||
.action(function(name) { require('../src/generators/adaptor')(name) });
|
.action(function(name) { require('../src/generators/adaptor')(name) });
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
||||||
|
// print help if no arguments were provided
|
||||||
|
if(!program.args.length) { program.help(); }
|
||||||
|
|
14
package.json
14
package.json
|
@ -19,6 +19,9 @@
|
||||||
"type": "Apache 2.0"
|
"type": "Apache 2.0"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"bin": {
|
||||||
|
"cylon": "./bin/cylon"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"matchdep": "~0.1.1",
|
"matchdep": "~0.1.1",
|
||||||
"grunt-contrib-jshint": "~0.6.0",
|
"grunt-contrib-jshint": "~0.6.0",
|
||||||
|
@ -29,13 +32,16 @@
|
||||||
"sinon-chai": "~2.4.0",
|
"sinon-chai": "~2.4.0",
|
||||||
"chai": "~1.7.2",
|
"chai": "~1.7.2",
|
||||||
"mocha": "~1.12.1",
|
"mocha": "~1.12.1",
|
||||||
"sinon": "~1.7.3",
|
"sinon": "~1.7.3"
|
||||||
"wrench": "~1.5.4",
|
|
||||||
"commander": "~2.1.0"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "~0.2.9",
|
"async": "~0.2.9",
|
||||||
"node-namespace": "~1.0.0",
|
"node-namespace": "~1.0.0",
|
||||||
"express.io": "~1.1.13"
|
"express.io": "~1.1.13",
|
||||||
|
|
||||||
|
"wrench": "~1.5.4",
|
||||||
|
"glob": "~3.2.7",
|
||||||
|
"ejs": "~0.8.5",
|
||||||
|
"commander": "~2.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
var wrench = require('wrench');
|
var wrench = require('wrench'),
|
||||||
|
ejs = require('ejs'),
|
||||||
var adaptorName = "";
|
glob = require('glob'),
|
||||||
|
fs = require('fs'),
|
||||||
|
pkg = require('../../package.json'),
|
||||||
|
adaptorName = "";
|
||||||
|
|
||||||
// Returns a cylon-namespaced adaptor name
|
// Returns a cylon-namespaced adaptor name
|
||||||
var cylonAdaptorName = function() {
|
var cylonAdaptorName = function() {
|
||||||
|
@ -16,11 +19,46 @@ var adaptorClassName = function() {
|
||||||
.replace(/\s/g, '');
|
.replace(/\s/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var compileTemplates = function() {
|
||||||
|
console.log("Compiling templates.");
|
||||||
|
|
||||||
|
glob(cylonAdaptorName() + "/**/*.tpl", function(err, files) {
|
||||||
|
files.forEach(function(filename) {
|
||||||
|
var templateData = generateTemplateData();
|
||||||
|
|
||||||
|
var newFilename = String(filename)
|
||||||
|
.replace(/adaptorName/, cylonAdaptorName())
|
||||||
|
.replace(/\.tpl$/, '');
|
||||||
|
|
||||||
|
fs.rename(filename, newFilename, function(err) {
|
||||||
|
if (err) { return console.log(err); }
|
||||||
|
|
||||||
|
fs.readFile(newFilename, 'utf8', function(err, contents) {
|
||||||
|
if (err) { return console.log(err); }
|
||||||
|
var result = ejs.render(contents, templateData);
|
||||||
|
|
||||||
|
fs.writeFile(newFilename, result, function(err) {
|
||||||
|
if (err) { return console.log(err); }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var generateTemplateData = function() {
|
||||||
|
return {
|
||||||
|
adaptorName: cylonAdaptorName(),
|
||||||
|
adaptorClassName: adaptorClassName(),
|
||||||
|
cylonVersion: pkg.version
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var generator = function(name) {
|
var generator = function(name) {
|
||||||
adaptorName = name;
|
adaptorName = name;
|
||||||
console.log("Creating " + cylonAdaptorName() + " adaptor...");
|
console.log("Creating " + cylonAdaptorName() + " adaptor.");
|
||||||
wrench.copyDirSyncRecursive(__dirname + "/adaptor", cylonAdaptorName());
|
wrench.copyDirSyncRecursive(__dirname + "/adaptor", cylonAdaptorName());
|
||||||
console.log("Done!");
|
compileTemplates();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = generator;
|
module.exports = generator;
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"name": "<%= adaptorName %>",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"main": "dist/<%= adaptorName %>.js",
|
||||||
|
"description": "Cylon module for <%= adaptorClassName %>",
|
||||||
|
"homepage": "http://cylonjs.com",
|
||||||
|
"bugs": "Your bug report URL here",
|
||||||
|
"author": {
|
||||||
|
"name": "Your Name Here",
|
||||||
|
"email": "Your Email Here",
|
||||||
|
"url": "Your URL here"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "your git URL here"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "Apache 2.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"devDependencies": {
|
||||||
|
"matchdep": "~0.1.1",
|
||||||
|
"grunt-contrib-jshint": "~0.6.0",
|
||||||
|
"grunt-contrib-watch": "~0.5.0",
|
||||||
|
"grunt-contrib-coffee": "~0.7.0",
|
||||||
|
"grunt-simple-mocha": "~0.4.0",
|
||||||
|
"grunt-contrib-clean": "~0.5.0",
|
||||||
|
"sinon-chai": "~2.4.0",
|
||||||
|
"chai": "~1.7.2",
|
||||||
|
"mocha": "~1.12.1",
|
||||||
|
"sinon": "~1.7.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"node-namespace": "~1.0.0",
|
||||||
|
"cylon": "~<%= cylonVersion %>"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue