Skip to content

Commit

Permalink
parallel build WS
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmiei committed Dec 16, 2022
1 parent a72e1af commit 499a87f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 3 additions & 3 deletions build/transpile.js
Expand Up @@ -1447,8 +1447,8 @@ class Transpiler {

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

async getTSClassDeclarationsAllFiles (folder, extension = '.js' ) {
const files = fs.readdirSync (folder).filter (file => exchangeIds.includes (basename (file, extension)))
async getTSClassDeclarationsAllFiles (ids, folder, extension = '.js')  {
const files = fs.readdirSync (folder).filter (file => ids.includes (basename (file, extension)))
const promiseReadFile = promisify (fs.readFile);
const fileArray = await Promise.all (files.map (file => promiseReadFile (folder + file, 'utf8')));
const classComponents = await Promise.all (fileArray.map (file => this.getClassDeclarationMatches (file)));
Expand Down Expand Up @@ -1488,7 +1488,7 @@ class Transpiler {

async exportTypeScriptDeclarations (file, jsFolder) {

const classes = await this.getTSClassDeclarationsAllFiles (jsFolder);
const classes = await this.getTSClassDeclarationsAllFiles (exchangeIds, jsFolder);

this.exportTypeScriptClassNames (file, classes)
this.exportTypeScriptExchangeIds (file, classes)
Expand Down
19 changes: 12 additions & 7 deletions build/transpileWS.js
Expand Up @@ -18,6 +18,8 @@ const fs = require ('fs')
, Exchange = require ('../js/pro/base/Exchange.js')
, tsFilename = './ccxt.d.ts'

const wsExchangeIds = require ('../exchanges.json').ws

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

class CCXTProTranspiler extends Transpiler {
Expand Down Expand Up @@ -242,28 +244,30 @@ class CCXTProTranspiler extends Transpiler {

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

exportTypeScriptDeclarations (file, classes) {
async exportTypeScriptDeclarations (file, jsFolder) {

const classes = await this.getTSClassDeclarationsAllFiles (wsExchangeIds, jsFolder);
this.exportTypeScriptClassNames (file, classes)
}

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

transpileEverything (force = false, child = false) {
async transpileEverything (force = false, child = false) {

// default pattern is '.js'
// const [ /* node */, /* script */, pattern ] = process.argv.filter (x => !x.startsWith ('--'))
const exchanges = process.argv.slice (2).filter (x => !x.startsWith ('--'))
// , python2Folder = './python/ccxtpro/', // CCXT Pro does not support Python 2
, python3Folder = './python/ccxt/pro/'
, phpAsyncFolder = './php/pro/'
, jsFolder = './js/pro/'
, options = { /* python2Folder, */ python3Folder, phpAsyncFolder, exchanges }

// createFolderRecursively (python2Folder)
createFolderRecursively (python3Folder)
createFolderRecursively (phpAsyncFolder)

const classes = this.transpileDerivedExchangeFiles ('./js/pro/', options, '.js', force, child || exchanges.length)
const classes = this.transpileDerivedExchangeFiles (jsFolder, options, '.js', force, child || exchanges.length)

if (child) {
return
Expand All @@ -280,7 +284,7 @@ class CCXTProTranspiler extends Transpiler {

// HINT: if we're going to support specific class definitions
// this process won't work anymore as it will override the definitions
this.exportTypeScriptDeclarations (tsFilename, classes)
await this.exportTypeScriptDeclarations (tsFilename, jsFolder)

//*/

Expand Down Expand Up @@ -309,10 +313,11 @@ if (require.main === module) {
log.bright.green ({ force })
}
if (multiprocess) {
const exchanges = require ('../exchanges.json').ws
parallelizeTranspiling (exchanges)
parallelizeTranspiling (wsExchangeIds)
} else {
transpiler.transpileEverything (force)
(async () => {
await transpiler.transpileEverything (force, child)
})()
}

} else {
Expand Down

0 comments on commit 499a87f

Please sign in to comment.