Skip to content

Commit

Permalink
整理learn_dart
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Apr 28, 2024
1 parent 88eafa3 commit e65b258
Show file tree
Hide file tree
Showing 43 changed files with 10 additions and 23 deletions.
File renamed without changes.

This file was deleted.

This file was deleted.

Empty file.
16 changes: 10 additions & 6 deletions packages/you_cli/bin/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ class Cmd_gen_routes_g_dart extends Command {
final description = "gen routes.g.dart .";
final FileSystem fs;

YouCli? _cli;

YouCli get cli => _cli != null ? _cli! : _cli = YouCli(projectDir: dir);

// example:
// - async page:
// (context, print) async => await notes_i18n_.loadLibrary().then((_) => notes_i18n_.build(context, print))
Expand All @@ -96,13 +100,14 @@ class Cmd_gen_routes_g_dart extends Command {
if (layout != null) {
builder = code.refer("${layout.flatName}__").property("layout").call([builder]);
}

if (async) {
return code.Method((b) => b
..modifier = MethodModifier.async
..body = code.Block.of(
[
code.refer("${node.flatName}_").property("loadLibrary").call([]).awaited.statement,
if(layout != null) code.refer("${layout.flatName}__").property("loadLibrary").call([]).awaited.statement,
if (layout != null) code.refer("${layout.flatName}__").property("loadLibrary").call([]).awaited.statement,
builder.returned.statement,
],
)).closure;
Expand All @@ -112,15 +117,15 @@ class Cmd_gen_routes_g_dart extends Command {
}

String _genRouteTreeCode(RouteNode node) {
code.Expression? builder=builderExpression(node);
String builderStr=builder==null?"":builder.accept(code.DartEmitter()).toString().split("\n").join();
code.Expression? builder = builderExpression(node);
String builderStr = builder == null ? "" : builder.accept(code.DartEmitter()).toString().split("\n").join();

String buildArg = !node.page_dart.existsSync() ? "" : ",builder:$builderStr";
String padding = "".padLeft(node.level, ' ');
if (node.children.isEmpty) {
return '''${padding}To${async?".lazy":""}("${node.dir.basename}" $buildArg) ''';
return '''${padding}To${async ? ".lazy" : ""}("${node.dir.basename}" $buildArg) ''';
}
return '''${padding}To${async?".lazy":""}("${node.dir.basename}" $buildArg, children:[
return '''${padding}To${async ? ".lazy" : ""}("${node.dir.basename}" $buildArg, children:[
${node.children.map((child) => _genRouteTreeCode(child)).map((e) => "$e,").join("\n")}
$padding])''';
}
Expand All @@ -137,7 +142,6 @@ $padding])''';
throw AssertionError("【--dir $dir】 not exists");
}

YouCli cli = YouCli(projectDir: fs.directory(dir));
var rootRoute = RouteNode.fromSync(cli.routeDir);
Iterable<RouteNode> pageDirs = rootRoute.toList();

Expand Down

0 comments on commit e65b258

Please sign in to comment.