forked from ccxt/ccxt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vss.js
50 lines (37 loc) · 2.04 KB
/
vss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"use strict";
const fs = require ('fs')
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
//-----------------------------------------------------------------------------
let packageJSON = fs.readFileSync ('./package.json', 'utf8')
let config = JSON.parse (packageJSON);
let version = config.version
//-----------------------------------------------------------------------------
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
// patch = (parseInt (patch) + 1).toString ()
version = [ major, minor, patch ].join ('.')
log.bright ('New version: '.cyan, version)
function vss (filename, regex, replacement) {
log.bright.cyan ('Single-sourcing version', version, './package.json → ' + filename.yellow)
let oldContent = fs.readFileSync (filename, 'utf8')
let parts = oldContent.split (regex)
let newContent = parts[0] + replacement + version + "'" + parts[1]
fs.truncateSync (filename)
fs.writeFileSync (filename, newContent)
}
//-----------------------------------------------------------------------------
vss ('./php/Exchange.php', /\$version \= \'[^\']+\'/, "$version = '")
vss ('./ccxt.js', /const version \= \'[^\']+\'/, "const version = '")
vss ('./python/ccxt/__init__.py', /\_\_version\_\_ \= \'[^\']+\'/, "__version__ = '")
vss ('./python/ccxt/async/__init__.py', /\_\_version\_\_ \= \'[^\']+\'/, "__version__ = '")
vss ('./python/ccxt/base/exchange.py', /\_\_version\_\_ \= \'[^\']+\'/, "__version__ = '")
vss ('./python/ccxt/async/base/exchange.py', /\_\_version\_\_ \= \'[^\']+\'/, "__version__ = '")
//-----------------------------------------------------------------------------
log.bright.green ('Version single-sourced successfully.')