Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appwrite CLI - Flutter and Generator commands #663

Open
wants to merge 17 commits into
base: 1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/SDK/Language/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,41 @@ public function getFiles(): array
'destination' => 'lib/commands/deploy.js',
'template' => 'cli/lib/commands/deploy.js.twig',
],
[
'scope' => 'default',
'destination' => 'lib/commands/flutter.js',
'template' => 'cli/lib/commands/flutter.js.twig',
],
[
'scope' => 'default',
'destination' => 'lib/commands/generate.js',
'template' => 'cli/lib/commands/generate.js.twig',
],
[
'scope' => 'default',
'destination' => 'flutter_res/apwrite.dart',
'template' => 'cli/flutter_res/appwrite.dart.twig',
],
[
'scope' => 'default',
'destination' => 'generator/template_dart.dart',
'template' => 'cli/generator/template_dart.dart.twig',
],
[
'scope' => 'default',
'destination' => 'generator/template_ts.ts',
'template' => 'cli/generator/template_ts.ts.twig',
],
[
'scope' => 'default',
'destination' => 'generator/template_swift.swift',
'template' => 'cli/generator/template_swift.swift.twig',
],
[
'scope' => 'default',
'destination' => 'generator/template_kotlin.kt',
'template' => 'cli/generator/template_kotlin.kt.twig',
],
[
'scope' => 'service',
'destination' => '/lib/commands/{{service.name | caseDash}}.js',
Expand Down
51 changes: 51 additions & 0 deletions templates/cli/flutter_res/appwrite.dart.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:appwrite/appwrite.dart';

class Appwrite {
final Client client = Client();
late final Account account;
late final Databases databases;
late final Avatars avatars;
late final Storage storage;
late final Functions functions;
late final Graphql graphql;
late final Teams teams;

// Comment out the following constructor if you prefer singleton
Appwrite() {
client
.setEndpoint('{ENDPOINT}')
.setProject('{PROJECT}');

account = Account(client);
databases = Databases(client);
avatars = Avatars(client);
storage = Storage(client);
functions = Functions(client);
graphql = Graphql(client);
teams = Teams(client);
}

// Uncoment the following code if you prefer using singleton
/*
static Appwrite? _instance;

Appwrite._internal() {
client
.setEndpoint('{ENDPOINT}')
.setProject('{PROJECT}');

account = Account(client);
databases = Databases(client);
avatars = Avatars(client);
storage = Storage(client);
functions = Functions(client);
graphql = Graphql(client);
teams = Teams(client);
}

static Appwrite get instance {
_instance ??= Appwrite._internal();
return _instance!;
}
*/
}
50 changes: 50 additions & 0 deletions templates/cli/generator/template_dart.dart.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
%IMPORTS%
class %NAME% {
final String $id;
final String $createdAt;
final String $updatedAt;
final String $collectionId;
final String $databaseId;
final List<String> $permissions;

%ATTRIBUTES%

%NAME%({
required this.$id,
required this.$createdAt,
required this.$updatedAt,
required this.$collectionId,
required this.$permissions,
required this.$databaseId,
%CONSTRUCTOR_PARAMETERS%
});

factory %NAME%.fromMap(Map<String, dynamic> map) {
return %NAME%(
$id: map['\$id'],
$createdAt: map['\$createdAt'],
$updatedAt: map['\$updatedAt'],
$collectionId: map['\$collectionId'],
$permissions: List<String>.from(map['\$permissions']),
$databaseId: map['\$databaseId'],
%CONSTRUCTOR_ARGUMENTS%
);
}

Map<String, dynamic> toMap() {
return {
'\$id': $id,
'\$createdAt': $createdAt,
'\$updatedAt': $updatedAt,
'\$collectionId': $collectionId,
'\$permissions': $permissions,
'\$databaseId': $databaseId,
%MAP_FIELDS%
};
}

@override
String toString() {
return '%NAME% ' + toMap().toString();
}
}
35 changes: 35 additions & 0 deletions templates/cli/generator/template_kotlin.kt.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class %NAME%(
val id: String,
val collectionId: String,
val databaseId: String,
val createdAt: String,
val updatedAt: String,
val permissions: List<Any>,
%CONSTRUCTOR_PARAMETERS%
) {
companion object {
fun from(map: Map<String, Any>): %NAME% {
return %NAME%(
id = map["$id"] as String,
collectionId = map["$collectionId"] as String,
databaseId = map["$databaseId"] as String,
createdAt = map["$createdAt"] as String,
updatedAt = map["$updatedAt"] as String,
permissions = map["$permissions"] as List<Any>,
%CONSTRUCTOR_ARGUMENTS%
)
}
}

fun toMap(): Map<String, Any> {
return mapOf(
"id" to id,
"collectionId" to collectionId,
"databaseId" to databaseId,
"createdAt" to createdAt,
"updatedAt" to updatedAt,
"permissions" to permissions as Any,
%MAP_FIELDS%
)
}
}
51 changes: 51 additions & 0 deletions templates/cli/generator/template_swift.swift.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
public class %NAME% {
public let id: String
public let collectionId: String
public let databaseId: String
public let createdAt: String
public let updatedAt: String
public let permissions: [Any]
%ATTRIBUTES%

init(
id: String,
collectionId: String,
databaseId: String,
createdAt: String,
updatedAt: String,
permissions: Permissions,
%CONSTRUCTOR_PARAMETERS%
) {
self.id = id
self.collectionId = collectionId
self.databaseId = databaseId
self.createdAt = createdAt
self.updatedAt = updatedAt
self.permissions = permissions
%CONSTRUCTOR_ASSIGNMENTS%
}

public static func from(map: [String: Any]) -> %NAME% {
return %NAME%(
id: map["$id"] as! String,
collectionId: map["$collectionId"] as! String,
databaseId: map["$databaseId"] as! String,
createdAt: map["$createdAt"] as! String,
updatedAt: map["$updatedAt"] as! String,
permissions: map["$permissions"] as! [Any],
%CONSTRUCTOR_ARGUMENTS%
)
}

public func toMap() -> [String: Any] {
return [
"id": id as Any,
"collectionId": collectionId as Any,
"databaseId": databaseId as Any,
"createdAt": createdAt as Any,
"updatedAt": updatedAt as Any,
"permissions": permissions as Any,
%MAP_FIELDS%
]
}
}
11 changes: 11 additions & 0 deletions templates/cli/generator/template_ts.ts.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%IMPORTS%

export type %NAME% {
$id: string;
$collectionId: string;
$databaseId: string;
$createdAt: string;
$updatedAt: string;
$permissions: string[];
%ATTRIBUTES%
}
4 changes: 4 additions & 0 deletions templates/cli/index.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const { client } = require("./lib/commands/generic");
const { login, logout } = require("./lib/commands/generic");
const { init } = require("./lib/commands/init");
const { deploy } = require("./lib/commands/deploy");
const { flutter } = require("./lib/commands/flutter");
const { generate } = require("./lib/commands/generate");
{% endif %}
{% for service in spec.services %}
const { {{ service.name | caseLower }} } = require("./lib/commands/{{ service.name | caseLower }}");
Expand All @@ -40,6 +42,8 @@ program
.addCommand(init)
.addCommand(deploy)
.addCommand(logout)
.addCommand(flutter)
.addCommand(generate)
{% endif %}
{% for service in spec.services %}
.addCommand({{ service.name | caseLower }})
Expand Down
Loading