Created
February 7, 2020 01:03
-
-
Save tehsis/6a7f588ce780077acc4ca2a21d5a0c09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const componentName = process.argv[2]; | |
console.log(`Creating Component: ${componentName}`); | |
const ComponentTemplate = | |
`import React from 'react'; | |
import styled from 'styled-components'; | |
export const ${componentName}: React.FC = () => { | |
return ( | |
<> | |
</> | |
); | |
} | |
` | |
const TestTemplate = | |
`import React from 'react'; | |
import { ${componentName} } from './${componentName}'; | |
import { render } from '@testing-library/react'; | |
test('A ${componentName}', () => { | |
// const { getByText } = render(<${componentName} />); | |
// const questionText = getByText(/foobar/i); | |
// expect(questionText).toBeInTheDocument(); | |
}) | |
` | |
const HistoryBookTemplate = | |
`import React from 'react'; | |
import { ${componentName} } from './${componentName}'; | |
export default { | |
component: ${componentName}, | |
title: '${componentName}', | |
excludeStories: /.*Data$/ | |
}; | |
export const ${componentName}Data = { | |
} | |
export const actionsData = { | |
}; | |
export const Default = () => { | |
return <${componentName} /> | |
} | |
test('A ${componentName}', () => { | |
// const { getByText } = render(<${componentName} />); | |
// const questionText = getByText(/foobar/i); | |
// expect(questionText).toBeInTheDocument(); | |
}) | |
` | |
fs.mkdirSync(`./src/Components/${componentName}`); | |
fs.writeFileSync(`./src/Components/${componentName}/${componentName}.tsx`, ComponentTemplate, 'utf-8'); | |
fs.writeFileSync(`./src/Components/${componentName}/${componentName}.test.tsx`, TestTemplate, 'utf-8'); | |
fs.writeFileSync(`./src/Components/${componentName}/${componentName}.stories.tsx`, HistoryBookTemplate, 'utf-8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment