reacterminator
node> = 6.0.0
用法
如何使用 reacterminator?
Reacterminator将html转换为es6响应组件。
首先,用几个简单的数据属性注释你的html标记,这是 reacterminator。
例如,可以将 data-component-name 属性添加到 html,以便reacterminator知道它是一个React组件://file: example.html
然后让reacterminator完成这项工作:$ reacterminator convert example.html
将在'./components/Unicorn.jsx'处生成名为'unicorn.jsx'的文件,其中包含以下内容:import React from 'react';
export default class Unicorn extends React.Component {
render() {
return (
);
}
}
npm i -g reacterminator
你可以使用 reacterminator 或者 rt。Usage: reacterminator [options] [command]
Commands:
convert|c convert html files into react component files.
generate|g generate custom files.
help [cmd] display help for [cmd]
Convert html files to react components
Options:
-h, --help output usage information
-V, --version output the version number
Examples:
$ reacterminator c design.html
$ reacterminator c design/
$ reacterminator g components/MyCustom
Notes:
If the input is a folder, files ending with -ignore.html will be ignored.
node/**
* convert html to react components
*
* @param {Object} input
* {('path'|'string')} input.type
* {string} input.content
* When input.type is 'string', input.content is the html content.
* When input.type is 'path', input.content specifies the path.
* The path can be a directory or a file.
*
* @param {Object} options
* {boolean} [options.generateFiles=false]
* {string} [options.outputPath='./components']
* {boolean} [options.recursive=false]
* When options.recursive is true, reacterminator will find. html files recursivly
* and convert them into react components.
* When false, reacterminator will only find the. html files
* in the current directory.
**/
var reacterminator = require('reacterminator');
var components = reacterminator(
{
type: 'string',
content: '
},
{
generatefiles: false,
}
);
console.log(components.Unicorn.formattedFileSnippet)
//import React from 'react';
//
//export default class Unicorn extends React.Component {
//render() {
//return (
//
//);
//}
//}
工作流在阅读中写规范
编写测试
实现( 请按 npm run test:watch:mocha 操作 TDD )
在执行 PR ( npm test ) 之前确保以下各项linting传递
测试通过
100%覆盖
设置安装正确的node 版本nvm install #. nvmrc is used to specify node version
nvm use确保你可以运行这里命令:npm run test
//Coverall will give you an error since your local is not a travis-ci environment.
//That is OK.
资源