<commit_before>const FS       = require('fs');
const Path     = require('path');
const Common   = require('./common');
const modules  = require('./modules');
const patterns = require('./patterns');

async function run()
{
    let token = FS.readFileSync(Path.normalize(`${process.env.USERPROFILE}/.npmrc`)).toString().replace('\n', '');


    let versionsFile = Path.resolve(__dirname, './versions.json')

    let versions = { };


    
    if (FS.existsSync(versionsFile))
        versions = require(versionsFile);
    
    let toPublish = [];
    
    for (let $module of modules)
    {
        if (!versions[$module.name])
        {
            versions[$module.name] = $module.version;
            toPublish.push($module.name);
        }
        
        if (versions[$module.name] < $module.version)
        {
            toPublish.push($module.name);
            versions[$module.name] = $module.version;
        }
    }
    
    const root = Path.resolve(__dirname, '../Surface/source');
    
    for (let $module of toPublish)
    {
        let source = Path.normalize(Path.join(root, $module));
        Common.cleanup(source, patterns.clean.include, patterns.clean.exclude);
        await Common.execute(`Compiling ${source}`, `tsc -p ${source} --noEmit false --declaration true`);

        await Common.execute(`Publishing ${$module}:`, `npm set ${token} & cd ${source} && npm publish --access public`);
    }
    
    if (toPublish.length > 0)
        FS.writeFileSync(versionsFile, JSON.stringify(versions, null, 4));
}

run();<commit_msg>Thes task/install now updates all dependees of updated module.<commit_after>const FS       = require('fs');
const Path     = require('path');
const Common   = require('./common');
const modules  = require('./modules');
const patterns = require('./patterns');

async function run()
{
    let token = FS.readFileSync(Path.normalize(`${process.env.USERPROFILE}/.npmrc`)).toString().replace('\n', '');

    let versionsFile = Path.resolve(__dirname, './versions.json')

    let versions = { };
    
    if (FS.existsSync(versionsFile))
        versions = require(versionsFile);
    
    let toPublish = [];
    
    modules.forEach(x => checkVersion(x));
    toPublish.forEach(x => checkDependencies(x));

    const root = Path.resolve(__dirname, '../Surface/source');
    
    for (let $module of toPublish)
    {
        let source = Path.normalize(Path.join(root, $module.name));

        FS.writeFileSync(Path.resolve(source, 'package.json'), JSON.stringify($module, null, 4));

        Common.cleanup(source, patterns.clean.include, patterns.clean.exclude);
        await Common.execute(`Compiling ${source}`, `tsc -p ${source} --noEmit false --declaration true`);
        
        await Common.execute(`Publishing ${$module.name}:`, `npm set ${token} & cd ${source} && npm publish --access public`);
    }
    
    if (toPublish.length > 0)
        FS.writeFileSync(versionsFile, JSON.stringify(versions, null, 4));
    
    function checkVersion($module)
    {
        if(!versions[$module.name])
        {
            versions[$module.name] = $module.version;
            toPublish.push($module);
        }
        
        if(isUpdated($module))
        {
            toPublish.push($module);
            versions[$module.name] = $module.version;
        }
    }
    
    function checkDependencies($module)
    {
        for(let dependee of modules.filter(x => x.dependencies && !!x.dependencies[$module.name]))
        {
            if(toPublish.findIndex(x => x.name == dependee.name && x.dependencies[$module.name] == $module.version) == -1)
            {
                dependee.dependencies[$module.name] = $module.version;
                
                if (toPublish.findIndex(x => x.name == dependee.name) == -1)
                {
                    updateVersion(dependee);
                    
                    versions[dependee.name] = dependee.version;
                
                    toPublish.push(dependee);
                }

                checkDependencies(dependee);
            }
        }
    }

    function isUpdated($module)
    {
        let [targetMajor, targetMinor, targetRevision] = $module.version.split('.').map(x => Number.parseInt(x));
        let [storedMajor, storedMinor, storedRevision]  = versions[$module.name].split('.').map(x => Number.parseInt(x));

        return (targetMajor > storedMajor)
            || (targetMajor == storedMajor && targetMinor  > storedMinor)
            || (targetMajor == storedMajor && targetMinor == storedMinor && targetRevision > storedRevision);
    }

    function updateVersion($module)
    {
        let [major, minor, revision] = $module.version.split('.').map(x => Number.parseInt(x));
    
        revision++;
    
        $module.version = [major, minor, revision].join('.');
    }
}

run();
{'fraction_non_alphanumeric': 0.15430696137161742, 'fraction_numerical': 0.0014459822350753977, 'mean_word_length': 2.3439226519337018, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7344316', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1368, 'n_words': 266}