Skip to content

Commit 7ec2427

Browse files
committed
feat(readme): added badge to generated readme
Added default badges to generated readme Closes #22
1 parent 46556e4 commit 7ec2427

File tree

5 files changed

+210
-39
lines changed

5 files changed

+210
-39
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
"cac": "^6.5.3",
77
"chalk": "^3.0.0",
88
"envinfo": "^7.4.0",
9+
"git-url-parse": "^11.1.2",
10+
"js-beautify": "^1.10.2",
911
"sao": "^1.7.0",
1012
"superb": "^4.0.0",
11-
"validate-npm-package-name": "^3.0.0",
12-
"js-beautify": "^1.10.2"
13+
"validate-npm-package-name": "^3.0.0"
1314
},
1415
"devDependencies": {
15-
"semantic-release": "^15.13.31",
1616
"@semantic-release/changelog": "^3.0.6",
1717
"@semantic-release/commit-analyzer": "^6.3.3",
1818
"@semantic-release/git": "^7.0.18",
1919
"@semantic-release/npm": "^5.3.4",
2020
"@semantic-release/release-notes-generator": "^7.3.4",
21-
"cz-conventional-changelog": "^3.0.2"
21+
"cz-conventional-changelog": "^3.0.2",
22+
"semantic-release": "^15.13.31"
2223
},
2324
"bin": "./cli.js",
2425
"scripts": {

prompts.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ const umdName = options.umd;
1818
const esBuild = options.es;
1919
const useTravis = options.travis;
2020
const useTests = options.tests;
21-
const useSemanticRelease = options["semantic-release"];
21+
let useSemanticRelease = options["semantic-release"];
22+
if (options.semanticRelease === false) {
23+
useSemanticRelease = false;
24+
}
2225
const useNPM = options["npm"];
2326

2427
module.exports = [

saofile.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ module.exports = {
135135
});
136136
}
137137

