Skip to content

Commit 15ea27f

Browse files
committed
chore: Added a build utility.
1 parent 152acc8 commit 15ea27f

3 files changed

Lines changed: 90 additions & 6 deletions

File tree

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ app.*.map.json
4747
/android/app/profile
4848
/android/app/release
4949

50-
# Bat files
51-
generate.bat
52-
msix.bat
53-
5450
# Generated files
5551
lib/app.dart
5652
**/*.g.dart

bin/build.dart

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import 'dart:io';
2+
3+
// ignore: depend_on_referenced_packages
4+
import 'package:pubspec_parse/pubspec_parse.dart';
5+
6+
/// Run pre-build commands and run `flutter build x` where x is the desired platform.
7+
void main() {
8+
exitCode = 0;
9+
stdout.writeln('Running `flutter clean`...');
10+
Process.runSync('flutter', ['clean'], runInShell: true);
11+
stdout.writeln('Done.');
12+
stdout.writeln('Running `flutter pub get`...');
13+
Process.runSync('flutter', ['pub', 'get'], runInShell: true);
14+
stdout.writeln('Done.');
15+
stdout.writeln('Running `dart run slang`...');
16+
Process.runSync('dart', ['run', 'slang'], runInShell: true);
17+
stdout.writeln('Done.');
18+
stdout.writeln('Running `dart run build_runner build --delete-conflicting-outputs`...');
19+
Process.runSync('dart', ['run', 'build_runner', 'build', '--delete-conflicting-outputs'], runInShell: true);
20+
stdout.writeln('Done.');
21+
stdout.writeln('For which platform do you want to build ? (android/ios/macos/windows/linux)');
22+
String platform = stdin.readLineSync() ?? '';
23+
switch (platform.toLowerCase()) {
24+
case 'android':
25+
stdout.writeln('Running `flutter build appbundle`...');
26+
Process.runSync('flutter', ['build', 'appbundle'], runInShell: true);
27+
stdout.writeln('Done.');
28+
break;
29+
case 'ios':
30+
stdout.writeln('Updating pods...');
31+
Process.runSync('pod', ['update'], workingDirectory: File('ios').path, runInShell: true);
32+
stdout.writeln('Done.');
33+
stdout.writeln('Running `flutter build ios`...');
34+
Process.runSync('flutter', ['build', 'ios']);
35+
stdout.writeln('Done.');
36+
break;
37+
case 'macos':
38+
stdout.writeln('Updating pods...');
39+
Process.runSync('pod', ['update'], workingDirectory: File('macos').path, runInShell: true);
40+
stdout.writeln('Done.');
41+
stdout.writeln('Running `flutter build macos`...');
42+
Process.runSync('flutter', ['build', 'macos'], runInShell: true);
43+
stdout.writeln('Done.');
44+
break;
45+
case 'windows':
46+
stdout.writeln('Running `dart run msix:create`...');
47+
Process.runSync('dart', ['run', 'msix:create'], runInShell: true);
48+
stdout.writeln('Done.');
49+
case 'linux':
50+
File pubspecFile = File('./pubspec.yaml');
51+
if (!pubspecFile.existsSync()) {
52+
stderr.writeln('Cannot find pubspec.yaml at "${pubspecFile.path}".');
53+
return;
54+
}
55+
String pubspecContent = pubspecFile.readAsStringSync();
56+
Pubspec pubspec = Pubspec.parse(pubspecContent);
57+
if (pubspec.version == null) {
58+
stderr.writeln('Cannot find current version.');
59+
return;
60+
}
61+
stdout.writeln('Current version is "${pubspec.version}".');
62+
stdout.writeln('Running `snapcraft`...');
63+
Process.runSync('snapcraft', [], runInShell: true);
64+
stdout.writeln('Done.');
65+
String snapName = 'open-authenticator_${pubspec.version!.major}.${pubspec.version!.minor}.${pubspec.version!.patch}_amd64.snap';
66+
File snap = File(snapName);
67+
if (!snap.existsSync()) {
68+
stderr.writeln('Cannot find snap at "${snap.path}".');
69+
return;
70+
}
71+
stdout.writeln('Running `snapcraft upload --release=stable $snapName`...');
72+
Process.runSync('snapcraft', ['upload', '--release=stable', snapName], runInShell: true);
73+
stdout.writeln('Done.');
74+
break;
75+
default:
76+
stderr.writeln('Invalid platform.');
77+
exitCode = -1;
78+
return;
79+
}
80+
stdout.writeln('Do you want to run `flutter clean && flutter pub get` ? (Y/N)');
81+
String yN = stdin.readLineSync() ?? '';
82+
if (yN.toLowerCase() == 'y') {
83+
stdout.writeln('Running `flutter clean`...');
84+
Process.runSync('flutter', ['clean'], runInShell: true);
85+
stdout.writeln('Done.');
86+
stdout.writeln('Running `flutter pub get`...');
87+
Process.runSync('flutter', ['pub', 'get'], runInShell: true);
88+
stdout.writeln('Done.');
89+
}
90+
}

bin/generate.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,4 @@ class Argon2Parameters {
176176
177177
''');
178178
stdout.writeln('Done.');
179-
180-
181179
}

0 commit comments

Comments
 (0)