forked from CanonicalLtd/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.js
More file actions
54 lines (46 loc) · 1.54 KB
/
bundle.js
File metadata and controls
54 lines (46 loc) · 1.54 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
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
const Promise = require('promise');
const sign = require('../sign');
const writeFile = require('./writeFile');
function buildBundle(packagerClient, requestOptions) {
return packagerClient.buildBundle(requestOptions);
}
function createCodeWithMap(bundle, dev) {
return {
code: bundle.getSource({dev}),
map: JSON.stringify(bundle.getSourceMap({dev})),
};
}
function saveBundleAndMap(bundle, options, log) {
const {
'bundle-output': bundleOutput,
'bundle-encoding': encoding,
dev,
'sourcemap-output': sourcemapOutput,
} = options;
log('start');
const codeWithMap = createCodeWithMap(bundle, dev);
log('finish');
log('Writing bundle output to:', bundleOutput);
const writeBundle = writeFile(bundleOutput, sign(codeWithMap.code), encoding);
writeBundle.then(() => log('Done writing bundle output'));
if (sourcemapOutput) {
log('Writing sourcemap output to:', sourcemapOutput);
const writeMap = writeFile(sourcemapOutput, codeWithMap.map, null);
writeMap.then(() => log('Done writing sourcemap output'));
return Promise.all([writeBundle, writeMap]);
} else {
return writeBundle;
}
}
exports.build = buildBundle;
exports.save = saveBundleAndMap;
exports.formatName = 'bundle';