1 | "use strict"; |
||
2 | |||
3 | const fs = require ('fs') |
||
4 | const ccxt = require ('./ccxt') |
||
5 | const log = require ('ololog') |
||
6 | const ansi = require ('ansicolor').nice |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
7 | |||
8 | //----------------------------------------------------------------------------- |
||
9 | |||
10 | let readmeRst = 'README.rst' |
||
11 | |||
12 | log.bright.cyan ('Updating badges →', readmeRst.yellow) |
||
13 | |||
14 | let rst = fs.readFileSync (readmeRst, 'utf8') |
||
15 | let rstNew = |
||
16 | rst.replace (/\`([^\`]+)\s\<\#[^\`]+\>\`\_\_/g, '$1') // PyPI doesn't like urls containing anchor hash symbol '#', strip it off to plain text |
||
17 | .replace (/\\\|/g, '|') // PyPI doesn't like escaped vertical bars |
||
18 | // .replace (/\|\\(\_[^\|]+)\|([\ ]+)\|/g, '|$1| $2|') |
||
19 | // .replace (/\|\\(\_[^\|]+)\|/g, '|$1|') |
||
20 | |||
21 | let rstExchangeTableRegex = /([\s\S]+?)APIs:[\n][\n](\+\-\-[\s\S]+\-\-\+)[\n][\n]([\s\S]+)/ |
||
22 | let match = rstExchangeTableRegex.exec (rstNew) |
||
23 | let rstExchangeTableLines = match[2].split ("\n") |
||
24 | |||
25 | let newRstExchangeTable = rstExchangeTableLines.map (line => { |
||
26 | return line.replace (/(\||\+)(.).+?(\s|\=|\-)(\||\+)/, '$1') // replace ascii table graphics |
||
27 | }).join ("\n") |
||
28 | |||
29 | let travisBadgeImage = ".. image:: https://travis-ci.org/kroitor/ccxt.svg?branch=master\n" |
||
30 | let travisBadgeTarget = " :target: https://travis-ci.org/kroitor/ccxt" |
||
31 | let npmBadgeImage = ".. image:: https://img.shields.io/npm/v/ccxt.svg\n" |
||
32 | let npmBadgeTarget = " :target: https://npmjs.com/package/ccxt" |
||
33 | let pypiBadgeImage = ".. image:: https://img.shields.io/pypi/v/ccxt.svg\n" |
||
34 | let pypiBadgeTarget = " :target: https://pypi.python.org/pypi/ccxt" |
||
35 | let npmDownloadsImage = ".. image:: https://img.shields.io/npm/dm/ccxt.svg\n" |
||
36 | let npmDownloadsTarget = " :target: https://www.npmjs.com/package/ccxt" |
||
37 | let pypiDownloadsImage = ".. image:: https://img.shields.io/pypi/dm/ccxt.svg\n" // always shows 0 |
||
38 | let pypiDownloadsTarget = " :target: https://pypi.org/project/ccxt" |
||
39 | let scrutinizerImage = ".. image:: https://img.shields.io/scrutinizer/g/kroitor/ccxt.svg\n" |
||
40 | let scrutinizerTarget = " :target: https://scrutinizer-ci.com/g/kroitor/ccxt/?branch=master" |
||
41 | let runkitImage = ".. image:: https://badge.runkitcdn.com/ccxt.svg\n" |
||
42 | let runkitTarget = " :target: https://npm.runkit.com/ccxt" |
||
43 | let exchangesImage = ".. image:: https://img.shields.io/badge/exchanges-" + ccxt.exchanges.length + "-blue.svg\n" |
||
44 | let exchangesTarget = " :target: https://github.com/kroitor/ccxt/wiki/Exchange-Markets" |
||
45 | |||
46 | let travisBadgeRST = travisBadgeImage + ' ' + travisBadgeTarget |
||
47 | let npmBadgeRST = npmBadgeImage + ' ' + npmBadgeTarget |
||
48 | let pypiBadgeRST = pypiBadgeImage + ' ' + pypiBadgeTarget |
||
49 | let npmDownloadsRST = npmDownloadsImage + ' ' + npmDownloadsTarget |
||
50 | let pypiDownloadsRST = pypiDownloadsImage + ' ' + pypiDownloadsTarget // always shows 0 |
||
0 ignored issues
–
show
|
|||
51 | let scrutinizerRST = scrutinizerImage + ' ' + scrutinizerTarget |
||
0 ignored issues
–
show
|
|||
52 | let runkitRST = runkitImage + ' ' + runkitTarget |
||
53 | let exchangesRST = exchangesImage + ' ' + exchangesTarget |
||
54 | |||
55 | let badges = [ |
||
56 | travisBadgeRST, |
||
57 | npmBadgeRST, |
||
58 | pypiBadgeRST, |
||
59 | npmDownloadsRST, |
||
60 | // pypiDownloadsRST, // always shows 0 |
||
61 | // scrutinizerRST, |
||
62 | runkitRST, |
||
63 | exchangesRST, |
||
64 | ].join ("\n") |
||
65 | |||
66 | |||
67 | let badgeTitles = [ |
||
68 | '|Build Status|', |
||
69 | '|npm|', |
||
70 | '|PyPI|', |
||
71 | '|NPM Downloads|', |
||
72 | // '|Scrutinizer Code Quality|', |
||
73 | '|Try ccxt on RunKit|', |
||
74 | '|Supported Exchanges|', |
||
75 | ].join (' ') |
||
76 | |||
77 | rstNew = match[1] + "APIs:\n\n" + newRstExchangeTable + "\n\n" + match[3] |
||
78 | rstNew = rstNew.replace (/\.\.[^\n]+image\:\:[^\n]+[\n]/g, '') |
||
79 | rstNew = rstNew.replace (badgeTitles, badges) |
||
80 | rstNew = rstNew.replace (/ :target[^#]+$/g, '') |
||
81 | fs.truncateSync (readmeRst) |
||
82 | fs.writeFileSync (readmeRst, rstNew) |
||
83 | |||
84 | //----------------------------------------------------------------------------- |
||
85 | |||
86 | let readmeMd = 'README.md' |
||
87 | |||
88 | log.bright.cyan ('Updating badges →', readmeMd.yellow) |
||
89 | |||
90 | let md = fs.readFileSync (readmeMd, 'utf8') |
||
91 | let mdNew = |
||
92 | md.replace (/shields\.io\/badge\/exchanges\-[0-9]+\-blue/g, 'shields.io/badge/exchanges-' + ccxt.exchanges.length + '-blue') |
||
93 | |||
94 | fs.truncateSync (readmeMd) |
||
95 | fs.writeFileSync (readmeMd, mdNew) |
||
96 | |||
97 | log.bright.green ('Badges updated successfully.') |