Merge pull request #3204 from benvinegar/GH-3202

Add --write-sourcemap option to 'bundle' cli command (fixes #3202)
This commit is contained in:
Martín Bigio 2015-10-06 18:18:05 -04:00
commit 82b3a6b967
1 changed files with 23 additions and 5 deletions

View File

@ -13,10 +13,15 @@ var URL_PATH = {
android: '/index.android.bundle?platform=android&dev=', android: '/index.android.bundle?platform=android&dev=',
ios: '/index.ios.bundle?platform=ios&dev=' ios: '/index.ios.bundle?platform=ios&dev='
}; };
var SOURCEMAP_OUT_PATH = {
android: 'android/index.android.map',
ios: 'ios/index.ios.map'
};
function getBundle(flags) { function getBundle(flags) {
var platform = flags.platform ? flags.platform : 'ios'; var platform = flags.platform ? flags.platform : 'ios';
var outPath = flags.out ? flags.out : OUT_PATH[platform]; var outPath = flags.out ? flags.out : OUT_PATH[platform];
var sourceMapOutPath = SOURCEMAP_OUT_PATH[platform];
var projectRoots = [path.resolve(__dirname, '../../..')]; var projectRoots = [path.resolve(__dirname, '../../..')];
if (flags.root) { if (flags.root) {
@ -50,12 +55,23 @@ function getBundle(flags) {
fs.writeFile(outPath, bundle.getSource({ fs.writeFile(outPath, bundle.getSource({
inlineSourceMap: false, inlineSourceMap: false,
minify: flags.minify minify: flags.minify
}), function(err) { }), function(bundleWriteErr) {
if (err) { if (bundleWriteErr) {
console.log(chalk.red('Error saving bundle to disk')); console.log(chalk.red('Error saving bundle to disk'));
throw err; throw bundleWriteErr;
} else { }
console.log('Successfully saved bundle to ' + outPath);
console.log('Successfully saved bundle to ' + outPath);
if (flags.writeSourcemap) {
fs.writeFile(sourceMapOutPath, bundle.getSourceMap(), function(sourceMapWriteErr) {
if (sourceMapWriteErr) {
console.log(chalk.red('Error saving source map to disk'));
throw sourceMapWriteErr;
} else {
console.log('Successfully saved source map to ' + sourceMapOutPath);
}
});
} }
}); });
}); });
@ -73,6 +89,7 @@ function showHelp() {
' --out\t\tspecify the output file', ' --out\t\tspecify the output file',
' --url\t\tspecify the bundle file url', ' --url\t\tspecify the bundle file url',
' --platform\t\tspecify the platform(android/ios)', ' --platform\t\tspecify the platform(android/ios)',
' --write-sourcemap\t\twrite bundle source map to disk'
].join('\n')); ].join('\n'));
process.exit(1); process.exit(1);
} }
@ -88,6 +105,7 @@ module.exports = {
assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false, assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false,
out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false, out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false,
url: args.indexOf('--url') !== -1 ? args[args.indexOf('--url') + 1] : false, url: args.indexOf('--url') !== -1 ? args[args.indexOf('--url') + 1] : false,
writeSourcemap: args.indexOf('--write-sourcemap') !== -1,
} }
if (flags.help) { if (flags.help) {