0.0.12 • Published 6 years ago
template-code-gen v0.0.12
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
import React from "react";
import PropTypes from "prop-types";
import BEMHelper from "react-bem-helper";
import "./Test.css";
const Test = ({ message,button }) => {
const classes = new BEMHelper({
name: "test",
prefix: "a-"
});
return (
<div {...classes()}>
</div>
);
};
Test.propTypes = {
message: PropTypes.any,
button: PropTypes.any,
};
export default Test;
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": {
"templates": "./templates/"
},
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}} {{~}}