| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 | 7 |
| 8 import 'package:archive/archive.dart'; | 8 import 'package:archive/archive.dart'; |
| 9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 10 import 'package:yaml/yaml.dart'; | 10 import 'package:yaml/yaml.dart'; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 if (manifestDescriptor == null || !manifestDescriptor.containsKey('material-de
sign-icons')) | 58 if (manifestDescriptor == null || !manifestDescriptor.containsKey('material-de
sign-icons')) |
| 59 return; | 59 return; |
| 60 for (Map assetDescriptor in manifestDescriptor['material-design-icons']) { | 60 for (Map assetDescriptor in manifestDescriptor['material-design-icons']) { |
| 61 for (MaterialAsset asset in generateMaterialAssets(assetDescriptor)) { | 61 for (MaterialAsset asset in generateMaterialAssets(assetDescriptor)) { |
| 62 yield asset; | 62 yield asset; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 Future loadManifest(String manifestPath) async { | 67 Future loadManifest(String manifestPath) async { |
| 68 if (manifestPath == null) |
| 69 return null; |
| 68 String manifestDescriptor = await new File(manifestPath).readAsString(); | 70 String manifestDescriptor = await new File(manifestPath).readAsString(); |
| 69 return loadYaml(manifestDescriptor); | 71 return loadYaml(manifestDescriptor); |
| 70 } | 72 } |
| 71 | 73 |
| 72 Future<ArchiveFile> createFile(MaterialAsset asset, String assetBase) async { | 74 Future<ArchiveFile> createFile(MaterialAsset asset, String assetBase) async { |
| 73 File file = new File('${assetBase}/${asset.key}'); | 75 File file = new File('${assetBase}/${asset.key}'); |
| 74 List<int> content = await file.readAsBytes(); | 76 List<int> content = await file.readAsBytes(); |
| 75 return new ArchiveFile.noCompress(asset.key, content.length, content); | 77 return new ArchiveFile.noCompress(asset.key, content.length, content); |
| 76 } | 78 } |
| 77 | 79 |
| 78 Future<ArchiveFile> createSnapshotFile(String snapshotPath) async { | 80 Future<ArchiveFile> createSnapshotFile(String snapshotPath) async { |
| 79 File file = new File(snapshotPath); | 81 File file = new File(snapshotPath); |
| 80 List<int> content = await file.readAsBytes(); | 82 List<int> content = await file.readAsBytes(); |
| 81 return new ArchiveFile(kSnapshotKey, content.length, content); | 83 return new ArchiveFile(kSnapshotKey, content.length, content); |
| 82 } | 84 } |
| 83 | 85 |
| 84 main(List<String> argv) async { | 86 main(List<String> argv) async { |
| 85 ArgParser parser = new ArgParser(); | 87 ArgParser parser = new ArgParser(); |
| 86 parser.addFlag('help', abbr: 'h', negatable: false); | 88 parser.addFlag('help', abbr: 'h', negatable: false); |
| 87 parser.addOption('asset-base'); | 89 parser.addOption('asset-base'); |
| 90 parser.addOption('manifest'); |
| 91 parser.addOption('output-file', abbr: 'o'); |
| 88 parser.addOption('snapshot'); | 92 parser.addOption('snapshot'); |
| 89 parser.addOption('output-file', abbr: 'o'); | |
| 90 | 93 |
| 91 ArgResults args = parser.parse(argv); | 94 ArgResults args = parser.parse(argv); |
| 92 if (args['help']) { | 95 if (args['help']) { |
| 93 print(parser.usage); | 96 print(parser.usage); |
| 94 return; | 97 return; |
| 95 } | 98 } |
| 96 | 99 |
| 97 String manifestPath = args.rest.first; | 100 String manifestPath = args['manifest']; |
| 98 | |
| 99 Map manifestDescriptor = await loadManifest(manifestPath); | 101 Map manifestDescriptor = await loadManifest(manifestPath); |
| 100 Iterable<MaterialAsset> materialAssets = parseMaterialAssets(manifestDescripto
r); | 102 Iterable<MaterialAsset> materialAssets = parseMaterialAssets(manifestDescripto
r); |
| 101 | 103 |
| 102 Archive archive = new Archive(); | 104 Archive archive = new Archive(); |
| 103 | 105 |
| 104 String snapshot = args['snapshot']; | 106 String snapshot = args['snapshot']; |
| 105 if (snapshot != null) | 107 if (snapshot != null) |
| 106 archive.addFile(await createSnapshotFile(snapshot)); | 108 archive.addFile(await createSnapshotFile(snapshot)); |
| 107 | 109 |
| 108 for (MaterialAsset asset in materialAssets) | 110 for (MaterialAsset asset in materialAssets) |
| 109 archive.addFile(await createFile(asset, args['asset-base'])); | 111 archive.addFile(await createFile(asset, args['asset-base'])); |
| 110 | 112 |
| 111 File outputFile = new File(args['output-file']); | 113 File outputFile = new File(args['output-file']); |
| 112 await outputFile.writeAsBytes(new ZipEncoder().encode(archive)); | 114 await outputFile.writeAsBytes(new ZipEncoder().encode(archive)); |
| 113 } | 115 } |
| OLD | NEW |