-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
yaml_variable_scanner: | ||
|
||
# File path for YAML variables | ||
yamlFilePath: | ||
- path: "src/_data/site.yml" # YAML path (Glob syntax) | ||
variablePrefix: "site." # Variable prefix. e.g. `a.` -> `a.x.xx` | ||
|
||
# Ignore YAML file path | ||
# | ||
# (Glob Syntax) | ||
ignoreYamlFilePath: | ||
|
||
# Ignore YAML Key | ||
# | ||
# e.g. "^a\.bb$" | ||
# | ||
# (RegExp Syntax) | ||
ignoreYamlKey: | ||
- ^site\.title$ | ||
- ^site\.url$ | ||
- ^site\.main-url$ | ||
- ^site\.github_username$ | ||
- ^site\.branch$ | ||
- ^site\.dart\.sdk\.channel$ | ||
- ^site\.sdk\.channel$ | ||
- ^site\.appmin\. | ||
- ^site\.devmin\. | ||
- ^site\.targetmin\. | ||
- ^site\.appnow\. | ||
- ^site\.bili\.std-size$ | ||
|
||
# File path for check file contents | ||
# | ||
# (Glob Syntax) | ||
checkFilePath: | ||
- "src/content/**/*.md" | ||
- "src/_includes/**/*.md" | ||
|
||
# Ignore file paths to check | ||
# | ||
# (Glob Syntax) | ||
ignoreCheckFilePath: | ||
- "src/content/release/release-notes/**" | ||
- "src/content/tools/devtools/release-notes/**" | ||
- "src/content/community/china-old.md" | ||
- "src/content/community/china/**" | ||
- "src/content/community/tutorials/**" | ||
- "src/content/posts/**" | ||
|
||
# Ignore text that doesn't need to match | ||
# | ||
# e.g. | ||
# - `r"^\s*---([\s\S]*?)---$"` | ||
# - `r"^\s*{%-?\s*comment\s*-?%}([\s\S]*?){%-?\s*endcomment\s*-?%}$"` | ||
# - `r"^\s*<!---?\s*([\s\S]*?)\s*-?-->$"` | ||
# | ||
# (RegExp Syntax) | ||
ignoreCheckText: | ||
# <!-- ignore-variable-check --> xxx <!-- end-ignore-variable-check --> | ||
- ^\s*<!---?\s*ignore-variable-check\s*-?-->([\s\S]*?)<!---?\s*end-ignore-variable-check\s*-?-->$ | ||
|
||
# --- xxx --- | ||
- ^\s*---([\s\S]*?)---$ | ||
|
||
# {%- comment %} xxx {% endcomment -%} | ||
- ^\s*{%-?\s*comment\s*-?%}([\s\S]*?){%-?\s*endcomment\s*-?%}$ | ||
|
||
# <!-- xxx --> | ||
- ^\s*<!---?\s*([\s\S]*?)\s*-?-->$ | ||
|
||
# ``` xxx ``` | ||
- ^\s*```([\s\S]*?)```$ | ||
|
||
# ` xxx ` | ||
- '`([^`]*)`' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tool/flutter_site/lib/src/commands/check_site_variable.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:yaml_variable_scanner/yaml_variable_scanner.dart'; | ||
|
||
import '../utils.dart'; | ||
|
||
final class CheckSiteVariableCommand extends Command<int> { | ||
static const String _printModeFlag = 'print-mode'; | ||
|
||
CheckSiteVariableCommand() { | ||
argParser.addOption( | ||
_printModeFlag, | ||
help: 'Configure the amount of information output.', | ||
allowed: ['none', 'detail', 'stats', 'detailAndStats'], | ||
allowedHelp: { | ||
'none': 'No content.', | ||
'detail': 'Detail to file lines and columns.', | ||
'stats': 'Total statistics.', | ||
'detailAndStats': 'detail & stats.', | ||
}, | ||
defaultsTo: 'detail', | ||
); | ||
} | ||
|
||
@override | ||
String get description => | ||
'Scan multiple files for text that can use site variables.'; | ||
|
||
@override | ||
String get name => 'check-site-variable'; | ||
|
||
@override | ||
Future<int> run() async { | ||
final printMode = argResults.get<String>(_printModeFlag, 'detail'); | ||
|
||
try { | ||
final checkResultAll = await YamlVariableScanner.run( | ||
'./tool/config/site_variable_scanner.yaml', | ||
stdout, | ||
printMode: PrintMode.values.byName(printMode), | ||
); | ||
if (checkResultAll.isNotEmpty) return 2; | ||
return 0; | ||
} catch (e, stackTrace) { | ||
stderr.writeln('Error: YamlVariableScanner failed to execute properly!'); | ||
stderr.writeln(e); | ||
stderr.writeln(stackTrace); | ||
return 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters