command method

List<String> command([
  1. List<String>? extraArgs
])

Returns the full command to run when executing this script.

Implementation

List<String> command([List<String>? extraArgs]) {
  String quoteScript(String script) => '"${script.replaceAll('"', r'\"')}"';

  final scriptCommand = run!.split(' ').toList();
  if (extraArgs != null && extraArgs.isNotEmpty) {
    scriptCommand.addAll(extraArgs);
  }

  final exec = this.exec;
  if (exec == null) {
    return scriptCommand;
  } else {
    final execCommand = ['melos', 'exec'];

    if (exec.concurrency != null) {
      execCommand.addAll(['--concurrency', '${exec.concurrency}']);
    }

    if (exec.failFast ?? false) {
      execCommand.add('--fail-fast');
    }

    if (exec.orderDependents ?? false) {
      execCommand.add('--order-dependents');
    }

    execCommand.addAll(['--', quoteScript(scriptCommand.join(' '))]);

    return execCommand;
  }
}