Skip to content

Commit

Permalink
feat: add 'readme' generator, templates
Browse files Browse the repository at this point in the history
  • Loading branch information
seantrane committed Aug 28, 2018
1 parent 1415d2f commit 58df7a3
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"build:e2e": "npm run build && npm run e2e",
"build:templates:app": "shx cp -Rf src/app/templates/ generators/app/templates/",
"build:templates:ignore": "shx cp -Rf src/ignore/templates/ generators/ignore/templates/",
"build:templates": "npm run build:templates:app && npm run build:templates:ignore",
"build:templates:readme": "shx cp -Rf src/readme/templates/ generators/readme/templates/",
"build:templates": "npm run build:templates:app && npm run build:templates:ignore && npm run build:templates:readme",
"build:test:e2e": "npm run build && npm test && npm run e2e",
"build:test": "npm run build && npm test",
"build": "npm run clean:dist && tsc && npm run build:templates",
Expand Down
20 changes: 20 additions & 0 deletions src/app/prompting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ export async function prompting(yo) {
website: yo.answers.homepageUrl || yo.answers.authorUrl,
});
}
if (yo.options['generators'].indexOf('readme') !== -1) {
yo.composeWith('repo:readme', {
authorEmail: yo.answers.authorEmail,
authorName: yo.answers.authorName,
authorUrl: yo.answers.authorUrl,
demo: yo.answers.demo,
dependencies: yo.answers.dependencies,
description: yo.answers.description,
destination: yo.answers.destination,
features: yo.answers.features,
homepageUrl: yo.answers.homepageUrl,
installation: yo.answers.installation,
license: yo.answers.license,
packageName: yo.answers.packageName,
profileName: yo.answers.profileName || yo.answers.username,
repositoryName: yo.answers.repositoryName || yo.answers.packageName,
repositoryUrl: yo.answers.repositoryUrl,
username: yo.answers.username,
});
}
yo.context = { ...yo.context, ...yo.answers };
}

Expand Down
40 changes: 40 additions & 0 deletions src/readme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { resolve as pathResolve } from 'path';
import * as Base from 'yeoman-generator';

import yoOptionOrPrompt from '../shared/yo-option-or-prompt';
import prompting from './prompting';

export class RepoReadmeGenerator extends Base {

answers: Base.Answers;
context: {};
optionOrPrompt: any;

constructor(args, opts) {
super(args, opts);
this.sourceRoot(pathResolve(__dirname, './templates'));
}

async initializing() {
this.optionOrPrompt = yoOptionOrPrompt;
}

async prompting() {
return prompting(this);
}

async configuring() {
this.destinationRoot(this.answers.destination);
}

async writing() {
this.fs.copyTpl(
this.templatePath('README.md'),
this.destinationPath('README.md'),
this.context,
);
}

}

export default RepoReadmeGenerator;
100 changes: 100 additions & 0 deletions src/readme/prompting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { resolve as pathResolve } from 'path';
import YoRepoPrompts from '../shared/yo-repo-prompts';

export async function prompting(yo) {
const {
username,
profileName,
repositoryName,
packageName,
destination,
description,
license,
authorName,
authorEmail,
authorUrl,
repositoryUrl,
homepageUrl,
} = await new YoRepoPrompts(yo).prompt({
username: true,
profileName: true,
repositoryName: true,
packageName: true,
destination: true,
description: true,
license: true,
authorName: true,
authorEmail: true,
authorUrl: true,
repositoryUrl: true,
homepageUrl: true,
});
const features = [];
while (true) {
const { feature } = await yo.prompt([
{
type: 'input',
name: 'feature',
message: 'Feature:',
},
]);
if (feature === '') break;
features.push(feature);
}
const { installation, demo } = await yo.prompt([
{
type: 'input',
name: 'installation',
message: 'Installation command:',
},
{
type: 'input',
name: 'demo',
message: 'Demo URL:',
},
]);
const dependencies = [];
while (true) {
const { dependencyName } = await yo.prompt([
{
type: 'input',
name: 'dependencyName',
message: 'Dependency:',
},
]);
if (dependencyName === '') break;
const { dependencyUrl } = await yo.prompt([
{
type: 'input',
name: 'dependencyUrl',
message: 'Dependency URL:',
default: 'https://example.com',
},
]);
dependencies.push({
name: dependencyName,
url: dependencyUrl,
});
}
yo.answers = {
authorEmail,
authorName,
authorUrl,
demo,
dependencies,
description,
destination,
features,
homepageUrl,
installation,
license,
packageName,
profileName,
repositoryName,
repositoryUrl,
username,
};
yo.context = { ...yo.context, ...yo.answers };
}

export default prompting;
114 changes: 114 additions & 0 deletions src/readme/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# <%= packageName %>

