diff --git a/CHANGELOG.md b/CHANGELOG.md index 24dd582..707281b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## [2.1.0] - 2023-09-13 +### Added +- Option to ignore certain packages ## [2.0.0] - 2022-06-05 ### Breaking - Updated to the dart 3.0.0 diff --git a/README.md b/README.md index 453578c..4fe1ecd 100755 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ license_generator: pub_dev_base_url: String #(optional) This will override the default pubdev base url for downloading the pubdev details (homepage/repository) -> Default: https://pub.dev licenses: #(optional) This will accept key value pairs (String/String) -> (package name/raw license url) #license_generator: https://raw.githubusercontent.com/icapps/flutter-icapps-license/master/LICENSE (example) + ignore_licenses: #(optional) This wil accept a list of package names (String) + - shared_preferences extra_licenses: #(optional) this will allow you to add extra licenses that are not added in your pubspec.yaml something_something: #the name of your package will be used if `name` is not specified name: String #(optional) This will override your package name diff --git a/bin/src/model/pubspec.dart b/bin/src/model/pubspec.dart index ad8e6a3..159b12a 100644 --- a/bin/src/model/pubspec.dart +++ b/bin/src/model/pubspec.dart @@ -1,5 +1,6 @@ import 'package:path/path.dart'; import 'package:yaml/yaml.dart'; + import '../util/logger.dart'; import 'dto/dependency.dart'; import 'dto/extra_dependency.dart'; @@ -21,6 +22,7 @@ class Params { static const yamlConfigPubDevBaseUrl = 'pub_dev_base_url'; static const yamlConfigLicensesList = 'licenses'; static const yamlConfigExtraLicensesList = 'extra_licenses'; + static const yamlConfigIgnoreLicenses = 'ignore_licenses'; late PubspecLock pubspecLock; String fileOutputPath = defaultFileOutputPath; @@ -73,10 +75,20 @@ class Params { icappsLicenseConfig[yamlConfigExtraLicensesList] as YamlMap?); } + final ignoredPackages = + icappsLicenseConfig?[yamlConfigIgnoreLicenses] as YamlList?; final packages = config['dependencies'] as YamlMap?; final devPackages = config['dev_dependencies'] as YamlMap?; - _generateDependencies(packages: packages, isDevDependency: false); - _generateDependencies(packages: devPackages, isDevDependency: true); + _generateDependencies( + packages: packages, + isDevDependency: false, + ignoredPackages: ignoredPackages, + ); + _generateDependencies( + packages: devPackages, + isDevDependency: true, + ignoredPackages: ignoredPackages, + ); final containsLicenseGenerator = devDependencies .where((element) => element.name == yamlConfigLicense) @@ -102,7 +114,9 @@ class Params { } void _generateDependencies( - {required YamlMap? packages, required bool isDevDependency}) { + {required YamlMap? packages, + required bool isDevDependency, + required YamlList? ignoredPackages}) { final type = isDevDependency ? 'dev_dependencies' : 'dependencies'; if (packages != null) { for (final package in packages.keys) { @@ -111,6 +125,9 @@ class Params { throw ArgumentError( 'package should be a String: the name of the package'); } + if (ignoredPackages?.contains(package) == true) { + continue; + } final dynamic values = packages.value[package]; Dependency dependency; if (values is String) { diff --git a/example/lib/util/license.dart b/example/lib/util/license.dart index eed66aa..2730b6f 100644 --- a/example/lib/util/license.dart +++ b/example/lib/util/license.dart @@ -212,39 +212,6 @@ SOFTWARE.''', homepage: null, repository: r'https://github.com/rrousselGit/provider', ), - const License( - name: r'shared_preferences', - license: r'''Copyright 2013 The Flutter Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -''', - version: r'^2.1.1', - homepage: null, - repository: - r'https://github.com/flutter/packages/tree/main/packages/shared_preferences/shared_preferences', - ), ]; } } diff --git a/example/pubspec.lock b/example/pubspec.lock index c166173..005a81f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.17.2" fast_barcode_scanner: dependency: "direct main" description: @@ -116,18 +116,10 @@ packages: dependency: transitive description: name: intl - sha256: a3715e3bc90294e971cb7dc063fbf3cd9ee0ebf8604ffeafabd9e6f16abbdbe6 + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" url: "https://pub.dev" source: hosted - version: "0.18.0" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" + version: "0.18.1" license_generator: dependency: "direct dev" description: @@ -147,10 +139,10 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" meta: dependency: transitive description: @@ -332,6 +324,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" win32: dependency: transitive description: @@ -357,5 +357,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.0.0 <4.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 210018c..f0a5c65 100755 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -29,6 +29,8 @@ license_generator: check_before_generate: true licenses: # license_generator: https://raw.githubusercontent.com/icapps/flutter-icapps-license/master/LICENSE + ignore_licenses: + - shared_preferences extra_licenses: something_something: name: Something Something diff --git a/test/command/generate_command_test.dart b/test/command/generate_command_test.dart index 5cd54fc..39c18f4 100644 --- a/test/command/generate_command_test.dart +++ b/test/command/generate_command_test.dart @@ -2,12 +2,13 @@ import 'dart:io'; import 'package:path/path.dart'; import 'package:test/test.dart'; + +import '../../bin/src/command/generate_command.dart'; import '../../bin/src/model/dto/dependency.dart'; import '../../bin/src/model/dto/dependency_license_data.dart'; import '../../bin/src/model/dto/dependency_lock.dart'; import '../../bin/src/model/dto/extra_dependency.dart'; import '../../bin/src/model/pubspec.dart'; -import '../../bin/src/command/generate_command.dart'; import '../../bin/src/repo/license_repository.dart'; void main() { @@ -73,7 +74,88 @@ class LicenseUtil { static List getLicenses() { return [ - License( + const License( + name: r'license_generator', + license: r'''this is the license_generator license''', + version: r'1.0.0', + homepage: null, + repository: null, + ), + ]; + } +} +"""); + }); + + test('Test generate command with ignore', () async { + const yaml = r''' +name: test_example +dependencies: + shared_preferences: ^2.1.1 +dev_dependencies: + license_generator: 1.0.0 + +license_generator: + ignore_licenses: + - shared_preferences +'''; + const lock = r''' +packages: + license_generator: + dependency: "direct dev" + description: + path: ".." + relative: true + source: path + version: "1.0.0" + shared_preferences: + dependency: "direct main" + description: + path: ".." + relative: true + source: path + version: "2.1.1" +'''; + final params = Params(yaml, lock); + final repo = TestLicenseRepository({ + 'license_generator': const DependencyLicenseData( + license: 'this is the license_generator license'), + 'shared_preferences': const DependencyLicenseData( + license: 'this is the shared_preference license'), + }); + params.fileOutputPath = outputPath; + final generateCommand = GenerateCommand(repo); + await generateCommand.generateLicenses(params); + final data = File(outputPath).readAsStringSync(); + expect(data, """import 'package:flutter/widgets.dart'; + +//============================================================// +//THIS FILE IS AUTO GENERATED. DO NOT EDIT// +//============================================================// + +@immutable +class License { + final String name; + final String license; + final String? version; + final String? homepage; + final String? repository; + + const License({ + required this.name, + required this.license, + this.version, + this.homepage, + this.repository, + }); +} + +class LicenseUtil { + LicenseUtil._(); + + static List getLicenses() { + return [ + const License( name: r'license_generator', license: r'''this is the license_generator license''', version: r'1.0.0', @@ -141,7 +223,7 @@ class LicenseUtil { static List getLicenses() { return [ - License( + const License( name: r'license_generator', license: r'''this is the license_generator license''', version: r'1.0.0', @@ -218,7 +300,7 @@ class LicenseUtil { static List getLicenses() { return [ - License( + const License( name: r'license_generator', license: r'''this is the license_generator license''', version: null, diff --git a/test/repo/license_repository_test.dart b/test/repo/license_repository_test.dart index 3ecf130..6df4c26 100644 --- a/test/repo/license_repository_test.dart +++ b/test/repo/license_repository_test.dart @@ -263,7 +263,8 @@ void main() { ), throwsA(predicate((e) => e is FatalException && - e.message == "Failed to get the license url for 'test_package'")), + e.message == + ".dart_tool/package_config.json is not up to date. Path: 'test/repo/test_data/no-local-license-file-dev/test_package-1.0.0' does not exist anymore.")), ); }); @@ -290,7 +291,8 @@ void main() { ), throwsA(predicate((e) => e is FatalException && - e.message == "Failed to get the license url for 'test_package'")), + e.message == + ".dart_tool/package_config.json is not up to date. Path: 'test/repo/test_data/no-local-license-file-dev/test_package-1.0.0' does not exist anymore.")), ); });