-
Notifications
You must be signed in to change notification settings - Fork 148
/
post_gen.dart
38 lines (32 loc) · 1.11 KB
/
post_gen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import 'dart:async';
import 'dart:io' as io;
import 'package:dart_frog_prod_server_hooks/dart_frog_prod_server_hooks.dart';
import 'package:mason/mason.dart' show HookContext, lightCyan;
import 'package:path/path.dart' as path;
void _defaultExit(int code) => ExitOverrides.current?.exit ?? io.exit;
Future<void> run(HookContext context) => postGen(context);
Future<void> postGen(
HookContext context, {
io.Directory? directory,
ProcessRunner runProcess = io.Process.run,
void Function(int exitCode) exit = _defaultExit,
}) async {
final projectDirectory = directory ?? io.Directory.current;
final buildDirectoryPath = path.join(projectDirectory.path, 'build');
await dartPubGet(
context,
workingDirectory: buildDirectoryPath,
runProcess: runProcess,
exit: exit,
);
final relativeBuildPath = path.relative(buildDirectoryPath);
context.logger
..info('')
..success('Created a production build!')
..info('')
..info('Start the production server by running:')
..info('')
..info(
'''${lightCyan.wrap('dart ${path.join(relativeBuildPath, 'bin', 'server.dart')}')}''',
);
}