From 1e27f9b1c0e055a0c9a5b4d51d8ae918db9fe12a Mon Sep 17 00:00:00 2001 From: Igor Kroitor Date: Tue, 29 Oct 2019 05:19:10 +0300 Subject: [PATCH] reusable build/vss --- .npmignore | 1 + build/transpile.js | 2 +- build/vss.js | 76 +++++++++++++++++++++++++++++++--------------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/.npmignore b/.npmignore index a672b63931b1..9a1533dd6e23 100644 --- a/.npmignore +++ b/.npmignore @@ -4,6 +4,7 @@ build/**/* !build/export-exchanges.js !build/fs.js !build/transpile.js +!build/vss.js examples/ node_modules/ python/ diff --git a/build/transpile.js b/build/transpile.js index 3755834465c4..348ad7a276d6 100644 --- a/build/transpile.js +++ b/build/transpile.js @@ -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 ], diff --git a/build/vss.js b/build/vss.js index 024059c1f866..5844536e60ea 100644 --- a/build/vss.js +++ b/build/vss.js @@ -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 @@ -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, +}