| 
									
										
										
										
											2023-04-03 18:50:22 -10:00
										 |  |  | import 'dart:io'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | part 'tool.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const excludeTagBegin = 'BEGIN: EXCLUDE_IN_RELEASE'; | 
					
						
							|  |  |  | const excludeTagEnd = 'END: EXCLUDE_IN_RELEASE'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Future<void> main(List<String> args) async { | 
					
						
							|  |  |  |   const help = '''
 | 
					
						
							|  |  |  | A build script that modifies build assets before building the release version of AppFlowy. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-17 06:03:29 -07:00
										 |  |  | args[0] (required): The subcommand to use (build, include-directives, exclude-directives, run). | 
					
						
							|  |  |  |   - run: calls exclude-directives, build, include-directives. | 
					
						
							|  |  |  |   - build: builds the release version of AppFlowy. | 
					
						
							|  |  |  |   - include-directives: adds the directives from pubspec.yaml. | 
					
						
							|  |  |  |   - exclude-directives: removes the directives from pubspec.yaml. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | args[1] (required): The repository root for appflowy (the directory containing pubspec.yaml). | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | args[2] (required): version (only relevant for build). The version of the app to build. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-03 18:50:22 -10:00
										 |  |  | ''';
 | 
					
						
							| 
									
										
										
										
											2023-08-17 06:03:29 -07:00
										 |  |  |   const numArgs = 3; | 
					
						
							| 
									
										
										
										
											2023-04-03 18:50:22 -10:00
										 |  |  |   assert(args.length == numArgs, | 
					
						
							|  |  |  |       'Expected ${numArgs}, got ${args.length}. Read the following for instructions about how to use this script.\n\n$help'); | 
					
						
							|  |  |  |   if (args[0] == '-h' || args[0] == '--help') { | 
					
						
							|  |  |  |     stdout.write(help); | 
					
						
							|  |  |  |     stdout.flush(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-08-17 06:03:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // parse the vesrion
 | 
					
						
							|  |  |  |   final version = args[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // parse the first required argument
 | 
					
						
							|  |  |  |   final repositoryRoot = Directory(args[1]); | 
					
						
							| 
									
										
										
										
											2023-04-03 18:50:22 -10:00
										 |  |  |   assert(await repositoryRoot.exists(), | 
					
						
							|  |  |  |       '$repositoryRoot is an invalid directory. Please try again with a valid directory.\n\n$help'); | 
					
						
							| 
									
										
										
										
											2023-08-17 06:03:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // parse the command
 | 
					
						
							|  |  |  |   final command = args[0]; | 
					
						
							|  |  |  |   final tool = | 
					
						
							|  |  |  |       BuildTool(repositoryRoot: repositoryRoot.path, appVersion: version); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (command) { | 
					
						
							|  |  |  |     case 'run': | 
					
						
							|  |  |  |       await tool.run(); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 'build': | 
					
						
							|  |  |  |       await tool.build(); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 'include-directives': | 
					
						
							|  |  |  |       await tool.directives(ModifyMode.include); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case 'exclude-directives': | 
					
						
							|  |  |  |       await tool.directives(ModifyMode.exclude); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       throw StateError('Invalid command: $command'); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2023-04-03 18:50:22 -10:00
										 |  |  | } |