Skip to content

Commit

Permalink
Merge pull request #45 from laurens-in/camelCase-replacement
Browse files Browse the repository at this point in the history
Camel case replacement
  • Loading branch information
arminbro authored Jun 12, 2021
2 parents 658fc0a + e858259 commit 8939bbf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ There is an optional `customTemplates` object that you can pass to the `componen
},
```

The keys represent the type of file, and the values are the paths that point to where your custom template lives in your project/system. Please note the `TemplateName` keyword in the template filename. GRC will use this keyword and replace it with your component name as the filename.
The keys represent the type of file, and the values are the paths that point to where your custom template lives in your project/system. Please note the `TemplateName` keyword in the template filename. GRC will use this keyword and replace it with your component name as the filename. You can also use the keyword `templateName`, which will be replaced with your component name in camelCase.

#### Example of using the `customTemplates` object within your generate-react-cli.json config file:

Expand Down
2 changes: 1 addition & 1 deletion src/templates/component/componentTsTemplate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = `import React from 'react';
import styles from './TemplateName.module.css';
const TemplateName: React.FC = () => (
const TemplateName = () => (
<div className={styles.TemplateName} data-testid="TemplateName">
TemplateName Component
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/utils/generateComponentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ function generateComponent(componentName, cmd, cliConfigFile) {
silent: true,
});

replace({
regex: 'templateName',
replacement: camelCase(componentName),
paths: [componentPath],
recursive: false,
silent: true,
});

console.log(chalk.green(`${filename} was successfully created at ${componentPath}`));
} catch (error) {
console.error(chalk.red(`${filename} failed and was not created.`));
Expand Down

0 comments on commit 8939bbf

Please sign in to comment.