run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
FutureOr? run() async {
final args = argResults;
if (args == null) {
return;
}
final fileId = args['fileId'] as String;
final token = args['token'] as String;
final outputFolder = args['outputFolder'] as String;
final iconsFormat = args['format'] as String;
final scales = args['scale'] as String;
final forceDownload = args['force'] as bool;
final frame = args['frame'] as String;
List<String> sectionsToDownload = [];
if (frame != 'APP_ASSET_') {
sectionsToDownload = frame.split(',').map((e) => e.trim()).toList();
}
List<double> scalesList = handleScales(iconsFormat, scales);
logger.log('\nπ₯ Fetching Figma file...');
final fileData =
await figmaApi.fetchFigmaFile(fileId: fileId, token: token);
logger.log("π Identifying 'APP_ASSET_' frames...");
final assets = figmaApi.findAppIcons(fileData, sectionsToDownload);
if (assets.isEmpty) {
logger.log("β No 'APP_ASSET_' frames found.");
return;
}
for (var frameName in assets.keys) {
logger.log('\nπ₯ Processing icons for frames: $frameName');
List<Map<String, String>> assetList =
assets[frameName]!; // Full asset list (id + name)
List<String> nodeIds =
assetList.map((e) => e['id']!).toList(); // Extract only IDs
// Loop over the scales list, fetch and download images for each scale
for (var scale in scalesList) {
logger.log(' π Fetching ${scale}x images...');
final imageUrls = await figmaApi.fetchImageUrls(
fileId: fileId,
token: token,
nodeIds: nodeIds,
imageFormat: iconsFormat,
scale: scale,
);
await figmaApi.downloadImages(
parentDirectory: outputFolder,
imageUrls: imageUrls,
sectionName: frameName,
imageFormat: iconsFormat,
scale: scale,
assets: assetList,
forceDownload: forceDownload);
}
}
logger.log('\nπ All images downloaded successfully!');
}