// generator: wizzi-lab-artifatcs/lib/js/module/gen/main.js, utc time: Tue, 14 Feb 2017 15:38:31 GMT
var path = require('path');
var util = require('util');
var wizzi = require('wizzi-core').wizzi;
var log = wizzi.log(module);
var ProductionManager = require('wizzi-factory').ProductionManager;
var options = require('wizzi-factory').options;
var thisWizziModule = require('./index');
var md = module.exports = {};
md.name = 'wizzi-lab-site';

md.executeWizziFactoryJob = function(path, wizziFactoryPackages) {
    var pman = new ProductionManager(options({
        indentSpaces: 4, 
        basedir: __dirname, 
        verbose: 2
    }));
    if (wizziFactoryPackages && wizzi.verify.isArray(wizziFactoryPackages)) {
        var i, i_len=wizziFactoryPackages.length, wfp;
        for (i=0; i<i_len; i++) {
            wfp = wizziFactoryPackages[i];
            pman.registerWizziFactoryPackage(wfp);
        }
    }
    pman.registerWizziFactoryPackage(thisWizziModule);
    pman.addWfJob({
        options: {}, 
        wfjob: {
            src: path
        }
    });
    pman.run(function(err, result) {
        if (err) {
            var msg = 'Package-examples ' + md.name + '\nError running production: ' + path + '\n' + util.inspect(err, { depth: null });
            wizzi.fail.warn(msg);
            throw new Error(msg);
        }
        log.success('run completed');
        pman.persistToFile(function(err, result) {
            if (err) {
                var msg = 'Package-examples ' + md.name + '\nError persisting production to file: ' + path + '\n' + util.inspect(err, { depth: null });
                wizzi.fail.warn(msg);
                throw new Error(msg);
            }
            log.success('persistToFile completed');
        });
    });
};

md.execute = function() {
    md.executeWizziFactoryJob(path.join(__dirname, 'lib', 'examples', 'js', 'js-examples.wfjob.ittf'));
    md.executeWizziFactoryJob(path.join(__dirname, 'lib', 'examples', 'css', 'css-examples.wfjob.ittf'));
    md.executeWizziFactoryJob(path.join(__dirname, 'lib', 'examples', 'html', 'html-examples.wfjob.ittf'));
};

// CLI execution
md.execute();
