fix: bug.
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
const FLAVORS = [
|
||||||
|
'test',
|
||||||
|
'tw',
|
||||||
|
'cn',
|
||||||
|
];
|
||||||
+26
-28
@@ -1,12 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'parse_arguments.dart';
|
import 'parse_arguments.dart';
|
||||||
import 'expressions/expressions.dart';
|
import 'expressions/expressions.dart';
|
||||||
|
import 'flavors.dart';
|
||||||
const FLAVORS = [
|
|
||||||
'test',
|
|
||||||
'tw',
|
|
||||||
'cn',
|
|
||||||
];
|
|
||||||
|
|
||||||
const BLACK_FILE_EXT = [
|
const BLACK_FILE_EXT = [
|
||||||
'md',
|
'md',
|
||||||
@@ -60,6 +55,7 @@ Match? ma;
|
|||||||
bool modified = false;
|
bool modified = false;
|
||||||
|
|
||||||
const evaluator = const ExpressionEvaluator();
|
const evaluator = const ExpressionEvaluator();
|
||||||
|
late List<String> lines;
|
||||||
|
|
||||||
// vars for replace mode
|
// vars for replace mode
|
||||||
int currentLineIndex = 0;
|
int currentLineIndex = 0;
|
||||||
@@ -87,7 +83,8 @@ void walkPath(FileSystemEntity path) {
|
|||||||
currentTempOperations.clear();
|
currentTempOperations.clear();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
file!.readAsLinesSync().forEach((line) {
|
lines = file!.readAsLinesSync();
|
||||||
|
lines.forEach((line) {
|
||||||
currentLineIndex++;
|
currentLineIndex++;
|
||||||
ma = re.firstMatch(line);
|
ma = re.firstMatch(line);
|
||||||
if (ma != null) {
|
if (ma != null) {
|
||||||
@@ -96,6 +93,9 @@ void walkPath(FileSystemEntity path) {
|
|||||||
exp = ma!.group(1);
|
exp = ma!.group(1);
|
||||||
if (exp == "default") {
|
if (exp == "default") {
|
||||||
if (isReplace) {
|
if (isReplace) {
|
||||||
|
if (currentTempOperations.isNotEmpty &&
|
||||||
|
!currentTempOperations.first.commented)
|
||||||
|
tempOperations.forEach((ele) => ele.commented = true);
|
||||||
tempOperations.addAll(currentTempOperations);
|
tempOperations.addAll(currentTempOperations);
|
||||||
currentTempOperations.clear();
|
currentTempOperations.clear();
|
||||||
}
|
}
|
||||||
@@ -131,13 +131,6 @@ void walkPath(FileSystemEntity path) {
|
|||||||
}
|
}
|
||||||
tmp.clear();
|
tmp.clear();
|
||||||
} else {
|
} else {
|
||||||
if (isReplace) {
|
|
||||||
if (currentTempOperations.isNotEmpty &&
|
|
||||||
!currentTempOperations.first.commented)
|
|
||||||
tempOperations.forEach((ele) => ele.commented = true);
|
|
||||||
tempOperations.addAll(currentTempOperations);
|
|
||||||
currentTempOperations.clear();
|
|
||||||
}
|
|
||||||
if (evaluator.eval(Expression.parse(exp!), _ctx)) {
|
if (evaluator.eval(Expression.parse(exp!), _ctx)) {
|
||||||
// 匹配到
|
// 匹配到
|
||||||
tmp.clear();
|
tmp.clear();
|
||||||
@@ -145,6 +138,12 @@ void walkPath(FileSystemEntity path) {
|
|||||||
} else {
|
} else {
|
||||||
state = STATE.notMatch;
|
state = STATE.notMatch;
|
||||||
}
|
}
|
||||||
|
if (isReplace) {
|
||||||
|
if (state == STATE.caching)
|
||||||
|
tempOperations.forEach((ele) => ele.commented = true);
|
||||||
|
tempOperations.addAll(currentTempOperations);
|
||||||
|
currentTempOperations.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// none状态时直接将line写入sb
|
// none状态时直接将line写入sb
|
||||||
@@ -169,21 +168,20 @@ void walkPath(FileSystemEntity path) {
|
|||||||
operations.forEach((ele) {
|
operations.forEach((ele) {
|
||||||
print('${ele.lineNumber} : ${ele.commented}');
|
print('${ele.lineNumber} : ${ele.commented}');
|
||||||
});
|
});
|
||||||
file!.readAsLines().then((lines) {
|
|
||||||
operations.forEach((operation) {
|
operations.forEach((operation) {
|
||||||
if (operation.commented &&
|
if (operation.commented &&
|
||||||
!lines[operation.lineNumber - 1].startsWith(_commentReg))
|
!lines[operation.lineNumber - 1].startsWith(_commentReg))
|
||||||
lines[operation.lineNumber - 1] =
|
lines[operation.lineNumber - 1] =
|
||||||
'${' ' * operation.indent}// ${lines[operation.lineNumber - 1].substring(operation.indent)}';
|
'${' ' * operation.indent}// ${lines[operation.lineNumber - 1].substring(operation.indent)}';
|
||||||
else if (!operation.commented &&
|
else if (!operation.commented &&
|
||||||
lines[operation.lineNumber - 1].startsWith(_commentReg))
|
lines[operation.lineNumber - 1].startsWith(_commentReg))
|
||||||
lines[operation.lineNumber - 1] =
|
lines[operation.lineNumber - 1] =
|
||||||
lines[operation.lineNumber - 1].replaceFirst('// ', '');
|
lines[operation.lineNumber - 1].replaceFirst('// ', '');
|
||||||
});
|
|
||||||
print(lines.join('\n'));
|
|
||||||
file!.deleteSync();
|
|
||||||
File(path.path).writeAsStringSync(lines.join('\n'), flush: true);
|
|
||||||
});
|
});
|
||||||
|
print(lines.join('\n'));
|
||||||
|
file!.deleteSync();
|
||||||
|
File(path.path).writeAsStringSync(lines.join('\n'), flush: true);
|
||||||
} else {
|
} else {
|
||||||
file!.renameSync(path.path + '.bak');
|
file!.renameSync(path.path + '.bak');
|
||||||
File(path.path).writeAsStringSync(sb.toString(), flush: true);
|
File(path.path).writeAsStringSync(sb.toString(), flush: true);
|
||||||
|
|||||||
Reference in New Issue
Block a user