Skip to content

Commit

Permalink
update REAME.md
Browse files Browse the repository at this point in the history
  • Loading branch information
laiiihz committed Nov 21, 2023
1 parent f4f0dfb commit 4714ad1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ A powerful tool app for all developers.

```shell
dart pub get
dart run grinder setup
```

### before build app
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: alga
description: A powerful tool app for all developers.

publish_to: "none"
version: 2.0.1-dev+36
version: 2.0.1-dev+37

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down
101 changes: 95 additions & 6 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,115 @@ import 'package:grinder/grinder.dart';
Logger logger = Logger.standard(ansi: Ansi(true));
main(args) => grind(args);

@Task('setup app')
@DefaultTask('setup app')
Future setup() async {
TaskArgs args = context.invocation.arguments;
bool noDep = args.getFlag('no-dep');
await wait('get latest packages', () async {
await Pub.getAsync();
});
await wait('generate l10n', () async {
await Process.run('flutter', ['gen-l10n']);
});
await wait('generate dart files', () async {
await Dart.runAsync('run', arguments: ['build_runner', 'build']);
});
if (!noDep) {
await installDepApps();
}
}

@Task('Install All nessary apps')
Future installDepApps() async {
if (Platform.isMacOS) {
if (await checkCliApp('pnpm')) {
await installAppDmg('pnpm');
await installDistributor();
return;
}

if (await checkCliApp('npm')) {
await installAppDmg('npm');
await installDistributor();
return;
}

throw Exception('npm or pnpm not found\n Please install Node first');
}

await installDistributor();

// if (Platform.isMacOS) {
// await wait('install appdmg', () async {
// await Process.run('npm', ['install', '-g', 'appdmg']);
// });
// }
}

Future installAppDmg(String package) async {
if (!await checkCliApp('appdmg')) {
await wait('install appdmg', () async {
await Process.run(package, ['install', '-g', 'appdmg']);
});
}
}

Future installDistributor() async {
if (!await checkCliApp('flutter_distributor')) {
await wait('install flutter_distributor', () async {
await Dart.runAsync('pub',
arguments: ['global', 'activate', 'flutter_distributor']);
});
}
}

Future<bool> checkCliApp(String app) async {
if (Platform.isLinux || Platform.isMacOS) {
return wait('check $app installed', () async {
final result = await Process.run('which', [app]);
return result.exitCode == 0;
});
} else {
return wait('check $app installed', () async {
final result = await Process.run('which', [app]);
return result.exitCode == 0;
});
}
}

@Task('build on Macos')
Future buildOnMac() async {
TaskArgs args = context.invocation.arguments;
final skip = args.getFlag('skip');

installDistributor();

await wait('build macos', () async {
if (skip) stdout.write('[SKIP CLEAN]');
await Process.run('flutter_distributor',
['release', '--name', 'macos', if (skip) '--skip-clean']);
});

await wait('build apk', () async {
if (skip) stdout.write('[SKIP CLEAN]');
await Process.run('flutter_distributor',
['release', '--name', 'android', if (skip) '--skip-clean']);
});
}

@Task()
@Task('Clean All generated artifacts')
clean() async {
wait('flutter clean', () async {
await wait('flutter clean', () async {
await Process.run('flutter', ['clean']);
});
defaultClean();
}

Future wait(String message, Future Function() runner) async {
Future<T> wait<T>(String message, Future<T> Function() runner) async {
final progress = logger.progress(message);
await runner();
progress.finish(showTiming: true);
try {
return await runner();
} finally {
progress.finish(showTiming: true);
}
}

0 comments on commit 4714ad1

Please sign in to comment.