0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dart アプリ/dart ライブライ用の pubspec.yaml を自動生成する

Last updated at Posted at 2025-04-21

dart アプリ/dart ライブライ用の pubspec.yaml を自動生成するためのパッケージ(specgen)を作成しました。

以下のページにインストールの方法がかかれています。

https://pub.dev/packages/specgen/install

specgen のインストール

specgen は、コマンドラインツールとしてインストールします。

インストール(バージョンアップ)方法
dart pub global activate specgen

上記でインストールされますが、以下のフォルダにパスを通す必要があります(Windowsの場合)。

C:\Users\【WindowsユーザーID】\AppData\Local\Pub\Cache\bin

再インストール方法
dart pub global deactivate specgen
dart pub global activate specgen

specgen の使用方法

pubspec.yaml を生成したいフォルダに移動します。

そのフォルダ配下の bin lib test フォルダ内に dart のソースを入れておきます。(段階的にソースは増やしていけばいいです)

specgen と入力して ENTER を押します。

specgen

カレントフォルダに pubspec.yaml が生成されます。

  • bin lib test フォルダ内のソースが参照しているパッケージ名(以下の例では sys と text_serializer)が pubspec.yaml の依存関係に追加されます。
import 'dart:core';
import 'dart:io' as io;
import 'package:sys/sys.dart' as sys;
import 'package:text_serializer/text_serializer.dart' as ts;
  • bin lib test フォルダのソースの import を追加・削除したら、再度 specgen を実行すれば依存関係が自動的に追加・削除されます。

ソースにまだ追加されていないパッケージを依存関係に追加するには以下のようにしてもかまいません。
IDE (IntelliJ Idea など) で編集している場合は、pubspec.yaml にパッケージ名を追加しておいたほうが、コンプリーションが効いて便利です。

dart pub add <パッケージ名> ...

ソースに、import 文を追加した後は、specgen を再実行してもかまいません。

specgen に引数("1.0.0" など)を与えると、pubspec.yaml 内の version がその値になります。
引数を与えないと pubspec.yaml に現在指定している version が保持されます。

最後に

ちょっと、この記事では魅力が伝わらないかもしれないので、気が向いたらまた説明記事を書きます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?