패키지, 저장소 및 앱 카테고리 검색

pubspec_generator 표지
패키지 상세v5.0.2

pubspec_generator

pubspec.yaml에서 코드 생성기 pubspec.yaml.g.dart를 생성합니다. 단순히 `pubspec_generator`를 가져오고, 그 후 `dart run build_runner build`를 실행하면 됩니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
2.1천
좋아요
45
Pub 점수
140

패키지 설치

flutter pub add pubspec_generator

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

프로젝트의 pubspec.yaml에서 `pubspec.yaml.g.dart` 파일을 생성하는 Flutter/Dart 패키지입니다. 자산, 종속성 및 기타 메타데이터를 Dart 파일로 자동으로 추출하여 pubspec 데이터에 타입 안전하게 접근할 수 있게 해줍니다. 패키지를 추가하고 `dart run build_runner build`를 실행하기만 하면 출력이 생성됩니다. YAML을 수동으로 파싱하지 않고도 pubspec 정보에 동적으로 액세스해야 하는 프로젝트에 이상적입니다.

사용 사례

  • 프로그래밍 방식으로 자산 경로에 액세스하기
  • pubspec 종속성에서 코드 생성
  • 타입 안전한 pubspec 메타데이터 사용
  • 빌드에서 자산 관리 자동화
  • 앱 로직에 pubspec 데이터 통합하기

주요 기능

  • pubspec.yaml에서 Dart 코드를 생성합니다
  • 모든 플러터 플랫폼을 지원합니다
  • 자동화에 build_runner를 사용합니다
  • 형 안전한 pubspec 접근을 제공합니다
  • 최소한의 설정 필요

적합한 대상

  • 복잡한 자산 구조를 가진 프로젝트
  • 빌드 시 코드 생성이 필요합니다
  • 동적 pubspec 액세스가 필요한 앱
  • 자동 pubspec 처리를 원하는 팀
  • build_runner 워크플로우를 사용하는 개발자

고려 사항

  • build_runner를 설정해야 합니다
  • 생성된 파일은 수동으로 편집해서는 안 됩니다
  • 빌드 시간을 약간 증가시킬 수 있습니다
  • 간단한 프로젝트에는 필요하지 않습니다
  • 올바른 pubspec.yaml 형식에 의존합니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

pubspec_generator

Code generator pubspec.yaml.g.dart from pubspec.yaml

Pub Checkout Coverage Code size License: MIT Linter GitHub stars

Pubspec Generator is a Dart library that auto-generates a class containing the information from pubspec.yaml description, dependencies and the current app version for all possible platforms. This is an efficient way to keep the application metadata up-to-date across your entire project.

Features

  • Automated code generation: Create a Dart class that includes your pubspec.yaml description and current application version automatically.

  • Cross-platform compatibility: Supports all platforms where Dart is available.

Continually updated: The generated class updates as your pubspec.yaml changes, so your application's metadata remains current at all times.

Command line utility

You can use the command line utility to generate a pubspec.dart file from a pubspec.yaml file. This is useful for quickly generating the Dart class without needing to set up a full build environment.

dart pub global activate pubspec_generator
dart pub global run pubspec_generator:generate --input pubspec.yaml --output lib/src/pubspec.yaml.g.dart

Better to prefer this approach for quick generation over the fully fledged build runner setup.

Installation

First, add pubspec_info_codegen to your pubspec.yaml:

dev_dependencies:
  build_runner: <VERSION>
  pubspec_generator: <VERSION>

or just run

$ dart pub add --dev build_runner pubspec_generator

Then, run the flutter pub get command to fetch the dependency:

$ dart pub get

Configuration

Create build.yaml at project root (near with pubspec.yaml). And set output path:

targets:
  $default:
    sources:
      - $package$
      - lib/**
      - pubspec.yaml
    builders:
      pubspec_generator:
        options:
          output: lib/src/constants/pubspec.yaml.g.dart
  • Read more about build.yaml at here.

Usage

To use the library, you need to run the provided script which triggers the code generation. Below is an example command to do so:

$ dart run build_runner build --delete-conflicting-outputs

This command generates a pubspec.yaml.g.dart file in your lib directory, which contains a class with your pubspec.yaml description and the current app version. You can import this file in your Dart code and use the class to access your app's metadata.

Use Cases

  1. Consistent app metadata across multiple platforms: This library ensures that the application metadata (description, version) is consistent across all platforms, reducing the chances of discrepancies.

  2. Reduced manual errors: Automated code generation eliminates the need for manual updates and thereby reduces the potential for errors.

  3. Faster development process: Less time spent managing app metadata means more time for feature development.

  4. Dynamic display of app information: You can use the generated class to dynamically display the app's description and version in the UI, which would automatically stay updated with changes in pubspec.yaml.

  5. Automated Version Migration: With the library's functionality, you can also handle automated version migration. If your app has different behavior or functionalities across different versions, you can use the auto-generated class to identify the current version and execute the necessary migration logic. This ensures a smooth and seamless user experience across updates.

  6. Backend Request Headers: The generated class can also be used to add meta information from pubspec.yaml into the headers of your backend requests. This can help your backend service identify the app version that is making the request, which can be useful for debugging, tracking, or version-specific behaviors on the backend.

  7. App Analytics Configuration: The metadata from pubspec.yaml (like app version) can be sent to your analytics tool (such as Firebase Analytics) to track the usage of different app versions. This can provide valuable insights into your user base, helping you understand how different versions of your app are being used, which versions are most popular, and how updates affect user behavior. It can also assist in identifying any issues or crashes specific to a certain version.

Result

Generated record for version. A full output example can be found here.

Changelog

Refer to the Changelog to get all release notes.

Maintainers

Funding

If you want to support the development of our library, there are several ways you can do it:

We appreciate any form of support, whether it's a financial donation or just a star on GitHub. It helps us to continue developing and improving our library. Thank you for your support!

License

The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT). It's a simple license that has minimal restrictions on what end-users can do with the software. Here's a summary of the permissions, conditions, and limitations under the MIT License:

Permissions:

  • Commercial Use: You are free to use the software for commercial purposes.
  • Modification: You can make changes to the software and distribute your modifications.
  • Distribution: You can distribute the original or modified (derivative) software.
  • Private Use: You are free to use the software for private purposes.

Conditions:

  • Include Copyright: You must include the original copyright notice in any copy of the software/source code.
  • Include License: You must include a copy of the license in any copy of the software/source code.

Limitations:

  • No Liability: The software is provided "as is". The authors or copyright holders cannot be held liable for any 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.
  • No Warranty: The authors or copyright holders provide no warranty of any kind.

It's important to note that this is a simplified explanation of the MIT License. If you're using MIT-licensed software in a manner that could expose you to legal risk, it's always a good idea to consult with a qualified legal professional.

카테고리

의존성

의존성 목록 7 개

소스 저장소

이 패키지를 사용하는 프로젝트