tools/functions.js
function findDependencies(startFile, class2Path, deps) {
    // Create a new regex object to reset the readIndex
    const depRegEx = /global ([a-zA-Z0-9,\s]+) \*/g;

    // Get global variable
    const contents = fs.readFileSync(startFile).toString();
    /** @type {string[]} */
    let fileDeps = [];
    let fileDepMatch;
    while ((fileDepMatch = depRegEx.exec(contents)) !== null) { // eslint-disable-line no-cond-assign
        const fileDep = fileDepMatch[1];
        fileDeps = fileDeps.concat(fileDep.split(/,\s*/g));
    }

    fileDeps.forEach(dep => {
        // CustomError classes
        if (dep.slice(-5) === 'Error') dep = 'errors';
        if (dep === 'runKeyguard' || dep === 'loadNimiq') dep = 'common';

        if (deps.indexOf(dep) > -1) return;

        deps.push(dep);

        if (dep === 'Nimiq') return;

        const depPath = class2Path.get(dep);
        if (!depPath) throw new Error(`Unknown dependency ${dep} referenced from ${startFile}`);

        // deps are passed by reference
        findDependencies(depPath, class2Path, deps); // recurse
    });

    return deps;
}
function findDependencies(startFile, class2Path, deps) {
    // Create a new regex object to reset the readIndex
    const depRegEx = /global ([a-zA-Z0-9,\s]+) \*/g;

    // Get global variable
    const contents = fs.readFileSync(startFile).toString();
    /** @type {string[]} */
    let fileDeps = [];
    let fileDepMatch;
    while ((fileDepMatch = depRegEx.exec(contents)) !== null) { // eslint-disable-line no-cond-assign
        const fileDep = fileDepMatch[1];
        fileDeps = fileDeps.concat(fileDep.split(/,\s*/g));
    }

    fileDeps.forEach(dep => {
        // CustomError classes
        if (dep.slice(-5) === 'Error') dep = 'errors';
        if (dep === 'runKeyguard' || dep === 'loadNimiq') dep = 'common';

        if (deps.indexOf(dep) > -1) return;

        deps.push(dep);

        if (dep === 'Nimiq') return;

        const depPath = class2Path.get(dep);
        if (!depPath) throw new Error(`Unknown dependency ${dep} referenced from ${startFile}`);

        // deps are passed by reference
        findDependencies(depPath, class2Path, deps); // recurse
    });

    return deps;
}
function findDependencies ( startFile , class2Path , deps ) { // Create a new regex object to reset the readIndex const depRegEx = / global ([a-zA-Z0-9,\s]+) \* / g ; // Get global variable const contents = fs . readFileSync ( startFile ) . toString ( ) ; /** @type {string[]} */ let fileDeps = [ ] ; let fileDepMatch ; while ( ( fileDepMatch = depRegEx . exec ( contents ) ) !== null ) { // eslint-disable-line no-cond-assign const fileDep = fileDepMatch [ 1 ] ; fileDeps = fileDeps . concat ( fileDep . split ( / ,\s* / g ) ) ; } fileDeps . forEach ( dep => { // CustomError classes if ( dep . slice ( - 5 ) === 'Error' ) dep = 'errors' ; if ( dep === 'runKeyguard' || dep === 'loadNimiq' ) dep = 'common' ; if ( deps . indexOf ( dep ) > - 1 ) return ; deps . push ( dep ) ; if ( dep === 'Nimiq' ) return ; const depPath = class2Path . get ( dep ) ; if ( ! depPath ) throw new Error ( ` ${ dep } ${ startFile } ` ) ; // deps are passed by reference findDependencies ( depPath , class2Path , deps ) ; // recurse } ) ; return deps ; }
Recursively collect class dependencies from files' global definitions.

@param {string} startFile
@param {object} class2Path
@param {string[]} deps
@returns {string[]}
Recursively collect class dependencies from files global definitions .