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