From d1a859e9f68bbb8bf303ef032207adf6ea775a3b Mon Sep 17 00:00:00 2001 From: debuggerx Date: Mon, 6 Sep 2021 14:08:48 +0800 Subject: [PATCH] feat: ignore hidden files; fix some issue. --- bin/pre_script.dart | 11 ++++++++--- flutter.sh | 29 +++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/bin/pre_script.dart b/bin/pre_script.dart index bbae6c3..860a7a1 100644 --- a/bin/pre_script.dart +++ b/bin/pre_script.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'path_utils.dart'; import 'parse_arguments.dart'; import 'expressions/expressions.dart'; import 'flavors.dart'; @@ -66,14 +67,17 @@ List operations = []; List tempOperations = []; List currentTempOperations = []; -final _commentReg = RegExp(' +\/\/'); +final _commentReg = RegExp(' *\/\/'); var lastIndent = -1; void walkPath(FileSystemEntity path) { var stat = path.statSync(); if (stat.type == FileSystemEntityType.directory) { - Directory(path.path).listSync().forEach(walkPath); + Directory(path.path) + .listSync() + .where((f) => !PathUtils.baseName(f).startsWith('.')) + .forEach(walkPath); } else if (stat.type == FileSystemEntityType.file && BLACK_FILE_EXT.indexWhere((ele) => path.path.endsWith(ele)) < 0) { file = File(path.path); @@ -183,7 +187,8 @@ void walkPath(FileSystemEntity path) { lines[operation.lineNumber - 1].replaceFirst('// ', ''); }); file!.deleteSync(); - File(path.path).writeAsStringSync(lines.join('\n'), flush: true); + File(path.path) + .writeAsStringSync(lines.join('\n') + '\n', flush: true); print("${file!.path} modified"); } else { file!.renameSync(path.path + '.bak'); diff --git a/flutter.sh b/flutter.sh index 020b20a..f2dd958 100644 --- a/flutter.sh +++ b/flutter.sh @@ -30,25 +30,26 @@ if [[ ! -x "$DART_EXE" ]]; then echo "Can't find dart executable file !" fi -if [[ -f "./.hooks/pre_script.dart" ]]; then - ${DART_EXE} ./.hooks/pre_script.dart "$@" -fi +${DART_EXE} "$SCRIPT_DIR"/bin/pre_script.dart "$@" -if [[ -f "./pre_script.dart" ]]; then - ${DART_EXE} ./.hooks/pre_script.dart "$@" -fi +if [[ "$JUST_REPLACE" == 0 ]]; then + if [[ -f "./.hooks/pre_script.dart" ]]; then + ${DART_EXE} ./.hooks/pre_script.dart "$@" + fi -if [[ -f "./.hooks/pre_script.sh" ]]; then - ./.hooks/pre_script.sh "$@" -fi + if [[ -f "./pre_script.dart" ]]; then + ${DART_EXE} ./pre_script.dart "$@" + fi -if [[ -f "./pre_script.sh" ]]; then - ./pre_script.sh "$@" -fi + if [[ -f "./.hooks/pre_script.sh" ]]; then + ./.hooks/pre_script.sh "$@" + fi -${DART_EXE} "$SCRIPT_DIR"/bin/pre_script.dart "$@" + if [[ -f "./pre_script.sh" ]]; then + ./pre_script.sh "$@" + fi -if [[ "$JUST_REPLACE" == 0 ]]; then + flutter pub get flutter ${ARGS[*]}