-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support create umi block (#15)
- Loading branch information
Showing
11 changed files
with
149 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
/templates/**/.umi | ||
/templates/**/.umi-production | ||
/templates/**/dist | ||
/templates/block/pages | ||
/.idea | ||
/yarn.lock |
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 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 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,59 @@ | ||
const Generator = require('yeoman-generator'); | ||
const { basename } = require('path'); | ||
const debug = require('debug')('create-umi'); | ||
|
||
module.exports = class PluginGenerator extends Generator { | ||
constructor(args, opts) { | ||
super(args, opts); | ||
|
||
this.name = basename(process.cwd()); | ||
this.props = {}; | ||
} | ||
|
||
prompting() { | ||
const prompts = [ | ||
{ | ||
name: 'name', | ||
message: `What's the block name?`, | ||
default: this.name, | ||
}, | ||
{ | ||
name: 'description', | ||
message: `What's your block description?`, | ||
}, | ||
{ | ||
name: 'mail', | ||
message: `What's your email?`, | ||
}, | ||
{ | ||
name: 'author', | ||
message: `What's your name?`, | ||
}, | ||
{ | ||
name: 'repo', | ||
message: `Which repo is your block stored under github?`, | ||
default: 'umijs/umi-blocks', | ||
}, | ||
]; | ||
return this.prompt(prompts).then(props => { | ||
this.props = Object.assign(this.props, props); | ||
}); | ||
} | ||
|
||
writing() { | ||
debug(`this.name: ${this.name}`); | ||
debug(`this.props: ${JSON.stringify(this.props)}`); | ||
|
||
const context = { | ||
name: this.name, | ||
props: this.props, | ||
}; | ||
|
||
this.fs.copy(this.templatePath('block', '_gitignore'), this.destinationPath('.gitignore')); | ||
this.fs.copy(this.templatePath('block', '.umirc.js'), this.destinationPath('.umirc.js')); | ||
this.fs.copy(this.templatePath('block', 'src'), this.destinationPath('src')); | ||
this.fs.copyTpl(this.templatePath('block', 'package.json'), this.destinationPath('package.json'), context); | ||
this.fs.copyTpl(this.templatePath('block', 'LICENSE'), this.destinationPath('LICENSE'), context); | ||
this.fs.copyTpl(this.templatePath('block', 'README.md'), this.destinationPath('README.md'), context); | ||
} | ||
}; |
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,5 @@ | ||
export default { | ||
plugins: [ | ||
['umi-plugin-block-dev', {}], | ||
], | ||
} |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018-present <%= props.author %> (<%= props.mail %>) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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 @@ | ||
# @umi-material/<%= props.name %> | ||
|
||
<%= props.description %> | ||
|
||
## Usage | ||
|
||
```sh | ||
umi block https://github.com/<%= props.repo %>/tree/master/<%= props.name %> | ||
``` | ||
|
||
## LICENSE | ||
|
||
MIT |
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,5 @@ | ||
/yarn.lock | ||
/package-lock.json | ||
/dist | ||
/node_modules | ||
/pages |
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,24 @@ | ||
{ | ||
"name": "@umi-material/<%= props.name %>", | ||
"version": "0.0.1", | ||
"description": "<%= props.description %>", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"dev": "umi dev" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/<%= props.repo %>/<%= props.name %>" | ||
}, | ||
"dependencies": { | ||
"react": ">=16.0.0" | ||
}, | ||
"devDependencies": { | ||
"umi": "^2.0.0", | ||
"umi-plugin-block-dev": "^1.0.0" | ||
}, | ||
"authors": [ | ||
"<%= props.author %> <<%= props.mail %>>" | ||
], | ||
"license": "ISC" | ||
} |
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 @@ | ||
.normal { | ||
background: #79F2AA; | ||
} |
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,9 @@ | ||
import styles from './index.css'; | ||
|
||
export default function() { | ||
return ( | ||
<div className={styles.normal}> | ||
<h1>I am a umi block!</h1> | ||
</div> | ||
); | ||
} |