More flexibility for defining the locations of assets packaged in an FLX (#4462)
* Add a map of relative to absolute paths for assets located outside the app's source directory * If a "packages" directory exists, obtain assets from there instead of using the packages/ prefix to indicate package map lookup
This commit is contained in:
parent
d303081e9a
commit
0db04819dc
@ -13,6 +13,7 @@ Future<int> assembleFlx({
|
||||
Map<String, dynamic> manifestDescriptor: const <String, dynamic>{},
|
||||
File snapshotFile: null,
|
||||
String assetBasePath: flx.defaultAssetBasePath,
|
||||
Map<String, String> assetPathOverrides: const <String, String>{},
|
||||
String outputPath: flx.defaultFlxOutputPath,
|
||||
String privateKeyPath: flx.defaultPrivateKeyPath
|
||||
}) async {
|
||||
@ -20,6 +21,7 @@ Future<int> assembleFlx({
|
||||
manifestDescriptor: manifestDescriptor,
|
||||
snapshotFile: snapshotFile,
|
||||
assetBasePath: assetBasePath,
|
||||
assetPathOverrides: assetPathOverrides,
|
||||
outputPath: outputPath,
|
||||
privateKeyPath: privateKeyPath
|
||||
);
|
||||
|
@ -129,7 +129,8 @@ List<_Asset> _getMaterialAssets(String fontSet) {
|
||||
Map<_Asset, List<_Asset>> _parseAssets(
|
||||
PackageMap packageMap,
|
||||
Map<String, dynamic> manifestDescriptor,
|
||||
String assetBase, {
|
||||
String assetBase,
|
||||
Map<String, String> assetPathOverrides, {
|
||||
List<String> excludeDirs: const <String>[]
|
||||
}) {
|
||||
Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{};
|
||||
@ -142,7 +143,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
||||
|
||||
if (manifestDescriptor.containsKey('assets')) {
|
||||
for (String asset in manifestDescriptor['assets']) {
|
||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
|
||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, assetPathOverrides, asset);
|
||||
|
||||
if (!baseAsset.assetFileExists) {
|
||||
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
||||
@ -153,7 +154,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
||||
result[baseAsset] = variants;
|
||||
|
||||
// Find asset variants
|
||||
String assetPath = path.join(baseAsset.base, baseAsset.relativePath);
|
||||
String assetPath = baseAsset.assetFile.path;
|
||||
String assetFilename = path.basename(assetPath);
|
||||
Directory assetDir = new Directory(path.dirname(assetPath));
|
||||
|
||||
@ -188,7 +189,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
||||
String asset = font['asset'];
|
||||
if (asset == null) continue;
|
||||
|
||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
|
||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, assetPathOverrides, asset);
|
||||
if (!baseAsset.assetFileExists) {
|
||||
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
||||
return null;
|
||||
@ -202,8 +203,22 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
||||
return result;
|
||||
}
|
||||
|
||||
_Asset _resolveAsset(PackageMap packageMap, String assetBase, String asset) {
|
||||
if (asset.startsWith('packages/')) {
|
||||
_Asset _resolveAsset(
|
||||
PackageMap packageMap,
|
||||
String assetBase,
|
||||
Map<String, String> assetPathOverrides,
|
||||
String asset
|
||||
) {
|
||||
String overridePath = assetPathOverrides[asset];
|
||||
if (overridePath != null) {
|
||||
return new _Asset(
|
||||
base: path.dirname(overridePath),
|
||||
source: path.basename(overridePath),
|
||||
relativePath: asset
|
||||
);
|
||||
}
|
||||
|
||||
if (asset.startsWith('packages/') && !FileSystemEntity.isFileSync(path.join(assetBase, asset))) {
|
||||
// Convert packages/flutter_gallery_assets/clouds-0.png to clouds-0.png.
|
||||
String packageKey = asset.substring(9);
|
||||
String relativeAsset = asset;
|
||||
@ -374,6 +389,7 @@ Future<int> assemble({
|
||||
Map<String, dynamic> manifestDescriptor: const <String, dynamic>{},
|
||||
File snapshotFile,
|
||||
String assetBasePath: defaultAssetBasePath,
|
||||
Map<String, String> assetPathOverrides: const <String, String>{},
|
||||
String outputPath: defaultFlxOutputPath,
|
||||
String privateKeyPath: defaultPrivateKeyPath,
|
||||
String workingDirPath: defaultWorkingDirPath,
|
||||
@ -385,6 +401,7 @@ Future<int> assemble({
|
||||
new PackageMap(path.join(assetBasePath, '.packages')),
|
||||
manifestDescriptor,
|
||||
assetBasePath,
|
||||
assetPathOverrides,
|
||||
excludeDirs: <String>[workingDirPath, path.join(assetBasePath, 'build')]
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user