> <%= description %>
<!-- markdownlint-disable -->
<%
if (typeof badges !== 'undefined' && badges.length > 0) {
%><%
if (badges.indexOf('travis') !== -1) {
%>[![Build Status](https://travis-ci.com/<%= profile %>/<%= repositoryName %>.svg?branch=master)](https://travis-ci.com/<%= profile %>/<%= repositoryName %>)&nbsp;<%
} %><%
if (badges.indexOf('codecov') !== -1) {
%>[![codecov](https://codecov.io/gh/<%= profile %>/<%= repositoryName %>/branch/master/graph/badge.svg)](https://codecov.io/gh/<%= profile %>/<%= repositoryName %>)&nbsp;<%
} %><%
if (badges.indexOf('coveralls') !== -1) {
%>[![Coverage Status](https://coveralls.io/repos/github/<%= profile %>/<%= repositoryName %>/badge.svg?branch=master)](https://coveralls.io/github/<%= profile %>/<%= repositoryName %>?branch=master)&nbsp;<%
} %><%
if (badges.indexOf('david') !== -1) {
%>[![Dependencies Status](https://david-dm.org/<%= profile %>/<%= repositoryName %>/status.svg)](https://david-dm.org/<%= profile %>/<%= repositoryName %>)&nbsp;<%
} %><%
if (badges.indexOf('davidDev') !== -1) {
%>[![devDependencies Status](https://david-dm.org/<%= profile %>/<%= repositoryName %>/dev-status.svg)](https://david-dm.org/<%= profile %>/<%= repositoryName %>?type=dev)&nbsp;<%
} %><%
if (badges.indexOf('greenkeeper') !== -1) {
%>[![Greenkeeper badge](https://badges.greenkeeper.io/<%= profile %>/<%= repositoryName %>.svg)](https://greenkeeper.io/)&nbsp;<%
} %><%
if (badges.indexOf('commitizen') !== -1) {
%>[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)&nbsp;<%
} %><%
if (badges.indexOf('semantic-release') !== -1) {
%>[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)&nbsp;<%
} %>

<%
if (badges.indexOf('npm') !== -1) {
%>[![npm latest version](https://img.shields.io/npm/v/<%= scopedEncoded || repositoryName %>/latest.svg)](https://www.npmjs.com/package/<%= scopedEncoded || repositoryName %>)&nbsp;[![npm next version](https://img.shields.io/npm/v/<%= scopedEncoded || repositoryName %>/next.svg)](https://www.npmjs.com/package/<%= scopedEncoded || repositoryName %>)&nbsp;[![npm downloads per week](https://img.shields.io/npm/dw/<%= scopedEncoded || repositoryName %>.svg)](https://www.npmjs.com/package/<%= scopedEncoded || repositoryName %>)&nbsp;[![npm total downloads](https://img.shields.io/npm/dt/<%= scopedEncoded || repositoryName %>.svg)](https://www.npmjs.com/package/<%= scopedEncoded || repositoryName %>)&nbsp;<%
} %><%
if (badges.indexOf('gitter') !== -1) {
%>[![Join the chat at https://gitter.im/<%= profile %>](https://badges.gitter.im/<%= profile %>.svg)](https://gitter.im/<%= profile %>?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)&nbsp;<%
} %><%
} %>

## Table of Contents

- [About](#about)<% if (typeof features !== 'undefined' && features.length > 0) { %>
- [Features](#features)<% } %><% if (typeof demo !== 'undefined' && demo.length > 0) { %>
- [Demo](#demo)<% } %><% if (typeof installation !== 'undefined' && installation.length > 0) { %>
- [Install](#install)<% } %><% if (typeof dependencies !== 'undefined' && dependencies.length > 0) { %>
- [Dependencies](#dependencies)<% } %>
- [Usage](#usage)
- [Support](#support)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

---

## About the App <a id="about"></a>
<% if (typeof features !== 'undefined' && features.length > 0) { %>
### Features <a id="features"></a>

<% for (var i in features) { %>
- <%= features[i] %><% } %>
<% } %><% if (typeof demo !== 'undefined' && demo.length > 0) { %>
### Demo <a id="demo"></a>

See a [demo](<%= demo %>)

<% } %>
<% if (typeof installation !== 'undefined' && installation.length > 0) { %>
## Install <a id="install"></a>

```sh
<%= installation %>
```
<% } %>
<% if (typeof dependencies !== 'undefined' && dependencies.length > 0) { %>
### Dependencies <a id="dependencies"></a>

<% for (var i in dependencies) { %>
- [<%= dependencies[i].name %>](<%= dependencies[i].url %>)<% } %>
<% } %>

## Usage <a id="usage"></a>

```sh
# CLI:
```

> :point_up: _more instructions coming soon._
---

## Support <a id="support"></a>

Submit an [issue](<%= repositoryUrl %>/issues/new)

## Contributing <a id="contributing"></a>

Contributions are always appreciated. Read [CONTRIBUTING.md](<%= repositoryUrl %>/blob/master/CONTRIBUTING.md) documentation to learn more.

## Changelog <a id="changelog"></a>

Release details are documented in the [CHANGELOG.md](<%= repositoryUrl %>/blob/master/CHANGELOG.md) file, and on the [GitHub Releases page](<%= repositoryUrl %>/releases).

---

## License <a id="license"></a>

[<%= license %> License](<%= repositoryUrl %>/blob/master/LICENSE)
<%
author_name = typeof authorName !== 'undefined' ? authorName : username
author_url = typeof authorUrl !== 'undefined' ? authorUrl : repositoryUrl
%>
Copyright (c) <%= new Date().getFullYear() %> [<%= author_name %>](<%= author_url %>)

0 comments on commit 58df7a3

Please sign in to comment.