Skip to content

Provide watch/build helper to make CLI tooling easier #718

Closed
@kevmoo

Description

@kevmoo

Per google/json_serializable.dart#80 (comment)

It's common to create two files in the tool directory (see below).

It'd be nice to have a run(List<String> args, List<BuildAction> buildActions, {...}) method in build_runner so we could create a trivial hybrid scripts. Where run does the work to switch between build or watch based on args, prints help w/ invalid args, sets the exit code, etc etc etc

#!/usr/bin/env dart --checked
import 'dart:io';
import 'package:build_runner/build_runner.dart';

Future main(List<String> args) => run(args, _buildActions, ...);

final _buildActions = ...

build and watch today...

build.dart

#!/usr/bin/env dart --checked
import 'dart:io';
import 'package:build_runner/build_runner.dart';
import 'build_actions.dart';

main() async {
  var result = await build(buildActions, deleteFilesByDefault: true);
  if (result.status == BuildStatus.failure) {
    exitCode = 1;
  }
}

and watch.dart

#!/usr/bin/env dart --checked
import 'package:build_runner/build_runner.dart';
import 'build_actions.dart';

main() {
  watch(buildActions, deleteFilesByDefault: true);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions