正在显示
13 个修改的文件
包含
138 行增加
和
17 行删除
_scripts/BlockGenerator/index.js
0 → 100644
1 | +const Generator = require('yeoman-generator'); | |
2 | +const { statSync } = require('fs'); | |
3 | +const glob = require('glob'); | |
4 | + | |
5 | +class BlockGenerator extends Generator { | |
6 | + writing() { | |
7 | + glob | |
8 | + .sync('**/*', { | |
9 | + cwd: this.templatePath(), | |
10 | + dot: true, | |
11 | + }) | |
12 | + .forEach(file => { | |
13 | + const filePath = this.templatePath(file); | |
14 | + if (statSync(filePath).isFile()) { | |
15 | + this.fs.copyTpl( | |
16 | + this.templatePath(filePath), | |
17 | + this.destinationPath(file.replace(/^_/, '.')), | |
18 | + { | |
19 | + name: process.env.BLOCK.split('/')[1], | |
20 | + }, | |
21 | + ); | |
22 | + } | |
23 | + }); | |
24 | + } | |
25 | +} | |
26 | + | |
27 | +module.exports = BlockGenerator; | ... | ... |
_scripts/BlockGenerator/package.json
0 → 100644
1 | +import React, { Component } from 'react'; | |
2 | +import { Button } from 'antd'; | |
3 | +import { connect } from 'dva'; | |
4 | + | |
5 | +import styles from './style.less'; | |
6 | + | |
7 | +@connect(({ BLOCK_NAME_CAMEL_CASE }) => BLOCK_NAME_CAMEL_CASE) | |
8 | +class Page extends Component { | |
9 | + componentDidMount() { | |
10 | + const { dispatch } = this.props; | |
11 | + dispatch({ | |
12 | + type: 'BLOCK_NAME_CAMEL_CASE/fetch', | |
13 | + }); | |
14 | + } | |
15 | + | |
16 | + render() { | |
17 | + const { text } = this.props; | |
18 | + return ( | |
19 | + <div className={styles.container}> | |
20 | + <Button>{text}</Button> | |
21 | + </div> | |
22 | + ); | |
23 | + } | |
24 | +} | |
25 | + | |
26 | +export default Page; | ... | ... |
1 | +import { getText } from './service'; | |
2 | + | |
3 | +export default { | |
4 | + namespace: 'BLOCK_NAME_CAMEL_CASE', | |
5 | + state: { | |
6 | + text: 'loading...', | |
7 | + }, | |
8 | + | |
9 | + effects: { | |
10 | + *fetch(_, { call, put }) { | |
11 | + const { text } = yield call(getText); | |
12 | + yield put({ | |
13 | + type: 'save', | |
14 | + payload: { | |
15 | + text, | |
16 | + }, | |
17 | + }); | |
18 | + }, | |
19 | + }, | |
20 | + | |
21 | + reducers: { | |
22 | + save(state, { payload }) { | |
23 | + return { | |
24 | + ...state, | |
25 | + ...payload, | |
26 | + }; | |
27 | + }, | |
28 | + }, | |
29 | +}; | ... | ... |
_scripts/create.js
0 → 100644
1 | +const { join } = require('path'); | |
2 | +const BlockGenerator = require('./BlockGenerator'); | |
3 | + | |
4 | +if (!process.env.BLOCK) { | |
5 | + console.log(` | |
6 | +Please specify the BLOCK env, | |
7 | + | |
8 | +e.g. | |
9 | + | |
10 | +$ BLOCK=templates/new-template yarn run create | |
11 | +$ BLOCK=blocks/new-block yarn run create | |
12 | + `); | |
13 | + process.exit(1); | |
14 | +} | |
15 | + | |
16 | +const generator = new BlockGenerator({ | |
17 | + name: 'foo', | |
18 | + env: { | |
19 | + cwd: join(__dirname, '..', process.env.BLOCK), | |
20 | + }, | |
21 | + resolved: require.resolve(require.resolve('./BlockGenerator')), | |
22 | +}); | |
23 | + | |
24 | +generator.run(() => { | |
25 | + console.log('done'); | |
26 | +}); | |
27 | + | ... | ... |
blocks/blank/README.md
已删除
100644 → 0
... | ... | @@ -8,7 +8,8 @@ |
8 | 8 | "lint-staged": "lint-staged", |
9 | 9 | "lint-staged:js": "eslint --ext .js", |
10 | 10 | "prettier": "node ./_scripts/prettier.js", |
11 | - "build": "node ./_scripts/generate.js" | |
11 | + "build": "node ./_scripts/build.js", | |
12 | + "create": "node ./_scripts/create.js" | |
12 | 13 | }, |
13 | 14 | "devDependencies": { |
14 | 15 | "@ant-design/pro-layout": "^4.5.16", |
... | ... | @@ -22,7 +23,7 @@ |
22 | 23 | "eslint-plugin-jsx-a11y": "^6.1.2", |
23 | 24 | "eslint-plugin-markdown": "^1.0.0-beta.6", |
24 | 25 | "eslint-plugin-react": "^7.11.1", |
25 | - "glob": "^7.1.3", | |
26 | + "glob": "^7.1.4", | |
26 | 27 | "husky": "^1.2.0", |
27 | 28 | "lint-staged": "^8.1.0", |
28 | 29 | "mkdirp": "^0.5.1", |
... | ... | @@ -33,7 +34,8 @@ |
33 | 34 | "umi": "^2.3.0-0", |
34 | 35 | "umi-plugin-block-dev": "^2.0.0", |
35 | 36 | "umi-plugin-react": "^1.3.0-0", |
36 | - "umi-request": "^1.2.6" | |
37 | + "umi-request": "^1.2.6", | |
38 | + "yeoman-generator": "^4.1.0" | |
37 | 39 | }, |
38 | 40 | "lint-staged": { |
39 | 41 | "x/**/*.{js,ts,tsx,json,jsx,less}": [ | ... | ... |
请
注册
或
登录
后发表评论