Current Folder

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 14:05:59 +01:00
1 parent 8b3382289b
commit cfcada880d
4379 files changed

No files matched your search

-94
View File
@@ -1,94 +0,0 @@
"use strict"
const { execSync } = require ('child_process')
const log = require ('ololog').noLocate
const { groupBy } = require ('../ccxt.js')
const { values } = Object
const assert = require ('assert')
function cleanupOldTags () {
const tags = execSync ('git tag').toString ().split ('\n').filter (s => s).map (t => {
const [major, minor, patch] = t.replace ('v', '').split ('.').map (Number)
assert (major < 100)
assert (minor < 100)
return {
key: (major * 100) + minor,
tag: t,
major,
minor,
patch,
}
})
const tagsByMajorMinor = values (groupBy (tags, 'key')).sort ((a, b) => a[0].key - b[0].key)
// Preserve all tags for first 5 minor versions
for (let i = 0; i < 5; i++) {
const tags = tagsByMajorMinor.pop ()
if (tags) {
log.green.bright ('Preserving', tags[0].tag, '...', tags[tags.length - 1].tag)
}
}
// For older versions, leave only "round" numbered versions (1/10th)
let tagsToDelete = []
for (const tags of tagsByMajorMinor) {
for (const { tag, patch } of tags) {
if (patch === 1) {
log.green ('Preserving', tag)
} else {
tagsToDelete.push (tag)
}
}
}
log.bright.red ('Deleting', tagsToDelete.length, 'tags...')
if (!process.argv.includes ('--paper')) {
/* If it happens on a CI server, we don't want it to fail the build because of a super
long execution time (one tag deletion takes ~5 sec...), hence that limit here */
if (process.argv.includes ('--limit')) {
tagsToDelete = tagsToDelete.slice (-500)
}
for (const tag of tagsToDelete) {
log.dim ('Deleting', tag)
execSync (`git tag -d ${tag} && git push origin :refs/tags/${tag}`)
}
}
}
// ============================================================================
// main entry point
if (require.main === module) {
// if called directly like `node module`
cleanupOldTags ()
} else {
// do nothing if required as a module
}
// ============================================================================
module.exports = {
cleanupOldTags,
}
-256
View File
@@ -1,256 +0,0 @@
"use strict";
module.exports = {
AF: 'Afghanistan',
AX: 'Åland Islands',
AL: 'Albania',
DZ: 'Algeria',
AS: 'American Samoa',
AD: 'Andorra',
AO: 'Angola',
AI: 'Anguilla',
AQ: 'Antarctica',
AG: 'Antigua and Barbuda',
AR: 'Argentina',
AM: 'Armenia',
AW: 'Aruba',
AU: 'Australia',
AT: 'Austria',
AZ: 'Azerbaijan',
BS: 'Bahamas',
BH: 'Bahrain',
BD: 'Bangladesh',
BB: 'Barbados',
BY: 'Belarus',
BE: 'Belgium',
BZ: 'Belize',
BJ: 'Benin',
BM: 'Bermuda',
BT: 'Bhutan',
BO: 'Bolivia',
BQ: 'Bonaire, Sint Eustatius and Saba',
BA: 'Bosnia and Herzegovina',
BW: 'Botswana',
BV: 'Bouvet Island',
BR: 'Brazil',
IO: 'British Indian Ocean Territory',
BN: 'Brunei Darussalam',
BG: 'Bulgaria',
BF: 'Burkina Faso',
BI: 'Burundi',
KH: 'Cambodia',
CM: 'Cameroon',
CA: 'Canada',
CV: 'Cabo Verde',
KY: 'Cayman Islands',
CF: 'Central African Republic',
TD: 'Chad',
CL: 'Chile',
CN: 'China',
CX: 'Christmas Island',
CC: 'Cocos (Keeling) Islands',
CO: 'Colombia',
KM: 'Comoros',
CG: 'Congo',
CD: 'Congo',
CK: 'Cook Islands',
CR: 'Costa Rica',
CI: 'Côte d\'Ivoire',
HR: 'Croatia',
CU: 'Cuba',
CW: 'Curaçao',
CY: 'Cyprus',
CZ: 'Czech Republic',
DK: 'Denmark',
DJ: 'Djibouti',
DM: 'Dominica',
DO: 'Dominican Republic',
EC: 'Ecuador',
EG: 'Egypt',
SV: 'El Salvador',
GQ: 'Equatorial Guinea',
ER: 'Eritrea',
EE: 'Estonia',
ET: 'Ethiopia',
EU: 'EU',
FK: 'Falkland Islands',
FO: 'Faroe Islands',
FJ: 'Fiji',
FI: 'Finland',
FR: 'France',
GF: 'French Guiana',
PF: 'French Polynesia',
TF: 'French Southern Territories',
GA: 'Gabon',
GM: 'Gambia',
GE: 'Georgia',
DE: 'Germany',
GH: 'Ghana',
GI: 'Gibraltar',
GR: 'Greece',
GL: 'Greenland',
GD: 'Grenada',
GP: 'Guadeloupe',
GU: 'Guam',
GT: 'Guatemala',
GG: 'Guernsey',
GN: 'Guinea',
GW: 'Guinea-Bissau',
GY: 'Guyana',
HT: 'Haiti',
HM: 'Heard Island and McDonald Islands',
VA: 'Holy See',
HN: 'Honduras',
HK: 'Hong Kong',
HU: 'Hungary',
IS: 'Iceland',
IN: 'India',
ID: 'Indonesia',
IR: 'Iran',
IQ: 'Iraq',
IE: 'Ireland',
IM: 'Isle of Man',
IL: 'Israel',
IT: 'Italy',
JM: 'Jamaica',
JP: 'Japan',
JE: 'Jersey',
JO: 'Jordan',
KZ: 'Kazakhstan',
KE: 'Kenya',
KI: 'Kiribati',
KP: 'North Korea (DPRK)',
KR: 'South Korea',
KW: 'Kuwait',
KG: 'Kyrgyzstan',
LA: 'Lao People\'s Democratic Republic',
LV: 'Latvia',
LB: 'Lebanon',
LS: 'Lesotho',
LR: 'Liberia',
LY: 'Libya',
LI: 'Liechtenstein',
LT: 'Lithuania',
LU: 'Luxembourg',
MO: 'Macao',
MK: 'Macedonia',
MG: 'Madagascar',
MW: 'Malawi',
MY: 'Malaysia',
MV: 'Maldives',
ML: 'Mali',
MT: 'Malta',
MH: 'Marshall Islands',
MQ: 'Martinique',
MR: 'Mauritania',
MU: 'Mauritius',
YT: 'Mayotte',
MX: 'Mexico',
FM: 'Micronesia (Federated States of)',
MD: 'Moldova',
MC: 'Monaco',
MN: 'Mongolia',
ME: 'Montenegro',
MS: 'Montserrat',
MA: 'Morocco',
MZ: 'Mozambique',
MM: 'Myanmar',
NA: 'Namibia',
NR: 'Nauru',
NP: 'Nepal',
NL: 'Netherlands',
NC: 'New Caledonia',
NZ: 'New Zealand',
NI: 'Nicaragua',
NE: 'Niger',
NG: 'Nigeria',
NU: 'Niue',
NF: 'Norfolk Island',
MP: 'Northern Mariana Islands',
NO: 'Norway',
OM: 'Oman',
PK: 'Pakistan',
PW: 'Palau',
PS: 'Palestine, State of',
PA: 'Panama',
PG: 'Papua New Guinea',
PY: 'Paraguay',
PE: 'Peru',
PH: 'Philippines',
PN: 'Pitcairn',
PL: 'Poland',
PT: 'Portugal',
PR: 'Puerto Rico',
QA: 'Qatar',
RE: 'Réunion',
RO: 'Romania',
RU: 'Russia',
RW: 'Rwanda',
BL: 'Saint Barthélemy',
SH: 'Saint Helena, Ascension and Tristan da Cunha',
KN: 'Saint Kitts and Nevis',
LC: 'Saint Lucia',
MF: 'Saint Martin (French)',
PM: 'Saint Pierre and Miquelon',
VC: 'St. Vincent & Grenadines',
WS: 'Samoa',
SM: 'San Marino',
ST: 'Sao Tome and Principe',
SA: 'Saudi Arabia',
SN: 'Senegal',
RS: 'Serbia',
SC: 'Seychelles',
SL: 'Sierra Leone',
SG: 'Singapore',
SX: 'Sint Maarten (Dutch)',
SK: 'Slovakia',
SI: 'Slovenia',
SB: 'Solomon Islands',
SO: 'Somalia',
ZA: 'South Africa',
GS: 'South Georgia and the South Sandwich Islands',
SS: 'South Sudan',
ES: 'Spain',
LK: 'Sri Lanka',
SD: 'Sudan',
SR: 'Suriname',
SJ: 'Svalbard and Jan Mayen',
SZ: 'Swaziland',
SE: 'Sweden',
CH: 'Switzerland',
SY: 'Syrian Arab Republic',
TW: 'Taiwan',
TJ: 'Tajikistan',
TZ: 'Tanzania',
TH: 'Thailand',
TL: 'Timor-Leste',
TG: 'Togo',
TK: 'Tokelau',
TO: 'Tonga',
TT: 'Trinidad and Tobago',
TN: 'Tunisia',
TR: 'Turkey',
TM: 'Turkmenistan',
TC: 'Turks and Caicos Islands',
TV: 'Tuvalu',
UG: 'Uganda',
UA: 'Ukraine',
AE: 'United Arab Emirates',
GB: 'UK',
UK: 'UK',
US: 'US',
UM: 'US Minor Islands',
UY: 'Uruguay',
UZ: 'Uzbekistan',
VU: 'Vanuatu',
VE: 'Venezuela',
VN: 'Vietnam',
VG: 'British Virgin Islands',
VI: 'US Virgin Islands',
WF: 'Wallis and Futuna',
EH: 'Western Sahara',
YE: 'Yemen',
ZM: 'Zambia',
ZW: 'Zimbabwe',
}
-455
View File
@@ -1,455 +0,0 @@
// ----------------------------------------------------------------------------
// Usage:
//
// npm run export-exchanges
// ----------------------------------------------------------------------------
"use strict";
const fs = require ('fs')
, countries = require ('./countries')
, asTable = require ('as-table')
, execSync = require ('child_process').execSync
, log = require ('ololog').unlimited
, ansi = require ('ansicolor').nice
, { keys, values, entries } = Object
, { replaceInFile } = require ('./fs.js')
// ----------------------------------------------------------------------------
function cloneGitHubWiki (gitWikiPath) {
if (!fs.existsSync (gitWikiPath)) {
log.bright.cyan ('Cloning ccxt.wiki...')
execSync ('git clone https://github.com/ccxt/ccxt.wiki.git ' + gitWikiPath)
}
}
// ----------------------------------------------------------------------------
function logExportExchanges (filename, regex, replacement) {
log.bright.cyan ('Exporting exchanges →', filename.yellow)
replaceInFile (filename, regex, replacement)
}
// ----------------------------------------------------------------------------
function getIncludedExchangeIds () {
const includedIds = fs.readFileSync ('exchanges.cfg')
.toString () // Buffer → String
.split ('\n') // String → Array
.map (line => line.split ('#')[0].trim ()) // trim comments
.filter (exchange => exchange); // filter empty lines
const isIncluded = (id) => ((includedIds.length === 0) || includedIds.includes (id))
const ids = fs.readdirSync ('./js/')
.filter (file => file.match (/[a-zA-Z0-9_-]+.js$/))
.map (file => file.slice (0, -3))
.filter (isIncluded);
return ids
}
// ----------------------------------------------------------------------------
function exportExchanges (replacements) {
log.bright.yellow ('Exporting exchanges...')
replacements.forEach (({ file, regex, replacement }) => {
logExportExchanges (file, regex, replacement)
})
log.bright.green ('Base sources updated successfully.')
}
// ----------------------------------------------------------------------------
function createExchanges (ids) {
const ccxt = require ('../ccxt.js')
const createExchange = (id) => {
ccxt[id].prototype.checkRequiredDependencies = () => {} // suppress it
return new (ccxt)[id] ()
}
return ccxt.indexBy (ids.map (createExchange), 'id')
}
// // ----------------------------------------------------------------------------
// // strategically placed exactly here (we can require it AFTER the export)
// const ccxt = require ('../ccxt.js')
// // ----------------------------------------------------------------------------
// // create exchanges
// const createExchange = (id) => {
// ccxt[id].prototype.checkRequiredDependencies = () => {} // suppress it
// return new (ccxt)[id] ()
// }
// const exchanges = ccxt.indexBy (ids.map (createExchange), 'id')
// ----------------------------------------------------------------------------
// TODO: REWRITE THIS ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
function exportSupportedAndCertifiedExchanges (exchanges, { allExchangesPaths, certifiedExchangesPaths, exchangesByCountriesPaths, proExchangesPaths }) {
// ............................................................................
// markup constants and helper functions
const countryName = (code) => countries[code] || code
const ccxtCertifiedBadge = '[![CCXT Certified](https://img.shields.io/badge/CCXT-Certified-green.svg)](https://github.com/ccxt/ccxt/wiki/Certification)'
const ccxtProBadge = '[![CCXT Pro](https://img.shields.io/badge/CCXT-Pro-black)](https://ccxt.pro)'
const logoHeading = '&nbsp;'.repeat (7) + 'logo' + '&nbsp;'.repeat (7)
const tableHeadings = [ logoHeading, 'id', 'name', 'ver', 'doc', 'certified', 'pro' ]
const exchangesByCountryHeading = [ 'country / region', ... tableHeadings.slice (0, 5) ]
// ----------------------------------------------------------------------------
// list all supported exchanges
const exchangesNotListedInDocs = [ 'hitbtc2' ]
function makeTableData (exchanges) {
return (
values (exchanges)
.filter (exchange => !exchangesNotListedInDocs.includes (exchange.id))
.map (exchange => {
let logo = exchange.urls['logo']
let website = Array.isArray (exchange.urls.www) ? exchange.urls.www[0] : exchange.urls.www
let url = exchange.urls.referral || website
let doc = Array.isArray (exchange.urls.doc) ? exchange.urls.doc[0] : exchange.urls.doc
let version = exchange.version ? exchange.version : '\*'
let matches = version.match (/[^0-9]*([0-9].*)/)
if (matches) {
version = matches[1];
}
return [
'[![' + exchange.id + '](' + logo + ')](' + url + ')',
exchange.id,
'[' + exchange.name + '](' + url + ')',
version,
'[API](' + doc + ')',
exchange.certified ? ccxtCertifiedBadge : '',
exchange.pro ? ccxtProBadge : '',
]
})
)
}
function makeTable (jsonArray) {
let table = asTable.configure ({ 'delimiter': ' | ' }) (jsonArray)
let lines = table.split ("\n")
lines.splice (1,0, lines[0].replace (/[^\|]/g, '-'))
let headerLine = lines[1].split ('|')
headerLine[3] = ':' + headerLine[3].slice (1, headerLine[3].length - 1) + ':'
headerLine[4] = ':' + headerLine[4].slice (1, headerLine[4].length - 1) + ':'
lines[1] = headerLine.join ('|')
return lines.map (line => '|' + line + '|').join ("\n")
}
if (allExchangesPaths) {
const tableData = makeTableData (exchanges)
const numExchanges = tableData.length
// prepend the table header
tableData.splice (0, 0, tableHeadings)
const exchangesTable = makeTable (tableData)
const beginning = "The CCXT library currently supports the following "
const ending = " cryptocurrency exchange markets and trading APIs:\n\n"
const totalString = beginning + numExchanges + ending
const allExchanges = totalString + exchangesTable + "$1"
const allExchangesRegex = new RegExp ("[^\n]+[\n]{2}\\|[^`]+\\|([\n][\n]|[\n]$|$)", 'm')
for (const path of allExchangesPaths) {
logExportExchanges (path, allExchangesRegex, allExchanges)
}
// logExportExchanges ('README.md', allExchangesRegex, allExchanges)
// logExportExchanges (wikiPath + '/Manual.md', allExchangesRegex, allExchanges)
// logExportExchanges (wikiPath + '/Exchange-Markets.md', allExchangesRegex, allExchanges)
}
if (proExchangesPaths) {
const pro = values (exchanges).filter (exchange => exchange.pro)
const tableData = makeTableData (pro)
const numExchanges = tableData.length
// prepend the table header
tableData.splice (0, 0, tableHeadings)
const exchangesTable = makeTable (tableData)
const beginning = "The CCXT Pro library currently supports the following "
const ending = " cryptocurrency exchange markets and WebSocket trading APIs:\n\n"
const totalString = beginning + numExchanges + ending
const proExchanges = totalString + exchangesTable + "$1"
const proExchangesRegex = new RegExp ("[^\n]+[\n]{2}\\|[^`]+\\|([\n][\n]|[\n]$|$)", 'm')
for (const path of proExchangesPaths) {
logExportExchanges (path, proExchangesRegex, proExchanges)
}
}
if (certifiedExchangesPaths) {
const certified = values (exchanges).filter (exchange => exchange.certified)
const tableData = makeTableData (certified)
// prepend the table header
tableData.splice (0, 0, tableHeadings)
const certifiedExchangesRegex = new RegExp ("^(## Certified Cryptocurrency Exchanges\n{3})(?:\\|.+\\|$\n)+", 'm')
const certifiedExchangesTable = makeTable (tableData)
const certifiedExchanges = '$1' + certifiedExchangesTable + "\n"
for (const path of certifiedExchangesPaths) {
logExportExchanges (path, certifiedExchangesRegex, certifiedExchanges)
}
// logExportExchanges ('README.md', certifiedExchangesRegex, certifiedExchanges)
}
if (exchangesByCountriesPaths) {
let exchangesByCountries = []
keys (countries).forEach (code => {
let country = countries[code]
let result = []
keys (exchanges).forEach (id => {
let exchange = exchanges[id]
let logo = exchange.urls['logo']
let website = Array.isArray (exchange.urls.www) ? exchange.urls.www[0] : exchange.urls.www
let url = exchange.urls.referral || website
let doc = Array.isArray (exchange.urls.doc) ? exchange.urls.doc[0] : exchange.urls.doc
let version = exchange.version ? exchange.version : '\*'
let matches = version.match (/[^0-9]*([0-9].*)/)
if (matches)
version = matches[1];
let shouldInclude = false
if (Array.isArray (exchange.countries)) {
if (exchange.countries.indexOf (code) > -1)
shouldInclude = true
} else {
if (code == exchange.countries)
shouldInclude = true
}
if (shouldInclude) {
let entry = [
country,
'[![' + exchange.id + '](' + logo + ')](' + url + ')',
exchange.id,
'[' + exchange.name + '](' + url + ')',
version,
'[API](' + doc + ')',
// doesn't fit in width
// exchange.certified ? ccxtCertifiedBadge : '',
]
result.push (entry)
}
})
exchangesByCountries = exchangesByCountries.concat (result)
});
const countryKeyIndex = exchangesByCountryHeading.indexOf ('country / region')
exchangesByCountries = exchangesByCountries.sort ((a, b) => {
const countryA = a[countryKeyIndex].toLowerCase ()
const countryB = b[countryKeyIndex].toLowerCase ()
if (countryA > countryB) {
return 1
} else if (countryA < countryB) {
return -1;
} else {
if (a['id'] > b['id'])
return 1;
else if (a['id'] < b['id'])
return -1;
else
return 0;
}
})
exchangesByCountries.splice (0, 0, exchangesByCountryHeading)
const lines = makeTable (exchangesByCountries)
const result = "# Exchanges By Country\n\nThe ccxt library currently supports the following cryptocurrency exchange markets and trading APIs:\n\n" + lines + "\n\n"
for (const path of exchangesByCountriesPaths) {
fs.truncateSync (path)
fs.writeFileSync (path, result)
}
}
}
// TODO: REWRITE THIS ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
// ----------------------------------------------------------------------------
function exportExchangeIdsToExchangesJson (exchanges) {
log.bright ('Exporting exchange ids to'.cyan, 'exchanges.json'.yellow)
const ids = keys (exchanges)
console.log (ids)
fs.writeFileSync ('exchanges.json', JSON.stringify ({ ids }, null, 4))
}
// ----------------------------------------------------------------------------
function exportWikiToGitHub (wikiPath, gitWikiPath) {
log.bright.cyan ('Exporting wiki to GitHub')
const ccxtWikiFiles = {
'README.md': 'Home.md',
'Install.md': 'Install.md',
'Manual.md': 'Manual.md',
'Exchange-Markets.md': 'Exchange-Markets.md',
'Exchange-Markets-By-Country.md': 'Exchange-Markets-By-Country.md',
'ccxt.pro.md': 'ccxt.pro.md',
'ccxt.pro.install.md': 'ccxt.pro.install.md',
'ccxt.pro.manual.md': 'ccxt.pro.manual.md',
}
for (const [ sourceFile, destinationFile ] of entries (ccxtWikiFiles)) {
const sourcePath = wikiPath + '/' + sourceFile
const destinationPath = gitWikiPath + '/' + destinationFile
log.bright.cyan ('Exporting', sourcePath.yellow, '→', destinationPath.yellow)
fs.writeFileSync (destinationPath, fs.readFileSync (sourcePath))
}
}
// ----------------------------------------------------------------------------
function exportKeywordsToPackageJson (exchanges) {
log.bright ('Exporting exchange keywords to'.cyan, 'package.json'.yellow)
// const packageJSON = require ('../package.json')
const packageJSON = JSON.parse (fs.readFileSync ('./package.json'))
const keywords = new Set (packageJSON.keywords)
for (const ex of values (exchanges)) {
for (const url of Array.isArray (ex.urls.www) ? ex.urls.www : [ex.urls.www]) {
keywords.add (url.replace (/(http|https):\/\/(www\.)?/, '').replace (/\/.*/, ''))
}
keywords.add (ex.name)
}
packageJSON.keywords = [...keywords]
fs.writeFileSync ('./package.json', JSON.stringify (packageJSON, null, 2) + "\n")
}
// ----------------------------------------------------------------------------
function flatten (nested, result = []) {
for (const key in nested) {
result.push (key)
if (Object.keys (nested[key]).length)
flatten (nested[key], result)
}
return result
}
function exportEverything () {
const ids = getIncludedExchangeIds ()
const errorHierarchy = require ('../js/base/errorHierarchy.js')
const flat = flatten (errorHierarchy)
flat.push ('error_hierarchy')
const replacements = [
{
file: './ccxt.js',
regex: /(?:const|var)\s+exchanges\s+\=\s+\{[^\}]+\}/,
replacement: "const exchanges = {\n" + ids.map (id => (" '" + id + "':").padEnd (30) + " require ('./js/" + id + ".js'),").join ("\n") + " \n}",
},
{
file: './python/ccxt/__init__.py',
regex: /exchanges \= \[[^\]]+\]/,
replacement: "exchanges = [\n" + " '" + ids.join ("',\n '") + "'," + "\n]",
},
{
file: './python/ccxt/__init__.py',
regex: /(?:from ccxt\.[^\.]+ import [^\s]+\s+\# noqa\: F401[\r]?[\n])+[\r]?[\n]exchanges/,
replacement: ids.map (id => ('from ccxt.' + id + ' import ' + id).padEnd (60) + '# noqa: F401').join ("\n") + "\n\nexchanges",
},
{
file: './python/ccxt/__init__.py',
regex: /(?:from ccxt\.base\.errors import [^\s]+\s+\# noqa\: F401[\r]?[\n])+[\r]?[\n]/,
replacement: flat.map (error => ('from ccxt.base.errors' + ' import ' + error).padEnd (60) + '# noqa: F401').join ("\n") + "\n\n",
},
{
file: './python/ccxt/async_support/__init__.py',
regex: /(?:from ccxt\.base\.errors import [^\s]+\s+\# noqa\: F401[\r]?[\n])+[\r]?[\n]/,
replacement: flat.map (error => ('from ccxt.base.errors' + ' import ' + error).padEnd (60) + '# noqa: F401').join ("\n") + "\n\n",
},
{
file: './python/ccxt/async_support/__init__.py',
regex: /(?:from ccxt\.async_support\.[^\.]+ import [^\s]+\s+\# noqa\: F401[\r]?[\n])+[\r]?[\n]exchanges/,
replacement: ids.map (id => ('from ccxt.async_support.' + id + ' import ' + id).padEnd (74) + '# noqa: F401').join ("\n") + "\n\nexchanges",
},
{
file: './python/ccxt/async_support/__init__.py',
regex: /exchanges \= \[[^\]]+\]/,
replacement: "exchanges = [\n" + " '" + ids.join ("',\n '") + "'," + "\n]",
},
{
file: './php/base/Exchange.php',
regex: /public static \$exchanges \= array\s*\([^\)]+\)/,
replacement: "public static $exchanges = array(\n '" + ids.join ("',\n '") + "',\n )",
},
]
exportExchanges (replacements)
// strategically placed exactly here (we can require it AFTER the export)
const exchanges = createExchanges (ids)
const wikiPath = 'wiki'
, gitWikiPath = 'build/ccxt.wiki'
cloneGitHubWiki (gitWikiPath)
exportSupportedAndCertifiedExchanges (exchanges, {
allExchangesPaths: [
'README.md',
wikiPath + '/Manual.md',
wikiPath + '/Exchange-Markets.md'
],
certifiedExchangesPaths: [
'README.md',
],
exchangesByCountriesPaths: [
wikiPath + '/Exchange-Markets-By-Country.md'
],
proExchangesPaths: [
wikiPath + '/ccxt.pro.manual.md',
],
})
exportExchangeIdsToExchangesJson (exchanges)
exportWikiToGitHub (wikiPath, gitWikiPath)
exportKeywordsToPackageJson (exchanges)
log.bright.green ('Exported successfully.')
}
// ============================================================================
// main entry point
if (require.main === module) {
// if called directly like `node module`
exportEverything ()
} else {
// do nothing if required as a module
}
// ============================================================================
module.exports = {
cloneGitHubWiki,
getIncludedExchangeIds,
exportExchanges,
createExchanges,
exportSupportedAndCertifiedExchanges,
exportExchangeIdsToExchangesJson,
exportWikiToGitHub,
exportKeywordsToPackageJson,
exportEverything,
}
-49
View File
@@ -1,49 +0,0 @@
"use strict";
const fs = require ('fs')
, path = require ('path')
function replaceInFile (filename, regex, replacement) {
const contents = fs.readFileSync (filename, 'utf8')
const newContents = contents.replace (regex, replacement)
fs.truncateSync (filename)
fs.writeFileSync (filename, newContents)
}
function copyFile (oldName, newName) {
const contents = fs.readFileSync (oldName, 'utf8')
fs.truncateSync (newName)
fs.writeFileSync (newName, contents)
}
function overwriteFile (filename, contents) {
// log.cyan ('Overwriting → ' + filename.yellow)
fs.closeSync (fs.openSync (filename, 'a'));
fs.truncateSync (filename)
fs.writeFileSync (filename, contents)
}
function createFolder (folder) {
try {
fs.mkdirSync (folder)
} catch (err) {
if (err.code !== 'EEXIST') {
throw err
}
}
}
function createFolderRecursively (folder) {
const parts = folder.split (path.sep)
for (let i = 1; i <= parts.length; i++) {
createFolder (path.join.apply (null, parts.slice (0, i)))
}
}
module.exports = {
replaceInFile,
copyFile,
overwriteFile,
createFolder,
createFolderRecursively,
}
-1350
View File
File diff suppressed because it is too large. Load diff
-87
View File
@@ -1,87 +0,0 @@
// ---------------------------------------------------------------------------
// Usage:
//
// npm run vss
// ---------------------------------------------------------------------------
"use strict";
const fs = require ('fs')
const log = require ('ololog')
const ansi = require ('ansicolor').nice
const { execSync } = require ('child_process')
//-----------------------------------------------------------------------------
function incrementVersionPatchNumber (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 ('.')
return version
}
//-----------------------------------------------------------------------------
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
.replace ('\\{version\\}', '\\d+\\.\\d+\\.\\d+'), 'g')
fs.truncateSync (filename)
fs.writeFileSync (filename, content.replace (regexp, template.replace ('{version}', version)))
}
// ----------------------------------------------------------------------------
function vssEverything () {
let { version } = require ('../package.json')
log.bright ('Old version: '.dim, version)
version = incrementVersionPatchNumber (version)
log.bright ('New version: '.cyan, version)
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}", version)
vss ('./wiki/Install.md', "ccxt@{version}", version)
execSync ('cp ./package.json ./LICENSE.txt ./keys.json ./python/')
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,
}