A VS Code extension for generating and managing component files. While designed with React components in mind, it's framework-agnostic and can be used for any project that follows a component-based architecture.
- Create components with multiple files from templates
- Add files to existing components
- Rename components and imports to them
- Fork component with deep renaming
- Supports defining and slecting from multiple template groups
- Smart case transforms for internal references to component names
- Install from VS Code marketplace: search for "Component Manager"
- Create
.component-templates.json
in your project root - Create a directory next to your config file to store your templates (e.g., "component-templates")
- Right-click any folder in VS Code's explorer and select "Component > Create..."
- Install the extension from the VS Code marketplace
- Create a
.component-templates.json
configuration file in your project root - Create your template directory as a sibling to your config file
- Right-click in the explorer to access component generation commands
Create a .component-templates.json
file in your project root or any parent directory of where you'll be creating components.
{
"templatesDirectory": "component-templates",
"directoryCase": "pascal",
"defaultTemplateGroup": ["component.tsx.template", "index.ts.template", "styles.scss.template"],
"templates": [
{
"source": "component.tsx.template",
"target": "{{PascalCaseComponentName}}.tsx",
"label": "Component"
},
{
"source": "index.ts.template",
"target": "index.ts",
"label": "Index"
},
{
"source": "styles.scss.template",
"target": "{{PascalCaseComponentName}}.module.scss",
"label": "Styles"
}
]
}
templatesDirectory
: Directory containing template files (relative to config file location)directoryCase
(optional): Specifies the case format for component directories. Can be one of: "pascal", "camel", "kebab", or "snake"defaultTemplateGroup
: Array of template sources to use for the default "Create..." commandalternateTemplateGroups
(optional): Array of named template groups for the "Create (choose file set)..." commandtemplates
: Array of template configurations with the following properties:source
: Template file name in the templates directorytarget
: Output file name (can include case-sensitive tokens)label
: Display name for the template in the UI
You can use these tokens in template files and target filenames for automatic case transformation:
{{PascalCaseComponentName}}
→ MyComponent{{camelCaseComponentName}}
→ myComponent{{kebab-case-component-name}}
→ my-component{{snake_case_component_name}}
→ my_component
{
"templatesDirectory": "component-templates",
"directoryCase": "pascal",
"defaultTemplateGroup": [
"component.tsx.template",
"index.ts.template",
"styles.scss.template",
"test.tsx.template"
],
"alternateTemplateGroups": [
{
"label": "Simple Component",
"templates": ["component-simple.tsx.template", "index.ts.template"]
},
{
"label": "Full Feature Set",
"templates": [
"component.tsx.template",
"index.ts.template",
"styles.scss.template",
"test.tsx.template",
"types.ts.template"
]
}
],
"templates": [
{
"source": "component.tsx.template",
"target": "{{PascalCaseComponentName}}.tsx",
"label": "Component"
},
{
"source": "component-simple.tsx.template",
"target": "{{PascalCaseComponentName}}.tsx",
"label": "Simple Component"
},
{
"source": "index.ts.template",
"target": "index.ts",
"label": "Index"
},
{
"source": "styles.scss.template",
"target": "{{PascalCaseComponentName}}.module.scss",
"label": "Styles"
},
{
"source": "test.tsx.template",
"target": "{{PascalCaseComponentName}}.test.tsx",
"label": "Test"
},
{
"source": "types.ts.template",
"target": "types.ts",
"label": "Types"
}
]
}
import styles from './{{PascalCaseComponentName}}.module.scss';
type {{PascalCaseComponentName}}Props = {};
const {{PascalCaseComponentName}} = ({}: {{PascalCaseComponentName}}Props) => {
return <div className={styles.{{camelCaseComponentName}}}></div>;
};
export default {{PascalCaseComponentName}};
.{{camelCaseComponentName}} {
}
export { default } from './{{PascalCaseComponentName}}';
import { render } from '@testing-library/react';
import {{PascalCaseComponentName}} from './{{PascalCaseComponentName}}';
describe('{{PascalCaseComponentName}}', () => {
it('renders without crashing', () => {
render(<{{PascalCaseComponentName}} />);
});
});
Right-click in the file explorer to access these commands:
-
Create...
- Creates a new component using the default template group
- Component name can be in PascalCase, camelCase, kebab-case, or snake_case
-
Create (choose file set)...
- Creates a new component after selecting from available template groups
- Shows template groups defined in
alternateTemplateGroups
-
Add Files...
- Adds additional files to an existing component
- Shows available templates from all groups
-
Rename...
- Renames a component directory and all its files
- Updates imports across the workspace
- Preserves case variations in files and content
Component names can be provided in any of these formats:
- PascalCase:
MyComponent
- camelCase:
myComponent
- kebab-case:
my-component
- snake_case:
my_component
The extension will automatically transform the name to the appropriate case based on:
- The
directoryCase
setting for the component directory - The token used in template files and target file names
- Node.js
- Visual Studio Code
- Clone the repository
- Run
npm install
- Open the project in VS Code
- Press F5 to start debugging
npm run compile
: Compile TypeScript filesnpm run watch
: Watch for file changes and recompilenpm run lint
: Run ESLintnpm test
: Run tests
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to your branch
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.