-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add a 'mono_repo' tweak * use => syntax
- Loading branch information
1 parent
1d3fccd
commit 601d5a8
Showing
11 changed files
with
161 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:path/path.dart' as p; | ||
|
||
import '../repo_tweak.dart'; | ||
import '../utils.dart'; | ||
|
||
final _instance = MonoRepoTweak._(); | ||
|
||
/// Regenerate the latest configuration files for package:mono_repo. | ||
class MonoRepoTweak extends RepoTweak { | ||
factory MonoRepoTweak() => _instance; | ||
|
||
MonoRepoTweak._() | ||
: super( | ||
id: 'monorepo', | ||
description: | ||
'regenerate the latest configuration files for package:mono_repo', | ||
); | ||
|
||
@override | ||
bool shouldRunByDefault(Directory checkout, String repoSlug) { | ||
return File(p.join(checkout.path, 'mono_repo.yaml')).existsSync(); | ||
} | ||
|
||
@override | ||
FutureOr<FixResult> fix(Directory checkout, String repoSlug) async { | ||
// get the latest mono_repo | ||
await runProc( | ||
'activating mono_repo', | ||
Platform.resolvedExecutable, | ||
['pub', 'global', 'activate', 'mono_repo'], | ||
workingDirectory: checkout.path, | ||
); | ||
|
||
// record the current values for the files | ||
final files = { | ||
'.github/workflows/dart.yml', | ||
'tool/ci.sh', | ||
}; | ||
final existingContent = { | ||
for (var path in files) | ||
path: File(p.join(checkout.path, path)).existsSync() | ||
? File(p.join(checkout.path, path)).readAsStringSync() | ||
: '', | ||
}; | ||
|
||
// run mono_repo generate | ||
await runProc( | ||
'run mono_repo generate', | ||
Platform.resolvedExecutable, | ||
['pub', 'global', 'run', 'mono_repo', 'generate'], | ||
workingDirectory: checkout.path, | ||
); | ||
|
||
// return the results | ||
final fixes = <String>[]; | ||
|
||
for (var entry in existingContent.entries) { | ||
final file = File(p.join(checkout.path, entry.key)); | ||
if (file.readAsStringSync() != entry.value) { | ||
fixes.add('updated ${entry.key}'); | ||
} | ||
} | ||
|
||
return fixes.isEmpty ? FixResult.noFixesMade : FixResult(fixes: fixes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io' as io; | ||
|
||
import 'package:blast_repo/src/tweaks/mono_repo_tweak.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:test_descriptor/test_descriptor.dart' as d; | ||
|
||
void main() { | ||
late MonoRepoTweak tweak; | ||
late io.Directory dir; | ||
|
||
setUp(() async { | ||
tweak = MonoRepoTweak(); | ||
await d.dir('foo', [ | ||
d.file('mono_repo.yaml', '# foo bar\n'), | ||
]).create(); | ||
dir = d.dir('foo').io; | ||
}); | ||
|
||
test('recognizes mono_repo repo', () async { | ||
expect(tweak.shouldRunByDefault(dir, 'my_org/my_repo'), true); | ||
}); | ||
|
||
test('ignores non-managed repo', () async { | ||
await d.dir('foo', [ | ||
d.file('README.md', '# package name\n\n'), | ||
]).create(); | ||
dir = d.dir('foo').io; | ||
|
||
expect(tweak.shouldRunByDefault(dir, 'my_org/my_repo'), true); | ||
}); | ||
} |