arrangeJsonFilesBySection function
Loads all the design token info into a single structure resulting in something that looks like it would if it was all in one file
Creates a single JSON strcture from the driven by the $metadata.json Adds the $metadata.json and $themes.json with pathing adjusted to in-memory
Implementation
Map<String, dynamic> arrangeJsonFilesBySection(String tokenFileDirectory) {
// each element of the token set is in this map keyed by the file name ish
final mergedTokenSet = <String, dynamic>{};
// load the metadata contents and massage the paths to be map paths
final metadataContents = json.decode(
File('$tokenFileDirectory/\$metadata.json').readAsStringSync(),
);
mergedTokenSet['\$metadata'] = metadataAsSection(metadataContents as Map<String, dynamic>);
// Load the themes and msassage the paths to the contents to be map paths
final themesContents = json.decode(
File('$tokenFileDirectory/\$themes.json').readAsStringSync(),
);
mergedTokenSet['\$themes'] = themesAsSection(themesContents as List<dynamic>);
// Iterate across the "tokenSetOrder" in the $metadata file and
// Has to be the original file locations because they include paths
// load the json files into their own sections in the map
for (final onePath in metadataContents['tokenSetOrder'] as List<dynamic>) {
final fullPath = '$tokenFileDirectory/$onePath.json';
final contents = jsonDecode(File(fullPath).readAsStringSync()) as Map<String, dynamic>;
mergedTokenSet[basename(onePath as String)] = contents;
}
return mergedTokenSet;
}