Skip to content

Commit

Permalink
feat: add tekartik_common_build
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Oct 4, 2024
1 parent 989c490 commit 14aec53
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/common_build/.gitignore
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions packages/common_build/README.md
Original file line number Diff line number Diff line change
@@ -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
```
30 changes: 30 additions & 0 deletions packages/common_build/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions packages/common_build/lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 25 additions & 0 deletions packages/common_build/lib/src/version_io.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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)}');
}
1 change: 1 addition & 0 deletions packages/common_build/lib/version_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/version_io.dart' show generateVersion;
17 changes: 17 additions & 0 deletions packages/common_build/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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'
11 changes: 11 additions & 0 deletions packages/common_build/test/version_io_test.dart
Original file line number Diff line number Diff line change
@@ -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();
});
}
5 changes: 5 additions & 0 deletions packages/firebase_build/lib/src/app_build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> flutterWebAppBuild(String directory) async {
Expand Down Expand Up @@ -102,6 +103,10 @@ class FlutterFirebaseWebAppBuilder {
await flutterWebAppClean(options.path);
}

Future<void> generateVersion() async {
await version_io.generateVersion(path: options.path);
}

Future<void> serve({FirebaseWebAppActionController? controller}) async {
await firebaseWebAppServe(options.path, options.deployOptions,
controller: controller);
Expand Down
7 changes: 7 additions & 0 deletions packages/firebase_build/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,3 +48,5 @@ dependency_overrides:
path: ../web_publish
tekartik_flutter_build:
path: ../flutter_build
tekartik_common_build:
path: ../common_build
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void menuFirebaseWebAppBuilderContent(
cancel();
await builder.clean();
});
item('generateVersion', () async {});
}

void menuFirebaseAppContent(
Expand Down
7 changes: 7 additions & 0 deletions packages/flutter_build/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,3 +36,5 @@ dev_dependencies:
dependency_overrides:
tekartik_web_publish:
path: ../web_publish
tekartik_common_build:
path: ../common_build
9 changes: 1 addition & 8 deletions packages/repo_support/tool/run_ci.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import 'package:dev_build/package.dart';
import 'package:path/path.dart';

var topDir = '..';

Future<void> main() async {
for (var dir in [
'repo_support',
'firebase_build',
]) {
var path = join(topDir, dir);
await packageRunCi(path);
}
await packageRunCi('..', options: PackageRunCiOptions(recursive: true));
}

0 comments on commit 14aec53

Please sign in to comment.