Skip to content

Commit

Permalink
+chore: Clean code and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
robmllze committed Sep 4, 2024
1 parent cb66fa2 commit 5c9e46a
Show file tree
Hide file tree
Showing 32 changed files with 275 additions and 170 deletions.
48 changes: 41 additions & 7 deletions .github/scripts/update_changelog.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
// source code is governed by an MIT-style license that can be found in the
// LICENSE file.
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
// source code is governed by an MIT-style license described in the LICENSE
// file located in this project's root directory.
//
// See: https://opensource.org/license/mit
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~
Expand All @@ -14,7 +16,7 @@ import 'dart:io';

void main(List<String> args) {
final version = args.isNotEmpty ? args[0] : '0.1.0';
final newReleaseNotes = args.length > 1 ? args[1] : 'Initial commit';
final comitMesssage = args.length > 1 ? args[1].replaceFirst('+', '') : '';
final changelogPath = 'CHANGELOG.md';
final file = File(changelogPath);
if (!file.existsSync()) {
Expand All @@ -27,19 +29,19 @@ void main(List<String> args) {
final versionExist = sections.where((e) => e.version == version).isNotEmpty;
if (versionExist) {
sections.where((e) => e.version == version).forEach((e) {
e.addUpdate(newReleaseNotes);
e.addUpdate(comitMesssage);
});
} else {
sections.add(
_VersionSection(
version: version,
releasedAt: DateTime.now().toUtc(),
updates: {newReleaseNotes},
updates: {comitMesssage},
),
);
}
contents = '# Changelog\n\n${(sections.toList()..sort((a, b) {
return b.version.compareTo(a.version);
return compareVersions(b.version, a.version);
})).map((e) => e.toString()).join('\n')}';

file.writeAsStringSync(contents);
Expand Down Expand Up @@ -127,3 +129,35 @@ class _VersionSection {
return '## [$version]\n\n- Released @ ${releasedAt.month}/${releasedAt.year} (UTC)\n$updatesString\n';
}
}

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

int compareVersions(String version1, String version2) {
List<int> parseVersion(String version) {
// Split by the '+' first to handle the build number
final parts = version.split('+');
final versionParts = parts[0].split('.').map(int.tryParse).map((e) => e ?? 0).toList();

// Add the build number as the last part (if it exists)
if (parts.length > 1) {
versionParts.add(int.tryParse(parts[1]) ?? 0);
}

return versionParts;
}

final v1 = parseVersion(version1);
final v2 = parseVersion(version2);

final maxLength = v1.length > v2.length ? v1.length : v2.length;

for (var i = 0; i < maxLength; i++) {
final part1 = i < v1.length ? v1[i] : 0;
final part2 = i < v2.length ? v2[i] : 0;

if (part1 > part2) return 1;
if (part1 < part2) return -1;
}

return 0;
}
60 changes: 45 additions & 15 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
## source code is governed by an MIT-style license that can be found in the
## LICENSE file.
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
## source code is governed by an MIT-style license described in the LICENSE
## file located in this project's root directory.
##
## For more about publishing, see: https://dart.dev/tools/pub/automated-publishing
## See: https://opensource.org/license/mit
##
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##.title~
Expand All @@ -25,40 +25,70 @@ jobs:
prepare:
runs-on: ubuntu-latest
steps:
# Checkout the code from the repository
- name: Checkout code
uses: actions/checkout@v3

# Get the latest commit message
- name: Get commit messages
id: get_commits
run: |
COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD)
echo "::set-output name=COMMIT_MESSAGES::${COMMIT_MESSAGES}"
# Check if the commit message starts with '+'
- name: Check commit message
id: check_message
run: |
if echo "${{ steps.get_commits.outputs.COMMIT_MESSAGES }}" | grep -q "^+"; then
echo "::set-output name=PROCEED::true"
else
echo "::set-output name=PROCEED::false"
fi
# Debug environment variables
- name: Debug environment variables
run: |
echo "PROCEED=${{ steps.check_message.outputs.PROCEED }}"
echo "COMMIT_MESSAGES=${{ steps.get_commits.outputs.COMMIT_MESSAGES }}"
# Set up Dart if the commit message check passed
- name: Set up Dart
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
uses: dart-lang/setup-dart@v1.2

# Format Dart code if the commit message check passed
- name: Format Dart code
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
run: dart format .

# Apply Dart fixes if the commit message check passed
- name: Apply Dart fixes
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
run: dart fix --apply

