Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
fixes #113
Browse files Browse the repository at this point in the history
  • Loading branch information
toddgeist committed Apr 14, 2016
1 parent a022c72 commit 54e12e5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions generators/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function importService(filename, name, moduleName) {
var ast = transform.parse(content);

transform.addImport(ast, name, moduleName);
name = inflect.camelize(inflect.underscore(name), false);
transform.addLastInFunction(ast, 'module.exports', 'app.configure(' + name + ');');

fs.writeFileSync(filename, transform.print(ast));
Expand Down
4 changes: 4 additions & 0 deletions lib/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var recast = require('recast');
var traverse = require('ast-traverse');
var inflect = require('i')();

var parse = exports.parse = function(code) {
return recast.parse(code);
Expand Down Expand Up @@ -88,6 +89,9 @@ exports.addLastInFunction = function(ast, search, code) {
};

exports.addImport = function(ast, varname, modulename) {

varname = inflect.camelize(inflect.underscore(varname), false)

ast = convert(ast);

var index = 0;
Expand Down
22 changes: 22 additions & 0 deletions test/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,28 @@ describe('transforms', () => {
};
`);
});

it('addImport with hyphenated-name', () => {
const ast = transform.addImport(`
const first = require('first');
module.exports = function() {
// A comment
};
`, 'my-service', 'my-service');

const output = transform.print(ast);

assert.equal(output, `
const myService = require('my-service');
const first = require('first');
module.exports = function() {
// A comment
};
`);
});


it('addImport with \'use strict\';', () => {
const code = `
Expand Down

0 comments on commit 54e12e5

Please sign in to comment.