Skip to content

Commit

Permalink
improve postinstall by using async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Sep 29, 2019
1 parent 161488d commit 107909d
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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) {
Expand All @@ -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.