UNPKG

2.98 kBJavaScriptView Raw
1/*
2Copyright 2020 Adobe. All rights reserved.
3This file is licensed to you under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License. You may obtain a copy
5of the License at http://www.apache.org/licenses/LICENSE-2.0
6Unless required by applicable law or agreed to in writing, software distributed under
7the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8OF ANY KIND, either express or implied. See the License for the specific language
9governing permissions and limitations under the License.
10*/
11
12const fs = require('fs-extra')
13const Readme = require('@oclif/dev-cli/lib/commands/readme').default
14
15function genRow (pkName) {
16 return `| [@${pkName}](https://github.com/${pkName}) ` +
17 `| [![Version](https://img.shields.io/npm/v/@${pkName}.svg)](https://npmjs.org/package/@${pkName})` +
18 `| [![Downloads/week](https://img.shields.io/npm/dw/@${pkName}.svg)](https://npmjs.org/package/@${pkName})` +
19 `| [![Build Status](https://travis-ci.com/${pkName}.svg?branch=master)](https://travis-ci.com/${pkName})` +
20 `| [![Codecov Coverage](https://img.shields.io/codecov/c/github/${pkName}/master.svg?style=flat-square)](https://codecov.io/gh/${pkName}/)` +
21 `| [![Github Issues](https://img.shields.io/github/issues/${pkName}.svg)](https://github.com/${pkName}/issues)` +
22 `| [![Github Pull Requests](https://img.shields.io/github/issues-pr/${pkName}.svg)](https://github.com/${pkName}/pulls)|`
23}
24
25function replaceTag (readme, tag, body) {
26 const oclDev = new Readme()
27 return oclDev.replaceTag(readme, tag, body)
28
29 // this is the code that oclif/dev-cli/readme runs:
30 // if (readme.includes(`<!-- ${tag} -->`)) {
31 // if (readme.includes(`<!-- ${tag}stop -->`)) {
32 // readme = readme.replace(new RegExp(`<!-- ${tag} -->(.|\n)*<!-- ${tag}stop -->`, 'm'), `<!-- ${tag} -->`)
33 // }
34 // console.log(`replacing <!-- ${tag} --> in README.md`)
35 // }
36 // return readme.replace(`<!-- ${tag} -->`, `<!-- ${tag} -->\n${body}\n<!-- ${tag}stop -->`)
37}
38
39// load package.json and get @adobe dependencies
40// only adobe cli plugins, and remove the '@'
41const pkjson = fs.readJSONSync('package.json')
42const adobeDeps = pkjson.oclif.plugins
43 .filter(item => item.indexOf('@adobe/aio-cli-plugin') === 0)
44 .concat([ // additional repos to show in health table
45 '@adobe/generator-aio-app'
46 ])
47 .map(item => item.substring(1))
48
49// add the aio-cli itself ...
50adobeDeps.unshift(pkjson.name.substring(1))
51
52// prime tableData with headers, and hrs
53const tableData = ['| Module | Version | Downloads | Build Status | Coverage | Issues | Pull Requests |',
54 '|---|---|---|---|---|---|---|']
55
56// add a row for each item
57adobeDeps.forEach(item => { tableData.push(genRow(item)) })
58
59// replace the text in README
60const readme = fs.readFileSync('README.md', 'utf8')
61fs.writeFileSync('README.md', replaceTag(readme, 'health', tableData.join('\n')))