From a5732a300491ad6f7d13280543a73fcd29f95854 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Thu, 2 Mar 2023 11:59:00 -0600 Subject: [PATCH] refactor: convert to mono-repo --- .../{main.yaml => shorebird_cli.yaml} | 14 ++--- README.md | 6 +- lib/src/commands/publish_command.dart | 26 -------- .gitignore => shorebird_cli/.gitignore | 0 CHANGELOG.md => shorebird_cli/CHANGELOG.md | 0 shorebird_cli/README.md | 3 + .../analysis_options.yaml | 0 {bin => shorebird_cli/bin}/shorebird.dart | 0 .../dart_test.yaml | 0 {lib => shorebird_cli/lib}/shorebird_cli.dart | 0 .../lib}/src/command_runner.dart | 0 .../lib}/src/commands/commands.dart | 0 .../lib/src/commands/publish_command.dart | 59 +++++++++++++++++++ .../lib}/src/commands/update_command.dart | 0 {lib => shorebird_cli/lib}/src/version.dart | 0 pubspec.yaml => shorebird_cli/pubspec.yaml | 1 + .../test}/ensure_build_test.dart | 0 .../test}/src/command_runner_test.dart | 0 .../src/commands/publish_command_test.dart | 0 .../src/commands/update_command_test.dart | 0 20 files changed, 74 insertions(+), 35 deletions(-) rename .github/workflows/{main.yaml => shorebird_cli.yaml} (76%) delete mode 100644 lib/src/commands/publish_command.dart rename .gitignore => shorebird_cli/.gitignore (100%) rename CHANGELOG.md => shorebird_cli/CHANGELOG.md (100%) create mode 100644 shorebird_cli/README.md rename analysis_options.yaml => shorebird_cli/analysis_options.yaml (100%) rename {bin => shorebird_cli/bin}/shorebird.dart (100%) rename dart_test.yaml => shorebird_cli/dart_test.yaml (100%) rename {lib => shorebird_cli/lib}/shorebird_cli.dart (100%) rename {lib => shorebird_cli/lib}/src/command_runner.dart (100%) rename {lib => shorebird_cli/lib}/src/commands/commands.dart (100%) create mode 100644 shorebird_cli/lib/src/commands/publish_command.dart rename {lib => shorebird_cli/lib}/src/commands/update_command.dart (100%) rename {lib => shorebird_cli/lib}/src/version.dart (100%) rename pubspec.yaml => shorebird_cli/pubspec.yaml (96%) rename {test => shorebird_cli/test}/ensure_build_test.dart (100%) rename {test => shorebird_cli/test}/src/command_runner_test.dart (100%) rename {test => shorebird_cli/test}/src/commands/publish_command_test.dart (100%) rename {test => shorebird_cli/test}/src/commands/update_command_test.dart (100%) diff --git a/.github/workflows/main.yaml b/.github/workflows/shorebird_cli.yaml similarity index 76% rename from .github/workflows/main.yaml rename to .github/workflows/shorebird_cli.yaml index fa9a05ae..f9c266ae 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/shorebird_cli.yaml @@ -1,4 +1,4 @@ -name: ci +name: shorebird_cli concurrency: group: ${{ github.workflow }}-${{ github.ref }} @@ -8,17 +8,17 @@ on: pull_request: paths: - ".github/workflows/shorebird_cli.yaml" - - "lib/**" - - "test/**" - - "pubspec.yaml" + - "packages/shorebird_cli/lib/**" + - "packages/shorebird_cli/test/**" + - "packages/shorebird_cli/pubspec.yaml" push: branches: - main paths: - ".github/workflows/shorebird_cli.yaml" - - "lib/**" - - "test/**" - - "pubspec.yaml" + - "packages/shorebird_cli/lib/**" + - "packages/shorebird_cli/test/**" + - "packages/shorebird_cli/pubspec.yaml" jobs: semantic-pull-request: diff --git a/README.md b/README.md index fba6ae29..70b0511f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -## shorebird_cli +## shorebird -The Shorebird command-line tool. +Home of the Shorebird Tools 🐦 + +🚧 Under construction... 🚧 diff --git a/lib/src/commands/publish_command.dart b/lib/src/commands/publish_command.dart deleted file mode 100644 index e1a3ce0e..00000000 --- a/lib/src/commands/publish_command.dart +++ /dev/null @@ -1,26 +0,0 @@ -import 'package:args/command_runner.dart'; -import 'package:mason_logger/mason_logger.dart'; - -/// {@template sample_command} -/// -/// `shorebird sample` -/// A [Command] to exemplify a sub command -/// {@endtemplate} -class PublishCommand extends Command { - /// {@macro sample_command} - PublishCommand({required Logger logger}) : _logger = logger; - - @override - String get description => 'Publish an update.'; - - @override - String get name => 'publish'; - - final Logger _logger; - - @override - Future run() async { - _logger.info('Coming soon...'); - return ExitCode.success.code; - } -} diff --git a/.gitignore b/shorebird_cli/.gitignore similarity index 100% rename from .gitignore rename to shorebird_cli/.gitignore diff --git a/CHANGELOG.md b/shorebird_cli/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to shorebird_cli/CHANGELOG.md diff --git a/shorebird_cli/README.md b/shorebird_cli/README.md new file mode 100644 index 00000000..fba6ae29 --- /dev/null +++ b/shorebird_cli/README.md @@ -0,0 +1,3 @@ +## shorebird_cli + +The Shorebird command-line tool. diff --git a/analysis_options.yaml b/shorebird_cli/analysis_options.yaml similarity index 100% rename from analysis_options.yaml rename to shorebird_cli/analysis_options.yaml diff --git a/bin/shorebird.dart b/shorebird_cli/bin/shorebird.dart similarity index 100% rename from bin/shorebird.dart rename to shorebird_cli/bin/shorebird.dart diff --git a/dart_test.yaml b/shorebird_cli/dart_test.yaml similarity index 100% rename from dart_test.yaml rename to shorebird_cli/dart_test.yaml diff --git a/lib/shorebird_cli.dart b/shorebird_cli/lib/shorebird_cli.dart similarity index 100% rename from lib/shorebird_cli.dart rename to shorebird_cli/lib/shorebird_cli.dart diff --git a/lib/src/command_runner.dart b/shorebird_cli/lib/src/command_runner.dart similarity index 100% rename from lib/src/command_runner.dart rename to shorebird_cli/lib/src/command_runner.dart diff --git a/lib/src/commands/commands.dart b/shorebird_cli/lib/src/commands/commands.dart similarity index 100% rename from lib/src/commands/commands.dart rename to shorebird_cli/lib/src/commands/commands.dart diff --git a/shorebird_cli/lib/src/commands/publish_command.dart b/shorebird_cli/lib/src/commands/publish_command.dart new file mode 100644 index 00000000..08b8ae4b --- /dev/null +++ b/shorebird_cli/lib/src/commands/publish_command.dart @@ -0,0 +1,59 @@ +import 'dart:io'; + +import 'package:args/command_runner.dart'; +import 'package:http/http.dart' as http; +import 'package:mason_logger/mason_logger.dart'; + +/// {@template sample_command} +/// +/// `shorebird sample` +/// A [Command] to exemplify a sub command +/// {@endtemplate} +class PublishCommand extends Command { + /// {@macro sample_command} + PublishCommand({required Logger logger, http.Client? httpClient}) + : _logger = logger, + _httpClient = httpClient ?? http.Client(); + + @override + String get description => 'Publish an update.'; + + @override + String get name => 'publish'; + + final Logger _logger; + final http.Client _httpClient; + + @override + Future run() async { + final args = argResults!.rest; + if (args.isEmpty || args.length > 1) { + usageException('A single file path must be specified.'); + } + + final artifact = File(args.first); + if (!artifact.existsSync()) { + _logger.err('File not found: ${artifact.path}'); + return ExitCode.noInput.code; + } + + final request = http.MultipartRequest( + 'POST', + Uri.parse('http://localhost:8080/deploy'), + ); + final file = await http.MultipartFile.fromPath('file', artifact.path); + request.files.add(file); + final response = await _httpClient.send(request); + + if (response.statusCode != HttpStatus.ok) { + _logger.err( + 'Deploy failed: ${response.statusCode} ${response.reasonPhrase}', + ); + return ExitCode.software.code; + } + + _logger.success('Deployed ${artifact.path} successfully!'); + + return ExitCode.success.code; + } +} diff --git a/lib/src/commands/update_command.dart b/shorebird_cli/lib/src/commands/update_command.dart similarity index 100% rename from lib/src/commands/update_command.dart rename to shorebird_cli/lib/src/commands/update_command.dart diff --git a/lib/src/version.dart b/shorebird_cli/lib/src/version.dart similarity index 100% rename from lib/src/version.dart rename to shorebird_cli/lib/src/version.dart diff --git a/pubspec.yaml b/shorebird_cli/pubspec.yaml similarity index 96% rename from pubspec.yaml rename to shorebird_cli/pubspec.yaml index 28e77e87..4a623779 100644 --- a/pubspec.yaml +++ b/shorebird_cli/pubspec.yaml @@ -8,6 +8,7 @@ environment: dependencies: args: ^2.3.1 cli_completion: ^0.2.0 + http: ^0.13.5 mason_logger: ^0.2.4 pub_updater: ^0.2.4 diff --git a/test/ensure_build_test.dart b/shorebird_cli/test/ensure_build_test.dart similarity index 100% rename from test/ensure_build_test.dart rename to shorebird_cli/test/ensure_build_test.dart diff --git a/test/src/command_runner_test.dart b/shorebird_cli/test/src/command_runner_test.dart similarity index 100% rename from test/src/command_runner_test.dart rename to shorebird_cli/test/src/command_runner_test.dart diff --git a/test/src/commands/publish_command_test.dart b/shorebird_cli/test/src/commands/publish_command_test.dart similarity index 100% rename from test/src/commands/publish_command_test.dart rename to shorebird_cli/test/src/commands/publish_command_test.dart diff --git a/test/src/commands/update_command_test.dart b/shorebird_cli/test/src/commands/update_command_test.dart similarity index 100% rename from test/src/commands/update_command_test.dart rename to shorebird_cli/test/src/commands/update_command_test.dart