This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const mkdirp = require('mkdirp') | ||
const _ = require('lodash') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
|
||
let option = process.argv.slice(2) | ||
let name = option[0] | ||
|
||
if (name) { | ||
let dir = path.join(__dirname, '../src/components/' + name + '/') | ||
let template = path.join(__dirname, 'template/') | ||
|
||
mkdirp.sync(dir) | ||
|
||
let files = [{ | ||
source: template + 'index.js', | ||
target: dir + 'index.js' | ||
}, { | ||
source: template + 'index.less', | ||
target: dir + 'index.less' | ||
}, { | ||
source: template + 'doc.js', | ||
target: path.join(__dirname, '../site/pages/components/docs/') + name + '.doc' | ||
}] | ||
|
||
let context = { | ||
name: name, | ||
className: name.replace(/([A-Z])/g, '-$1').slice(1).toLowerCase() | ||
} | ||
files.forEach(function (item) { | ||
fs.writeFileSync(item.target, _.template(fs.readFileSync(item.source, 'utf8'))(context)) | ||
}) | ||
|
||
console.log(chalk.green('Build success!')) | ||
} else { | ||
console.log(chalk.red('No component name provided, try `npm run create MyComponent` instead.')) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* @title 基本功能 | ||
* @desc 描述 | ||
*/ | ||
import <%= name %> from 'earth-ui/<%= name %>' | ||
|
||
const <%= name %>Basic = () => { | ||
return ( | ||
<<%= name %> /> | ||
) | ||
} | ||
|
||
@component <%= name %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import cx from 'classnames' | ||
import './index.less' | ||
|
||
class <%= name %> extends Component { | ||
constructor () { | ||
super() | ||
this.state = { | ||
|
||
} | ||
} | ||
|
||
render () { | ||
const { className, ...other } = this.props | ||
return ( | ||
<div className={cx('cmui-<%= className %>', className)} {...other}> | ||
something... | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
<%= name %>.propTypes = { | ||
className: PropTypes.string, | ||
|
||
// intro to test prop | ||
test: PropTypes.string | ||
} | ||
|
||
export default <%= name %> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cmui-<%= className %> { | ||
|
||
} |