From 005c4ebe8c93ed1b652154f38afe4f0a980c5fa1 Mon Sep 17 00:00:00 2001 From: Chen Peng Date: Wed, 8 May 2024 18:03:20 +0800 Subject: [PATCH] clean --- packages/you_cli/lib/src/cli_core.dart | 32 ++++++++++++------- .../test/{bin => src}/cli_core_test.dart | 3 -- 2 files changed, 21 insertions(+), 14 deletions(-) rename packages/you_cli/test/{bin => src}/cli_core_test.dart (94%) diff --git a/packages/you_cli/lib/src/cli_core.dart b/packages/you_cli/lib/src/cli_core.dart index 29a19c1f..bf1c5ab9 100644 --- a/packages/you_cli/lib/src/cli_core.dart +++ b/packages/you_cli/lib/src/cli_core.dart @@ -60,12 +60,13 @@ class YouCli { var children = await Future.wait(dir.listSync(recursive: false).whereType().map((e) async => await from(e))); var (layout: layoutFunction, toType: forBuildType) = await analyzeLayout(dir.childFile(layoutDart)); - + var pageAnno = await analyzePageAnno(dir.childFile(pageDart)); return RouteNode( cli: this, dir: dir, page: await analyzePage(dir.childFile(pageDart)), - layouot: layoutFunction, + pageAnno: pageAnno, + layout: layoutFunction, toType: forBuildType, children: children, ); @@ -115,26 +116,26 @@ class YouCli { return unit.topFunction(pageBuildFunctionName); } - Future analyzePageAnno(File file) async { + Future analyzePageAnno(File file) async { if (!await file.exists()) { return null; } GetUnit unit = await GetUnit.resolve(analysisSession, file); - return PageMetaObject.find(unit); + return PageAnnotation.find(unit); } } -class PageMetaObject { +class PageAnnotation { final Annotation annotation; final DartObject dartObject; final GetUnit unit; - PageMetaObject(this.annotation, this.dartObject, this.unit); + PageAnnotation(this.annotation, this.dartObject, this.unit); - static PageMetaObject? find(GetUnit unit) { + static PageAnnotation? find(GetUnit unit) { var anno = unit.annotationOnTopFunction(funcName: "build", annoType: "PageMeta"); if (anno == null) return null; - return PageMetaObject(anno.ast, anno.value, unit); + return PageAnnotation(anno.ast, anno.value, unit); } String get label => dartObject.getField("label")!.toStringValue()!; @@ -159,11 +160,20 @@ class RouteNode { final List children; final Directory dir; final Reference? toType; - final FunctionElement? layouot; + final FunctionElement? layout; final FunctionElement? page; late RouteNode _parent = this; - - RouteNode({required this.dir, this.toType, required this.children, this.layouot, this.page, required this.cli}) { + final PageAnnotation? pageAnno; + + RouteNode({ + required this.dir, + this.toType, + required this.children, + this.layout, + this.page, + required this.cli, + this.pageAnno, + }) { for (var child in children) { child._parent = this; } diff --git a/packages/you_cli/test/bin/cli_core_test.dart b/packages/you_cli/test/src/cli_core_test.dart similarity index 94% rename from packages/you_cli/test/bin/cli_core_test.dart rename to packages/you_cli/test/src/cli_core_test.dart index 70f70460..1b8b41d9 100644 --- a/packages/you_cli/test/bin/cli_core_test.dart +++ b/packages/you_cli/test/src/cli_core_test.dart @@ -1,8 +1,5 @@ -import 'package:path/path.dart' as path; import 'package:checks/checks.dart'; import 'package:code_builder/code_builder.dart'; -import 'package:file/file.dart'; -import 'package:file/local.dart'; import 'package:file/memory.dart'; import 'package:test/test.dart'; import 'package:you_cli/src/cli_core.dart';