<commit_before>var fs = require('fs'),
    path = require('path'),
    SharePointProcessor = require('../compiler/sharepoint_processor'),
    NunjucksProcessor = require('../compiler/nunjucks_processor'),
    process = require('process'),
    glob = require('glob'),
    _ = require('lodash'),
    util = require('util'),
    spawn = require('child_process').spawn,
    templateVersion = require('root-require')('package.json').version,
    async = require('async'),
    archiver = require('archiver');

module.exports = class ZipPackager {

    constructor() {
        this.repoRoot = path.normalize(path.join(__filename, '../../..'));
        this.baseName = util.format("lcc_templates-%s", templateVersion);
    }

    isWin() {
        return /^win/.test(process.platform);
    }

    get compiledExtensions() {
        return [".ejs"];
    }

    package(callback) {
        var self = this;
        fs.mkdir(this.targetDir, (err, folder) => {
            async.series([function(cb) {
                self.prepareContents(cb) }, 
            function(cb) { 
                self.generatePackageJson(cb) },
            function(cb) {
                self.createZip(cb)
            }], function(err, results) {
                if(err) throw err;
                callback();
            });    
        });
    }

    prepareContents(callback) {
        var self = this;
        var files = glob.sync('**/*', {
            cwd: path.join(this.repoRoot, "app")
        });

        var contentTasks = [];
        contentTasks.push(function(cb) {
            self.copyStaticFiles(cb)
        });
        contentTasks.push(function(cb) {
            process.chdir(path.join(self.repoRoot, "app"));

            var templateTasks = [];
            _.forEach(files, function(file) {
              if (fs.lstatSync(file).isDirectory(file)) {
                    return;
              }
              
              if (self.compiledExtensions.indexOf(path.extname(file)) > -1) {
                templateTasks.push(function(cb1) {
                    self.processTemplate(file, cb1)
                });
              }
            });

            async.parallel(templateTasks, function(err, results) {
                if (err) return cb(err);
                return cb(null, []);
            })
        });

        async.series(contentTasks, function(err, results) {
            if (err) return callback(err);
            return callback(null, []);
        })
    }

    copyStaticFiles(callback) {
        var self = this;
        var copy = isWin() ? spawn('robocopy', [path.join(this.repoRoot, "app"), self.targetDir, "/MIR", "/XF"]
            .concat(_.map(self.compiledExtensions, (item) => util.format("*%s", item)))) :
               spawn('rsync', ['-av'].concat(_.map(self.compiledExtensions, (item) => util.format("--exclude *%s", item)).concat([path.join(this.repoRoot, "app"), self.targetDir])));

        copy.on('exit', function(code) {
            fs.open(path.join(self.targetDir, "VERSION.txt"), 'w', (err, fd) => {<commit_msg>corrected isWin ref<commit_after>var fs = require('fs'),
    path = require('path'),
    SharePointProcessor = require('../compiler/sharepoint_processor'),
    NunjucksProcessor = require('../compiler/nunjucks_processor'),
    process = require('process'),
    glob = require('glob'),
    _ = require('lodash'),
    util = require('util'),
    spawn = require('child_process').spawn,
    templateVersion = require('root-require')('package.json').version,
    async = require('async'),
    archiver = require('archiver');

module.exports = class ZipPackager {

    constructor() {
        this.repoRoot = path.normalize(path.join(__filename, '../../..'));
        this.baseName = util.format("lcc_templates-%s", templateVersion);
    }

    isWin() {
        return /^win/.test(process.platform);
    }

    get compiledExtensions() {
        return [".ejs"];
    }

    package(callback) {
        var self = this;
        fs.mkdir(this.targetDir, (err, folder) => {
            async.series([function(cb) {
                self.prepareContents(cb) }, 
            function(cb) { 
                self.generatePackageJson(cb) },
            function(cb) {
                self.createZip(cb)
            }], function(err, results) {
                if(err) throw err;
                callback();
            });    
        });
    }

    prepareContents(callback) {
        var self = this;
        var files = glob.sync('**/*', {
            cwd: path.join(this.repoRoot, "app")
        });

        var contentTasks = [];
        contentTasks.push(function(cb) {
            self.copyStaticFiles(cb)
        });
        contentTasks.push(function(cb) {
            process.chdir(path.join(self.repoRoot, "app"));

            var templateTasks = [];
            _.forEach(files, function(file) {
              if (fs.lstatSync(file).isDirectory(file)) {
                    return;
              }
              
              if (self.compiledExtensions.indexOf(path.extname(file)) > -1) {
                templateTasks.push(function(cb1) {
                    self.processTemplate(file, cb1)
                });
              }
            });

            async.parallel(templateTasks, function(err, results) {
                if (err) return cb(err);
                return cb(null, []);
            })
        });

        async.series(contentTasks, function(err, results) {
            if (err) return callback(err);
            return callback(null, []);
        })
    }

    copyStaticFiles(callback) {
        var self = this;
        var copy = this.isWin() ? spawn('robocopy', [path.join(this.repoRoot, "app"), self.targetDir, "/MIR", "/XF"]
            .concat(_.map(self.compiledExtensions, (item) => util.format("*%s", item)))) :
               spawn('rsync', ['-av'].concat(_.map(self.compiledExtensions, (item) => util.format("--exclude *%s", item)).concat([path.join(this.repoRoot, "app"), self.targetDir])));

        copy.on('exit', function(code) {
            fs.open(path.join(self.targetDir, "VERSION.txt"), 'w', (err, fd) => {
{'fraction_non_alphanumeric': 0.1612797374897457, 'fraction_numerical': 0.0009844134536505333, 'mean_word_length': 1.9279538904899136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '6862518', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1703, 'n_words': 280}