From 14aec53217ed13eb1d839736197aa747c9e5f85a Mon Sep 17 00:00:00 2001 From: Alexandre Roux Date: Fri, 4 Oct 2024 10:15:23 +0200 Subject: [PATCH] feat: add tekartik_common_build --- packages/common_build/.gitignore | 7 +++++ packages/common_build/README.md | 15 ++++++++++ packages/common_build/analysis_options.yaml | 30 +++++++++++++++++++ packages/common_build/lib/src/version.dart | 8 +++++ packages/common_build/lib/src/version_io.dart | 25 ++++++++++++++++ packages/common_build/lib/version_io.dart | 1 + packages/common_build/pubspec.yaml | 17 +++++++++++ .../common_build/test/version_io_test.dart | 11 +++++++ .../firebase_build/lib/src/app_build.dart | 5 ++++ packages/firebase_build/pubspec.yaml | 7 +++++ .../lib/src/app_build_menu.dart | 1 + packages/flutter_build/pubspec.yaml | 7 +++++ packages/repo_support/tool/run_ci.dart | 9 +----- 13 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 packages/common_build/.gitignore create mode 100644 packages/common_build/README.md create mode 100644 packages/common_build/analysis_options.yaml create mode 100644 packages/common_build/lib/src/version.dart create mode 100644 packages/common_build/lib/src/version_io.dart create mode 100644 packages/common_build/lib/version_io.dart create mode 100644 packages/common_build/pubspec.yaml create mode 100644 packages/common_build/test/version_io_test.dart diff --git a/packages/common_build/.gitignore b/packages/common_build/.gitignore new file mode 100644 index 0000000..3cceda5 --- /dev/null +++ b/packages/common_build/.gitignore @@ -0,0 +1,7 @@ +# https://dart.dev/guides/libraries/private-files +# Created by `dart pub` +.dart_tool/ + +# Avoid committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock diff --git a/packages/common_build/README.md b/packages/common_build/README.md new file mode 100644 index 0000000..c907171 --- /dev/null +++ b/packages/common_build/README.md @@ -0,0 +1,15 @@ +# tekartik_common_build + +Common build helpers: +- version + +## Setup + +```yaml +dependencies: + tekartik_common_build: + git: + url: https://github.com/tekartik/app_build.dart + ref: dart3a + path: packages/common_build +``` \ No newline at end of file diff --git a/packages/common_build/analysis_options.yaml b/packages/common_build/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/packages/common_build/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/packages/common_build/lib/src/version.dart b/packages/common_build/lib/src/version.dart new file mode 100644 index 0000000..e0db24a --- /dev/null +++ b/packages/common_build/lib/src/version.dart @@ -0,0 +1,8 @@ +// ignore: depend_on_referenced_packages +import 'package:pub_semver/pub_semver.dart'; + +/// Package version text +const packageVersionText = '1.0.0'; + +/// Package version +final packageVersion = Version.parse(packageVersionText); diff --git a/packages/common_build/lib/src/version_io.dart b/packages/common_build/lib/src/version_io.dart new file mode 100644 index 0000000..5f7143b --- /dev/null +++ b/packages/common_build/lib/src/version_io.dart @@ -0,0 +1,25 @@ +import 'package:dev_build/build_support.dart'; +import 'package:path/path.dart'; +import 'package:process_run/shell.dart'; +import 'package:process_run/stdio.dart'; + +Future generateVersion({String path = '.'}) async { + var pubspecYamlMap = await pathGetPubspecYamlMap(path); + + var version = pubspecYamlGetVersion(pubspecYamlMap); + var versionPackageName = 'pub_semver'; + var dependencies = pubspecYamlGetDependenciesPackageName(pubspecYamlMap); + var file = File(join(path, 'lib', 'src', 'version.dart')); + file.parent.createSync(recursive: true); + await file.writeAsString(''' +${dependencies.contains(versionPackageName) ? '' : '// ignore: depend_on_referenced_packages'} +import 'package:pub_semver/pub_semver.dart'; + +/// Package version text +const packageVersionText = '$version'; +/// Package version +final packageVersion = Version.parse(packageVersionText); +'''); + await Shell(workingDirectory: path) + .run('dart format ${shellArgument(file.path)}'); +} diff --git a/packages/common_build/lib/version_io.dart b/packages/common_build/lib/version_io.dart new file mode 100644 index 0000000..5b0ad75 --- /dev/null +++ b/packages/common_build/lib/version_io.dart @@ -0,0 +1 @@ +export 'src/version_io.dart' show generateVersion; diff --git a/packages/common_build/pubspec.yaml b/packages/common_build/pubspec.yaml new file mode 100644 index 0000000..6a90068 --- /dev/null +++ b/packages/common_build/pubspec.yaml @@ -0,0 +1,17 @@ +name: tekartik_common_build +description: Common build helper. +version: 1.0.0 +publish_to: none; + +environment: + sdk: ^3.5.0 + +# Add regular dependencies here. +dependencies: + dev_build: '>=1.0.0' + process_run: '>=1.2.0' + path: '>=1.8.0' + +dev_dependencies: + lints: '>=4.0.0' + test: '>=1.24.0' diff --git a/packages/common_build/test/version_io_test.dart b/packages/common_build/test/version_io_test.dart new file mode 100644 index 0000000..9f5bdd4 --- /dev/null +++ b/packages/common_build/test/version_io_test.dart @@ -0,0 +1,11 @@ +@TestOn('vm') +library; + +import 'package:tekartik_common_build/src/version_io.dart'; +import 'package:test/test.dart'; + +void main() { + test('Generate Version', () async { + await generateVersion(); + }); +} diff --git a/packages/firebase_build/lib/src/app_build.dart b/packages/firebase_build/lib/src/app_build.dart index 2e80755..fa82bd3 100644 --- a/packages/firebase_build/lib/src/app_build.dart +++ b/packages/firebase_build/lib/src/app_build.dart @@ -3,6 +3,7 @@ import 'package:process_run/shell.dart'; import 'package:tekartik_flutter_build/app_build.dart'; import 'firebase_deploy.dart'; +import 'package:tekartik_common_build/version_io.dart' as version_io; /// Build a web app Future flutterWebAppBuild(String directory) async { @@ -102,6 +103,10 @@ class FlutterFirebaseWebAppBuilder { await flutterWebAppClean(options.path); } + Future generateVersion() async { + await version_io.generateVersion(path: options.path); + } + Future serve({FirebaseWebAppActionController? controller}) async { await firebaseWebAppServe(options.path, options.deployOptions, controller: controller); diff --git a/packages/firebase_build/pubspec.yaml b/packages/firebase_build/pubspec.yaml index 334d46c..51d4dfb 100644 --- a/packages/firebase_build/pubspec.yaml +++ b/packages/firebase_build/pubspec.yaml @@ -16,6 +16,11 @@ dependencies: url: https://github.com/tekartik/app_build.dart ref: dart3a path: packages/flutter_build + tekartik_common_build: + git: + url: https://github.com/tekartik/app_build.dart + ref: dart3a + path: packages/common_build tekartik_deploy: git: url: https://github.com/tekartik/deploy.dart @@ -43,3 +48,5 @@ dependency_overrides: path: ../web_publish tekartik_flutter_build: path: ../flutter_build + tekartik_common_build: + path: ../common_build diff --git a/packages/firebase_build_menu_flutter/lib/src/app_build_menu.dart b/packages/firebase_build_menu_flutter/lib/src/app_build_menu.dart index aaff88d..ad6e849 100644 --- a/packages/firebase_build_menu_flutter/lib/src/app_build_menu.dart +++ b/packages/firebase_build_menu_flutter/lib/src/app_build_menu.dart @@ -52,6 +52,7 @@ void menuFirebaseWebAppBuilderContent( cancel(); await builder.clean(); }); + item('generateVersion', () async {}); } void menuFirebaseAppContent( diff --git a/packages/flutter_build/pubspec.yaml b/packages/flutter_build/pubspec.yaml index d7dde4b..7580815 100644 --- a/packages/flutter_build/pubspec.yaml +++ b/packages/flutter_build/pubspec.yaml @@ -10,6 +10,11 @@ dependencies: path: '>=1.7.0' process_run: '>=1.0.0+1' dev_build: '>=0.1.0' + tekartik_common_build: + git: + url: https://github.com/tekartik/app_build.dart + ref: dart3a + path: packages/common_build tekartik_deploy: git: url: https://github.com/tekartik/deploy.dart @@ -31,3 +36,5 @@ dev_dependencies: dependency_overrides: tekartik_web_publish: path: ../web_publish + tekartik_common_build: + path: ../common_build \ No newline at end of file diff --git a/packages/repo_support/tool/run_ci.dart b/packages/repo_support/tool/run_ci.dart index 298fff2..0ff71c8 100644 --- a/packages/repo_support/tool/run_ci.dart +++ b/packages/repo_support/tool/run_ci.dart @@ -1,14 +1,7 @@ import 'package:dev_build/package.dart'; -import 'package:path/path.dart'; var topDir = '..'; Future main() async { - for (var dir in [ - 'repo_support', - 'firebase_build', - ]) { - var path = join(topDir, dir); - await packageRunCi(path); - } + await packageRunCi('..', options: PackageRunCiOptions(recursive: true)); }