diff --git a/create-sails-generator/package.json b/create-sails-generator/package.json index 8c164c5..7eb879c 100644 --- a/create-sails-generator/package.json +++ b/create-sails-generator/package.json @@ -1,6 +1,6 @@ { "name": "create-sails-generator", - "version": "0.0.1", + "version": "0.0.2", "description": "Sails generator for The Boring JavaScript Stack.", "scripts": { "test": "node --test" diff --git a/create-sails-generator/tests/utils/get-action-name.test.js b/create-sails-generator/tests/utils/get-action-name.test.js index 732b330..4aea7a3 100644 --- a/create-sails-generator/tests/utils/get-action-name.test.js +++ b/create-sails-generator/tests/utils/get-action-name.test.js @@ -9,4 +9,10 @@ describe('getActionName', function () { it("returns 'user/view-users' when given 'users/index'", function () { assert.equal(getActionName('users/index'), 'user/view-users') }) + it("returns 'user/view-user' when given 'users/user'", function () { + assert.equal(getActionName('users/user'), 'user/view-user') + }) + it("returns 'user/view-profile' when given 'users/profile'", function () { + assert.equal(getActionName('users/profile'), 'user/view-profile') + }) }) diff --git a/create-sails-generator/utils/get-action-name.js b/create-sails-generator/utils/get-action-name.js index 8167db3..d28b0cf 100644 --- a/create-sails-generator/utils/get-action-name.js +++ b/create-sails-generator/utils/get-action-name.js @@ -1,7 +1,9 @@ module.exports = function getActionName(pageName) { - if (!pageName.includes('/')) return 'view-' + pageName - const [firstPart] = pageName.split('/') - const actionName = 'view-' + firstPart - const singularizedFirsPart = firstPart.replace(/s$/, '') - return `${singularizedFirsPart}/${actionName}` + if (!pageName.includes('/')) return `view-${pageName}` + + const [firstPart, secondPart] = pageName.split('/') + const actionName = + secondPart === 'index' ? `view-${firstPart}` : `view-${secondPart}` + + return `${firstPart.replace(/s$/, '')}/${actionName}` } diff --git a/package.json b/package.json index c335bac..e71a776 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "boring-stack", - "version": "0.2.3", + "version": "0.2.4", "private": "true", "description": "The Boring JavaScript Stack 🥱 - an opinionated project starter for fullstack JavaScript", "scripts": {