Skip to content

Commit

Permalink
reusable build/vss
Browse files Browse the repository at this point in the history
  • Loading branch information
kroitor committed Oct 29, 2019
1 parent 0a3122b commit 1e27f9b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 25 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/**/*
!build/export-exchanges.js
!build/fs.js
!build/transpile.js
!build/vss.js
examples/
node_modules/
python/
Expand Down
2 changes: 1 addition & 1 deletion build/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ function transpileDerivedExchangeFile (jsFolder, filename, options) {

log.cyan ('Transpiling from', filename.yellow)

[
;[
[ python2Folder, filename.replace ('.js', '.py'), python2 ],
[ python3Folder, filename.replace ('.js', '.py'), python3 ],
[ phpFolder, filename.replace ('.js', '.php'), php ],
Expand Down
76 changes: 52 additions & 24 deletions build/vss.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ const { execSync } = require ('child_process')

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

let { version } = require ('../package.json')
function incrementVersionPatchNumber (version) {

//-----------------------------------------------------------------------------
let [ major, minor, patch ] = version.split ('.')

log.bright ('Old version: '.dim, version)
let [ major, minor, patch ] = version.split ('.')
// we don't increment it here anymore, because
// npm version patch will be explicitly called before

// we don't increment it here anymore, because
// npm version patch will be explicitly called before
// patch = (parseInt (patch) + 1).toString ()

// patch = (parseInt (patch) + 1).toString ()
version = [ major, minor, patch ].join ('.')

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

function vss (filename, template) {
//-----------------------------------------------------------------------------

function vss (filename, template, version) {
log.bright.cyan ('Single-sourcing version', version, './package.json → ' + filename.yellow)
const content = fs.readFileSync (filename, 'utf8')
const regexp = new RegExp (template.replace (/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') // escape string for use in regexp
Expand All @@ -37,23 +38,50 @@ function vss (filename, template) {
fs.writeFileSync (filename, content.replace (regexp, template.replace ('{version}', version)))
}

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

vss ('./php/base/Exchange.php', "$version = '{version}'")
vss ('./php/base/Exchange.php', "VERSION = '{version}'")
vss ('./ccxt.js', "const version = '{version}'")
vss ('./python/ccxt/__init__.py', "__version__ = '{version}'")
vss ('./python/ccxt/async_support/__init__.py', "__version__ = '{version}'")
vss ('./python/ccxt/base/exchange.py', "__version__ = '{version}'")
vss ('./python/ccxt/async_support/base/exchange.py', "__version__ = '{version}'")
function vssEverything () {

vss ('./README.md', "ccxt@{version}")
vss ('./wiki/Install.md', "ccxt@{version}")
let { version } = require ('../package.json')

//-----------------------------------------------------------------------------
log.bright ('Old version: '.dim, version)
version = incrementVersionPatchNumber (version)
log.bright ('New version: '.cyan, version)

execSync ('cp ./package.json ./LICENSE.txt ./keys.json ./python/')
vss ('./ccxt.js', "const version = '{version}'", version)
vss ('./php/base/Exchange.php', "$version = '{version}'", version)
vss ('./php/base/Exchange.php', "VERSION = '{version}'", version)
vss ('./python/ccxt/__init__.py', "__version__ = '{version}'", version)
vss ('./python/ccxt/base/exchange.py', "__version__ = '{version}'", version)
vss ('./python/ccxt/async_support/__init__.py', "__version__ = '{version}'", version)
vss ('./python/ccxt/async_support/base/exchange.py', "__version__ = '{version}'", version)

//-----------------------------------------------------------------------------
vss ('./README.md', "ccxt@{version}")
vss ('./wiki/Install.md', "ccxt@{version}")

execSync ('cp ./package.json ./LICENSE.txt ./keys.json ./python/')

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

log.bright.green ('Version single-sourced successfully.')
// ============================================================================
// main entry point

if (require.main === module) {

// if called directly like `node module`

vssEverything ()

} else {

// do nothing if required as a module
}

// ============================================================================

module.exports = {
incrementVersionPatchNumber,
vss,
vssEverything,
}

0 comments on commit 1e27f9b

Please sign in to comment.