-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): Add precache prisma engines command
- Loading branch information
Seven Du
committed
Sep 20, 2022
1 parent
35728d6
commit d7c2bd8
Showing
3 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:orm/version.dart'; | ||
|
||
import '../binary_engine/binary_engine.dart'; | ||
import '../binary_engine/binary_engine_platform.dart'; | ||
import '../binary_engine/binray_engine_type.dart'; | ||
import '../utils/ansi_progress.dart'; | ||
|
||
class PrecacheCommand extends Command { | ||
@override | ||
String get description => | ||
'Populate the Prisma engines cache of binary artifacts.'; | ||
|
||
@override | ||
String get name => 'precache'; | ||
|
||
PrecacheCommand() { | ||
argParser.addMultiOption( | ||
'type', | ||
abbr: 't', | ||
help: 'The engine type to precache.', | ||
valueHelp: 'engine', | ||
allowed: BinaryEngineType.values.map((e) => e.name), | ||
defaultsTo: BinaryEngineType.values.map((e) => e.name), | ||
); | ||
} | ||
|
||
Iterable<BinaryEngineType> get types { | ||
final List<String> types = argResults?['type'] as List<String>; | ||
if (types.isEmpty) return BinaryEngineType.values; | ||
|
||
return BinaryEngineType.values | ||
.where((element) => types.contains(element.name)); | ||
} | ||
|
||
@override | ||
void run() async { | ||
for (final BinaryEngineType type in types) { | ||
final BinaryEngine binaryEngine = BinaryEngine( | ||
platform: BinaryEnginePlatform.current, | ||
type: type, | ||
version: binaryVersion, | ||
); | ||
|
||
if (!await binaryEngine.hasDownloaded) { | ||
await binaryEngine.download(AnsiProgress.createFutureHandler( | ||
'Download Prisma ${type.name} engine')); | ||
await Future.delayed(Duration(microseconds: 100)); | ||
continue; | ||
} | ||
|
||
print('Prisma ${type.name} engine is already downloaded.'); | ||
} | ||
} | ||
} |