Skip to content

Commit

Permalink
fix(mason): allow optional __brick__ directory (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Nov 12, 2022
1 parent 98a958a commit 4e1ac92
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
42 changes: 22 additions & 20 deletions packages/mason/lib/src/generator.dart
Expand Up @@ -84,26 +84,28 @@ class MasonGenerator extends Generator {
file.readAsStringSync(),
(m) => BrickYaml.fromJson(m!),
).copyWith(path: file.path);
final brickDirectory = p.join(path, BrickYaml.dir);
final brickFiles = Directory(brickDirectory)
.listSync(recursive: true)
.whereType<File>()
.map((file) {
return () async {
final resource = await _descriptorPool.request();
try {
final content = await File(file.path).readAsBytes();
final relativePath = file.path.substring(
file.path.indexOf(BrickYaml.dir) + 1 + BrickYaml.dir.length,
);
return TemplateFile.fromBytes(relativePath, content);
} on Exception {
return null;
} finally {
resource.release();
}
}();
});
final brickDirectory = Directory(p.join(path, BrickYaml.dir));
final brickFiles = brickDirectory.existsSync()
? brickDirectory
.listSync(recursive: true)
.whereType<File>()
.map((file) {
return () async {
final resource = await _descriptorPool.request();
try {
final content = await File(file.path).readAsBytes();
final relativePath = file.path.substring(
file.path.indexOf(BrickYaml.dir) + 1 + BrickYaml.dir.length,
);
return TemplateFile.fromBytes(relativePath, content);
} on Exception {
return null;
} finally {
resource.release();
}
}();
})
: <Future<TemplateFile?>>[];

return MasonGenerator(
brickYaml.name,
Expand Down
3 changes: 3 additions & 0 deletions packages/mason/test/fixtures/empty/brick.yaml
@@ -0,0 +1,3 @@
name: empty
description: An empty brick
version: 0.1.0+1
10 changes: 10 additions & 0 deletions packages/mason/test/src/generator_test.dart
Expand Up @@ -36,6 +36,16 @@ void main() {
expect(files, isEmpty);
});

test('constructs an instance (empty)', () async {
final brick = Brick.path(path.join('test', 'fixtures', 'empty'));
final generator = await MasonGenerator.fromBrick(brick);
final tempDir = Directory.systemTemp.createTempSync();
final files = await generator.generate(
DirectoryGeneratorTarget(tempDir),
);
expect(files, isEmpty);
});

test('constructs an instance (hello_world)', () async {
const name = 'Dash';
final brick = Brick.path(
Expand Down

0 comments on commit 4e1ac92

Please sign in to comment.