-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileCreators.ts
81 lines (63 loc) · 2.11 KB
/
fileCreators.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Fsify, Structure } from 'fsify';
import fsify from 'fsify';
export function createFsifier(path:string):Fsify {
return fsify({cwd: path, persistent: true});
}
const getTestFileContents = (componentName:string):string => {
return `import React from 'react';
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import { ${componentName} } from './${componentName}';
describe('${componentName}', () => {
it('renders', () => {
const { container } = render(<${componentName}></${componentName}>);
expect(container).toBeDefined();
});
\\it('does something else', () => {
\\ const { getByTestId } = render(<${componentName}></${componentName}>);
\\ expect(getByTestId('id')).toBeDefined();
\\});
});`;
}
const getScssFileContents = (componentName:string):string => {
return `.${componentName} {
}`;
}
const getCodeFileContents = (componentName: string):string => {
return `import React, { FunctionComponent } from 'react';
import './${componentName}.scss';
interface ${componentName}Props {
}
export const ${componentName}:FunctionComponent<${componentName}Props> = ({}) => {
return (
<div className='${componentName}'>
</div>
);
}`;
}
export function createDirectoryAndFiles(fsifier: Fsify, componentName: string) {
const filesStructure: Structure = [
{
type: fsifier.DIRECTORY,
name: componentName,
contents: [
{
type: fsifier.FILE,
name: `${componentName}.tsx`,
contents: getCodeFileContents(componentName)
},
{
type: fsifier.FILE,
name: `${componentName}.test.tsx`,
contents: getTestFileContents(componentName)
},
{
type: fsifier.FILE,
name: `${componentName}.scss`,
contents: getScssFileContents(componentName)
}
] as Structure
}
];
return fsifier(filesStructure);
}