diff --git a/test/utils/yeomanTest.js b/test/utils/yeomanTest.js index eff08ac..8e2b006 100644 --- a/test/utils/yeomanTest.js +++ b/test/utils/yeomanTest.js @@ -94,4 +94,19 @@ describe('Utilities:Yeoman', () => { }); }); + describe('#getDestinationPath', () => { + + it('should return the correct filesystem path for all components', () => { + + expect(utils.getDestinationPath('test', 'action', 'Actions')).to.equal('src/actions/TestActions.js'); + expect(utils.getDestinationPath('subfolder/test', 'action', 'Actions')).to.equal('src/actions/subfolder/TestActions.js'); + + expect(utils.getDestinationPath('test', 'source', 'Source')).to.equal('src/sources/TestSource.js'); + expect(utils.getDestinationPath('subfolder/test', 'source', 'Source')).to.equal('src/sources/subfolder/TestSource.js'); + + expect(utils.getDestinationPath('test', 'store', 'Store')).to.equal('src/stores/TestStore.js'); + expect(utils.getDestinationPath('subfolder/test', 'store', 'Store')).to.equal('src/stores/subfolder/TestStore.js'); + }); + }); + }); diff --git a/utils/yeoman.js b/utils/yeoman.js index 3bf0764..b56476d 100644 --- a/utils/yeoman.js +++ b/utils/yeoman.js @@ -113,10 +113,37 @@ let getAppName = (appName) => { return _.camelize(_.slugify(_.humanize(appName))); }; +/** + * Get the wanted destination path + * @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} Final path + */ +let getDestinationPath = (name, type, suffix) => { + + let cleanedPaths = getCleanedPathName(name, suffix); + let fsParts = cleanedPaths.split('/'); + let actionBaseName = _.capitalize(fsParts.pop()); + let partPath = fsParts.join('/'); + + let fsPath = configUtils.getChoiceByKey('path', type).path; + + let parts = [ fsPath ]; + if(partPath.length > 0) { + parts.push(partPath); + } + parts.push(actionBaseName); + let fullPath = parts.join('/'); + + return `${fullPath}.js`; +}; + module.exports = { getBaseDir: getBaseDir, getAllSettingsFromComponentName: getAllSettingsFromComponentName, getAppName: getAppName, getCleanedPathName: getCleanedPathName, - getComponentStyleName: getComponentStyleName + getComponentStyleName: getComponentStyleName, + getDestinationPath: getDestinationPath };