Skip to content

Commit

Permalink
[CLI] Handle underscores in app name when replacing prefix (#817)
Browse files Browse the repository at this point in the history
* Handle underscores in app name when replacing prefix

* Remove display name from vue content block
  • Loading branch information
CobyPear authored Sep 20, 2021
1 parent f9e0450 commit 3fc85de
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/sitecore-jss-cli/src/create/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ describe('getPascalCaseName', () => {
expect(result).to.match(/MyNextSitecoreApp/);
});

it('should reformat snake_case to PascalCase', () => {
const result = getPascalCaseName('my_next_sitecore_app');

expect(result).to.match(/MyNextSitecoreApp/);
});

it('should reformat one word lowercase app name to be capitalized', () => {
const result = getPascalCaseName('onewordappnamenohyphen');

Expand Down
3 changes: 2 additions & 1 deletion packages/sitecore-jss-cli/src/create/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export function applyNameToProject(
* @param {string} name
*/
export function getPascalCaseName(name: string): string {
const temp: string[] = name.split('-');
// handle underscores by converting them to hyphens
const temp: string[] = name.replace(/_/g, '-').split('-');
name = temp.map((item: string) => (item = item.charAt(0).toUpperCase() + item.slice(1))).join('');
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function(manifest) {
manifest.addComponent({
name: 'ContentBlock',
templateName: 'JssVueWeb-ContentBlock',
displayName: 'Content Block',
// totally optional, but fun
icon: SitecoreIcon.DocumentTag,
fields: [
Expand Down

0 comments on commit 3fc85de

Please sign in to comment.