Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed May 8, 2024
1 parent 0b685a7 commit 005c4eb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
32 changes: 21 additions & 11 deletions packages/you_cli/lib/src/cli_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ class YouCli {

var children = await Future.wait(dir.listSync(recursive: false).whereType<Directory>().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,
);
Expand Down Expand Up @@ -115,26 +116,26 @@ class YouCli {
return unit.topFunction(pageBuildFunctionName);
}

Future<PageMetaObject?> analyzePageAnno(File file) async {
Future<PageAnnotation?> 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()!;
Expand All @@ -159,11 +160,20 @@ class RouteNode {
final List<RouteNode> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 005c4eb

Please sign in to comment.