From f9d80a451a3009a5f62ce1321d456f4060d516c7 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Wed, 23 Nov 2016 06:15:17 -0800 Subject: [PATCH] Bring back programmatic packager API Summary: Brings back parts of the programmatic API removed in 7762f374d50d3b1df8513c826862c2056e8718f9. This is used by a few people. Also updates the docs accordingly. cc akaila Reviewed By: jeanlauliac Differential Revision: D4226348 fbshipit-source-id: e5c0794f9c5415f14b54d16c6f35f902eafc3064 --- packager/README.md | 33 ++++++++++++++++++-------------- packager/react-packager/index.js | 10 ++++++++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/packager/README.md b/packager/README.md index 51b0a7979a6bba..b7970273dc3082 100644 --- a/packager/README.md +++ b/packager/README.md @@ -90,10 +90,11 @@ ReactPackager is how you mainly interact with the API. var ReactPackager = require('./react-packager'); ``` -### ReactPackager.middleware(options) +### ReactPackager.buildBundle(serverOptions, bundleOptions) -Returns a function that can be used in a connect-like -middleware. Takes the following options: +Builds a bundle according to the provided options. + +#### `serverOptions` * `projectRoots` array (required): Is the roots where your JavaScript file will exist @@ -109,21 +110,25 @@ middleware. Takes the following options: * `nonPersistent` boolean, defaults to false: Whether the server should be used as a persistent deamon to watch files and update itself -* `assetRoots` array: Where should the packager look for assets * `getTransformOptionsModulePath` string: Path to module that exports a function that acts as a middleware for generating options to pass to the transformer - based on the bundle and module being transformed. - -### ReactPackager.buildPackageFromUrl(options, url) - -Build a package from a url (see the `.bundle` endpoint). `options` is -the same options that is passed to `ReactPackager.middleware` + based on the bundle being built. -### ReactPackager.getDependencies(options, main) +#### `bundleOptions` -Given an entry point module. Recursively collect all the dependent -modules and return it as an array. `options` is the same options that -is passed to `ReactPackager.middleware` +* `entryFile` string (required): the entry file of the bundle, relative to one + of the asset roots. +* `dev` boolean (defaults to `true`): sets a global `__DEV__` variable + which will effect how the React Native core libraries behave. +* `minify` boolean: Whether to minify code and apply production optimizations. +* `runModule` boolean (defaults to `true`): whether to require your entry + point module. +* `inlineSourceMap` boolean, defaults to false: whether to inline + source maps. +* `platform` string: The target platform for the build +* `generateSourceMaps` boolean: Whether to generate source maps. +* `sourceMapUrl` string: The url of the source map (will be appended to + the bundle). ## Debugging diff --git a/packager/react-packager/index.js b/packager/react-packager/index.js index 2df2fff0bac09d..172018df20ec0a 100644 --- a/packager/react-packager/index.js +++ b/packager/react-packager/index.js @@ -15,6 +15,16 @@ const Logger = require('./src/Logger'); exports.createServer = createServer; exports.Logger = Logger; + +exports.buildBundle = function(options, bundleOptions) { + var server = createNonPersistentServer(options); + return server.buildBundle(bundleOptions) + .then(p => { + server.end(); + return p; + }); +}; + exports.getOrderedDependencyPaths = function(options, bundleOptions) { var server = createNonPersistentServer(options); return server.getOrderedDependencyPaths(bundleOptions)