|
2 | 2 | // MIT-style license that can be found in the LICENSE file or at
|
3 | 3 | // https://opensource.org/licenses/MIT.
|
4 | 4 |
|
| 5 | +import 'dart:async'; |
5 | 6 | import 'dart:convert';
|
6 | 7 | import 'dart:io';
|
7 | 8 |
|
8 | 9 | import 'package:cli_pkg/cli_pkg.dart' as pkg;
|
9 | 10 | import 'package:grinder/grinder.dart';
|
10 | 11 | import 'package:path/path.dart' as p;
|
11 | 12 |
|
| 13 | +// Work around the lack of google/grinder.dart#402. |
| 14 | +import 'package:grinder/src/singleton.dart'; |
| 15 | + |
12 | 16 | /// Options for [run] that tell Git to commit using SassBot's name and email.
|
13 | 17 | final sassBotEnvironment = RunOptions(environment: {
|
14 | 18 | "GIT_AUTHOR_NAME": pkg.botName.value,
|
@@ -75,3 +79,21 @@ String cloneOrCheckout(String url, String ref, {String? name}) {
|
75 | 79 |
|
76 | 80 | return path;
|
77 | 81 | }
|
| 82 | + |
| 83 | +/// Registers [callback] to run after the task named [taskName]. |
| 84 | +/// |
| 85 | +/// This must be called after the base [taskName] is registered. |
| 86 | +void afterTask(String taskName, FutureOr<void> callback()) { |
| 87 | + // This takes advantage of the fact that Grinder's task list is mutable to |
| 88 | + // override the existing task with our new one. |
| 89 | + var index = grinder.tasks.indexWhere((task) => task.name == taskName); |
| 90 | + if (index == -1) fail("There is no task named $taskName."); |
| 91 | + |
| 92 | + var oldTask = grinder.tasks[index]; |
| 93 | + grinder.tasks[index] = GrinderTask(taskName, |
| 94 | + description: oldTask.description, |
| 95 | + depends: oldTask.depends, taskFunction: (TaskArgs args) async { |
| 96 | + await oldTask.execute(context, args); |
| 97 | + await callback(); |
| 98 | + }); |
| 99 | +} |
0 commit comments