Skip to content

Commit

Permalink
packager: buck library: expose asset content
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D4945778

fbshipit-source-id: ea132a3d284ed09c59c69afbdd7b707af9e521b9
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Apr 25, 2017
1 parent 3afbcfc commit 1f8d100
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
18 changes: 9 additions & 9 deletions Libraries/Image/AssetRegistry.js
Expand Up @@ -13,15 +13,15 @@


export type PackagerAsset = {
__packager_asset: boolean,
fileSystemLocation: string,
httpServerLocation: string,
width: number,
height: number,
scales: Array<number>,
hash: string,
name: string,
type: string,
+__packager_asset: boolean,
+fileSystemLocation: string,
+httpServerLocation: string,
+width: ?number,
+height: ?number,
+scales: Array<number>,
+hash: string,
+name: string,
+type: string,
};


Expand Down
4 changes: 2 additions & 2 deletions Libraries/Image/AssetSourceResolver.js
Expand Up @@ -13,8 +13,8 @@

export type ResolvedAssetSource = {
__packager_asset: boolean,
width: number,
height: number,
width: ?number,
height: ?number,
uri: string,
scale: number,
};
Expand Down
7 changes: 6 additions & 1 deletion local-cli/bundle/getAssetDestPathAndroid.js
Expand Up @@ -5,13 +5,18 @@
* 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.
*
* @flow
*/

'use strict';

const assetPathUtils = require('./assetPathUtils');
const path = require('path');

function getAssetDestPathAndroid(asset, scale) {
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';

function getAssetDestPathAndroid(asset: PackagerAsset, scale: number): string {
const androidFolder = assetPathUtils.getAndroidDrawableFolderName(asset, scale);
const fileName = assetPathUtils.getAndroidResourceIdentifier(asset);
return path.join(androidFolder, fileName + '.' + asset.type);
Expand Down
7 changes: 6 additions & 1 deletion local-cli/bundle/getAssetDestPathIOS.js
Expand Up @@ -5,12 +5,17 @@
* 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.
*
* @flow
*/

'use strict';

const path = require('path');

function getAssetDestPathIOS(asset, scale) {
import type {PackagerAsset} from '../../Libraries/Image/AssetRegistry';

function getAssetDestPathIOS(asset: PackagerAsset, scale: number): string {
const suffix = scale === 1 ? '' : '@' + scale + 'x';
const fileName = asset.name + suffix + '.' + asset.type;
return path.join(asset.httpServerLocation.substr(1), fileName);
Expand Down
4 changes: 2 additions & 2 deletions packager/src/Bundler/index.js
Expand Up @@ -68,7 +68,7 @@ export type GetTransformOptions = (
getDependenciesOf: string => Promise<Array<string>>,
) => Promise<ExtraTransformOptions>;

type AssetDescriptor = {
export type AssetDescriptor = {
+__packager_asset: boolean,
+httpServerLocation: string,
+width: ?number,
Expand All @@ -79,7 +79,7 @@ type AssetDescriptor = {
+type: string,
};

type ExtendedAssetDescriptor = AssetDescriptor & {
export type ExtendedAssetDescriptor = AssetDescriptor & {
+fileSystemLocation: string,
+files: Array<string>,
};
Expand Down
8 changes: 8 additions & 0 deletions packager/src/ModuleGraph/types.flow.js
Expand Up @@ -140,3 +140,11 @@ export type LibraryOptions = {|
platform?: string,
root: string,
|};

export type Base64Content = string;

export type Library = {|
files: Array<TransformedFile>,
/* cannot be a Map because it's JSONified later on */
assets: {[destFilePath: string]: Base64Content},
|};

0 comments on commit 1f8d100

Please sign in to comment.