packager: buck library: expose asset content

Reviewed By: davidaurelio

Differential Revision: D4945778

fbshipit-source-id: ea132a3d284ed09c59c69afbdd7b707af9e521b9
This commit is contained in:
Jean Lauliac 2017-04-25 11:49:41 -07:00 committed by Facebook Github Bot
parent 3afbcfcd6b
commit 1f8d1002ef
6 changed files with 33 additions and 15 deletions

View File

@ -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,
};

View File

@ -13,8 +13,8 @@
export type ResolvedAssetSource = {
__packager_asset: boolean,
width: number,
height: number,
width: ?number,
height: ?number,
uri: string,
scale: number,
};

View File

@ -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);

View File

@ -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);

View File

@ -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,
@ -79,7 +79,7 @@ type AssetDescriptor = {
+type: string,
};
type ExtendedAssetDescriptor = AssetDescriptor & {
export type ExtendedAssetDescriptor = AssetDescriptor & {
+fileSystemLocation: string,
+files: Array<string>,
};

View File

@ -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},
|};