-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(templates): 使用plop+hbs替代metalsmith+hbs手动处理组件模板
- Loading branch information
zhaozhiwen
committed
May 6, 2020
1 parent
c98d24e
commit 5cdd15c
Showing
17 changed files
with
292 additions
and
491 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export { default as Alert } from './alert'; | ||
|
||
/* PLOP_INJECT_EXPORT */ |
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
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import { NodePlopAPI } from 'plop'; | ||
import path from 'path'; | ||
|
||
export default function(plop: NodePlopAPI) { | ||
plop.setGenerator('component', { | ||
description: '创建一个新组件', | ||
prompts: [ | ||
{ type: 'input', name: 'name', message: '请输入组件名称(多个单词以中横线命名)' }, | ||
{ type: 'input', name: 'CN', message: '请输入组件中文名称' }, | ||
{ type: 'input', name: 'description', message: '请输入组件描述' }, | ||
], | ||
actions: [ | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/index.ts'), | ||
templateFile: path.resolve(__dirname, '../templates/component/index.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/{{kebabCase name}}.tsx'), | ||
templateFile: path.resolve(__dirname, '../templates/component/comp.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/style/index.less'), | ||
templateFile: path.resolve(__dirname, '../templates/component/style/style.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/style/index.ts'), | ||
templateFile: path.resolve(__dirname, '../templates/component/style/index.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/index.mdx'), | ||
templateFile: path.resolve(__dirname, '../templates/component/doc.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/interface.ts'), | ||
templateFile: path.resolve(__dirname, '../templates/component/interface.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/demo/basic.tsx'), | ||
templateFile: path.resolve(__dirname, '../templates/component/demo/basic.hbs'), | ||
}, | ||
{ | ||
type: 'add', | ||
path: path.resolve(__dirname, '../components/{{kebabCase name}}/__tests__/index.test.tsx'), | ||
templateFile: path.resolve(__dirname, '../templates/component/__tests__/index.test.hbs'), | ||
}, | ||
{ | ||
type: 'append', | ||
path: path.resolve(__dirname, '../components/index.ts'), | ||
pattern: '/* PLOP_INJECT_EXPORT */', | ||
template: "export { default as {{pascalCase name}} } from './{{kebabCase name}}';", | ||
}, | ||
], | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import {{pascalCase name}} from '../index'; | ||
|
||
describe('{{pascalCase name}}', () => { | ||
it('renders without error', () => { | ||
|
||
}); | ||
}); |
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,14 @@ | ||
import React from 'react'; | ||
import { Props } from './interface'; | ||
|
||
const defaultProps = { | ||
|
||
}; | ||
|
||
const {{pascalCase name}}: React.FC<Props> = userProps => { | ||
const props = { ...defaultProps, ...userProps }; | ||
|
||
return <>{{pascalCase name}}</>; | ||
}; | ||
|
||
export default {{pascalCase 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,6 @@ | ||
import React from 'react'; | ||
import { {{pascalCase name}} } from 'happy-ui'; | ||
|
||
export default () => ( | ||
<{{pascalCase 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,28 @@ | ||
--- | ||
name: {{pascalCase name}} {{CN}} | ||
route: /components/{{kebabCase name}} | ||
menu: 组件 | ||
--- | ||
|
||
import CodeBox from '../../doc-comps/happy-box'; | ||
|
||
import BasicDemo from './demo/basic'; | ||
import BasicDemoCode from '!raw-loader!./demo/basic'; | ||
|
||
## {{pascalCase name}} {{CN}} | ||
|
||
{{description}} | ||
|
||
### 代码演示 | ||
|
||
#### 基本使用 | ||
|
||
<CodeBox code={BasicDemoCode} title="" desc=""> | ||
<BasicDemo></BasicDemo> | ||
</CodeBox> | ||
|
||
|
||
### API | ||
|
||
| 属性 | 说明 | 类型 | 默认值 | | ||
| ---- | ---- | ---- | ------ | |
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 @@ | ||
export * from './interface'; | ||
|
||
export { default } from './{{kebabCase 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 @@ | ||
export interface Props { | ||
|
||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.