Skip to content

add graphql api service #10

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

Merged
merged 1 commit into from
Nov 18, 2022
Merged
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
73 changes: 51 additions & 22 deletions lib/src/cli/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:io';

import 'package:path/path.dart';

import 'package:flutter_starter_cli/src/utils.dart';

class Cli {
static Future<ProcessResult> _run(
String cmd,
Expand All @@ -17,8 +19,8 @@ class Cli {
return result;
}

static _delete(Directory target, [bool isFile = false]) {
if (isFile || target.existsSync()) target.deleteSync(recursive: true);
static _delete(target) {
if (target.existsSync()) target.deleteSync(recursive: true);
}

static Future<void> cloneProject(String path, String state) async {
Expand All @@ -37,36 +39,63 @@ class Cli {
}

static Future<void> removeFiles(String path, String api, bool test) async {
Directory target;
target = Directory(join(path, '.git'));
await _delete(target);
if (api == 'dio') {
target = Directory(join(path, 'lib', 'api_sdk', 'http'));
await _delete(target);
target = Directory(join(path, 'lib', 'api_sdk', 'http_api_sdk.dart'));
await _delete(target, true);
} else {
target = Directory(join(path, 'lib', 'api_sdk', 'dio'));
await _delete(target);
target = Directory(join(path, 'lib', 'api_sdk', 'dio_api_sdk.dart'));
await _delete(target, true);
File file;
Directory folder;
folder = Directory(join(path, '.git'));
await _delete(folder);
final String apiSdk = join(path, 'lib', 'api_sdk');
if (api == APIService.dio.name) {
folder = Directory(join(apiSdk, 'http'));
await _delete(folder);
file = File(join(apiSdk, 'http_api_sdk.dart'));
await _delete(file);
folder = Directory(join(apiSdk, 'graphql'));
await _delete(folder);
file = File(join(apiSdk, 'graphql_api_sdk.dart'));
await _delete(file);
} else if (api == APIService.http.name) {
folder = Directory(join(apiSdk, 'dio'));
await _delete(folder);
file = File(join(apiSdk, 'dio_api_sdk.dart'));
await _delete(file);
folder = Directory(join(apiSdk, 'graphql'));
await _delete(folder);
file = File(join(apiSdk, 'graphql_api_sdk.dart'));
await _delete(file);
} else if (api == APIService.graphql.name) {
folder = Directory(join(apiSdk, 'http'));
await _delete(folder);
file = File(join(apiSdk, 'http_api_sdk.dart'));
await _delete(file);
folder = Directory(join(apiSdk, 'dio'));
await _delete(folder);
file = File(join(apiSdk, 'dio_api_sdk.dart'));
await _delete(file);
}
if (!test) {
target = Directory(join(path, 'integration_test'));
await _delete(target);
target = Directory(join(path, 'test'));
await _delete(target);
folder = Directory(join(path, 'integration_test'));
await _delete(folder);
folder = Directory(join(path, 'test'));
await _delete(folder);
}
}

static Future<void> removePackages(String path, String api, bool test) async {
var args = [];
if (api == 'dio') {
if (api == APIService.dio.name) {
args
..add('http')
..add('http_interceptor');
} else {
..add('http_interceptor')
..add('graphql_flutter');
} else if (api == APIService.http.name) {
args
..add('dio')
..add('retrofit')
..add('graphql_flutter');
} else if (api == APIService.graphql.name) {
args
..add('http')
..add('http_interceptor')
..add('dio')
..add('retrofit');
}
Expand Down
12 changes: 10 additions & 2 deletions lib/src/commands/create_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class CreateCommand extends Command<int> {
'api',
abbr: 'a',
help: 'The API service for the project.',
allowed: [APIService.dio.name, APIService.http.name],
allowed: [
APIService.dio.name,
APIService.http.name,
APIService.graphql.name
],
)
..addFlag(
'test',
Expand Down Expand Up @@ -112,7 +116,11 @@ In order to run your application.''');
return argResults?['api'] ??
_logger.chooseOne(
'Select the API Service',
choices: [APIService.dio.name, APIService.http.name],
choices: [
APIService.dio.name,
APIService.http.name,
APIService.graphql.name
],
defaultValue: APIService.dio.name,
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:mason_logger/mason_logger.dart';
enum APIService {
dio,
http,
graphql,
}

enum StateManagement {
Expand Down