Wanted to learn Go so started with a simple CLI to can create the boilerplate for files.
go install github.com/wbroberts/go-react@latest
go-react
Creates a component and component test file.
go-react component <ComponentName>
Options:
--props
or-p
adds an empty props type for component--skip-tests
skips adding the test file--dir
or-d
sets the path for the directory the component should be added to. Will create the directory if it does not exist yet
go-react component Example
- Component
./components/Example.component.tsx
import React from 'react';
export const Example = () => {
return <div>Example renders</div>;
}
- Component test
./components/Example.component.test.tsx
import { screen, render } from '@testing-library/react';
import { Example } from './Example.component';
describe('Example', () => {
it('renders', () => {
render(<Example />);
expect(screen.getByText(/Example renders/)).toBeDefined();
});
});
Can add a config file to set default flags when running commands.
touch go-react.yaml
# All values are optional
component:
dir: src/components
props: true
skip-tests: false