1
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?

More than 1 year has passed since last update.

melosに登録しているscriptのヘルプコマンドを作ってみた

Last updated at Posted at 2024-06-16

はじめに

Flutterプロジェクトのコマンドはgrinderを使っていたのだが、マルチパッケージも考慮するとmelosに統一したくなった。
grinderはgrind -hで使えるタスクを表示できるのだが、melosのscriptsにはヘルプのような機能がなさそうなので簡単に作ってみた。

コード

以下のdartのコードを用意する
grinderの便利関数が使いたかったので、grinderをターミナルからは叩かないが利用している。

scripts/help.dart
import 'dart:io';

import 'package:grinder/grinder.dart';
import 'package:yaml/yaml.dart';

Future<void> main() async {
  final melosFile = File('melos.yaml');
  if (!melosFile.existsSync()) {
    fail('Required files not found.');
  }

  final melosFileString = melosFile.readAsStringSync();

  final yaml = loadYaml(melosFileString) as YamlMap;
  final scripts = yaml['scripts'] as YamlMap;

  log('Available scripts:');
  for (final script in scripts.entries) {
    log('${script.key}');
    final scriptValue = script.value as YamlMap;
    if (scriptValue['description'] != null) {
      log('  ${scriptValue['description']}');
    }
  }
}

melos.yamlのscriptsから使えるようにする

melos.yaml
scripts:
  h:
    description: Show help
    run: dart run scripts/help.dart

実行

melos run h
〜略
Available scripts:
h
  Show help
build
  build_runner build
watch
  build_runner watch
yumemi_lints_update
  Update yumemi_lints configuration

まとめ

melos.yaml見たほうが早い…

実装はこちら

1
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
1
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?