Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camel case replacement #45

Merged
merged 3 commits into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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