browser-builder.js
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
var path = require('path');
var AWS = require('../index');
var license = [
'// AWS SDK for JavaScript v' + AWS.VERSION,
'// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.',
'// License at https://sdk.amazonaws.com/js/BUNDLE_LICENSE.txt'
].join('\n') + '\n';
function minify(code) {
var uglify = require('uglify-js');
var minified = uglify.minify(code, {fromString: true});
return minified.code;
}
function build(options, callback) {
if (arguments.length === 1) {
callback = options;
options = {};
}
var img = require('insert-module-globals');
img.vars.process = function() { return '{browser:true}'; };
if (options.services) process.env.AWS_SERVICES = options.services;
var browserify = require('browserify');
var brOpts = { basedir: path.resolve(__dirname, '..') };
browserify(brOpts).add('./').ignore('domain').bundle(function(err, data) {
if (err) return callback(err);
var code = (data || '').toString();
if (options.minify) code = minify(code);
code = license + code;
callback(null, code);
});
}
// run if we called this tool directly
if (require.main === module) {
var opts = {
services: process.argv[2] || process.env.SERVICES,
minify: process.env.MINIFY ? true : false
};
build(opts, function(err, code) {
if (err) console.error(err.message);
else console.log(code);
});
}
build.license = license;
module.exports = build;