build_flowy.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'dart:io';
  2. part 'tool.dart';
  3. const excludeTagBegin = 'BEGIN: EXCLUDE_IN_RELEASE';
  4. const excludeTagEnd = 'END: EXCLUDE_IN_RELEASE';
  5. Future<void> main(List<String> args) async {
  6. const help = '''
  7. A build script that modifies build assets before building the release version of AppFlowy.
  8. args[0] (required): The subcommand to use (build, include-directives, exclude-directives, run).
  9. - run: calls exclude-directives, build, include-directives.
  10. - build: builds the release version of AppFlowy.
  11. - include-directives: adds the directives from pubspec.yaml.
  12. - exclude-directives: removes the directives from pubspec.yaml.
  13. args[1] (required): The repository root for appflowy (the directory containing pubspec.yaml).
  14. args[2] (required): version (only relevant for build). The version of the app to build.
  15. ''';
  16. const numArgs = 3;
  17. assert(args.length == numArgs,
  18. 'Expected ${numArgs}, got ${args.length}. Read the following for instructions about how to use this script.\n\n$help');
  19. if (args[0] == '-h' || args[0] == '--help') {
  20. stdout.write(help);
  21. stdout.flush();
  22. }
  23. // parse the vesrion
  24. final version = args[2];
  25. // parse the first required argument
  26. final repositoryRoot = Directory(args[1]);
  27. assert(await repositoryRoot.exists(),
  28. '$repositoryRoot is an invalid directory. Please try again with a valid directory.\n\n$help');
  29. // parse the command
  30. final command = args[0];
  31. final tool =
  32. BuildTool(repositoryRoot: repositoryRoot.path, appVersion: version);
  33. switch (command) {
  34. case 'run':
  35. await tool.run();
  36. break;
  37. case 'build':
  38. await tool.build();
  39. break;
  40. case 'include-directives':
  41. await tool.directives(ModifyMode.include);
  42. break;
  43. case 'exclude-directives':
  44. await tool.directives(ModifyMode.exclude);
  45. break;
  46. default:
  47. throw StateError('Invalid command: $command');
  48. }
  49. }