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\`\`\`
17116npm install --save ${ name }
18117\`\`\`
22121\`\`\`
23122yarn 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\`\`\`
41136npm run build // for single build
42137
@@ -50,12 +145,27 @@ yarn build // for single build
50145
51146yarn 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
61171module . exports = createREADME ;
0 commit comments