template-code-gen
code generate from your template file.
example
template
import React from "react";
import PropTypes from "prop-types";
import BEMHelper from "react-bem-helper";
import "./{{=it.name.pascalCase}}.css";
const {{=it.name.pascalCase}} = ({ {{=it.props.toString()}} }) => {
const classes = new BEMHelper({
name: "{{=it.name.paramCase}}",
prefix: "{{=it.prefix}}-"
});
return (
<div {...classes()}>
</div>
);
};
{{=it.name.pascalCase}}.propTypes = {
{{~it.props :value:index}}
{{=value}}: PropTypes.any,
{{~}}
};
export default {{=it.name.pascalCase}};
command
template-code-gen test stateless -d ./atoms --props message,button --prefix a
outputfile
;;;; const Test = { const classes = name: "test" prefix: "a-" ; return <div ...> </div> ;}; TestpropTypes = message: PropTypesany button: PropTypesany ; ;
install
npm i template-code-gen -D
usage
template-code-gen name templatePath
command option
props (csv)
react props
prefix (string)
prefix
dest (string)
output directory path
destDirName (string)
output directory name
If you want to specify a name, write name.pascalCase or name.paramCase.
package.json
root template path
"tcg": ,
template syntax
ref doT
Built-in variables
paramCase name
{{=it.name.paramCase}}
coffeeCup > coffee-cup
pascalCase name
{{=it.name.pascalCase}}
test-case > TestCase
prefix
prefix value
{{=it.prefix}}
props(array)
props value
{{~it.props :value:index}} {{=value}} {{~}}