Skip to content

Commit

Permalink
better logging in build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
xpl committed Jul 30, 2017
1 parent 90046f5 commit 1b8ed0a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
9 changes: 6 additions & 3 deletions export-markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const countries = require ('./countries')
const asTable = require ('as-table')
const util = require ('util')
const execSync = require ('child_process').execSync
const log = require ('ololog')
const ansi = require ('ansicolor').nice

let markets
let verbose = false
Expand All @@ -14,7 +16,7 @@ let wikiPath = 'ccxt.wiki'

if (!fs.existsSync (wikiPath)) {

console.log ('Checking out ccxt.wiki...')
log.bright.cyan ('Checking out ccxt.wiki...')
execSync ('git clone https://github.com/kroitor/ccxt.wiki.git')
}

Expand Down Expand Up @@ -103,7 +105,7 @@ lines[1] = headerLine.join ('|')
lines = lines.map (line => '|' + line + '|').join ("\n")

let changeInFile = (filename) => {
console.log (filename)
log.bright ('Exporting markets to'.cyan, filename.yellow, '...')
let oldContent = fs.readFileSync (filename, 'utf8')
let beginning = "The ccxt library currently supports the following "
let ending = " cryptocurrency exchange markets and trading APIs:\n\n"
Expand Down Expand Up @@ -196,6 +198,7 @@ marketsByCountries = marketsByCountries.sort ((a, b) => {
// console.log (marketsByCountries)
// console.log (asTable.configure ({ delimiter: ' | ' }) (marketsByCountries))

log.bright ('Exporting market IDs to'.cyan, 'markets.json'.yellow)
fs.writeFileSync ('markets.json', JSON.stringify ({ ids: Object.keys (markets) }, null, 4))

console.log ('Markets exported successfully.')
log.bright.green ('Markets exported successfully.')
14 changes: 9 additions & 5 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const fs = require ('fs')

/* ------------------------------------------------------------------------ */

const warn = log.bright.yellow.error // .error goes to stderr

/* ------------------------------------------------------------------------ */

process.on ('uncaughtException', e => { log.bright.red.error (e); process.exit (1) })
process.on ('unhandledRejection', e => { log.bright.red.error (e); process.exit (1) })

Expand Down Expand Up @@ -338,15 +342,15 @@ let tryAllProxies = async function (market, proxies) {

currentProxy = ++currentProxy % proxies.length
if (e instanceof ccxt.DDoSProtectionError) {
log.bright.yellow (market.id, '[DDoS Protection Error] ' + e.message)
warn (market.id, '[DDoS Protection Error] ' + e.message)
} else if (e instanceof ccxt.TimeoutError) {
log.bright.yellow (market.id, '[Timeout Error] ' + e.message)
warn (market.id, '[Timeout Error] ' + e.message)
} else if (e instanceof ccxt.AuthenticationError) {
log.bright.yellow (market.id, '[Authentication Error] ' + e.message)
warn (market.id, '[Authentication Error] ' + e.message)
} else if (e instanceof ccxt.MarketNotAvailableError) {
log.bright.yellow (market.id, '[Market Not Available Error] ' + e.message)
warn (market.id, '[Market Not Available Error] ' + e.message)
} else if (e instanceof ccxt.EndpointNotAvailableError) {
log.bright.yellow (market.id, '[Endpoint Not Available Error] ' + e.message)
warn (market.id, '[Endpoint Not Available Error] ' + e.message)
} else {
throw e;
}
Expand Down
14 changes: 9 additions & 5 deletions update-badges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

const fs = require ('fs')
const ccxt = require ('./ccxt')
const log = require ('ololog')
const ansi = require ('ansicolor').nice

//-----------------------------------------------------------------------------

console.log ('Updating badges → ./README.rst')

let readmeRst = 'README.rst'

log.bright.cyan ('Updating badges →', readmeRst.yellow)

let rst = fs.readFileSync (readmeRst, 'utf8')
let rstNew =
rst.replace (/\`([^\`]+)\s\<\#[^\`]+\>\`\_\_/g, '$1')
Expand Down Expand Up @@ -67,14 +70,15 @@ fs.writeFileSync (readmeRst, rstNew)

//-----------------------------------------------------------------------------

console.log ('Updating badges → ./README.md')

let readmeMd = 'README.md'

log.bright.cyan ('Updating badges →', readmeMd.yellow)

let md = fs.readFileSync (readmeMd, 'utf8')
let mdNew =
md.replace (/shields\.io\/badge\/exchanges\-[0-9]+\-blue/g, 'shields.io/badge/exchanges-' + ccxt.markets.length + '-blue')

fs.truncateSync (readmeMd)
fs.writeFileSync (readmeMd, mdNew)

console.log ('Badges updated successfully.')
log.bright.green ('Badges updated successfully.')
17 changes: 8 additions & 9 deletions vss.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const ccxt = require ('./ccxt')
const countries = require ('./countries')
const asTable = require ('as-table')
const util = require ('util')
const log = require ('ololog')
const ansi = require ('ansicolor').nice

//-----------------------------------------------------------------------------

Expand All @@ -14,7 +16,7 @@ let version = config.version

//-----------------------------------------------------------------------------

console.log ('Old version: ', version)
log.bright ('Old version: '.dim, version)
let [ major, minor, patch ] = version.split ('.')

// we don't increment it here anymore, because
Expand All @@ -23,41 +25,38 @@ let [ major, minor, patch ] = version.split ('.')
// patch = (parseInt (patch) + 1).toString ()

version = [ major, minor, patch ].join ('.')
console.log ('New version: ', version)
log.bright ('New version: '.cyan, version)

//-----------------------------------------------------------------------------

console.log ('Single-sourcing version', version, './package.json → ./ccxt.js')
log.bright.cyan ('Single-sourcing version', version, './package.json → ./ccxt.js'.yellow)
let ccxtjsFilename = './ccxt.js'
let ccxtjs = fs.readFileSync (ccxtjsFilename, 'utf8')
let ccxtjsParts = ccxtjs.split (/var version \= \'[^\']+\'/)
let ccxtjsNewContent = ccxtjsParts[0] + "var version = '" + version + "'" + ccxtjsParts[1]
fs.truncateSync (ccxtjsFilename)
fs.writeFileSync (ccxtjsFilename, ccxtjsNewContent)
console.log ('Done.')

//-----------------------------------------------------------------------------

console.log ('Single-sourcing version', version, './package.json → ./ccxt/__init__.py')
log.bright.cyan ('Single-sourcing version', version, './package.json → ./ccxt/__init__.py'.yellow)
let ccxtpyFilename = './ccxt/__init__.py'
let ccxtpy = fs.readFileSync (ccxtpyFilename, 'utf8')
let ccxtpyParts = ccxtpy.split (/\_\_version\_\_ \= \'[^\']+\'/)
let ccxtpyNewContent = ccxtpyParts[0] + "__version__ = '" + version + "'" + ccxtpyParts[1]
fs.truncateSync (ccxtpyFilename)
fs.writeFileSync (ccxtpyFilename, ccxtpyNewContent)
console.log ('Done.')

//-----------------------------------------------------------------------------

console.log ('Single-sourcing version', version, './package.json → ./ccxt.php')
log.bright.cyan ('Single-sourcing version', version, './package.json → ./ccxt.php'.yellow)
let ccxtphpFilename = './ccxt.php'
let ccxtphp = fs.readFileSync (ccxtphpFilename, 'utf8')
let ccxtphpParts = ccxtphp.split (/\$version \= \'[^\']+\'/)
let ccxtphpNewContent = ccxtphpParts[0] + '$version' + " = '" + version + "'" + ccxtphpParts[1]
fs.truncateSync (ccxtphpFilename)
fs.writeFileSync (ccxtphpFilename, ccxtphpNewContent)
console.log ('Done.')

//-----------------------------------------------------------------------------

console.log ('Version single-sourced successfully.')
log.bright.green ('Version single-sourced successfully.')

0 comments on commit 1b8ed0a

Please sign in to comment.