Skip to content

Commit 2cc55b0

Browse files
authored
Version 0.0.3. (#4)
* πŸ—οΈ Update main architecture. * 🩹 Fix JetBrain's terminal issue. * 🎨 Update code structure. * πŸ“ Update README.md. * 🚸 Add cancelSign to empty informed messages. * 🎨 Create NullableStringExtension. * πŸ”– Version bump 0.0.3.
1 parent a5007f9 commit 2cc55b0

File tree

10 files changed

+187
-63
lines changed

10 files changed

+187
-63
lines changed

β€Ž.github/workflows/main.ymlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- name: Get Pubspec Version
1818
run: |
1919
VERSION=$(grep 'version:' pubspec.yaml | cut -c 10- | cut -f 1 -d '+')
20+
sed -i "s/dev/$VERSION/g" bin/gitmoji.dart
2021
echo "VERSION=$VERSION" >> $GITHUB_ENV
2122
2223
- name: Check if version is used

β€ŽREADME.mdβ€Ž

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# πŸš€ gitmoji
1+
# πŸš€ gitmoji πŸ˜„
22

33
A tool inspired by **[gitmoji](https://gitmoji.dev/)** that helps you create
44
standardized, emoji-based Git commits β€” **without installing any dependencies,
@@ -24,3 +24,9 @@ This project solves that by providing:
2424
## πŸ“¦ Installation
2525

2626
Just download the binary for your operating system and make it executable.
27+
28+
```shell
29+
curl -sSLO https://github.com/edufolly/gitmoji/releases/latest/download/gitmoji
30+
chmod +x gitmoji
31+
sudo mv gitmoji /usr/local/bin
32+
```

β€Žbin/gitmoji.dartβ€Ž

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
import 'package:gitmoji/github_client.dart';
12
import 'package:gitmoji/gitmoji.dart';
23
import 'package:gitmoji/gitmoji_client.dart';
34
import 'package:gitmoji/main.dart';
45

56
void main(List<String> arguments) async {
6-
List<Gitmoji> gitmojiList = await GitmojiClient().fetch(false);
7+
final String version = 'dev';
8+
final bool debug = false;
79

8-
if (gitmojiList.isNotEmpty) Main().run(gitmojiList);
10+
await GithubClient(debug).fetch(version);
11+
12+
List<Gitmoji> gitmojiList = await GitmojiClient(debug).fetch();
13+
14+
if (gitmojiList.isNotEmpty) Main(debug).run(gitmojiList);
915
}

β€Žlib/ansi.dartβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class Ansi {
1818
static String cursorPosition({int row = 1, int col = 1}) =>
1919
row < 1 || col < 1 ? '' : '$csi$row;${col}H';
2020

21-
static String cursorSavePosition = '${csi}s';
22-
23-
static String cursorRestorePosition = '${csi}u';
24-
21+
static const String cursorSavePosition = '${csi}s';
22+
static const String cursorRestorePosition = '${csi}u';
2523
static const String clearDisplayDown = '${csi}0J';
2624
static const String clearDisplayUp = '${csi}1J';
2725
static const String clearEntireLine = '${csi}2K';
@@ -32,6 +30,8 @@ class Ansi {
3230
static const String dim = '${csi}2m';
3331
static const String italic = '${csi}3m';
3432
static const String underline = '${csi}4m';
33+
static const String slowBlink = '${csi}5m';
34+
static const String fastBlink = '${csi}6m';
3535

3636
/// Colors - 3-bit and 4-bit
3737
static const String red = '${csi}31m';

β€Žlib/github_client.dartβ€Ž

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'dart:convert';
2+
3+
import 'package:http/http.dart' as http;
4+
5+
import 'ansi.dart';
6+
7+
class GithubClient {
8+
final bool debug;
9+
10+
GithubClient(this.debug);
11+
12+
Future<void> fetch(
13+
String version, {
14+
String newVersionMessage = 'New version available:',
15+
String url =
16+
'https://api.github.com/repos/edufolly/gitmoji/releases/latest',
17+
int timeout = 2,
18+
}) async {
19+
if (version == 'dev') return;
20+
21+
try {
22+
final response = await http
23+
.get(
24+
Uri.parse(url),
25+
headers: {'Accept': 'application/vnd.github+json'},
26+
)
27+
.timeout(Duration(seconds: timeout));
28+
29+
if (response.statusCode != 200) {
30+
if (debug) {
31+
print('Status code: ${response.statusCode}');
32+
print('Body: ${response.body}');
33+
}
34+
return;
35+
}
36+
37+
final body = jsonDecode(response.body);
38+
39+
final name = body['name']?.toString() ?? 'ERROR';
40+
41+
if (version != name) {
42+
print(
43+
'\n$newVersionMessage ${Ansi.green}${Ansi.bold}$name${Ansi.reset}\n',
44+
);
45+
}
46+
} on Exception catch (e, s) {
47+
if (debug) {
48+
print(e);
49+
print(s);
50+
}
51+
}
52+
}
53+
}

β€Žlib/gitmoji.dartβ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ class Gitmoji {
1616
required this.semver,
1717
}) : key = '$name $description'.toLowerCase();
1818

19+
factory Gitmoji.fromJson(dynamic map) {
20+
if (map is Map<dynamic, dynamic>) {
21+
return Gitmoji(
22+
emoji: map['emoji'].toString(),
23+
entity: map['entity'].toString(),
24+
code: map['code'].toString(),
25+
description: map['description'].toString().trim(),
26+
name: map['name'].toString(),
27+
semver: map['semver']?.toString(),
28+
);
29+
} else {
30+
throw Exception();
31+
}
32+
}
33+
1934
@override
2035
String toString() => '$emoji $description';
2136
}

β€Žlib/gitmoji_client.dartβ€Ž

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import 'dart:convert';
22
import 'dart:io' as io;
33

4+
import 'package:gitmoji/nullable_string_extension.dart';
45
import 'package:http/http.dart' as http;
56

67
import 'gitmoji.dart';
78

89
class GitmojiClient {
9-
Future<List<Gitmoji>> fetch(
10-
bool debug, {
10+
final bool debug;
11+
12+
GitmojiClient(this.debug);
13+
14+
Future<List<Gitmoji>> fetch({
1115
String url =
1216
'https://raw.githubusercontent.com/carloscuesta/gitmoji/refs/heads'
1317
'/master/packages/gitmojis/src/gitmojis.json',
@@ -25,33 +29,25 @@ class GitmojiClient {
2529
if (debug) print('Getting definition...');
2630
jsonString = await _fetchFromWeb(debug, url);
2731

28-
if (jsonString.isEmpty && cacheFile.existsSync()) {
29-
print('Using old cache.');
30-
jsonString = cacheFile.readAsStringSync();
32+
if (jsonString.isNotEmpty) {
33+
cacheFile.writeAsStringSync(jsonString);
34+
} else {
35+
if (cacheFile.existsSync()) {
36+
if (debug) print('Using old cache.');
37+
jsonString = cacheFile.readAsStringSync();
38+
}
3139
}
3240
}
3341

34-
if (jsonString.trim().isEmpty) {
35-
throw Exception('GitMojis definition not found.');
42+
if (jsonString.isNullOrBlank) {
43+
throw Exception('Gitmojis definition not found.');
3644
}
3745

3846
final body = jsonDecode(jsonString);
3947

40-
cacheFile.writeAsStringSync(jsonString);
41-
4248
final List<dynamic> list = body['gitmojis'];
4349

44-
return list.map((item) {
45-
final map = item as Map<String, dynamic>;
46-
return Gitmoji(
47-
emoji: map['emoji'].toString(),
48-
entity: map['entity'].toString(),
49-
code: map['code'].toString(),
50-
description: map['description'].toString().trim(),
51-
name: map['name'].toString(),
52-
semver: map['semver']?.toString(),
53-
);
54-
}).toList();
50+
return list.map((item) => Gitmoji.fromJson(item)).toList();
5551
}
5652

5753
Future<String> _fetchFromWeb(bool debug, String url) async {

0 commit comments

Comments
Β (0)