feat: update expressions.
This commit is contained in:
@@ -122,6 +122,10 @@ class ExpressionEvaluator {
|
||||
return left / right();
|
||||
case '%':
|
||||
return left % right();
|
||||
case 'in':
|
||||
return (right() as List).contains(left);
|
||||
case 'notIn':
|
||||
return !(right() as List).contains(left);
|
||||
}
|
||||
throw ArgumentError(
|
||||
'Unknown operator ${expression.operator} in expression');
|
||||
|
||||
@@ -123,7 +123,9 @@ class ExpressionParser {
|
||||
'-': 9,
|
||||
'*': 10,
|
||||
'/': 10,
|
||||
'%': 10
|
||||
'%': 10,
|
||||
'in': 11,
|
||||
'notIn': 11,
|
||||
};
|
||||
|
||||
// This function is responsible for gobbling an individual expression,
|
||||
|
||||
+21
-3
@@ -2,6 +2,19 @@ import 'dart:io';
|
||||
import 'parse_arguments.dart';
|
||||
import 'expressions/expressions.dart';
|
||||
|
||||
const FLAVORS = [
|
||||
'test',
|
||||
'tw',
|
||||
'cn',
|
||||
];
|
||||
|
||||
final _ctx = {
|
||||
'debug': 'debug',
|
||||
'release': 'release',
|
||||
'profile': 'profile',
|
||||
'default': 'default',
|
||||
};
|
||||
|
||||
String? exp;
|
||||
late String mode;
|
||||
late String flavor;
|
||||
@@ -19,6 +32,13 @@ void main(List<String> arguments) {
|
||||
mode = args.mode;
|
||||
flavor = args.flavor;
|
||||
|
||||
_ctx.addEntries(FLAVORS.map((e) => MapEntry(e, e)));
|
||||
|
||||
_ctx.addAll({
|
||||
'mode': mode,
|
||||
'flavor': flavor,
|
||||
});
|
||||
|
||||
var rootDir = Directory('./');
|
||||
rootDir.listSync().forEach(walkPath);
|
||||
}
|
||||
@@ -67,8 +87,7 @@ void walkPath(FileSystemEntity path) {
|
||||
state = STATE.none;
|
||||
tmp.clear();
|
||||
} else {
|
||||
if (evaluator.eval(
|
||||
Expression.parse(exp!), {'mode': mode, 'flavor': flavor})) {
|
||||
if (evaluator.eval(Expression.parse(exp!), _ctx)) {
|
||||
// 匹配到
|
||||
tmp.clear();
|
||||
state = STATE.caching;
|
||||
@@ -90,7 +109,6 @@ void walkPath(FileSystemEntity path) {
|
||||
if (modified) {
|
||||
file!.renameSync(path.path + '.bak');
|
||||
File(path.path).writeAsStringSync(sb.toString(), flush: true);
|
||||
print(sb.toString());
|
||||
}
|
||||
} catch (e) {
|
||||
if (!(e is FileSystemException)) {
|
||||
|
||||
+19
-10
@@ -6,6 +6,12 @@ SCRIPT_DIR=$(dirname "$SCRIPT_ABS")
|
||||
# shellcheck disable=SC2005
|
||||
DART_EXE=$(command -v dart)
|
||||
|
||||
JUST_REPLACE=0
|
||||
for i in "$@"
|
||||
do
|
||||
[ "$i" == "--replace" ] && JUST_REPLACE=1
|
||||
done
|
||||
|
||||
if [[ ! -x "$DART_EXE" ]]; then
|
||||
echo "Can't find dart executable file !"
|
||||
return 1
|
||||
@@ -30,23 +36,26 @@ fi
|
||||
|
||||
${DART_EXE} "$SCRIPT_DIR"/bin/pre_script.dart "$@"
|
||||
|
||||
flutter "$@"
|
||||
if [[ "$JUST_REPLACE" == 0 ]]; then
|
||||
|
||||
${DART_EXE} "$SCRIPT_DIR"/bin/after_script.dart "$@"
|
||||
flutter "$@"
|
||||
|
||||
if [[ -f "./.hooks/after_script.dart" ]]; then
|
||||
${DART_EXE} "$SCRIPT_DIR"/bin/after_script.dart "$@"
|
||||
|
||||
if [[ -f "./.hooks/after_script.dart" ]]; then
|
||||
${DART_EXE} ./.hooks/after_script.dart "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "./after_script.dart" ]]; then
|
||||
if [[ -f "./after_script.dart" ]]; then
|
||||
${DART_EXE} ./after_script.dart "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "./.hooks/after_script.sh" ]]; then
|
||||
if [[ -f "./.hooks/after_script.sh" ]]; then
|
||||
./.hooks/after_script.sh "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "./after_script.sh" ]]; then
|
||||
if [[ -f "./after_script.sh" ]]; then
|
||||
./after_script.sh "$@"
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user