138-
const readmeContent = createREADME({
139-
name: package.name,
140-
description: package.description,
141-
author,
142-
email,
143-
licenseContent
144-
});
145-
146138
if (this.answers.umd) {
147139
if (!this.answers.umd_name || !this.answers.umd_name.trim()) {
148140
console.error(
@@ -249,6 +241,21 @@ module.exports = {
249241

250242
const pmRun = this.answers.pm === "yarn" ? "yarn" : "npm run";
251243

244+
const readmeContent = createREADME({
245+
name: package.name,
246+
description: package.description,
247+
author,
248+
email,
249+
license: package.license,
250+
licenseContent,
251+
repository: this.answers.repository,
252+
travis: this.answers.travis,
253+
semanticrelease: this.answers.semanticrelease,
254+
umd: this.answers.umd,
255+
umd_name: this.answers.umd_name,
256+
es: this.answers.es
257+
});
258+
252259
return {
253260
tsconfig: serializeTSConfig(tsconfig),
254261
package: serializePackage(package),

utils/createREADME.js

Lines changed: 136 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,117 @@
1-
const createREADME = ({ name, description, author, email, licenseContent }) => {
2-
const authorBlock = [];
3-
if (author) {
4-
authorBlock.push(author);
1+
const gitUrlParse = require("git-url-parse");
2+
3+
const createBadges = ({
4+
name,
5+
license,
6+
travis,
7+
repository,
8+
semanticrelease,
9+
es,
10+
umd
11+
}) => {
12+
const badges = [];
13+
const licenseBadge = `<a href="./LICENSE">
14+
<img alt="license" src="https://img.shields.io/badge/license-${license}-blue.svg" />
15+
</a>`;
16+
const typescriptBadge = `<a href="https://www.typescriptlang.org/">
17+
<img alt="typescript version" src="https://img.shields.io/npm/dependency-version/${name}/dev/typescript.svg" />
18+
</a>
19+
`;
20+
const npmVersion = `<a href="https://www.npmjs.com/package/${name}">
21+
<img alt="npm version" src="https://img.shields.io/npm/v/${name}.svg?style=flat" />
22+
</a>`;
23+
const npmDownloads = `<a href="https://www.npmjs.com/package/${name}">
24+
<img alt="npm downloads" src="https://img.shields.io/npm/dt/${name}.svg?style=flat" />
25+
</a>`;
26+
badges.push(licenseBadge);
27+
if (umd) {
28+
const umdBadge = `<a href="https://github.com/umdjs/umd">
29+
<img alt="umd module" src="https://img.shields.io/badge/module-UMD-blue" />
30+
</a>`;
31+
badges.push(umdBadge);
32+
} else {
33+
const cjsBadge = `<a href="https://requirejs.org/docs/commonjs.html">
34+
<img alt="commonjs module" src="https://img.shields.io/badge/module-CommonJS-blue" />
35+
</a>`;
36+
badges.push(cjsBadge);
537
}
6-
if (email) {
7-
authorBlock.push(`[${email}](mailto:${email})`);
38+
if (es) {
39+
const esBadge = `<a href="https://nodejs.org/api/esm.html">
40+
<img alt="es module" src="https://img.shields.io/badge/module-ESM-blue" />
41+
</a>`;
42+
badges.push(esBadge);
843
}
44+
badges.push(typescriptBadge, npmVersion, npmDownloads);
45+
if (travis && repository) {
46+
const gitUrl = gitUrlParse(repository);
47+
const travisBadge = `<a href="https://travis-ci.org/${gitUrl.full_name}">
48+
<img alt="ci travis" src="https://img.shields.io/badge/ci-travis-yellow" />
49+
</a>`;
50+
const buildBadge = `<a href="https://travis-ci.org/${gitUrl.full_name}">
51+
<img alt="build status" src="https://travis-ci.org/${gitUrl.full_name}.svg?branch=master" />
52+
</a>`;
53+
badges.push(buildBadge, travisBadge);
54+
}
55+
if (semanticrelease) {
56+
const semanticReleaseBadge = `<a href="https://github.com/semantic-release/semantic-release">
57+
<img alt="semantic release" src="https://img.shields.io/badge/%E2%9C%A8-semantic--release-e10079" />
58+
</a>`;
59+
badges.push(semanticReleaseBadge);
60+
}
61+
const generatedWith = `<a href="https://github.com/epranka/create-tsx-package">
62+
<img alt="generated with" src="https://img.shields.io/badge/generated%20with-%40epranka%2Fcreate--tsx--package-blue" />
63+
</a>`;
64+
badges.push(generatedWith);
65+
if (badges.length) {
66+
return [
67+
`<p align="center">
68+
${badges.join(" ")}
69+
</p>`
70+
];
71+
}
72+
return [];
73+
};
974

10-
return `# ${name}
11-
12-
${description}
13-
14-
## Install
15-
75+
const createREADME = ({
76+
name,
77+
description,
78+
author,
79+
email,
80+
license,
81+
licenseContent,
82+
repository,
83+
travis,
84+
semanticrelease,
85+
es,
86+
umd,
87+
umd_name
88+
}) => {
89+
const nameBlock = [];
90+
const descriptionBlock = [];
91+
nameBlock.push(
92+
`<h1 align="center" style="border-bottom: none;">⚒️ ${
93+
umd ? umd_name : name
94+
}</h1>`
95+
);
96+
if (description) {
97+
descriptionBlock.push(`<h3 align="center">${description}</h3>`);
98+
}
99+
const badgesBlock = createBadges({
100+
name,
101+
travis,
102+
repository,
103+
license,
104+
semanticrelease,
105+
es,
106+
umd
107+
});
108+
109+
const readme = [];
110+
111+
readme.push(nameBlock.join(" "));
112+
readme.push(descriptionBlock.join(" "));
113+
readme.push(badgesBlock.join(" "));
114+
readme.push(`## Install
16115
\`\`\`
17116
npm install --save ${name}
18117
\`\`\`
@@ -22,21 +121,17 @@ or
22121
\`\`\`
23122
yarn install ${name}
24123
\`\`\`
124+
`);
25125

26-
## Import module
27-
28-
## Usage
126+
readme.push(`## Import module
127+
Comming soon
128+
`);
29129

30-
${
31-
authorBlock.length
32-
? `## Author
33-
34-
${authorBlock.join("\n\n")}
35-
`
36-
: ""
37-
}
38-
## Build
130+
readme.push(`## Usage
131+
Comming soon
132+
`);
39133

134+
readme.push(`## Build
40135
\`\`\`
41136
npm run build // for single build
42137
@@ -50,12 +145,27 @@ yarn build // for single build
50145
51146
yarn watch // to watch changes
52147
\`\`\`
148+
`);
149+
150+
const authorBlock = [];
151+
if (author) {
152+
authorBlock.push(author);
153+
}
154+
if (email) {
155+
authorBlock.push(`[${email}](mailto:${email})`);
156+
}
53157

158+
if (authorBlock.length) {
159+
authorBlock.unshift("## Author");
160+
}
54161

55-
## License
162+
readme.push(authorBlock.join("\n\n"));
56163

164+
readme.push(`## License
57165
${licenseContent}
58-
`;
166+
`);
167+
168+
return readme.join("\n\n");
59169
};
60170

61171
module.exports = createREADME;

yarn.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,21 @@ git-log-parser@^1.2.0:
22332233
through2 "~2.0.0"
22342234
traverse "~0.6.6"
22352235

2236+
git-up@^4.0.0:
2237+
version "4.0.1"
2238+
resolved "https://registry.yarnpkg.com/git-up/-/git-up-4.0.1.tgz#cb2ef086653640e721d2042fe3104857d89007c0"
2239+
integrity sha512-LFTZZrBlrCrGCG07/dm1aCjjpL1z9L3+5aEeI9SBhAqSc+kiA9Or1bgZhQFNppJX6h/f5McrvJt1mQXTFm6Qrw==
2240+
dependencies:
2241+
is-ssh "^1.3.0"
2242+
parse-url "^5.0.0"
2243+
2244+
git-url-parse@^11.1.2:
2245+
version "11.1.2"
2246+
resolved "https://registry.yarnpkg.com/git-url-parse/-/git-url-parse-11.1.2.tgz#aff1a897c36cc93699270587bea3dbcbbb95de67"
2247+
integrity sha512-gZeLVGY8QVKMIkckncX+iCq2/L8PlwncvDFKiWkBn9EtCfYDbliRTTp6qzyQ1VMdITUfq7293zDzfpjdiGASSQ==
2248+
dependencies:
2249+
git-up "^4.0.0"
2250+
22362251
glob-parent@^3.1.0:
22372252
version "3.1.0"
22382253
resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-3.1.0.tgz#9e6af6299d8d3bd2bd40430832bd113df906c5ae"
@@ -2931,6 +2946,13 @@ is-retry-allowed@^1.0.0:
29312946
resolved "https://registry.yarnpkg.com/is-retry-allowed/-/is-retry-allowed-1.2.0.tgz#d778488bd0a4666a3be8a1482b9f2baafedea8b4"
29322947
integrity sha512-RUbUeKwvm3XG2VYamhJL1xFktgjvPzL0Hq8C+6yrWIswDy3BIXGqCxhxkc30N9jqK311gVU137K8Ei55/zVJRg==
29332948

2949+
is-ssh@^1.3.0:
2950+
version "1.3.1"
2951+
resolved "https://registry.yarnpkg.com/is-ssh/-/is-ssh-1.3.1.tgz#f349a8cadd24e65298037a522cf7520f2e81a0f3"
2952+
integrity sha512-0eRIASHZt1E68/ixClI8bp2YK2wmBPVWEismTs6M+M099jKgrzl/3E976zIbImSIob48N2/XGe9y7ZiYdImSlg==
2953+
dependencies:
2954+
protocols "^1.1.0"
2955+
29342956
is-stream@^1.0.0, is-stream@^1.1.0:
29352957
version "1.1.0"
29362958
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
@@ -3888,6 +3910,11 @@ normalize-package-data@^2.0.0, normalize-package-data@^2.3.2, normalize-package-
38883910
semver "2 || 3 || 4 || 5"
38893911
validate-npm-package-license "^3.0.1"
38903912

3913+
normalize-url@^3.3.0:
3914+
version "3.3.0"
3915+
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-3.3.0.tgz#b2e1c4dc4f7c6d57743df733a4f5978d18650559"
3916+
integrity sha512-U+JJi7duF1o+u2pynbp2zXDW2/PADgC30f0GsHZtRh+HOcXHnw137TrNlyxxRvWW5fjKd3bcLHPxofWuCjaeZg==
3917+
38913918
normalize-url@^4.0.0:
38923919
version "4.5.0"
38933920
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129"
@@ -4470,6 +4497,24 @@ parse-passwd@^1.0.0:
44704497
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
44714498
integrity sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=
44724499

4500+
parse-path@^4.0.0:
4501+
version "4.0.1"
4502+
resolved "https://registry.yarnpkg.com/parse-path/-/parse-path-4.0.1.tgz#0ec769704949778cb3b8eda5e994c32073a1adff"
4503+
integrity sha512-d7yhga0Oc+PwNXDvQ0Jv1BuWkLVPXcAoQ/WREgd6vNNoKYaW52KI+RdOFjI63wjkmps9yUE8VS4veP+AgpQ/hA==
4504+
dependencies:
4505+
is-ssh "^1.3.0"
4506+
protocols "^1.4.0"
4507+
4508+
parse-url@^5.0.0:
4509+
version "5.0.1"
4510+
resolved "https://registry.yarnpkg.com/parse-url/-/parse-url-5.0.1.tgz#99c4084fc11be14141efa41b3d117a96fcb9527f"
4511+
integrity sha512-flNUPP27r3vJpROi0/R3/2efgKkyXqnXwyP1KQ2U0SfFRgdizOdWfvrrvJg1LuOoxs7GQhmxJlq23IpQ/BkByg==
4512+
dependencies:
4513+
is-ssh "^1.3.0"
4514+
normalize-url "^3.3.0"
4515+
parse-path "^4.0.0"
4516+
protocols "^1.4.0"
4517+
44734518
pascalcase@^0.1.1:
44744519
version "0.1.1"
44754520
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
@@ -4626,6 +4671,11 @@ proto-list@~1.2.1:
46264671
resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849"
46274672
integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=
46284673

4674+
protocols@^1.1.0, protocols@^1.4.0:
4675+
version "1.4.7"
4676+
resolved "https://registry.yarnpkg.com/protocols/-/protocols-1.4.7.tgz#95f788a4f0e979b291ffefcf5636ad113d037d32"
4677+
integrity sha512-Fx65lf9/YDn3hUX08XUc0J8rSux36rEsyiv21ZGUC1mOyeM3lTRpZLcrm8aAolzS4itwVfm7TAPyxC2E5zd6xg==
4678+
46294679
protoduck@^5.0.1:
46304680
version "5.0.1"
46314681
resolved "https://registry.yarnpkg.com/protoduck/-/protoduck-5.0.1.tgz#03c3659ca18007b69a50fd82a7ebcc516261151f"

0 commit comments

Comments
 (0)