|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:openapi_generator/src/determine_flutter_project_status.dart'; |
| 4 | +import 'package:openapi_generator/src/gen_on_spec_changes.dart'; |
1 | 5 | import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
|
2 | 6 |
|
3 | 7 | /// Creates a representation of a cli request for Flutter or Dart.
|
@@ -29,3 +33,52 @@ class Command {
|
29 | 33 | arguments,
|
30 | 34 | );
|
31 | 35 | }
|
| 36 | + |
| 37 | +/// CommandRunner provides an abstraction layer to external functions / processes. |
| 38 | +class CommandRunner { |
| 39 | + const CommandRunner(); |
| 40 | + |
| 41 | + Future<ProcessResult> runCommand({ |
| 42 | + required Command command, |
| 43 | + required String workingDirectory, |
| 44 | + }) async => |
| 45 | + Process.run( |
| 46 | + command.executable, |
| 47 | + command.arguments, |
| 48 | + workingDirectory: workingDirectory, |
| 49 | + runInShell: Platform.isWindows, |
| 50 | + ); |
| 51 | + |
| 52 | + Future<List<String>> loadAnnotatedFile({required String path}) async { |
| 53 | + final f = File(path); |
| 54 | + return f.readAsLines(); |
| 55 | + } |
| 56 | + |
| 57 | + Future<void> writeAnnotatedFile( |
| 58 | + {required String path, required List<String> content}) async { |
| 59 | + final f = File(path); |
| 60 | + return f.writeAsStringSync(content.join('\n'), flush: true); |
| 61 | + } |
| 62 | + |
| 63 | + Future<void> cacheSpecFile({ |
| 64 | + required Map<String, dynamic> updatedSpec, |
| 65 | + required String cachedPath, |
| 66 | + }) async => |
| 67 | + cacheSpec(outputLocation: cachedPath, spec: updatedSpec); |
| 68 | + |
| 69 | + Future<Map<String, dynamic>> loadSpecFile( |
| 70 | + {required InputSpec specConfig, bool isCached = false}) async => |
| 71 | + loadSpec(specConfig: specConfig); |
| 72 | + |
| 73 | + Future<bool> isSpecFileDirty({ |
| 74 | + required Map<String, dynamic> cachedSpec, |
| 75 | + required Map<String, dynamic> loadedSpec, |
| 76 | + }) async => |
| 77 | + isSpecDirty(cachedSpec: cachedSpec, loadedSpec: loadedSpec); |
| 78 | + |
| 79 | + Future<bool> checkForFlutterEnvironemt( |
| 80 | + {Wrapper? wrapper = Wrapper.none, |
| 81 | + String? providedPubspecPath}) async => |
| 82 | + checkPubspecAndWrapperForFlutterSupport( |
| 83 | + wrapper: wrapper, providedPubspecPath: providedPubspecPath); |
| 84 | +} |
0 commit comments