Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mason): allow optional __brick__ directory #616

Merged
merged 2 commits into from Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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