Skip to content

Commit de67dbf

Browse files
authored
feat(cli): Add Celest Cloud commands (#309)
- Adds commands for working with Celest Cloud organizations, projects and environments. - Adds back auth commands - Adds back `celest deploy` for deploying projects.
1 parent f682a5a commit de67dbf

File tree

69 files changed

+2549
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2549
-180
lines changed

apps/cli/Makefile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
database:
44
@echo "Generating Dart Drift classes..."
55
@dart run build_runner build --delete-conflicting-outputs
6-
@for DB in cache cloud project; do \
7-
echo "Generating schema JSON for $${DB} database..."; \
8-
mkdir -p lib/database/$${DB}/schema/; \
9-
dart run drift_dev schema dump lib/database/$${DB}/$${DB}_database.dart lib/database/$${DB}/schema/; \
10-
echo "Generating migration file for $${DB} database..."; \
11-
dart run drift_dev schema steps lib/database/$${DB}/schema/ lib/database/$${DB}/$${DB}.migrations.dart; \
12-
done
6+
@echo "Generating schema JSON for databases..."
7+
@dart run drift_dev make-migrations

apps/cli/bin/celest.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import 'package:celest_cli/celest_cli.dart';
2+
import 'package:celest_cli/src/commands/auth_command.dart';
3+
import 'package:celest_cli/src/commands/deploy_command.dart';
4+
import 'package:celest_cli/src/commands/organizations/organizations_command.dart';
5+
import 'package:celest_cli/src/commands/project_environments/project_environments_command.dart';
6+
import 'package:celest_cli/src/commands/projects/projects_command.dart';
27

38
void main(List<String> args) async {
49
final cli = Cli(
@@ -12,7 +17,15 @@ void main(List<String> args) async {
1217
..addCommand(AnalysisServerCommand())
1318
..addCommand(UpgradeCommand())
1419
..addCommand(UninstallCommand())
15-
..addCommand(PrecacheCommand());
20+
..addCommand(PrecacheCommand())
21+
..addCommand(DeployCommand())
22+
..addCommand(AuthCommand());
23+
24+
// Cloud API commands
25+
cli
26+
..addCommand(OrganizationsCommand())
27+
..addCommand(ProjectsCommand())
28+
..addCommand(ProjectEnvironmentsCommand());
1629

1730
await cli.run(args);
1831
}

apps/cli/build.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ targets:
3434
generate_for:
3535
- "lib/src/database/**"
3636
options: &options
37+
databases:
38+
cache: lib/src/database/cache/cache_database.dart
39+
project: lib/src/database/project/project_database.dart
40+
schema_dir: lib/src/database/schema/
41+
test_dir: test/database/
42+
3743
sql:
3844
dialect: sqlite
3945
options:

apps/cli/fixtures/standalone/auth/goldens/ast.resolved.json

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/cli/fixtures/standalone/auth/goldens/celest.json

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/cli/fixtures/standalone/streaming/goldens/ast.resolved.json

Lines changed: 18 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/cli/fixtures/standalone/streaming/goldens/celest.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'package:celest_auth/celest_auth.dart';
2+
import 'package:celest_auth/src/auth_impl.dart';
3+
import 'package:celest_cli/src/context.dart' as ctx;
4+
import 'package:celest_cli/src/context.dart';
5+
import 'package:celest_core/_internal.dart';
6+
import 'package:http/http.dart' as http;
7+
import 'package:native_storage/native_storage.dart';
8+
9+
export 'package:celest_cli/src/context.dart' show cloud;
10+
11+
final CliAuth auth = CliAuth();
12+
final Authenticator authenticator = Authenticator(
13+
secureStorage: ctx.secureStorage,
14+
);
15+
16+
final class _CliClient with CelestBase {
17+
_CliClient();
18+
19+
@override
20+
Uri get baseUri => ctx.baseUri;
21+
22+
@override
23+
late final http.Client httpClient = CelestHttpClient(
24+
secureStorage: ctx.secureStorage,
25+
baseClient: ctx.httpClient,
26+
);
27+
28+
@override
29+
NativeSecureStorage get nativeStorage => ctx.secureStorage;
30+
}
31+
32+
extension type CliAuth._(AuthImpl _hub) implements Auth {
33+
CliAuth()
34+
: _hub = AuthImpl(
35+
_CliClient(),
36+
cloud: cloud,
37+
storage: ctx.secureStorage,
38+
);
39+
40+
Email get email => Email(_hub);
41+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:celest_auth/celest_auth.dart';
2+
import 'package:celest_cli/src/commands/auth/cli_auth.dart';
3+
import 'package:celest_cli/src/commands/authenticate.dart';
4+
import 'package:celest_cli/src/commands/celest_command.dart';
5+
import 'package:celest_cli/src/context.dart';
6+
7+
final class LoginCommand extends CelestCommand with Authenticate {
8+
@override
9+
String get name => 'login';
10+
11+
@override
12+
String get description => 'Login to Celest Cloud.';
13+
14+
@override
15+
Future<int> run() async {
16+
await super.run();
17+
18+
final authState = await auth.init();
19+
logger.finest('Auth state: $authState');
20+
switch (authState) {
21+
case Authenticated(:final user):
22+
cliLogger.success(
23+
'You are already logged in as: ${user.primaryEmail?.email}',
24+
);
25+
default:
26+
logger.finest('Unauthenticated user. Signing up...');
27+
final res = await signUp();
28+
if (res != 0) {
29+
return res;
30+
}
31+
cliLogger.success('You have been logged in!');
32+
}
33+
34+
return 0;
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:celest_cli/src/commands/auth/cli_auth.dart';
2+
import 'package:celest_cli/src/commands/authenticate.dart';
3+
import 'package:celest_cli/src/commands/celest_command.dart';
4+
import 'package:celest_cli/src/config/celest_config.dart';
5+
import 'package:celest_cli/src/context.dart';
6+
7+
final class LogoutCommand extends CelestCommand with Authenticate {
8+
@override
9+
String get name => 'logout';
10+
11+
@override
12+
String get description => 'Logout of Celest Cloud.';
13+
14+
@override
15+
Future<int> run() async {
16+
await super.run();
17+
18+
final authState = await auth.init();
19+
logger.finest('Auth state: $authState');
20+
try {
21+
await auth.signOut();
22+
} on Object catch (e, st) {
23+
performance.captureError(e, stackTrace: st);
24+
}
25+
26+
// Remove local cloud cache
27+
try {
28+
final config = await CelestConfig.load();
29+
final cloudDb = config.configDir.childFile('cloud.db');
30+
if (cloudDb.existsSync()) {
31+
await cloudDb.delete();
32+
}
33+
} on Object catch (e, st) {
34+
performance.captureError(e, stackTrace: st);
35+
}
36+
37+
cliLogger.success('You have been logged out.');
38+
return 0;
39+
}
40+
}

0 commit comments

Comments
 (0)