Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major functionality overhaul and improvements #21

Merged
merged 13 commits into from
Feb 2, 2024
4 changes: 4 additions & 0 deletions .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"flutterSdkVersion": "stable",
"flavors": {}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build/
# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
.fvm/flutter_sdk
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"yaml.schemaStore.enable": false,
"dart.sdkPaths": [
".fvm/flutter_sdk"
],
}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 0.1.0
- Upgrade to Dart 3
- Add prunning option - prune when pubspec.lock was changed
- Add verbose mode
- Add debug mode
- Support part file imports, relative imports, package imports.
- Support generated files that are imported rather than as "part" file.
- Support other generated files, not just .g.dart.
- Add cache commands
- Prune - clears cache directory
- List - list files, their actual hash and dirty state

**Breaking change**
- Drop support for "redis".

## 0.0.7

- Fix a major bug where a class's dependencies were not considered while generating digest, so any change in the super classes caused wrong output.
Expand Down
48 changes: 18 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@ Cached Build Runner is a Dart package that optimizes the build_runner by caching
cached_build_runner <command> [arguments]
```

### Usage
### Commands
Global options:
-h, --help Print this usage information.

Available commands:
* **build**: Performs a single build on the specified targets and then exits.
* **watch**: Builds the specified targets, watching the file system for updates and rebuilding as appropriate.
* **build**: Performs a single build on the specified targets and then exits.
* **watch**: Builds the specified targets, watching the file system for updates and rebuilding as appropriate.
* **cache**: Commands for manipulating cache.

Available arguments:
* -h, --help: Print out usage instructions.
* -q, --quiet: Disables printing out logs during the build.
* -r, --redis: Use Redis database if installed on the system. Using Redis allows multiple instance access and is ideal for usage in pipelines. The default implementation uses a file system storage (Hive), which is ideal for usage in local systems.
* -v, --verbose: Enables verbose logs.
* -d, --debug: Enables even more verbose logs.
* -p, --[no]prune: Enable pruning cache directory when pubspec.lock was changed since last build. Defaults true.
* -c, --cache-directory: Provide the directory where this tool can keep the caches.

## Cache sub-commands
* **prune**: Clear cache directory.
* **list**: List table of files with hash (digest) and their dirty state.

arguments
* -h, --help: Print out usage instructions.
* -v, --verbose: Enables verbose logs.
* -c, --cache-directory: Provide the directory where this tool can keep the caches.

# Cached Build Runner
# Installation
Add the package to your pubspec.yaml file under dev_dependencies:

```yaml
Expand All @@ -35,28 +45,6 @@ dev_dependencies:

Replace latest_version with the latest available version of the package.

# License

```
MIT License

Copyright (c) 2021 Jyotirmoy Paul

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```
---
Original work done by @jyotirmoy-paul.
43 changes: 13 additions & 30 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,13 @@
# 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
include: package:netglade_analysis/lints.yaml

analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "build/"

dart_code_metrics:
extends:
- package:netglade_analysis/dcm.yaml
pubspec-rules:
prefer-publish-to-none: false
14 changes: 9 additions & 5 deletions bin/cached_build_runner.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import 'package:args/command_runner.dart';
import 'package:cached_build_runner/commands/build_command.dart';
import 'package:cached_build_runner/commands/cache/cache_command.dart';
import 'package:cached_build_runner/commands/watch_command.dart';
import 'package:cached_build_runner/di_container.dart';

Future<void> main(List<String> arguments) async {
DiContainer.setup();

const commandName = 'cached_build_runner';
const commandDescription =
'Optimizes the build_runner by caching generated codes for non changed .dart files';
const commandDescription = 'Optimizes the build_runner by caching generated codes for non changed .dart files';

final runner = CommandRunner(commandName, commandDescription)
final runner = CommandRunner<void>(commandName, commandDescription)
..addCommand(BuildCommand())
..addCommand(WatchCommand());
..addCommand(WatchCommand())
..addCommand(CacheCommand());

runner.run(arguments);
await runner.run(arguments);
}
17 changes: 17 additions & 0 deletions example/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# # targets:
# # $default:
# # builders:
# # drift_dev:
# # enabled: false
# # drift_dev:not_shared:
# # enabled: true
# # generate_for:
# # include:
# # - lib/domain/data/**.dart
# global_options:
# freezed:
# runs_before:
# - auto_mappr
# json_serializable:
# runs_before:
# - auto_mappr
21 changes: 21 additions & 0 deletions example/lib/core_models/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:json_annotation/json_annotation.dart';

part 'user.g.dart';

@JsonSerializable()
class User {
final int id;
final String name;
final int age;

int get ageX => age;

factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);

User({
required this.id,
required this.name,
required this.age,
});
Map<String, dynamic> toJson() => _$UserToJson(this);
}
11 changes: 11 additions & 0 deletions example/lib/core_models/user_dto.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class UserDto {
final int id;
final String name;
final int age;

UserDto({
required this.id,
required this.name,
required this.age,
});
}
76 changes: 1 addition & 75 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,75 +1 @@
import 'package:example/models/counter_model.dart';
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
final _counterModel = CounterModel(
description: 'Model which can keep a count.',
);

void _incrementCounter() {
setState(() {
_counterModel.count++;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'${_counterModel.count}',
style: Theme.of(context).textTheme.headlineMedium,
),
Text(
'${_counterModel.toJson()}',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
void main() {}
1 change: 1 addition & 0 deletions example/lib/models/base_class.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:example/core_models/core_class.dart'; // absolute import
import 'package:example/core_models/core_interface.dart'; // absolute import

import '../core_models/core_mixin.dart'; // relative import

class BaseClass extends CoreClass with CoreMixin implements CoreInterface {
Expand Down
10 changes: 7 additions & 3 deletions example/lib/models/counter_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:json_annotation/json_annotation.dart';

import 'base_class.dart';

part 'counter_model.g.dart';
Expand All @@ -7,14 +8,17 @@ part 'counter_model.g.dart';
class CounterModel extends BaseClass {
int count;
final String description;
final String x;
final String y;

CounterModel({
this.count = 0,
this.description = 'description',
this.description = 'descriptionx',
required this.x,
this.y = 'yza',
});

factory CounterModel.fromJson(Map<String, dynamic> json) =>
_$CounterModelFromJson(json);
factory CounterModel.fromJson(Map<String, dynamic> json) => _$CounterModelFromJson(json);

Map<String, dynamic> toJson() => _$CounterModelToJson(this);
}
23 changes: 23 additions & 0 deletions example/lib/models/counter_model2.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:json_annotation/json_annotation.dart';

import '../core_models/user.dart';
import 'base_class.dart';

part 'counter_model2.g.dart';

@JsonSerializable()
class CounterModel2 extends BaseClass {
int count;
final String description;
final User user;

CounterModel2({
this.count = 0,
this.description = 'descriptionsadsadasaaa',
required this.user,
});

factory CounterModel2.fromJson(Map<String, dynamic> json) => _$CounterModel2FromJson(json);

Map<String, dynamic> toJson() => _$CounterModel2ToJson(this);
}
11 changes: 11 additions & 0 deletions example/lib/models/freezed_union.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:freezed_annotation/freezed_annotation.dart';

import '../core_models/user.dart';

part 'freezed_union.freezed.dart';

@freezed
abstract class FreezedUnion with _$FreezedUnion {
const factory FreezedUnion.home() = Home;
const factory FreezedUnion.user(User user) = UserUnion;
}
Loading