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

feat: Add support for managing pubspec_overrides.yaml #51

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "pubspec_manager",
"request": "launch",
"type": "dart",
"program": "bin/manage.dart",
"args": [
"manage",
"-f",
"test",
"-b",
"no-pub-get"
]
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
}
]
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### 0.3.0+1 (2024-01-25)
#### Added
- Added support to mange overridden dependencies in pubspec_overrides.yaml file.
- Added support to avoid running pub get after managing the dependencies, can be called by `pubm -f <flavor> -b no-pub-get` or `dart run pub:manage -f <flavor> -b no-pub-get`, -b is abbreviation for `--build-args`
- Added support to both `flutter pub get` and `dart pub get` commands (If the pubspec.yaml file contains flutter sdk dependency then it will run flutter pub get else dart pub get).

#### Fixed
- Fixed the issue of of removing and managing dependencies when clubbed together.

### 0.2.0 (2023-11-04)
#### Added
- Added support to remove values from pubspec.yaml file.
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ pubm -f <flavor> -v
# else
dart run pubm:manage -f <flavor> -v
```

Once the pubspec is managed, this run the pub get command, if the pubspec.yaml file contains flutter sdk dependency then it will run flutter pub get else dart pub get.
To stop calling pub get after managing the pubspec.yaml file, use the -b flag with no-pub-get value.
-b (--build-args)
```console
# if activated from https://pub.dev
pubm -f <flavor> -b no-pub-get -v

# else
dart run pubm:manage -f <flavor> -b no-pub-get -v
```

Pubm also supports managing the overridden dependencies in `pubspec_overrides.yaml` file.


### 📋 Example: pubspec_dev.yaml
Here's an example of a flavor-specific pubspec.yaml file for a 'dev' flavor:
```yaml
Expand Down
28 changes: 12 additions & 16 deletions backup_pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
name: pubm
description: A Dart command line tool to help with managing pubspec dependencies.
version: 0.1.0
version: 0.0.1-beta
homepage: https://github.com/kushalmahapatro/pubspec_manager
repository: https://github.com/kushalmahapatro/pubspec_manager
homepage: https://github.com/kushalmahapatro/pubspec_manager
topics:
- pubspec
- pubspec-manager
- pubspec-splitter
- pubspec-updater
- pubspec-dependency-manager


environment:
sdk: ^3.0.0

dependencies:
# normal dependencies
args: ^2.4.2
cli_util: ^0.4.0
collection: ^1.17.1
cli_util: ^0.4.1
collection: ^1.18.0
cupertino_icons: ^1.0.2
equatable: ^2.0.5
get_it: ^7.2.0
get_it: ^7.6.7
json2yaml: ^3.0.1
path: ^1.8.0
path: ^1.9.0
yaml: ^3.1.2

dev_dependencies:
# normal dependencies
lints: ^2.1.1
test: ^1.24.3


flutter:
uses-material-design: true
generate: true

topics:
- pubspec
- pubspec-manager
- pubspec-splitter
- pubspec-updater
- pubspec-dependency-manager
executables:
pubm: manage
4 changes: 4 additions & 0 deletions backup_pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

dependency_overrides:
# normal dependencies
args: ^2.4.1
43 changes: 11 additions & 32 deletions example/_pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
name: pubm
description: Actual description
version: 0.0.1
homepage: https://test.homepage
description: prod version of pubspec.yaml
version: 0.0.1-dev

environment:
sdk: ^3.0.0

dependencies:
# path related dependencies
example_dependency:
path: example/dependency
# normal dependencies
cupertino_icons: ^1.0.2
unwanted_dependency: ^0.0.1

dev_dependencies:
flutter_lints: ^2.0.0
unwanted_dependency: ^0.0.1-dev

dependency_overrides:
flutter_lints: ^1.0.0
unwanted_dependency: ^0.0.1-override

flutter:
uses-material-design: true
generate: true

assets:
- assets/dev/
- assets/prod/

fonts:
- family: font1
fonts:
- asset: actual/font1/700.ttf
weight: 700
- asset: actual/font1/600.ttf
weight: 600
- asset: actual/font1/500.ttf
weight: 500
- asset: actual/font1/400.ttf
weight: 400
- family: font
fonts:
- asset: actual/font2/700.ttf
- asset: dev/font2/700.ttf
weight: 700
- asset: actual/font2/600.ttf
- asset: dev/font2/600.ttf
weight: 600
- asset: actual/font2/500.ttf
- asset: dev/font2/500.ttf
weight: 500
- asset: actual/font2/400.ttf
weight: 400
- asset: dev/font2/400.ttf
weight: 400
28 changes: 28 additions & 0 deletions example/backup_pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: pubm
description: prod version of pubspec.yaml
version: 0.0.1-dev

