Created
October 4, 2016 11:01
-
-
Save cevek/9e65196329ff5378568731dc606ba02e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { | |
IGeneratorClass, currentDir, UpperCamelCase, lowerCamelCase, trimLines, | |
findGenTemplatesRoot | |
} from 'gen-templates'; | |
import {relative} from 'path'; | |
export default class Component implements IGeneratorClass { | |
help(){ | |
return ` | |
Creates something good | |
`; | |
} | |
generator(args:{_:string[], optional:boolean}) { | |
const name = args._[0]; | |
if (!name) { | |
throw new Error("name is required"); | |
} | |
const cls = UpperCamelCase(name); | |
const lowerCase = lowerCamelCase(name); | |
const optional = args.optional; | |
const dir = currentDir(); | |
const styleRelativePath = relative(dir, findGenTemplatesRoot() + '/styles/'); | |
return [ | |
{ | |
filename: `${dir}/${cls}/${cls}.tsx`, | |
content: trimLines(` | |
import * as React from 'react'; | |
import * as styles from './${cls}.scss'; | |
interface ${cls}Props { | |
} | |
export class ${cls} extends React.Component<${cls}Props, {}> { | |
render() { | |
return ( | |
<div className={styles.${lowerCase}}>${cls}</div> | |
); | |
} | |
} | |
`) | |
}, | |
{ | |
filename: `${dir}/${cls}/${cls}.scss`, | |
content: trimLines(` | |
@import "${styleRelativePath}/variables"; | |
@import "${styleRelativePath}/mixins"; | |
.${lowerCase} { | |
} | |
`) | |
}, | |
{ | |
filename: `${dir}/${cls}/${cls}.spec.tsx`, | |
content: trimLines(` | |
import * as React from 'react'; | |
import {${cls}} from './${cls}'; | |
import * as styles from './${cls}.scss'; | |
describe('${cls}', () => { | |
let renderer: any; | |
beforeEach(() => { | |
}); | |
it('case1', () => { | |
const result = renderer(<${cls}/>); | |
expect(result).toEqual(<div className={styles.${lowerCase}}>${cls}</div>); | |
}); | |
}); | |
`) | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment