<commit_before>const prompt = require('prompt'),
    simpleGit = require('simple-git'),
    fse = require('fs-extra'),
    path = require('path'),
    AdmZip = require('adm-zip'),
    glob = require('glob'),
    _template = require('lodash/template');

const CDN_ROOT = '../cdn.knightlab.com', // maybe parameterize later
    PROJECT_NAME = 'timeline3'; // can we read this from package.json?

function makeCDNPath(version) {
    return path.normalize(path.join(CDN_ROOT, 'app/libs', PROJECT_NAME, version));
}

function writeBanner(file, options) {
    let pkginfo = require(path.join('../package.json'))
    pkginfo['year'] = new Date().getFullYear()
    Object.keys(options).forEach(k => {
        pkginfo[k] = options[k]
    })
    let banner = fse.readFileSync(options['banner'], 'utf-8')
    let template = _template(banner)
    let rendered = template(pkginfo)
    let contents = fse.readFileSync(file, 'utf-8')
    fse.writeFileSync(file, rendered + contents)
}

function stageToCDN(version, latest) {
    var banner_version = (version == 'dev') ? new Date().toISOString() : version;

    // var to_banner = glob.sync('dist/**/*.+(js|css)');
    // for (var i = 0; i < to_banner.length; i++) {
    //     writeBanner(to_banner[i], {
    //         banner: 'banner.tmpl',
    //         version: banner_version,
    //     })
    // }

    // backwards compatibility -- we've offered timeline-min.js
    // webpack makes something smaller even than that, so just copy.
    // for people who want to debug, there's the sourcemap.
    fse.copySync('dist/js/timeline.js', 'dist/js/timeline-min.js')

    if (fse.existsSync(CDN_ROOT)) {
        var dest = makeCDNPath(version);
        var zip = new AdmZip();
        zip.addLocalFolder('dist', PROJECT_NAME);
        zip.writeZip(path.join('dist', PROJECT_NAME + ".zip"));
        fse.copySync('dist', dest, onErr);
        console.log('copied to ' + dest);

        if (latest) {
            var latest_dir = makeCDNPath('latest');
            fse.removeSync(latest_dir, onErr);
            fse.copySync(dest, latest_dir, onErr);
            console.log('copied version ' + version + ' to latest');
        }

    } else {
        console.error("CDN directory " + CDN_ROOT + "does not exist; nothing was copied")
    }
}

if (process.argv[2] == 'dev') {
    stageToCDN('dev')
} else {
    // if not 'dev' then ask for a new tag, update package.json, and tag the git repository
    simpleGit().tags(function(_, tagList) {<commit_msg>remove bogus error handler<commit_after>const prompt = require('prompt'),
    simpleGit = require('simple-git'),
    fse = require('fs-extra'),
    path = require('path'),
    AdmZip = require('adm-zip'),
    glob = require('glob'),
    _template = require('lodash/template');

const CDN_ROOT = '../cdn.knightlab.com', // maybe parameterize later
    PROJECT_NAME = 'timeline3'; // can we read this from package.json?

function makeCDNPath(version) {
    return path.normalize(path.join(CDN_ROOT, 'app/libs', PROJECT_NAME, version));
}

function writeBanner(file, options) {
    let pkginfo = require(path.join('../package.json'))
    pkginfo['year'] = new Date().getFullYear()
    Object.keys(options).forEach(k => {
        pkginfo[k] = options[k]
    })
    let banner = fse.readFileSync(options['banner'], 'utf-8')
    let template = _template(banner)
    let rendered = template(pkginfo)
    let contents = fse.readFileSync(file, 'utf-8')
    fse.writeFileSync(file, rendered + contents)
}

function stageToCDN(version, latest) {
    var banner_version = (version == 'dev') ? new Date().toISOString() : version;

    // var to_banner = glob.sync('dist/**/*.+(js|css)');
    // for (var i = 0; i < to_banner.length; i++) {
    //     writeBanner(to_banner[i], {
    //         banner: 'banner.tmpl',
    //         version: banner_version,
    //     })
    // }

    // backwards compatibility -- we've offered timeline-min.js
    // webpack makes something smaller even than that, so just copy.
    // for people who want to debug, there's the sourcemap.
    fse.copySync('dist/js/timeline.js', 'dist/js/timeline-min.js')

    if (fse.existsSync(CDN_ROOT)) {
        var dest = makeCDNPath(version);
        var zip = new AdmZip();
        zip.addLocalFolder('dist', PROJECT_NAME);
        zip.writeZip(path.join('dist', PROJECT_NAME + ".zip"));
        fse.copySync('dist', dest, onErr);
        console.log('copied to ' + dest);

        if (latest) {
            var latest_dir = makeCDNPath('latest');
            fse.removeSync(latest_dir);
            fse.copySync(dest, latest_dir, onErr);
            console.log('copied version ' + version + ' to latest');
        }

    } else {
        console.error("CDN directory " + CDN_ROOT + "does not exist; nothing was copied")
    }
}

if (process.argv[2] == 'dev') {
    stageToCDN('dev')
} else {
    // if not 'dev' then ask for a new tag, update package.json, and tag the git repository
    simpleGit().tags(function(_, tagList) {
{'fraction_non_alphanumeric': 0.156425702811245, 'fraction_numerical': 0.002008032128514056, 'mean_word_length': 2.8404009252120277, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6223500', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1593, 'n_words': 370}