Comments (3)
I don't think you need cmd.exe
import 'dart:io';
import 'package:mason/mason.dart';
void run(HookContext context) async {
String output = 'Test_2';
var result0 = await Process.run('', ['echo', 'Test', '0'], runInShell: true);
var result1 = await Process.run('echo', ['Test 1'], runInShell: true);
var result2 =
await Process.run('echo', [output, '$output'], runInShell: true);
stdout.write(result0.stdout);
stdout.write(result1.stdout);
stdout.write(result2.stdout);
}
*** Result ***
Test 0
"Test 1"
Test_2 Test_2
from mason.
Hi @ljoly83 👋
Thanks for opening an issue!
Does your same code work outside the context of a mason hook?
from mason.
Hi @felangel
Not sure to understand.
Here it is a simple DOS command echo and off course it works.
I try to use this postgen with windows:
https://github.com/hadiyaaamir/mason-bricks/blob/main/bricks/flutter_app_template/hooks/post_gen.dart
Here is my modified code:
import 'dart:io';
import 'package:mason/mason.dart';
Future<void> run(HookContext context) async {
// final appName = context.vars['appName'].toString().snakeCase;
// final appDirectory = Directory('${Directory.current.path}/$appName');
final appDirectory = Directory('${Directory.current.path}');
print('Running post_gen hook for ${appDirectory.path}');
// Test command
var result = await Process.run('cmd.exe', ['echo test'], runInShell: true);
stdout.write(result.stdout);
stderr.write(result.stderr);
await Future.wait([
// main app pubspec
addAllDependencies(
path: appDirectory.path,
dependencies: [
'dio',
'intl',
'equatable',
'provider',
'get_it',
'package_info_plus',
'path_provider',
'flutter_animate',
'animations',
'page_transition',
'flutter_spinkit'
// 'authentication_repository --path="packages/authentication_repository"',
// 'cache_client --path="packages/cache_client"',
// 'localization --path="packages/localization"',
],
devDependencies: ['mocktail'],
),
// localization package
addAllDependencies(
path: '${appDirectory.path}/packages/localization',
dependencies: ['easy_localization'],
devDependencies: ['mocktail', 'test'],
),
]);
String cdCommand = 'cd ${appDirectory.path}';
String cleanAndGetCommand = 'flutter clean && flutter pub get';
await Process.run(
getOsCommand(), ['-c', '$cdCommand && $cleanAndGetCommand']);
// await Process.run(getOsCommand(), ['-c', '$cleanAndGetCommand']);
// // await Process.run('bash', ['-c', '$cdCommand/ios && pod install']);
// await Process.start('flutter', ['clean'], runInShell: true);
// await Process.start('flutter', ['get'], runInShell: true);
// Delete gitkeep files
if (!appDirectory.existsSync()) return;
final gitKeepFiles = appDirectory
.listSync(recursive: true, followLinks: false)
.where((entity) => entity is File && entity.path.endsWith('.gitkeep'));
for (final file in gitKeepFiles) {
file.deleteSync();
}
}
Future<void> addAllDependencies({
required String path,
required List<String> dependencies,
required List<String> devDependencies,
}) async {
await Future.wait([
addDependencies(path: path, dependencies: dependencies),
addDevDependencies(path: path, devDependencies: devDependencies),
]);
}
Future<void> addDependencies({
required String path,
required List<String> dependencies,
bool devDependency = false,
}) async {
final cdCommand = 'cd $path';
final pubAddCommand = 'flutter pub add${devDependency ? ' -d' : ''}';
print('Nb dependencies: ${dependencies.length}');
await Future.wait(
List.generate(
dependencies.length,
(index) {
final command = '$cdCommand && $pubAddCommand ${dependencies[index]}';
// print('Running: $command');
// return Process.run(getOsCommand(), ['-c', command]);
return Process.run(getOsCommand(), [command], runInShell: true);
// var result = Process.run(getOsCommand(), [command], runInShell: true);
// stdout.write(result.stdout);
// stderr.write(result.stderr);
// return result;
},
),
);
// await Process.run('bash', ['-c', '$cdCommand && flutter pub get']);
await Process.run(getOsCommand(), ['$cdCommand && flutter pub get'],
runInShell: true);
}
Future<void> addDevDependencies({
required String path,
required List<String> devDependencies,
}) async {
await addDependencies(
path: path,
dependencies: devDependencies,
devDependency: true,
);
}
String getOsCommand() {
if (Platform.isWindows) {
return 'cmd.exe';
} else {
return 'bash';
}
}
from mason.
Related Issues (20)
- logger.prompt with defaultValue if no input is provided, keeps waiting until we provide some input in Windows Powershell HOT 2
- fix: allow bundling path dependencies that are not within hook path
- fix: capture ProcessException when hook generation fails due to `dart pub get`
- chore: `mason_logger` - update win32 package HOT 2
- feat: support conditional prompting for variables HOT 6
- feat: include `prompt` style in `LogTheme`
- fix: Extra line with condition statement HOT 5
- feat: hook resource sharing
- perf: Generating files from a list which is not a simple string rather a List<Map<String, dynamic>> takes over 30 minutes HOT 2
- feat: simplify relying on defaults when using `mason make` in CI HOT 2
- fix: Generating files from array not working HOT 6
- fix: Crash with "StreamSink is bound to stream" HOT 5
- fix: mason_logger does not handle `stdin.hasTerminal` being false
- fix: The getter 'STD_HANDLE' isn't defined for the class 'WindowsTerminal'. HOT 8
- Failing to activate mason_cli after upgrading to mason_cli: ^0.1.0-dev.54 HOT 1
- feat: set default output directory HOT 2
- feat: ask to overwrite or not for duplicate brick name
- feat: Retain colors across process boundary HOT 2
- fix: `Isolate.spawnUri()` does not contain a valid AOT snapshot on script compiled with `dart compile exe` HOT 4
- feat: Mirror logger output to a file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mason.