mirror of
https://github.com/status-im/react-native.git
synced 2025-02-10 08:26:23 +00:00
Merge pull request #1428 from JohnyDays/master
[CLI][Bundle][Packager] Implement --root --assetRoot and --out for consistency with packager and more flexibility
This commit is contained in:
commit
a6b6f97ba1
@ -9,12 +9,27 @@ var OUT_PATH = 'iOS/main.jsbundle';
|
|||||||
|
|
||||||
function getBundle(flags) {
|
function getBundle(flags) {
|
||||||
|
|
||||||
|
var outPath = flags.out ? flags.out : OUT_PATH;
|
||||||
|
|
||||||
|
var projectRoots = [path.resolve(__dirname, '../../..')];
|
||||||
|
if (flags.root) {
|
||||||
|
projectRoots.push(path.resolve(flags.root));
|
||||||
|
}
|
||||||
|
|
||||||
|
var assetRoots = [path.resolve(__dirname, '../../..')];
|
||||||
|
if (flags.assetRoots) {
|
||||||
|
assetRoots = assetRoots.concat(flags.assetRoots.split(",").map(function(root) {
|
||||||
|
return path.resolve(root);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
projectRoots: [path.resolve(__dirname, '../../..')],
|
projectRoots: projectRoots,
|
||||||
transformModulePath: require.resolve('../packager/transformer.js'),
|
transformModulePath: require.resolve('../packager/transformer.js'),
|
||||||
assetRoots: [path.resolve(__dirname, '../../..')],
|
assetRoots: assetRoots,
|
||||||
cacheVersion: '2',
|
cacheVersion: '2',
|
||||||
blacklistRE: blacklist('ios')
|
blacklistRE: blacklist('ios'),
|
||||||
};
|
};
|
||||||
|
|
||||||
var url = '/index.ios.bundle?dev=' + flags.dev;
|
var url = '/index.ios.bundle?dev=' + flags.dev;
|
||||||
@ -23,7 +38,7 @@ function getBundle(flags) {
|
|||||||
ReactPackager.buildPackageFromUrl(options, url)
|
ReactPackager.buildPackageFromUrl(options, url)
|
||||||
.done(function(bundle) {
|
.done(function(bundle) {
|
||||||
console.log('Build complete');
|
console.log('Build complete');
|
||||||
fs.writeFile(OUT_PATH, bundle.getSource({
|
fs.writeFile(outPath, bundle.getSource({
|
||||||
inlineSourceMap: false,
|
inlineSourceMap: false,
|
||||||
minify: flags.minify
|
minify: flags.minify
|
||||||
}), function(err) {
|
}), function(err) {
|
||||||
@ -31,7 +46,7 @@ function getBundle(flags) {
|
|||||||
console.log(chalk.red('Error saving bundle to disk'));
|
console.log(chalk.red('Error saving bundle to disk'));
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
console.log('Successfully saved bundle to ' + OUT_PATH);
|
console.log('Successfully saved bundle to ' + outPath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -43,7 +58,10 @@ function showHelp() {
|
|||||||
'',
|
'',
|
||||||
'Options:',
|
'Options:',
|
||||||
' --dev\t\tsets DEV flag to true',
|
' --dev\t\tsets DEV flag to true',
|
||||||
' --minify\tminify js bundle'
|
' --minify\tminify js bundle',
|
||||||
|
' --root\t\tadd another root(s) to be used in bundling in this project',
|
||||||
|
' --assetRoots\t\tspecify the root directories of app assets',
|
||||||
|
' --out\t\tspecify the output file',
|
||||||
].join('\n'));
|
].join('\n'));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -53,7 +71,10 @@ module.exports = {
|
|||||||
var flags = {
|
var flags = {
|
||||||
help: args.indexOf('--help') !== -1,
|
help: args.indexOf('--help') !== -1,
|
||||||
dev: args.indexOf('--dev') !== -1,
|
dev: args.indexOf('--dev') !== -1,
|
||||||
minify: args.indexOf('--minify') !== -1
|
minify: args.indexOf('--minify') !== -1,
|
||||||
|
root: args.indexOf('--root') !== -1 ? args[args.indexOf('--root') + 1] : false,
|
||||||
|
assetRoots: args.indexOf('--assetRoots') !== -1 ? args[args.indexOf('--assetRoots') + 1] : false,
|
||||||
|
out: args.indexOf('--out') !== -1 ? args[args.indexOf('--out') + 1] : false,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags.help) {
|
if (flags.help) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user