# Extract the version from pubspec.yaml if the commit message check passed
- name: Extract version from pubspec.yaml
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
id: get_version
run: |
VERSION=$(grep "version:" pubspec.yaml | sed 's/version: //')
echo "Extracted version: $VERSION"
echo "::set-output name=extracted_version::$VERSION"
- name: Get commit messages
id: get_commits
run: |
COMMIT_MESSAGES=$(git log --format=%B -n 1 HEAD)
echo "::set-output name=messages::${COMMIT_MESSAGES}"
echo "Version extracted from pubspec.yaml: $VERSION"
echo "::set-output name=PUBSPEC_VERSION::${VERSION}"
# Update CHANGELOG.md if the commit message check passed
- name: Update CHANGELOG.md
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
run: |
RELEASE_NOTES="${{ steps.get_commits.outputs.messages }}"
dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.extracted_version }}" "$RELEASE_NOTES"
RELEASE_NOTES="${{ steps.get_commits.outputs.COMMIT_MESSAGES }}"
dart run .github/scripts/update_changelog.dart "${{ steps.get_version.outputs.PUBSPEC_VERSION }}" "$RELEASE_NOTES"
# Commit and push changes if the commit message check passed
- name: Commit and push changes
if: ${{ steps.check_message.outputs.PROCEED == 'true' }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Prepare version ${{ steps.get_version.outputs.extracted_version }}"
git commit -m "Prepare version ${{ steps.get_version.outputs.PUBSPEC_VERSION }}"
git push
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors.
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
## source code is governed by an MIT-style license described in the LICENSE
## file located in this project's root directory.
##
## See MIT LICENSE file in root directory.
##
## For more about publishing, see: https://dart.dev/tools/pub/automated-publishing
## See: https://opensource.org/license/mit
##
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##.title~
Expand Down
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
## source code is governed by an MIT-style license that can be found in the
## LICENSE file.
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
## source code is governed by an MIT-style license described in the LICENSE
## file located in this project's root directory.
##
## See: https://opensource.org/license/mit
##
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##.title~
Expand Down
23 changes: 5 additions & 18 deletions DEVELOPER_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Developer Notes

## Commmit Tag Descriptions
## Some Commin Commmit Tags

- `feat`: New feature or enhancement
- `fix`: Bug fix or issue resolution
Expand All @@ -20,6 +20,10 @@

https://github.com/robmllze/YOUR_PROJECT_NAME/settings/actions

## Changelog

If your commit message starts with `+`, the `prepare.yml` workflow will automatically format and apply fixes to the code, and add the provided commit message to `CHANGELOG.md` under the current version specified in `pubspec.yaml`.

## Public Repo Setup

```sh
Expand All @@ -46,14 +50,6 @@ git push -u origin main

## macOS and Linux

### Fetching Generators

```bash
rm -rf ___generators/
git clone https://github.com/robmllze/___generators.git
dart pub get -C ___generators
```

### Adding the Workflow

```bash
Expand All @@ -71,15 +67,6 @@ find . -name '.DS_Store' -type f -delete

## Windows

### Fetching Generators

```bash
rmdir /s /q ___generators/
git clone https://github.com/robmllze/___generators.git
dart pub get -C ___generators
rmdir /s /q ___generators/.git
```

### Adding the Workflow

```bash
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DF Collection
# DF - Collection

<a href="https://www.buymeacoffee.com/robmllze" target="_blank"><img align="right" src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a>

Expand Down
13 changes: 10 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
##.title
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
## source code is governed by an MIT-style license that can be found in the
## LICENSE file.
## Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
## source code is governed by an MIT-style license described in the LICENSE
## file located in this project's root directory.
##
## See: https://opensource.org/license/mit
##
## ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
##.title~
Expand All @@ -30,6 +32,10 @@ linter:
unnecessary_this: true

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
exclude:
- build/**

Expand All @@ -40,6 +46,7 @@ analyzer:
depend_on_referenced_packages: error
flutter_style_todos: error
invalid_use_of_protected_member: error
invalid_override_of_non_virtual_member: error
no_leading_underscores_for_local_identifiers: error
prefer_final_in_for_each: error
prefer_relative_imports: error
Expand Down
8 changes: 5 additions & 3 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
// source code is governed by an MIT-style license that can be found in the
// LICENSE file.
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
// source code is governed by an MIT-style license described in the LICENSE
// file located in this project's root directory.
//
// See: https://opensource.org/license/mit
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~
Expand Down
8 changes: 5 additions & 3 deletions lib/df_collection.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
// source code is governed by an MIT-style license that can be found in the
// LICENSE file.
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
// source code is governed by an MIT-style license described in the LICENSE
// file located in this project's root directory.
//
// See: https://opensource.org/license/mit
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~
Expand Down
19 changes: 9 additions & 10 deletions lib/src/csv.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
// source code is governed by an MIT-style license that can be found in the
// LICENSE file.
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
// source code is governed by an MIT-style license described in the LICENSE
// file located in this project's root directory.
//
// See: https://opensource.org/license/mit
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~

/// Converts a map to a CSV string.
String mapToCsv(Map input) {
String mapToCsv(Map<dynamic, dynamic> input) {
var output = '';
for (final entry in input.entries) {
final key = entry.key;
Expand All @@ -26,16 +28,13 @@ String mapToCsv(Map input) {

/// Converts a CSV string to a map.
Map<int, List<String>> csvToMap(String input) {
final processedInput =
input.replaceAll(r'\,', '\u{F0001}').replaceAll(r'\"', '\u{F0002}');
final processedInput = input.replaceAll(r'\,', '\u{F0001}').replaceAll(r'\"', '\u{F0002}');
final lines = processedInput.split('\n');
final res = <int, List<String>>{};
for (var i = 0; i < lines.length; i++) {
final line = lines[i];
var parts = line
.split(RegExp(r',(?=(?:[^"]*"[^"]*")*[^"]*$)'))
.map((part) => part.trim())
.toList();
var parts =
line.split(RegExp(r',(?=(?:[^"]*"[^"]*")*[^"]*$)')).map((part) => part.trim()).toList();
parts = parts.map((e) {
return e.replaceAll('\u{F0001}', ',').replaceAll('\u{F0002}', r'\"');
}).toList();
Expand Down
8 changes: 5 additions & 3 deletions lib/src/etc.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//.title
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. Use of this
// source code is governed by an MIT-style license that can be found in the
// LICENSE file.
// Dart/Flutter (DF) Packages by DevCetra.com & contributors. The use of this
// source code is governed by an MIT-style license described in the LICENSE
// file located in this project's root directory.
//
// See: https://opensource.org/license/mit
//
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
//.title~
Expand Down
Loading

0 comments on commit 5c9e46a

Please sign in to comment.