@_nazmiforreal/flutter-ota 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dart-src/packages/cli-tools/.dart_tool/package_config.json +496 -0
  2. package/dart-src/packages/cli-tools/.dart_tool/package_graph.json +743 -0
  3. package/dart-src/packages/cli-tools/lib/src/cli_base.dart +7 -6
  4. package/dart-src/packages/cli-tools/lib/src/commands/build.dart +46 -49
  5. package/dart-src/packages/cli-tools/lib/src/commands/bundle.dart +44 -23
  6. package/dart-src/packages/cli-tools/lib/src/commands/channel.dart +27 -17
  7. package/dart-src/packages/cli-tools/lib/src/commands/console.dart +11 -6
  8. package/dart-src/packages/cli-tools/lib/src/commands/deploy.dart +39 -22
  9. package/dart-src/packages/cli-tools/lib/src/commands/doctor.dart +22 -13
  10. package/dart-src/packages/cli-tools/lib/src/commands/init.dart +117 -36
  11. package/dart-src/packages/cli-tools/lib/src/commands/keys.dart +15 -9
  12. package/dart-src/packages/cli-tools/lib/src/commands/migrate.dart +14 -8
  13. package/dart-src/packages/cli-tools/lib/src/commands/rollback.dart +37 -12
  14. package/dart-src/packages/cli-tools/lib/src/config.dart +13 -3
  15. package/dart-src/packages/cli-tools/lib/src/operations.dart +45 -0
  16. package/dart-src/packages/cli-tools/lib/src/pack.dart +9 -0
  17. package/dart-src/packages/cli-tools/lib/src/ui/ui.dart +234 -0
  18. package/dart-src/packages/cli-tools/pubspec.lock +638 -0
  19. package/dart-src/packages/cli-tools/test/backends_test.dart +207 -0
  20. package/dart-src/packages/cli-tools/test/build_pack_test.dart +101 -0
  21. package/dart-src/packages/cli-tools/test/cli_test.dart +442 -0
  22. package/dart-src/packages/cli-tools/test/mocks/mock_aws_s3_client.dart +83 -0
  23. package/dart-src/packages/cli-tools/test/mocks/mock_d1_client.dart +256 -0
  24. package/dart-src/packages/cli-tools/test/mocks/mock_postgres_client.dart +347 -0
  25. package/dart-src/packages/cli-tools/test/standalone_backend_test.dart +315 -0
  26. package/dart-src/packages/core/test/rollout_test.dart +128 -0
  27. package/dart-src/packages/core/test/semver_test.dart +52 -0
  28. package/dart-src/packages/core/test/semver_vectors.json +1 -0
  29. package/dart-src/packages/core/test/types_test.dart +129 -0
  30. package/dart-src/packages/core/test/uuid_test.dart +38 -0
  31. package/dart-src/plugins/aws/test/aws_database_test.dart +167 -0
  32. package/dart-src/plugins/aws/test/aws_lambda_edge_storage_test.dart +190 -0
  33. package/dart-src/plugins/aws/test/aws_storage_test.dart +73 -0
  34. package/dart-src/plugins/aws/test/mock_aws_s3_client.dart +83 -0
  35. package/dart-src/plugins/cloudflare/test/cloudflare_worker_database_test.dart +122 -0
  36. package/dart-src/plugins/cloudflare/test/d1_bundle_mapper_test.dart +106 -0
  37. package/dart-src/plugins/cloudflare/test/d1_database_test.dart +190 -0
  38. package/dart-src/plugins/cloudflare/test/mock_d1_client.dart +256 -0
  39. package/dart-src/plugins/cloudflare/test/mock_r2_client.dart +83 -0
  40. package/dart-src/plugins/cloudflare/test/r2_storage_test.dart +77 -0
  41. package/dart-src/plugins/plugin-core/test/asset_storage_layout_test.dart +166 -0
  42. package/dart-src/plugins/plugin-core/test/bundle_unit_of_work_store_test.dart +74 -0
  43. package/dart-src/plugins/plugin-core/test/bundle_unit_of_work_test.dart +332 -0
  44. package/dart-src/plugins/plugin-core/test/create_blob_database_plugin_test.dart +711 -0
  45. package/dart-src/plugins/plugin-core/test/create_database_plugin_test.dart +294 -0
  46. package/dart-src/plugins/plugin-core/test/create_storage_plugin_test.dart +192 -0
  47. package/dart-src/plugins/plugin-core/test/generate_min_bundle_id_test.dart +51 -0
  48. package/dart-src/plugins/plugin-core/test/get_update_info_test.dart +1600 -0
  49. package/dart-src/plugins/plugin-core/test/helpers_test.dart +259 -0
  50. package/dart-src/plugins/plugin-core/test/query_bundles_test.dart +139 -0
  51. package/dart-src/plugins/plugin-core/test/request_update_bundle_state_test.dart +86 -0
  52. package/dart-src/plugins/plugin-core/test/uuidv7_test.dart +77 -0
  53. package/dart-src/plugins/postgres/test/mock_postgres_client.dart +297 -0
  54. package/dart-src/plugins/postgres/test/postgres_bundle_mapper_test.dart +140 -0
  55. package/dart-src/plugins/postgres/test/postgres_database_test.dart +181 -0
  56. package/dart-src/plugins/standalone/test/standalone_test.dart +264 -0
  57. package/dart-src/plugins/supabase/test/mock_supabase_client.dart +654 -0
  58. package/dart-src/plugins/supabase/test/supabase_bundle_mapper_test.dart +112 -0
  59. package/dart-src/plugins/supabase/test/supabase_database_test.dart +207 -0
  60. package/dart-src/plugins/supabase/test/supabase_storage_test.dart +175 -0
  61. package/package.json +1 -1
  62. package/scripts/vendor.sh +29 -0
