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>{},
|
Map<String, dynamic> manifestDescriptor: const <String, dynamic>{},
|
||||||
File snapshotFile: null,
|
File snapshotFile: null,
|
||||||
String assetBasePath: flx.defaultAssetBasePath,
|
String assetBasePath: flx.defaultAssetBasePath,
|
||||||
|
Map<String, String> assetPathOverrides: const <String, String>{},
|
||||||
String outputPath: flx.defaultFlxOutputPath,
|
String outputPath: flx.defaultFlxOutputPath,
|
||||||
String privateKeyPath: flx.defaultPrivateKeyPath
|
String privateKeyPath: flx.defaultPrivateKeyPath
|
||||||
}) async {
|
}) async {
|
||||||
@ -20,6 +21,7 @@ Future<int> assembleFlx({
|
|||||||
manifestDescriptor: manifestDescriptor,
|
manifestDescriptor: manifestDescriptor,
|
||||||
snapshotFile: snapshotFile,
|
snapshotFile: snapshotFile,
|
||||||
assetBasePath: assetBasePath,
|
assetBasePath: assetBasePath,
|
||||||
|
assetPathOverrides: assetPathOverrides,
|
||||||
outputPath: outputPath,
|
outputPath: outputPath,
|
||||||
privateKeyPath: privateKeyPath
|
privateKeyPath: privateKeyPath
|
||||||
);
|
);
|
||||||
|
@ -129,7 +129,8 @@ List<_Asset> _getMaterialAssets(String fontSet) {
|
|||||||
Map<_Asset, List<_Asset>> _parseAssets(
|
Map<_Asset, List<_Asset>> _parseAssets(
|
||||||
PackageMap packageMap,
|
PackageMap packageMap,
|
||||||
Map<String, dynamic> manifestDescriptor,
|
Map<String, dynamic> manifestDescriptor,
|
||||||
String assetBase, {
|
String assetBase,
|
||||||
|
Map<String, String> assetPathOverrides, {
|
||||||
List<String> excludeDirs: const <String>[]
|
List<String> excludeDirs: const <String>[]
|
||||||
}) {
|
}) {
|
||||||
Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{};
|
Map<_Asset, List<_Asset>> result = <_Asset, List<_Asset>>{};
|
||||||
@ -142,7 +143,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
|||||||
|
|
||||||
if (manifestDescriptor.containsKey('assets')) {
|
if (manifestDescriptor.containsKey('assets')) {
|
||||||
for (String asset in manifestDescriptor['assets']) {
|
for (String asset in manifestDescriptor['assets']) {
|
||||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
|
_Asset baseAsset = _resolveAsset(packageMap, assetBase, assetPathOverrides, asset);
|
||||||
|
|
||||||
if (!baseAsset.assetFileExists) {
|
if (!baseAsset.assetFileExists) {
|
||||||
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
||||||
@ -153,7 +154,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
|||||||
result[baseAsset] = variants;
|
result[baseAsset] = variants;
|
||||||
|
|
||||||
// Find asset variants
|
// Find asset variants
|
||||||
String assetPath = path.join(baseAsset.base, baseAsset.relativePath);
|
String assetPath = baseAsset.assetFile.path;
|
||||||
String assetFilename = path.basename(assetPath);
|
String assetFilename = path.basename(assetPath);
|
||||||
Directory assetDir = new Directory(path.dirname(assetPath));
|
Directory assetDir = new Directory(path.dirname(assetPath));
|
||||||
|
|
||||||
@ -188,7 +189,7 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
|||||||
String asset = font['asset'];
|
String asset = font['asset'];
|
||||||
if (asset == null) continue;
|
if (asset == null) continue;
|
||||||
|
|
||||||
_Asset baseAsset = _resolveAsset(packageMap, assetBase, asset);
|
_Asset baseAsset = _resolveAsset(packageMap, assetBase, assetPathOverrides, asset);
|
||||||
if (!baseAsset.assetFileExists) {
|
if (!baseAsset.assetFileExists) {
|
||||||
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
printError('Error: unable to locate asset entry in flutter.yaml: "$asset".');
|
||||||
return null;
|
return null;
|
||||||
@ -202,8 +203,22 @@ Map<_Asset, List<_Asset>> _parseAssets(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
_Asset _resolveAsset(PackageMap packageMap, String assetBase, String asset) {
|
_Asset _resolveAsset(
|
||||||
if (asset.startsWith('packages/')) {
|
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.
|
// Convert packages/flutter_gallery_assets/clouds-0.png to clouds-0.png.
|
||||||
String packageKey = asset.substring(9);
|
String packageKey = asset.substring(9);
|
||||||
String relativeAsset = asset;
|
String relativeAsset = asset;
|
||||||
@ -374,6 +389,7 @@ Future<int> assemble({
|
|||||||
Map<String, dynamic> manifestDescriptor: const <String, dynamic>{},
|
Map<String, dynamic> manifestDescriptor: const <String, dynamic>{},
|
||||||
File snapshotFile,
|
File snapshotFile,
|
||||||
String assetBasePath: defaultAssetBasePath,
|
String assetBasePath: defaultAssetBasePath,
|
||||||
|
Map<String, String> assetPathOverrides: const <String, String>{},
|
||||||
String outputPath: defaultFlxOutputPath,
|
String outputPath: defaultFlxOutputPath,
|
||||||
String privateKeyPath: defaultPrivateKeyPath,
|
String privateKeyPath: defaultPrivateKeyPath,
|
||||||
String workingDirPath: defaultWorkingDirPath,
|
String workingDirPath: defaultWorkingDirPath,
|
||||||
@ -385,6 +401,7 @@ Future<int> assemble({
|
|||||||
new PackageMap(path.join(assetBasePath, '.packages')),
|
new PackageMap(path.join(assetBasePath, '.packages')),
|
||||||
manifestDescriptor,
|
manifestDescriptor,
|
||||||
assetBasePath,
|
assetBasePath,
|
||||||
|
assetPathOverrides,
|
||||||
excludeDirs: <String>[workingDirPath, path.join(assetBasePath, 'build')]
|
excludeDirs: <String>[workingDirPath, path.join(assetBasePath, 'build')]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user