environment:
sdk: ^3.0.0

dependencies:
# path related dependencies
example_dependency:
path: example/dependency
# normal dependencies
cupertino_icons: ^1.0.2

flutter:
uses-material-design: true
generate: true
fonts:
- family: font
fonts:
- asset: dev/font2/700.ttf
weight: 700
- asset: dev/font2/600.ttf
weight: 600
- asset: dev/font2/500.ttf
weight: 500
- asset: dev/font2/400.ttf
weight: 400
5 changes: 5 additions & 0 deletions example/backup_pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

dependency_overrides:
# normal dependencies
flutter_lints: ^9.0.0
unwanted_dependency: ^0.0.1-override
14 changes: 9 additions & 5 deletions example/pubspec_dev.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
description: prod version of pubspec.yaml
version: 0.0.1-prod
version: 0.0.1-dev

dependencies:
example_dependency:
path: example/dependency

dependency_overrides:
flutter_lints: ^9.0.0
unwanted_override: ^1.0.1-override

dev_dependencies:
lints: ^2.1.1

Expand All @@ -20,19 +24,19 @@ flutter:
weight: 500
- asset: dev/font2/400.ttf
weight: 400

remove:
homepage: https://test.homepage

dependencies:
unwanted_dependency:

dev_dependencies:
dependency_overrides:

dependency_overrides:
unwanted_override:

flutter:
assets:
- assets/dev/

fonts:
- family: font1
- family: font1
5 changes: 5 additions & 0 deletions example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

dependency_overrides:
# normal dependencies
flutter_lints: ^9.0.0
unwanted_dependency: ^0.0.1-override
4 changes: 2 additions & 2 deletions example/pubspec_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ remove:

flutter:
assets:
- assets/dev/
- assets/prod/

fonts:
- family: font1
- family: font1
1 change: 1 addition & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const String comment = "Pubspec Manager Comment";
const String pubspecYamlPath = "pubspec.yaml";
const String pubspecOverridesYamlPath = "pubspec_overrides.yaml";

/// Pubspec keys
const String name = 'name';
Expand Down
26 changes: 13 additions & 13 deletions lib/models/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,36 @@ class Pubspec extends Equatable {
Pubspec pubspec = Pubspec();
Map<String, dynamic> others = {};
map.forEach((key, value) {
if (key == 'name') {
if (key == 'name' && value != null) {
pubspec = pubspec.copyWith(name: value);
} else if (key == 'description') {
} else if (key == 'description' && value != null) {
pubspec = pubspec.copyWith(description: value);
} else if (key == 'version') {
} else if (key == 'version' && value != null) {
pubspec = pubspec.copyWith(version: value);
} else if (key == 'homepage') {
} else if (key == 'homepage' && value != null) {
pubspec = pubspec.copyWith(homepage: value);
} else if (key == 'repository') {
} else if (key == 'repository' && value != null) {
pubspec = pubspec.copyWith(repository: value);
} else if (key == 'issue_tracker') {
} else if (key == 'issue_tracker' && value != null) {
pubspec = pubspec.copyWith(issueTracker: value);
} else if (key == 'documentation') {
} else if (key == 'documentation' && value != null) {
pubspec = pubspec.copyWith(documentation: value);
} else if (key == 'publish_to') {
} else if (key == 'publish_to' && value != null) {
pubspec = pubspec.copyWith(publishTo: value);
} else if (key == 'environment') {
} else if (key == 'environment' && value != null) {
pubspec = pubspec.copyWith(
environment: Environment.fromMap(value.cast<String, dynamic>()));
} else if (key == 'dependencies') {
} else if (key == 'dependencies' && value != null) {
pubspec = pubspec.copyWith(
dependencies: getDependencies(value.cast<String, dynamic>()));
} else if (key == 'dev_dependencies') {
} else if (key == 'dev_dependencies' && value != null) {
pubspec = pubspec.copyWith(
devDependencies: getDependencies(value.cast<String, dynamic>()));
} else if (key == 'dependency_overrides') {
} else if (key == 'dependency_overrides' && value != null) {
pubspec = pubspec.copyWith(
dependenciesOverride:
getDependencies(value.cast<String, dynamic>()));
} else if (key == 'flutter') {
} else if (key == 'flutter' && value != null) {
pubspec = pubspec.copyWith(
flutter: FlutterData.fromMap(value.cast<String, dynamic>()));
} else {
Expand Down
Loading
Loading