source: imaps-frontend/node_modules/ajv/scripts/bundle.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2
3var fs = require('fs')
4 , path = require('path')
5 , browserify = require('browserify')
6 , uglify = require('uglify-js');
7
8var pkg = process.argv[2]
9 , standalone = process.argv[3]
10 , compress = process.argv[4];
11
12var packageDir = path.join(__dirname, '..');
13if (pkg != '.') packageDir = path.join(packageDir, 'node_modules', pkg);
14
15var json = require(path.join(packageDir, 'package.json'));
16
17var distDir = path.join(__dirname, '..', 'dist');
18if (!fs.existsSync(distDir)) fs.mkdirSync(distDir);
19
20var bOpts = {};
21if (standalone) bOpts.standalone = standalone;
22
23browserify(bOpts)
24.require(path.join(packageDir, json.main), {expose: json.name})
25.bundle(function (err, buf) {
26 if (err) {
27 console.error('browserify error:', err);
28 process.exit(1);
29 }
30
31 var outputFile = path.join(distDir, json.name);
32 var uglifyOpts = {
33 warnings: true,
34 compress: {},
35 output: {
36 preamble: '/* ' + json.name + ' ' + json.version + ': ' + json.description + ' */'
37 }
38 };
39 if (compress) {
40 var compressOpts = compress.split(',');
41 for (var i=0, il = compressOpts.length; i<il; ++i) {
42 var pair = compressOpts[i].split('=');
43 uglifyOpts.compress[pair[0]] = pair.length < 1 || pair[1] != 'false';
44 }
45 }
46 if (standalone) {
47 uglifyOpts.sourceMap = {
48 filename: json.name + '.min.js',
49 url: json.name + '.min.js.map'
50 };
51 }
52
53 var result = uglify.minify(buf.toString(), uglifyOpts);
54 fs.writeFileSync(outputFile + '.min.js', result.code);
55 if (result.map) fs.writeFileSync(outputFile + '.min.js.map', result.map);
56 if (standalone) fs.writeFileSync(outputFile + '.bundle.js', buf);
57 if (result.warnings) {
58 for (var j=0, jl = result.warnings.length; j<jl; ++j)
59 console.warn('UglifyJS warning:', result.warnings[j]);
60 }
61});
Note: See TracBrowser for help on using the repository browser.