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

Allow hyphenated-names in services - fixes #113 #114

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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