Skip to content

Commit

Permalink
[you_cli] clean
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed May 21, 2024
1 parent b414e49 commit 4759471
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/you_cli/bin/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ class Cmd_gen_routes_g_dart extends Command {
var fmt = DartFormatter(pageWidth: 200);
var dartEmitter = DartEmitterForCli(allocator: _allocator, orderDirectives: false, useNullSafetySyntax: true);
var allCode = '${all.accept(dartEmitter)}';
_log("gen: ${cli.file_routes_g_dart.path} : $allCode");
_log("gen: ${cli.path_routes_g_dart.path} : $allCode");
allCode = fmt.format(allCode);
await cli.file_routes_g_dart.writeAsString(allCode);
await cli.path_routes_g_dart.writeAsString(allCode);
// 暂时不格式化,因为要保持变量名后的padding,对齐变量更好看
// file.writeAsString(_fmt.format(toCode));
}
Expand Down
24 changes: 12 additions & 12 deletions packages/you_cli/lib/src/cli_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ import 'package:_you_dart_internal/src/pubspec.dart';
// final Glob _PAGE_GLOB = Glob("{**/page.dart,page.dart}");
class YouCli {
YouCli({required Directory projectDir})
: dir_project = projectDir.fileSystem.directory(path.normalize(path.absolute(projectDir.path))),
: path_project = projectDir.fileSystem.directory(path.normalize(path.absolute(projectDir.path))),
fs = projectDir.fileSystem;

static const Reference toType = Reference("To", "package:you_flutter/router.dart");
static const Reference toNoteType = Reference("ToNote", "package:you_flutter/note.dart");
static const Reference forPageType = Reference("To", "package:you_flutter/router.dart");
static const String layoutFunctionName = "build";
static const String pageFunctionName = "build";
final Directory dir_project;
final Directory path_project;
final FileSystem fs;
Pubspec? _pubspec;
RouteNode? _rootRoute;
AnalysisSession? _session;

Directory get dir_lib => dir_project.childDirectory("lib");
Directory get path_lib => path_project.childDirectory("lib");

Directory get dir_routes => dir_project.childDirectory("lib/routes");
Directory get path_routes => path_project.childDirectory("lib/routes");

Directory get dir_notes => dir_project.childDirectory("lib/routes/notes");
Directory get path_notes => path_project.childDirectory("lib/routes/notes");

File get file_routes_g_dart => dir_project.childFile("lib/routes.g.dart");
File get path_routes_g_dart => path_project.childFile("lib/routes.g.dart");

File get file_pubspec_yaml => dir_project.childFile("pubspec.yaml");
File get path_pubspec_yaml => path_project.childFile("pubspec.yaml");

Pubspec get pubspec => _pubspec ??= Pubspec.parse(file_pubspec_yaml.readAsStringSync());
Pubspec get pubspec => _pubspec ??= Pubspec.parse(path_pubspec_yaml.readAsStringSync());

AnalysisSession get analysisSession {
return _session ??= AnalysisContextCollection(
includedPaths: [dir_lib.path],
includedPaths: [path_lib.path],
resourceProvider: PhysicalResourceProvider(),
).contexts[0].currentSession;
}

Future<RouteNode> get rootRoute async => _rootRoute ??= await RouteNode.from(this, dir_routes);
Future<RouteNode> get rootRoute async => _rootRoute ??= await RouteNode.from(this, path_routes);

Future<FunctionElement?> analyzeLayout(File file) async {
if (!await file.exists()) {
Expand Down Expand Up @@ -156,11 +156,11 @@ class RouteNode {
}

String get pagePackageUrl {
return "package:${cli.pubspec.name}/${path.relative(file_page_dart.path, from: cli.dir_lib.path)}";
return "package:${cli.pubspec.name}/${path.relative(file_page_dart.path, from: cli.path_lib.path)}";
}

String get layoutPackageUrl {
return "package:${cli.pubspec.name}/${path.relative(file_layout_dart.path, from: cli.dir_lib.path)}";
return "package:${cli.pubspec.name}/${path.relative(file_layout_dart.path, from: cli.path_lib.path)}";
}

/// note name平整化,可作为变量名:
Expand Down
2 changes: 1 addition & 1 deletion packages/you_cli/test/src/cli_core_analyzer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void main() {
check(result!.displayName).equals("build");
});
test('page anno', () async {
var pageMeta = await cli.analyzePageAnno(cli.dir_lib.childFile("routes/notes/page.dart"));
var pageMeta = await cli.analyzePageAnno(cli.path_lib.childFile("routes/notes/page.dart"));
check(pageMeta!.label).equals("笔记");
check(pageMeta.toType).equals(YouCli.toNoteType);
check(pageMeta.toSource).equals('@NoteAnnotation(label: "笔记")');
Expand Down

0 comments on commit 4759471

Please sign in to comment.