project 0.1.2 copy "project: ^0.1.2" to clipboard
project: ^0.1.2 copied to clipboard

Parse the dart project and convert it into a dart node, so that some command-line tools can quickly parse the project.

example/example.dart

import 'package:project/project.dart';

Set<String> names = {};

/// The file will output some info: see [example.log][]
///
/// [example.log]: https://github.com/CaiJingLong/dart_project/blob/main/example/example.log
void main() {
  final rootPkg = Package.fromPath('.');

  printPktInfo(rootPkg, 1, false);
}

String tab(int level) {
  if (level == 0) {
    return '';
  }

  return ('|  ' * (level - 1)) + '|--';
}

void printPktInfo(Package pkg, int level, [bool showInfo = true]) {
  final name = pkg.name;
  final ouputName = '${tab(level - 1)}${name}: ';
  if (names.contains(name)) {
    print('$ouputName ...');
    return;
  }
  print('$ouputName${pkg.version}');

  names.add(name);
  final space = tab(level);
  // print('${space}version: ${pkg.version}');
  if (showInfo) {
    print('${space}description: ${pkg.description}');
    print('${space}local path: ${pkg.packageDir.path}');
  }

  for (var dependency in pkg.dependencies) {
    final pkg = dependency.package;
    printPktInfo(pkg, level + 1, showInfo);
  }

  for (var dependency in pkg.devDependencies) {
    final subPkg = dependency.package;
    if (subPkg == null) {
      continue;
    }
    printPktInfo(subPkg, level + 1, showInfo);
  }
}
0
likes
40
pub points
35%
popularity

Publisher

unverified uploader

Parse the dart project and convert it into a dart node, so that some command-line tools can quickly parse the project.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

analyzer, meta, path, pub_semver, yaml

More

Packages that depend on project