main function

void main(
  1. List<String> args
)

Implementation

void main(List<String> args) {
	final bool isTest = args.isNotEmpty && args.first == '--test';
	if (isTest) args = args.sublist(1);
	final String srcPath = Directory.current.path + (args.isEmpty ? '' : '/${args[0]}');
	final String outPath = Directory.current.path + (args.length < 2 ? '' : '/${args[1]}');
	List<String> filenames = args.sublist(min(2, args.length));

	/// Add file extension if not specified
	final RegExp extension = RegExp(r'\.json$');
	for (int i = 0; i < filenames.length; i++) {
		if (!extension.hasMatch(filenames[i])) filenames[i] += '.json';
	}

	/// Remove duplicates
	filenames = filenames.toSet().toList();

	try {
		print('${GREEN}Compiling ${filenames.isEmpty ? 'all .json files...' : '${filenames.length} files: ${filenames.join(', ')}...'}$RESET');
		print('$GREEN    Input directory: $YELLOW$srcPath$RESET');
		print('$GREEN    Output directory: $YELLOW$outPath$RESET');
		process(srcPath, outPath, filenames, isTest);
	}
	catch (err) {
		if (isTest) rethrow;
		else print('$RED$err$RESET');
		exit(-1);
	}
}