@@ -0,0 +1,234 @@
1
+ library;
2
+
3
+ import 'dart:async';
4
+ import 'dart:io';
5
+ import 'dart:math' as math;
6
+
7
+ /// Terminal UI toolkit for the flutter_patcher CLI: colored text, banners,
8
+ /// bordered boxes, step logs, dynamic spinners and progress bars.
9
+ ///
10
+ /// Everything degrades gracefully to plain text when stdout is not a TTY or the
11
+ /// `NO_COLOR` env var is set, so pipes/CI/tests stay clean. Boxes auto-size to
12
+ /// the terminal width and wrap long content so they never render broken.
13
+
14
+ const _kReset = '\x1b[0m';
15
+ const _kRed = '\x1b[31m';
16
+ const _kGreen = '\x1b[32m';
17
+ const _kYellow = '\x1b[33m';
18
+ const _kBlue = '\x1b[34m';
19
+ const _kMagenta = '\x1b[35m';
20
+ const _kCyan = '\x1b[36m';
21
+ const _kGray = '\x1b[90m';
22
+ const _kBold = '\x1b[1m';
23
+
24
+ const List<String> _frames = [
25
+ '⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏',
26
+ ];
27
+
28
+ bool get _noColor {
29
+ final v = Platform.environment['NO_COLOR'];
30
+ return v != null && v.isNotEmpty;
31
+ }
32
+
33
+ bool get _colorOn =>
34
+ !_noColor && stdout.hasTerminal && stdout.supportsAnsiEscapes;
35
+
36
+ String _c(String code, String s) => _colorOn ? '$code$s$_kReset' : s;
37
+
38
+ String red(String s) => _c(_kRed, s);
39
+ String green(String s) => _c(_kGreen, s);
40
+ String yellow(String s) => _c(_kYellow, s);
41
+ String blue(String s) => _c(_kBlue, s);
42
+ String magenta(String s) => _c(_kMagenta, s);
43
+ String cyan(String s) => _c(_kCyan, s);
44
+ String gray(String s) => _c(_kGray, s);
45
+ String dim(String s) => _c(_kGray, s);
46
+ String bold(String s) => _c(_kBold, s);
47
+
48
+ int get _cols => stdout.hasTerminal ? stdout.terminalColumns : 80;
49
+
50
+ final _ansi = RegExp('\x1b\\[[0-9;]*m');
51
+
52
+ int _dispWidth(String s) => s.replaceAll(_ansi, '').length;
53
+
54
+ void _echo(String s) => stdout.writeln(s);
55
+
56
+ /// `key value` laid out in a fixed 18-char column (visible-width aware).
57
+ String kv(String k, String v) {
58
+ final pad = math.max(0, 18 - _dispWidth(k));
59
+ return '${dim(k)}${' ' * pad} $v';
60
+ }
61
+
62
+ void banner(String name) {
63
+ _echo('');
64
+ _echo(' ${cyan('▶')} ${cyan(bold('flutter_patcher'))} ${dim('·')} ${bold(name)}');
65
+ _echo(' ${dim('─' * math.min(_cols - 4, 60))}');
66
+ }
67
+
68
+ void step(String msg) => _echo(' ${green('✓')} $msg');
69
+
70
+ void err(String msg) =>
71
+ _echo(' ${red('✗')} ${red(msg)}');
72
+
73
+ /// Run [task] while showing a live spinner; replaces the line with a
74
+ /// `${green('✓')} done` summary when finished (or `✗` on error).
75
+ Future<T> spinner<T>(
76
+ Future<T> Function() task,
77
+ String label, {
78
+ String? done,
79
+ }) async {
80
+ if (!_colorOn) {
81
+ _echo(' ${dim('•')} $label');
82
+ final r = await task();
83
+ _echo(' ${green('✓')} ${done ?? label}');
84
+ return r;
85
+ }
86
+ var i = 0;
87
+ final timer = Timer.periodic(const Duration(milliseconds: 80), (_) {
88
+ i = (i + 1) % _frames.length;
89
+ stdout.write('\r\x1b[K ${cyan(_frames[i])} $label');
90
+ });
91
+ try {
92
+ final r = await task();
93
+ timer.cancel();
94
+ stdout.write('\r\x1b[K ${green('✓')} ${done ?? label}\n');
95
+ return r;
96
+ } catch (e) {
97
+ timer.cancel();
98
+ stdout.write('\r\x1b[K ${red('✗')} $label\n');
99
+ rethrow;
100
+ }
101
+ }
102
+
103
+ List<String> _wrap(String text, int inner) {
104
+ if (text.isEmpty) return [''];
105
+ final result = <String>[];
106
+ for (final raw in text.split('\n')) {
107
+ if (_dispWidth(raw) <= inner) {
108
+ result.add(raw);
109
+ continue;
110
+ }
111
+ var line = '';
112
+ for (final word in raw.split(' ')) {
113
+ if (word.isEmpty) continue;
114
+ if (line.isEmpty) {
115
+ if (_dispWidth(word) <= inner) {
116
+ line = word;
117
+ } else {
118
+ var rem = word;
119
+ while (_dispWidth(rem) > inner) {
120
+ final cut = _cut(rem, inner);
121
+ result.add(cut);
122
+ rem = rem.substring(cut.length);
123
+ }
124
+ line = rem;
125
+ }
126
+ } else if (_dispWidth(line) + 1 + _dispWidth(word) <= inner) {
127
+ line += ' $word';
128
+ } else {
129
+ result.add(line);
130
+ line = word.length <= inner
131
+ ? word
132
+ : _splitLong(word, inner, result);
133
+ }
134
+ }
135
+ result.add(line);
136
+ }
137
+ return result;
138
+ }
139
+
140
+ String _cut(String s, int inner) {
141
+ final buf = StringBuffer();
142
+ for (final ch in s.runes) {
143
+ if (buf.length + 1 > inner) break;
144
+ buf.writeCharCode(ch);
145
+ }
146
+ return buf.toString();
147
+ }
148
+
149
+ String _splitLong(String word, int inner, List<String> out) {
150
+ var rem = word;
151
+ while (_dispWidth(rem) > inner) {
152
+ final cut = _cut(rem, inner);
153
+ out.add(cut);
154
+ rem = rem.substring(cut.length);
155
+ }
156
+ return rem;
157
+ }
158
+
159
+ int _boxWidth(List<String> lines, String title) {
160
+ var longest = _dispWidth(title) + 4;
161
+ for (final l in lines) {
162
+ for (final w in l.split('\n')) {
163
+ longest = math.max(longest, _dispWidth(w));
164
+ }
165
+ }
166
+ final target = math.max(longest + 4, 40);
167
+ return math.max(math.min(_cols - 1, target), 20);
168
+ }
169
+
170
+ /// Bordered box with a centered title; auto-sizes to the terminal and wraps
171
+ /// long content so the right/left edges always stay aligned.
172
+ void box(String title, List<String> lines) {
173
+ final width = _boxWidth(lines, title);
174
+ final inner = width - 4;
175
+ final wrapped = <String>[];
176
+ for (final l in lines) wrapped.addAll(_wrap(l, inner));
177
+
178
+ final titleText = ' $title ';
179
+ final tVisible = _dispWidth(titleText);
180
+ var dashes = math.max(2, width - 2 - tVisible);
181
+ final left = math.max(1, dashes ~/ 2);
182
+ final right = dashes - left;
183
+ final top =
184
+ '╭${'─' * left}$titleText${'─' * right}╮';
185
+ _echo(top);
186
+ for (final l in wrapped) {
187
+ final pad = math.max(0, inner - _dispWidth(l));
188
+ _echo('│ $l${' ' * pad} │');
189
+ }
190
+ _echo('╰${'─' * (width - 2)}╯');
191
+ }
192
+
193
+ /// Live progress bar with an animated spinner prefix. Call [update] as work
194
+ /// progresses; it renders a `[████░░] 45%` bar that overwrites the same line.
195
+ class ProgressBar {
196
+ ProgressBar(this.total, this.label);
197
+
198
+ int total;
199
+ final String label;
200
+ int _current = 0;
201
+ int _spin = 0;
202
+ bool _closed = false;
203
+
204
+ void update(int current, [String? label]) {
205
+ _current = current;
206
+ if (label != null) _label = label;
207
+ _draw();
208
+ if (total > 0 && _current >= total) _finish();
209
+ }
210
+
211
+ late String _label = label;
212
+
213
+ void _draw() {
214
+ if (_closed) return;
215
+ if (!_colorOn) {
216
+ _echo(' $_label: $_current/$total');
217
+ return;
218
+ }
219
+ const barW = 28;
220
+ final pct = total > 0 ? (_current / total).clamp(0.0, 1.0) : 1.0;
221
+ final filled = (barW * pct).round();
222
+ final bar =
223
+ '${green('█' * filled)}${gray('·' * (barW - filled))}';
224
+ _spin = (_spin + 1) % _frames.length;
225
+ final pctStr = '${(pct * 100).round()}%'.padLeft(4);
226
+ stdout.write('\r\x1b[K ${cyan(_frames[_spin])} $_label [$bar] $pctStr');
227
+ }
228
+
229
+ void _finish() {
230
+ if (_closed) return;
231
+ _closed = true;
232
+ if (_colorOn) stdout.write('\n');
233
+ }
234
+ }