Skip to content

Commit

Permalink
fix(all): rewrite with new generator api
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuabei committed Oct 25, 2016
1 parent 567c14a commit 634ba76
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
30 changes: 15 additions & 15 deletions src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import yosay from 'yosay';
const QUESTIONS = [
{
type: 'input',
name: 'module:name',
name: 'moduleName',
message: 'Module name'
},
{
type: 'input',
name: 'module:description',
name: 'moduleDescription',
message: 'Module description'
},
{
type: 'input',
name: 'module:author:nickname',
name: 'githubUsername',
message: 'Your GitHub username'
},
{
type: 'input',
name: 'module:author:fullName',
name: 'fullName',
message: 'Your full name'
},
{
'type': 'list',
'name': 'module:license',
'name': 'license',
'message': 'Choose a license',
'default': 'MIT',
'choices': [
Expand Down Expand Up @@ -84,23 +84,23 @@ module.exports = class AppGenerator extends Base {
writing() {
this.directory('src', 'src');
this.directory('test', 'test');
this.copy('babelrc', '.babelrc');
this.copy('editorconfig', '.editorconfig');
this.copy('gitignore', '.gitignore');
this.copy('npmignore', '.npmignore');
this.copy('package.json', 'package.json');
this.copy('README.md', 'README.md');
this.copy('travis.yml', '.travis.yml');
this.fs.copy(this.templatePath('babelrc'), this.destinationPath('.babelrc'));
this.fs.copy(this.templatePath('editorconfig'), this.destinationPath('.editorconfig'));
this.fs.copy(this.templatePath('gitignore'), this.destinationPath('.gitignore'));
this.fs.copy(this.templatePath('npmignore'), this.destinationPath('.npmignore'));
this.fs.copyTpl(this.templatePath('package.json'), this.destinationPath('package.json'), this.answers);
this.fs.copyTpl(this.templatePath('README.md'), this.destinationPath('README.md'), this.answers);
this.fs.copy(this.templatePath('travis.yml'), this.destinationPath('.travis.yml'));

let done = this.async();
this::fetchLicense(
this.answers['module:license'],
this.answers.license,
tpl => {
let content = tpl
.replace(/-+[\d\D]*?-+\n\n/, '')
.replace(/\[year\]/g, new Date().getFullYear())
.replace(/\[fullname\]/g, this.answers['module:author:fullName']);
this.write('LICENSE', content);
.replace(/\[fullname\]/g, this.answers.fullName);
this.fs.write(this.destinationPath('LICENSE'), content);
done();
}
);
Expand Down
26 changes: 13 additions & 13 deletions src/app/templates/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# <%= answers['module:name'] %>
# <%= moduleName %>

![Build Status](https://img.shields.io/travis/<%= answers['module:author:nickname'] %>/<%= answers['module:name'] %>.svg)
![Coverage](https://img.shields.io/coveralls/<%= answers['module:author:nickname'] %>/<%= answers['module:name'] %>.svg)
![Downloads](https://img.shields.io/npm/dm/<%= answers['module:name'] %>.svg)
![Downloads](https://img.shields.io/npm/dt/<%= answers['module:name'] %>.svg)
![npm version](https://img.shields.io/npm/v/<%= answers['module:name'] %>.svg)
![dependencies](https://img.shields.io/david/<%= answers['module:author:nickname'] %>/<%= answers['module:name'] %>.svg)
![dev dependencies](https://img.shields.io/david/dev/<%= answers['module:author:nickname'] %>/<%= answers['module:name'] %>.svg)
![License](https://img.shields.io/npm/l/<%= answers['module:name'] %>.svg)
![Build Status](https://img.shields.io/travis/<%= githubUsername %>/<%= moduleName %>.svg)
![Coverage](https://img.shields.io/coveralls/<%= githubUsername %>/<%= moduleName %>.svg)
![Downloads](https://img.shields.io/npm/dm/<%= moduleName %>.svg)
![Downloads](https://img.shields.io/npm/dt/<%= moduleName %>.svg)
![npm version](https://img.shields.io/npm/v/<%= moduleName %>.svg)
![dependencies](https://img.shields.io/david/<%= githubUsername %>/<%= moduleName %>.svg)
![dev dependencies](https://img.shields.io/david/dev/<%= githubUsername %>/<%= moduleName %>.svg)
![License](https://img.shields.io/npm/l/<%= moduleName %>.svg)

<%= answers['module:description'] %>
<%= moduleDescription %>

## Getting Started

Install it via npm:

```shell
npm install <%= answers['module:name'] %>
npm install <%= moduleName %>
```

And include in your project:

```javascript
import <%= answers['module:name'] %> from '<%= answers['module:name'] %>';
import <%= moduleName %> from '<%= moduleName %>';
```

## License

<%= answers['module:license'] %>
<%= license %>
10 changes: 5 additions & 5 deletions src/app/templates/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "<%= answers['module:name'] %>",
"description": "<%= answers['module:description'] %>",
"name": "<%= moduleName %>",
"description": "<%= moduleDescription %>",
"version": "0.1.0",
"main": "lib/index.js",
"author": "<%= answers['module:author:nickname'] %>",
"repository": "<%= answers['module:author:nickname'] %>/<%= answers['module:name'] %>",
"license": "<%= answers['module:license'] %>",
"author": "<%= githubUsername %>",
"repository": "<%= githubUsername %>/<%= moduleName %>",
"license": "<%= license %>",
"scripts": {
"compile": "babel src --out-dir lib",
"coveralls": "cat ./coverage/lcov.info | coveralls",
Expand Down
2 changes: 1 addition & 1 deletion test/unit/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('app', () => {
before(done => {
test
.run(path.join(__dirname, '../../src/app'))
.withPrompts({'module:license': 'MIT'})
.withPrompts({license: 'MIT'})
.on('end', done);
});

Expand Down

0 comments on commit 634ba76

Please sign in to comment.