Skip to content
Permalink
Browse files

improve postinstall by using async/await

  • Loading branch information
Johann-S committed Sep 29, 2019
1 parent 161488d commit 107909d5011a519ade42e3be66683be020194166
Showing with 30 additions and 25 deletions.
  1. +30 −25 postinstall.js
@@ -5,13 +5,13 @@ function style(s, style) {
}

const colors = {
'black': 30,
'red': 31,
'green': 32,
'yellow': 33,
'blue': 34,
'white': 37,
'gray': 90,
black: 30,
red: 31,
green: 32,
yellow: 33,
blue: 34,
white: 37,
gray: 90,
}

let colorFunctions = {}
@@ -56,17 +56,18 @@ let footer = [
]

async function getData () {
let data = {}
let collectiveData = await (await fetch ('https://opencollective.com/ccxt.json')).json ()
let githubData = await (await fetch ('https://api.github.com/repos/ccxt/ccxt')).json ()
data['contributors'] = collectiveData['contributorsCount'].toLocaleString ()
data['backers'] = collectiveData['backersCount'].toLocaleString ()
data['balance'] = Math.floor (collectiveData['balance'] / 100).toLocaleString ()
data['budget'] = Math.floor (collectiveData['yearlyIncome'] / 100).toLocaleString ()
data['stars'] = githubData['stargazers_count'].toLocaleString ()
data['forks'] = githubData['forks_count'].toLocaleString ()
data['size'] = (githubData['size'] / 1000000).toFixed (2)
return data
const collectiveData = await (await fetch ('https://opencollective.com/ccxt.json')).json ()
const githubData = await (await fetch ('https://api.github.com/repos/ccxt/ccxt')).json ()

return {
contributors: collectiveData['contributorsCount'].toLocaleString (),
backers: collectiveData['backersCount'].toLocaleString (),
balance: Math.floor (collectiveData['balance'] / 100).toLocaleString (),
budget: Math.floor (collectiveData['yearlyIncome'] / 100).toLocaleString (),
stars: githubData['stargazers_count'].toLocaleString (),
forks: githubData['forks_count'].toLocaleString (),
size: (githubData['size'] / 1000000).toFixed (2)
}
}

function pad (string) {
@@ -75,16 +76,20 @@ function pad (string) {
return ' '.repeat (half + (padding % 2)) + string + ' '.repeat (half)
}

getData().then ((data) => {
async function main () {
const data = await getData()

colorFunctions['blue'] (ascii.join ('\n'))
colorFunctions['red'] (pad (`Stars: ${data['stars']}`))
colorFunctions['red'] (pad (`Forks: ${data['forks']}`))
colorFunctions['red'] (pad (`Contributors: ${data['contributors']}`))
colorFunctions['red'] (pad (`Size: ${data['size']}MB`))
colorFunctions['red'] (pad (`Stars: ${data.stars}`))
colorFunctions['red'] (pad (`Forks: ${data.forks}`))
colorFunctions['red'] (pad (`Contributors: ${data.contributors}`))
colorFunctions['red'] (pad (`Size: ${data.size}MB`))
colorFunctions['yellow'] ('\n' + pad ('Thanks for installing ccxt 🙏'))
colorFunctions['gray'] (pad ('Please consider donating to our open collective'))
colorFunctions['gray'] (pad ('to help us maintain this package.'))
colorFunctions['yellow'] (pad ('👉 Donate: https://opencollective.com/ccxt/donate 🎉'))
colorFunctions['white'] (pad (`Thanks to our ${data['backers']} backers we are operating on an annual budget of $${data['budget']}`))
colorFunctions['white'] (pad (`Thanks to our ${data.backers} backers we are operating on an annual budget of $${data.budget}`))
colorFunctions['yellow'] (footer.join ('\n'))
})
}

main()

0 comments on commit 107909d

Please sign in to comment.
You can’t perform that action at this time.