diff --git a/test/utils/yeomanTest.js b/test/utils/yeomanTest.js index 8e2b006..7368526 100644 --- a/test/utils/yeomanTest.js +++ b/test/utils/yeomanTest.js @@ -109,4 +109,12 @@ describe('Utilities:Yeoman', () => { }); }); + describe('#getDestinationClassName', () => { + + it('should return the correct javascript class name for the given paths', () => { + expect(utils.getDestinationClassName('test', 'action', 'Actions')).to.equal('TestActions'); + expect(utils.getDestinationClassName('test', 'source', 'Source')).to.equal('TestSource'); + expect(utils.getDestinationClassName('test', 'store', 'Store')).to.equal('TestStore'); + }); + }); }); diff --git a/utils/yeoman.js b/utils/yeoman.js index b56476d..a19fe9a 100644 --- a/utils/yeoman.js +++ b/utils/yeoman.js @@ -139,11 +139,25 @@ let getDestinationPath = (name, type, suffix) => { return `${fullPath}.js`; }; +/** + * Get the destinations class name + * @param {String} name Name of the file + * @param {String} type The type to use (e.g. action, store, ...) + * @param {Suffix} suffix The suffix to use for the file (e.g. Store, Actions, ...) + * @return {String} The javascript class name to use + */ +let getDestinationClassName = (name, type, suffix) => { + + let fixedName = getDestinationPath(name, type, suffix); + return _.capitalize(fixedName.split('/').pop().split('.js')[0]); +}; + module.exports = { getBaseDir: getBaseDir, getAllSettingsFromComponentName: getAllSettingsFromComponentName, getAppName: getAppName, getCleanedPathName: getCleanedPathName, getComponentStyleName: getComponentStyleName, - getDestinationPath: getDestinationPath + getDestinationPath: getDestinationPath, + getDestinationClassName: getDestinationClassName };