-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting flutterSdkPath and dartSdkPath for the flutter and dart…
… commands (#75) Co-authored-by: Giuseppe Cianci <[email protected]>
- Loading branch information
Showing
10 changed files
with
315 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:dcli/dcli.dart' as dcli; | ||
import 'package:sidekick_core/sidekick_core.dart'; | ||
|
||
/// Executes Flutter command from Flutter SDK set in [flutterSdk] | ||
int flutter( | ||
List<String> args, { | ||
Directory? workingDirectory, | ||
dcli.Progress? progress, | ||
}) { | ||
final workingDir = | ||
workingDirectory?.absolute ?? entryWorkingDirectory.absolute; | ||
|
||
final sdk = flutterSdk; | ||
if (sdk == null) { | ||
throw FlutterSdkNotSetException(); | ||
} | ||
|
||
if (Platform.isWindows) { | ||
final process = dcli.startFromArgs( | ||
'bash', | ||
[sdk.file('bin/flutter.exe').path, ...args], | ||
workingDirectory: workingDir.path, | ||
nothrow: true, | ||
progress: progress, | ||
terminal: progress == null, | ||
); | ||
return process.exitCode ?? -1; | ||
} else { | ||
final process = dcli.startFromArgs( | ||
sdk.file('bin/flutter').path, | ||
args, | ||
workingDirectory: workingDir.path, | ||
nothrow: true, | ||
progress: progress, | ||
terminal: progress == null, | ||
); | ||
return process.exitCode ?? -1; | ||
} | ||
} | ||
|
||
/// The Flutter SDK path is not set in [initializeSidekick] (param [flutterSdk]) | ||
class FlutterSdkNotSetException implements Exception { | ||
final String message = | ||
"No Flutter SDK set. Please set it in `initializeSidekick(flutterSdkPath: 'path/to/sdk')`"; | ||
@override | ||
String toString() { | ||
return "FlutterSdkNotSetException{message: $message}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:sidekick_core/sidekick_core.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'fake_sdk.dart'; | ||
import 'init_test.dart'; | ||
|
||
void main() { | ||
test('dart command works when dartSdkPath is set', () async { | ||
await insideFakeSidekickProject((dir) async { | ||
final runner = initializeSidekick( | ||
name: 'dash', | ||
dartSdkPath: fakeDartSdk().path, | ||
); | ||
runner.addCommand(DartCommand()); | ||
await runner.run(['dart']); | ||
}); | ||
}); | ||
|
||
test('dart command fails when dartSdkPath is not set', () async { | ||
await insideFakeSidekickProject((dir) async { | ||
final runner = initializeSidekick( | ||
name: 'dash', | ||
// ignore: avoid_redundant_argument_values | ||
dartSdkPath: null, | ||
); | ||
runner.addCommand(DartCommand()); | ||
expect( | ||
() => runner.run(['dart']), | ||
throwsA(isA<DartSdkNotSetException>()), | ||
); | ||
}); | ||
}); | ||
|
||
test('dart command links to embedded Dart SDK in Flutter SDK', () async { | ||
await insideFakeSidekickProject((dir) async { | ||
final runner = initializeSidekick( | ||
name: 'dash', | ||
flutterSdkPath: fakeFlutterSdk().path, | ||
); | ||
runner.addCommand(DartCommand()); | ||
await runner.run(['dart']); | ||
}); | ||
}); | ||
} | ||
|
||
Future<File> installFlutterWrapper(Directory directory) async { | ||
writeAndRunShellScript( | ||
r'sh -c "$(curl -fsSL https://raw.githubusercontent.com/passsy/flutter_wrapper/master/install.sh)"', | ||
workingDirectory: directory, | ||
); | ||
final exe = directory.file('flutterw'); | ||
assert(exe.existsSync()); | ||
return exe; | ||
} |
Oops, something went wrong.