|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:args/args.dart'; |
| 4 | +import 'package:git/git.dart'; |
| 5 | +import 'package:helper/helper.dart'; |
| 6 | +import 'package:parser/parser.dart'; |
| 7 | +import 'package:path/path.dart' as p; |
| 8 | + |
| 9 | +void main(List<String> arguments) async { |
| 10 | + final parser = ArgParser() |
| 11 | + ..addOption('path', mandatory: true) |
| 12 | + ..addOption('api-key', mandatory: true); |
| 13 | + |
| 14 | + final args = parser.parse(arguments); |
| 15 | + |
| 16 | + final path = args['path'] as String; |
| 17 | + final apiKey = args['api-key'] as String; |
| 18 | + |
| 19 | + if (await GitDir.isGitDir(p.current)) { |
| 20 | + final gitDir = await GitDir.fromExisting( |
| 21 | + p.current, |
| 22 | + allowSubdirectory: true, |
| 23 | + ); |
| 24 | + final branch = await gitDir.currentBranch(); |
| 25 | + |
| 26 | + // final status = await gitDir.runCommand(['status']); |
| 27 | + // final asString = status.stdout as String; |
| 28 | + |
| 29 | + final branchName = branch.branchName; |
| 30 | + final sha = branch.sha; |
| 31 | + |
| 32 | + final directory = Directory(path); |
| 33 | + |
| 34 | + final file = WidgetbookZipEncoder().encode(directory); |
| 35 | + if (file != null) { |
| 36 | + await WidgetbookHttpClient().uploadDeployment( |
| 37 | + deploymentFile: file, |
| 38 | + data: DeploymentData( |
| 39 | + branchName: branchName, |
| 40 | + repositoryName: '', |
| 41 | + commitSha: sha, |
| 42 | + actor: '', |
| 43 | + apiKey: apiKey, |
| 44 | + provider: 'CLI', |
| 45 | + ), |
| 46 | + ); |
| 47 | + } else { |
| 48 | + print('Could not create .zip file for upload.'); |
| 49 | + } |
| 50 | + } else { |
| 51 | + print('Please make sure to execute this CLI within a git folder.'); |
| 52 | + } |
| 53 | +} |
0 commit comments