update: working on melos based config and build system

This commit is contained in:
Patrick Stewart 2024-10-20 18:50:34 -07:00
parent 250ae606a1
commit 8ad6633cd1
15 changed files with 291 additions and 45 deletions

10
.melos/analyze.yaml Normal file
View file

@ -0,0 +1,10 @@
scripts:
_: &analyze_scripts
analyze:
run: dart analyze .
description: Run static analysis on all packages
format:
run: dart format .
description: Format all Dart files in the repository

20
.melos/base.yaml Normal file
View file

@ -0,0 +1,20 @@
name: protevus_platform
repository: https://github.com/protevus/platform
packages:
- packages/**
- examples/**
command:
version:
linkToCommits: true
message: "chore: Bump version to %v"
branch: main
workspaceChangelog: true
ide:
intellij:
enabled: false
scripts:
_: &base_scripts

5
.melos/ci.yaml Normal file
View file

@ -0,0 +1,5 @@
scripts:
_: &ci_scripts
ci:
run: melos run analyze && melos run test
description: Run full CI pipeline

25
.melos/debug.yaml Normal file
View file

@ -0,0 +1,25 @@
scripts:
_: &debug_scripts
debug_pkg_name:
run: melos exec -- echo "Package name is {MELOS_PACKAGE_NAME}"
description: Debug package name resolution
debug_pkg_path:
run: melos exec -- echo "Package name is {MELOS_PACKAGE_PATH}"
description: Debug package path resolution
debug:reflectable:
run: >
melos exec --scope="$MELOS_SCOPE" -- "
echo \"Checking for .reflectable.dart files in {MELOS_PACKAGE_NAME}\" &&
find lib test example -name '*.reflectable.dart' -print 2>/dev/null
"
description: Debug script to find .reflectable.dart files (use with MELOS_SCOPE env var)
list:dart:files:
run: >
melos exec --scope="$MELOS_SCOPE" -- "
echo \"Listing all Dart files in {MELOS_PACKAGE_NAME}:\" &&
find lib test example -name '*.dart' -print 2>/dev/null
"
description: List all Dart files in specified package(s) (use with MELOS_SCOPE env var)

13
.melos/dependencies.yaml Normal file
View file

@ -0,0 +1,13 @@
scripts:
_: &dependencies_scripts
deps:check:
run: melos exec -- "dart pub outdated"
description: Check for outdated dependencies
deps:upgrade:
run: melos exec -- "dart pub upgrade"
description: Upgrade all dependencies to their latest versions
deps:upgrade:custom:
run: melos exec --scope="$MELOS_SCOPE" -- "dart pub upgrade"
description: Upgrade dependencies for specified packages (use with MELOS_SCOPE env var)

20
.melos/docs.yaml Normal file
View file

@ -0,0 +1,20 @@
scripts:
_: &docs_scripts
docs:generate:
run: melos exec -- "dart doc ."
description: Generate documentation for all packages
docs:generate:custom:
run: melos exec --scope="$MELOS_SCOPE" -- "dart doc ."
description: Generate documentation for specified packages (use with MELOS_SCOPE env var)
docs:serve:
run: dhttpd --path doc
description: Serve generated documentation
docs:serve:custom:
run: >
melos exec --scope="$MELOS_SCOPE" --
"echo 'Serving docs for {MELOS_PACKAGE_NAME}' &&
dhttpd --path doc --port \${DOC_PORT:-8080}"
description: Serve generated documentation for specified packages (use with MELOS_SCOPE and optionally DOC_PORT env vars)

51
.melos/generate.yaml Normal file
View file

@ -0,0 +1,51 @@
scripts:
_: &generate_scripts
generate:
run: melos exec -- "dart run build_runner build --delete-conflicting-outputs"
description: Run code generation for all packages
generate:custom:
run: melos exec --scope="$MELOS_SCOPE" -- "dart run build_runner build --delete-conflicting-outputs"
description: Run code generation for specified packages (use with MELOS_SCOPE env var)
generate:check:
run: >
melos exec --scope="$MELOS_SCOPE" -- "
if grep -q 'build_runner' pubspec.yaml; then
if [ -n \"$(find lib test example -name '*.g.dart' -o -name '*.freezed.dart' -o -name '*.reflectable.dart' 2>/dev/null)\" ]; then
echo \"Package {MELOS_PACKAGE_NAME} needs code generation.\"
else
echo \"Package {MELOS_PACKAGE_NAME} has build_runner but no generated files found.\"
fi
else
echo \"Package {MELOS_PACKAGE_NAME} does not use build_runner.\"
fi
"
description: Check if code generation is needed (use with MELOS_SCOPE env var)
generate:dummy:test:
run: >
melos exec --scope="$MELOS_SCOPE" -- "
echo '
import \"package:test/test.dart\";
void main() {
group(\"Dummy Test\", () {
test(\"Always passes\", () {
expect(true, isTrue);
});
test(\"Basic arithmetic\", () {
expect(2 + 2, equals(4));
});
test(\"String manipulation\", () {
String testString = \"Protevus Platform\";
expect(testString.contains(\"Platform\"), isTrue);
expect(testString.toLowerCase(), equals(\"protevus platform\"));
});
});
}
' > test/dummy_test.dart
"
description: Generate a dummy test file in the specified package(s)

9
.melos/publish.yaml Normal file
View file

@ -0,0 +1,9 @@
scripts:
_: &publish_scripts
publish:
run: melos publish
description: Publish all packages that have changed.
publish:check:
run: melos publish --dry-run
description: Check which packages would be published

10
.melos/test.yaml Normal file
View file

@ -0,0 +1,10 @@
scripts:
_: &test_scripts
test:
run: melos exec -c 1 --fail-fast -- "dart test"
description: Run tests for all packages
test:custom:
run: melos exec --scope="$MELOS_SCOPE" -- dart test
description: Run tests for specified packages (use with MELOS_SCOPE env var)

5
.melos/utils.yaml Normal file
View file

@ -0,0 +1,5 @@
scripts:
_: &utils_scripts
combine_config:
run: dart helpers/combine_melos_config.dart
description: Combine Melos configuration files

View file

@ -0,0 +1,53 @@
import 'dart:io';
import 'package:yaml/yaml.dart';
import 'package:yaml_edit/yaml_edit.dart';
import 'package:args/args.dart';
void main(List<String> arguments) {
final parser = ArgParser()
..addOption('input',
abbr: 'i', defaultsTo: '.melos', help: 'Input directory for YAML files')
..addOption('output',
abbr: 'o', defaultsTo: 'melos.yaml', help: 'Output file path');
final results = parser.parse(arguments);
final inputDir = results['input'];
final outputFile = results['output'];
try {
final baseContent = File('$inputDir/base.yaml').readAsStringSync();
final scriptFiles = Directory(inputDir)
.listSync()
.where((file) =>
file.path.endsWith('.yaml') && !file.path.endsWith('base.yaml'))
.map((file) => file.path.split('/').last)
.toList();
final combinedScripts = {};
for (final file in scriptFiles) {
print('Processing $file');
final content = File('$inputDir/$file').readAsStringSync();
final yaml = loadYaml(content);
if (yaml == null ||
yaml['scripts'] == null ||
yaml['scripts']['_'] == null) {
print(
'Warning: $file does not contain expected script structure. Skipping.');
continue;
}
combinedScripts.addAll(yaml['scripts']['_']);
}
final outputYamlEditor = YamlEditor(baseContent);
outputYamlEditor.update(['scripts'], combinedScripts);
File(outputFile).writeAsStringSync(outputYamlEditor.toString());
print('Combined Melos configuration written to $outputFile');
} catch (e, stackTrace) {
print('Error: $e');
print('Stack trace: $stackTrace');
exit(1);
}
}

View file

@ -6,10 +6,8 @@ packages:
command: command:
version: version:
# Generate commit links in package changelogs.
linkToCommits: true linkToCommits: true
message: "chore: Bump version to %v" message: "chore: Bump version to %v"
# Only allow versioning to happen on main branch.
branch: main branch: main
workspaceChangelog: true workspaceChangelog: true
@ -17,49 +15,74 @@ ide:
intellij: intellij:
enabled: false enabled: false
# Project scripts
scripts: scripts:
analyze: analyze:
run: dart analyze . run: dart analyze .
description: Run static analysis on all packages description: Run static analysis on all packages
test:
run: melos exec -c 1 --fail-fast -- "dart test"
description: Run tests for all packages
format: format:
run: dart format . run: dart format .
description: Format all Dart files in the repository description: Format all Dart files in the repository
generate: generate:
run: melos exec -- "dart run build_runner build --delete-conflicting-outputs" run: melos exec -- "dart run build_runner build --delete-conflicting-outputs"
description: Run code generation for all packages description: Run code generation for all packages
generate:custom:
ci: run: melos exec --scope="$MELOS_SCOPE" -- "dart run build_runner build --delete-conflicting-outputs"
run: melos run analyze && melos run test description: Run code generation for specified packages (use with MELOS_SCOPE env var)
description: Run full CI pipeline generate:check:
run: "melos exec --scope=\"$MELOS_SCOPE\" -- \" if grep -q 'build_runner' pubspec.yaml; then\n if [ -n \\\"$(find lib test example -name '*.g.dart' -o -name '*.freezed.dart' -o -name '*.reflectable.dart' 2>\/dev\/null)\\\" ]; then\n echo \\\"Package {MELOS_PACKAGE_NAME} needs code generation.\\\"\n else\n echo \\\"Package {MELOS_PACKAGE_NAME} has build_runner but no generated files found.\\\"\n fi\nelse\n echo \\\"Package {MELOS_PACKAGE_NAME} does not use build_runner.\\\"\nfi \"\n"
description: Check if code generation is needed (use with MELOS_SCOPE env var)
generate:dummy:test:
run: "melos exec --scope=\"$MELOS_SCOPE\" -- \" echo ' import \\\"package:test\/test.dart\\\";\nvoid main() {\n group(\\\"Dummy Test\\\", () {\n test(\\\"Always passes\\\", () {\n expect(true, isTrue);\n });\n\n test(\\\"Basic arithmetic\\\", () {\n expect(2 + 2, equals(4));\n });\n\n test(\\\"String manipulation\\\", () {\n String testString = \\\"Protevus Platform\\\";\n expect(testString.contains(\\\"Platform\\\"), isTrue);\n expect(testString.toLowerCase(), equals(\\\"protevus platform\\\"));\n });\n });\n} ' > test\/dummy_test.dart \"\n"
description: Generate a dummy test file in the specified package(s)
publish:
run: melos publish
description: Publish all packages that have changed.
publish:check:
run: melos publish --dry-run
description: Check which packages would be published
docs:generate: docs:generate:
run: melos exec -- "dart doc ." run: melos exec -- "dart doc ."
description: Generate documentation for all packages description: Generate documentation for all packages
docs:generate:custom:
run: melos exec --scope="$MELOS_SCOPE" -- "dart doc ."
description: Generate documentation for specified packages (use with MELOS_SCOPE env var)
docs:serve:
run: dhttpd --path doc
description: Serve generated documentation
docs:serve:custom:
run: "melos exec --scope=\"$MELOS_SCOPE\" -- \"echo 'Serving docs for {MELOS_PACKAGE_NAME}' && dhttpd --path doc --port \\${DOC_PORT:-8080}\"\n"
description: Serve generated documentation for specified packages (use with MELOS_SCOPE and optionally DOC_PORT env vars)
test:
run: melos exec -c 1 --fail-fast -- "dart test"
description: Run tests for all packages
test:custom:
run: melos exec --scope="$MELOS_SCOPE" -- dart test
description: Run tests for specified packages (use with MELOS_SCOPE env var)
deps:check: deps:check:
run: melos exec -- "dart pub outdated" run: melos exec -- "dart pub outdated"
description: Check for outdated dependencies description: Check for outdated dependencies
deps:upgrade: deps:upgrade:
run: melos exec -- "dart pub upgrade" run: melos exec -- "dart pub upgrade"
description: Upgrade all dependencies to their latest versions description: Upgrade all dependencies to their latest versions
deps:upgrade:custom:
publish: run: melos exec --scope="$MELOS_SCOPE" -- "dart pub upgrade"
run: melos publish description: Upgrade dependencies for specified packages (use with MELOS_SCOPE env var)
description: Publish all packages that have changed. ci:
run: melos run analyze && melos run test
description: Run full CI pipeline
debug_pkg_name: debug_pkg_name:
run: melos exec -- echo "Package name is {MELOS_PACKAGE_NAME}" run: "melos exec -- echo \"Package name is {MELOS_PACKAGE_NAME}\""
description: Debug package name resolution description: Debug package name resolution
debug_pkg_path: debug_pkg_path:
run: melos exec -- echo "Package name is {MELOS_PACKAGE_PATH}" run: "melos exec -- echo \"Package name is {MELOS_PACKAGE_PATH}\""
description: Debug package name resolution description: Debug package path resolution
debug:reflectable:
run: "melos exec --scope=\"$MELOS_SCOPE\" -- \" echo \\\"Checking for .reflectable.dart files in {MELOS_PACKAGE_NAME}\\\" && find lib test example -name '*.reflectable.dart' -print 2>\/dev\/null \"\n"
description: Debug script to find .reflectable.dart files (use with MELOS_SCOPE env var)
list:dart:files:
run: "melos exec --scope=\"$MELOS_SCOPE\" -- \" echo \\\"Listing all Dart files in {MELOS_PACKAGE_NAME}:\\\" && find lib test example -name '*.dart' -print 2>\/dev\/null \"\n"
description: List all Dart files in specified package(s) (use with MELOS_SCOPE env var)
combine_config:
run: dart helpers/combine_melos_config.dart
description: Combine Melos configuration files

View file

@ -1,19 +1,18 @@
import 'package:test/test.dart'; import "package:test/test.dart";
void main() { void main() {
group('Dummy Test', () { group("Dummy Test", () {
test('Always passes', () { test("Always passes", () {
expect(true, isTrue); expect(true, isTrue);
}); });
test('Basic arithmetic', () { test("Basic arithmetic", () {
expect(2 + 2, equals(4)); expect(2 + 2, equals(4));
}); });
test('String manipulation', () { test("String manipulation", () {
String testString = 'Protevus Platform'; String testString = "Protevus Platform";
expect(testString.contains('Platform'), isTrue); expect(testString.contains("Platform"), isTrue);
expect(testString.toLowerCase(), equals('protevus platform')); expect(testString.toLowerCase(), equals("protevus platform"));
}); });
}); });
} }

View file

@ -31,7 +31,7 @@ packages:
source: hosted source: hosted
version: "0.3.2+1" version: "0.3.2+1"
args: args:
dependency: transitive dependency: "direct dev"
description: description:
name: args name: args
sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6 sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
@ -543,7 +543,7 @@ packages:
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
yaml: yaml:
dependency: transitive dependency: "direct dev"
description: description:
name: yaml name: yaml
sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5" sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
@ -551,7 +551,7 @@ packages:
source: hosted source: hosted
version: "3.1.2" version: "3.1.2"
yaml_edit: yaml_edit:
dependency: transitive dependency: "direct dev"
description: description:
name: yaml_edit name: yaml_edit
sha256: e9c1a3543d2da0db3e90270dbb1e4eebc985ee5e3ffe468d83224472b2194a5f sha256: e9c1a3543d2da0db3e90270dbb1e4eebc985ee5e3ffe468d83224472b2194a5f

View file

@ -16,4 +16,7 @@ dev_dependencies:
lints: ^4.0.0 lints: ^4.0.0
melos: ^6.1.0 melos: ^6.1.0
test: ^1.24.0 test: ^1.24.0
yaml: ^3.1.2
args: ^2.6.0
yaml_edit: ^2.2.1
#path: ^1.8.0 #path: ^1.8.0