File: build/index.js

Recommend this page to a friend!
  Classes of Gamaiel Zavala  >  cmbn  >  build/index.js  >  Download  
File: build/index.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: cmbn
Generate combos of JavaScript code served via CDNs
Author: By
Last change: Add copyright and license
Date: 2 months ago
Size: 1,166 bytes
 

Contents

Class file image Download
var fs = require('fs'),
    strip = require('stripper').strip,
    uglify = require('uglify-js'),
    root = __dirname + '/../',
    cdns = root + 'lib/cdns.js',
    client = root + 'lib/combine.js',
    pkg = JSON.parse(fs.readFileSync(root + 'package.json', 'utf-8')),
    c = fs.readFileSync(root + 'build/copyright.js', 'utf-8'),
    ver = pkg.version,
    outfile = root + 'examples/public/libs/cmbn/' + ver + '/cmbn.min.js',
    out = strip(cdns) + '\n' + strip(client);

function write(outfile, out)
{
    var file = outfile.replace(new RegExp('[^/]+/../'), ''),
        dir = file.substr(0, file.lastIndexOf('/')),
        outmin = uglify(out);
    
    // make the dirs
    try
    {
        fs.mkdirSync(dir);
        console.log('Created dir ' + dir);
    }
    catch (e)
    {
        console.log(e.message);
    }
    
    // write minified
    console.log('Writing ' + file + '...');
    fs.writeFileSync(file, c + outmin, 'utf-8');
    
    // write unminified
    file = file.replace('.min', '');
    console.log('Writing ' + file + '...');
    fs.writeFileSync(file, out, 'utf-8');
}

write(outfile, out);
// write('latest');

console.log('Done.');