Skip to content

Commit

Permalink
clean,准备lib/pages 改为 lib/routes
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Apr 27, 2024
1 parent 68064f9 commit 1415beb
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import 'package:flutter/widgets.dart';
import 'package:you_note_dart/note.dart';

void build(BuildContext context, Cell print) {
void build(BuildContext context, Cell print) async{
print(const MD(r'''
# web 优化
Expand Down
213 changes: 106 additions & 107 deletions notes/flutter_web/lib/routes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,113 +72,112 @@ import 'package:flutter_web/pages/notes/x.note_inside/note_test_self/page.dart'
import 'package:flutter_web/pages/notes/layout.dart' as notes__;


var root = To("pages", children: [
To("notes", builder: notes__.layout(notes_.build), children: [
To("research", children: [
To("research_parameterized_example", builder: notes__.layout(notes_research_research_parameterized_example_.build)),
To("remote_view", builder: notes__.layout(notes_research_remote_view_.build)),
To("research_note_bash"),
]),
To("env_info", builder: notes__.layout(notes_env_info_.build)),
To("layout", builder: notes__.layout(notes_layout_.build), children: [
To("old", children: [
To("layout", builder: notes__.layout(notes_layout_old_layout_.build)),
]),
To("box_layout", children: [
To("constraints", builder: notes__.layout(notes_layout_box_layout_constraints_.build)),
]),
To("responsive_design", builder: notes__.layout(notes_layout_responsive_design_.build)),
To("1.welcome"),
]),
To("navigation", builder: notes__.layout(notes_navigation_.build), children: [
To("navigator_v1"),
To("navigator_v2"),
]),
To("state", builder: notes__.layout(notes_state_.build), children: [
To("1.vanilla_state", builder: notes__.layout(notes_state_vanilla_state_.build)),
To("StatefulBuilder", builder: notes__.layout(notes_state_StatefulBuilder_.build)),
]),
To("media&assets&file", children: [
To("file_desktop", builder: notes__.layout(notes_media_assets_file_file_desktop_.build)),
To("file_web", builder: notes__.layout(notes_media_assets_file_file_web_.build)),
To("assets", builder: notes__.layout(notes_media_assets_file_assets_.build)),
]),
To("style&theming", children: [
To("material3", builder: notes__.layout(notes_style_theming_material3_.build)),
To("Material"),
]),
To("pure_dart", children: [
To("dart3", builder: notes__.layout(notes_pure_dart_dart3_.build)),
To("async", builder: notes__.layout(notes_pure_dart_async_.build)),
To("safe_interface", builder: notes__.layout(notes_pure_dart_safe_interface_.build)),
To("execption", builder: notes__.layout(notes_pure_dart_execption_.build)),
To("serialization_json", builder: notes__.layout(notes_pure_dart_serialization_json_.build)),
To("analyzer", builder: notes__.layout(notes_pure_dart_analyzer_.build)),
]),
To("dev", children: [
To("host_mirror", builder: notes__.layout(notes_dev_host_mirror_.build)),
To("macos_config", builder: notes__.layout(notes_dev_macos_config_.build)),
To("devtool", builder: notes__.layout(notes_dev_devtool_.build), children: [
To("vmservice", builder: notes__.layout(notes_dev_devtool_vmservice_.build)),
]),
To("debug", builder: notes__.layout(notes_dev_debug_.build)),
]),
To("i18n", builder: notes__.layout(notes_i18n_.build)),
To("thinking_in_ui", children: [
To("readable_html_vs_dart", builder: notes__.layout(notes_thinking_in_ui_readable_html_vs_dart_.build)),
]),
To("x.note_inside", children: [
To("how_note_work", builder: notes__.layout(notes_x_note_inside_how_note_work_.build)),
To("note_api_thinking"),
To("mockup_content", builder: notes__.layout(notes_x_note_inside_mockup_content_.build)),
To("1.welcome", builder: notes__.layout(notes_x_note_inside_welcome_.build)),
To("note_test_self", builder: notes__.layout(notes_x_note_inside_note_test_self_.build), children: [
To("nobody", builder: notes__.layout(notes_x_note_inside_note_test_self_nobody_.build)),
]),
]),
To("widgets", children: [
To("specific_widgets", children: [
To("input", builder: notes__.layout(notes_widgets_specific_widgets_input_.build)),
To("webview", builder: notes__.layout(notes_widgets_specific_widgets_webview_.build)),
To("slider", builder: notes__.layout(notes_widgets_specific_widgets_slider_.build)),
To("selectable", builder: notes__.layout(notes_widgets_specific_widgets_selectable_.build)),
To("button", children: [
To("ButtonStyleButton", builder: notes__.layout(notes_widgets_specific_widgets_button_ButtonStyleButton_.build)),
To("FloatingActionButton", builder: notes__.layout(notes_widgets_specific_widgets_button_FloatingActionButton_.build)),
To("IconButton", builder: notes__.layout(notes_widgets_specific_widgets_button_IconButton_.build)),
To("overview", builder: notes__.layout(notes_widgets_specific_widgets_button_overview_.build)),
]),
To("Divider"),
To("text", children: [
To("RichText", builder: notes__.layout(notes_widgets_specific_widgets_text_RichText_.build)),
To("Text", builder: notes__.layout(notes_widgets_specific_widgets_text_Text_.build)),
]),
To("icon", builder: notes__.layout(notes_widgets_specific_widgets_icon_.build)),
]),
To("container_widgets", children: [
To("drawer"),
To("Card"),
To("app"),
To("dialog"),
To("menu", builder: notes__.layout(notes_widgets_container_widgets_menu_.build)),
To("scrollable", children: [
To("Dismissible", builder: notes__.layout(notes_widgets_container_widgets_scrollable_Dismissible_.build)),
To("DraggableScrollableSheet"),
]),
To("page_view"),
To("bar", builder: notes__.layout(notes_widgets_container_widgets_bar_.build)),
]),
]),
To("Improve_app", builder: notes__.layout(notes_Improve_app_.build), children: [
To("1.overview", builder: notes__.layout(notes_Improve_app_overview_.build)),
To("error_handle"),
To("web_optimization", builder: notes__.layout(notes_Improve_app_web_optimization_.build)),
To("RepaintBoundary", builder: notes__.layout(notes_Improve_app_RepaintBoundary_.build)),
To("event&listener&lifeycle", builder: notes__.layout(notes_Improve_app_event_listener_lifeycle_.build)),
]),
]),
]);

var root=To("pages" , children:[
To("notes" ,builder:notes__.layout(notes_.build), children:[
To("research" , children:[
To("research_parameterized_example" ,builder:notes__.layout(notes_research_research_parameterized_example_.build)) ,
To("remote_view" ,builder:notes__.layout(notes_research_remote_view_.build)) ,
To("research_note_bash" ) ,
]),
To("env_info" ,builder:notes__.layout(notes_env_info_.build)) ,
To("layout" ,builder:notes__.layout(notes_layout_.build), children:[
To("old" , children:[
To("layout" ,builder:notes__.layout(notes_layout_old_layout_.build)) ,
]),
To("box_layout" , children:[
To("constraints" ,builder:notes__.layout(notes_layout_box_layout_constraints_.build)) ,
]),
To("responsive_design" ,builder:notes__.layout(notes_layout_responsive_design_.build)) ,
To("1.welcome" ) ,
]),
To("navigation" ,builder:notes__.layout(notes_navigation_.build), children:[
To("navigator_v1" ) ,
To("navigator_v2" ) ,
]),
To("state" ,builder:notes__.layout(notes_state_.build), children:[
To("1.vanilla_state" ,builder:notes__.layout(notes_state_vanilla_state_.build)) ,
To("StatefulBuilder" ,builder:notes__.layout(notes_state_StatefulBuilder_.build)) ,
]),
To("media&assets&file" , children:[
To("file_desktop" ,builder:notes__.layout(notes_media_assets_file_file_desktop_.build)) ,
To("file_web" ,builder:notes__.layout(notes_media_assets_file_file_web_.build)) ,
To("assets" ,builder:notes__.layout(notes_media_assets_file_assets_.build)) ,
]),
To("style&theming" , children:[
To("material3" ,builder:notes__.layout(notes_style_theming_material3_.build)) ,
To("Material" ) ,
]),
To("pure_dart" , children:[
To("dart3" ,builder:notes__.layout(notes_pure_dart_dart3_.build)) ,
To("async" ,builder:notes__.layout(notes_pure_dart_async_.build)) ,
To("safe_interface" ,builder:notes__.layout(notes_pure_dart_safe_interface_.build)) ,
To("execption" ,builder:notes__.layout(notes_pure_dart_execption_.build)) ,
To("serialization_json" ,builder:notes__.layout(notes_pure_dart_serialization_json_.build)) ,
To("analyzer" ,builder:notes__.layout(notes_pure_dart_analyzer_.build)) ,
]),
To("dev" , children:[
To("host_mirror" ,builder:notes__.layout(notes_dev_host_mirror_.build)) ,
To("macos_config" ,builder:notes__.layout(notes_dev_macos_config_.build)) ,
To("devtool" ,builder:notes__.layout(notes_dev_devtool_.build), children:[
To("vmservice" ,builder:notes__.layout(notes_dev_devtool_vmservice_.build)) ,
]),
To("debug" ,builder:notes__.layout(notes_dev_debug_.build)) ,
]),
To("i18n" ,builder:notes__.layout(notes_i18n_.build)) ,
To("thinking_in_ui" , children:[
To("readable_html_vs_dart" ,builder:notes__.layout(notes_thinking_in_ui_readable_html_vs_dart_.build)) ,
]),
To("x.note_inside" , children:[
To("how_note_work" ,builder:notes__.layout(notes_x_note_inside_how_note_work_.build)) ,
To("note_api_thinking" ) ,
To("mockup_content" ,builder:notes__.layout(notes_x_note_inside_mockup_content_.build)) ,
To("1.welcome" ,builder:notes__.layout(notes_x_note_inside_welcome_.build)) ,
To("note_test_self" ,builder:notes__.layout(notes_x_note_inside_note_test_self_.build), children:[
To("nobody" ,builder:notes__.layout(notes_x_note_inside_note_test_self_nobody_.build)) ,
]),
]),
To("widgets" , children:[
To("specific_widgets" , children:[
To("input" ,builder:notes__.layout(notes_widgets_specific_widgets_input_.build)) ,
To("webview" ,builder:notes__.layout(notes_widgets_specific_widgets_webview_.build)) ,
To("slider" ,builder:notes__.layout(notes_widgets_specific_widgets_slider_.build)) ,
To("selectable" ,builder:notes__.layout(notes_widgets_specific_widgets_selectable_.build)) ,
To("button" , children:[
To("ButtonStyleButton" ,builder:notes__.layout(notes_widgets_specific_widgets_button_ButtonStyleButton_.build)) ,
To("FloatingActionButton" ,builder:notes__.layout(notes_widgets_specific_widgets_button_FloatingActionButton_.build)) ,
To("IconButton" ,builder:notes__.layout(notes_widgets_specific_widgets_button_IconButton_.build)) ,
To("overview" ,builder:notes__.layout(notes_widgets_specific_widgets_button_overview_.build)) ,
]),
To("Divider" ) ,
To("text" , children:[
To("RichText" ,builder:notes__.layout(notes_widgets_specific_widgets_text_RichText_.build)) ,
To("Text" ,builder:notes__.layout(notes_widgets_specific_widgets_text_Text_.build)) ,
]),
To("icon" ,builder:notes__.layout(notes_widgets_specific_widgets_icon_.build)) ,
]),
To("container_widgets" , children:[
To("drawer" ) ,
To("Card" ) ,
To("app" ) ,
To("dialog" ) ,
To("menu" ,builder:notes__.layout(notes_widgets_container_widgets_menu_.build)) ,
To("scrollable" , children:[
To("Dismissible" ,builder:notes__.layout(notes_widgets_container_widgets_scrollable_Dismissible_.build)) ,
To("DraggableScrollableSheet" ) ,
]),
To("page_view" ) ,
To("bar" ,builder:notes__.layout(notes_widgets_container_widgets_bar_.build)) ,
]),
]),
To("Improve_app" ,builder:notes__.layout(notes_Improve_app_.build), children:[
To("1.overview" ,builder:notes__.layout(notes_Improve_app_overview_.build)) ,
To("error_handle" ) ,
To("web_optimization" ,builder:notes__.layout(notes_Improve_app_web_optimization_.build)) ,
To("RepaintBoundary" ,builder:notes__.layout(notes_Improve_app_RepaintBoundary_.build)) ,
To("event&listener&lifeycle" ,builder:notes__.layout(notes_Improve_app_event_listener_lifeycle_.build)) ,
]),
]),
]) ;

final Routes routes=Routes();

Expand Down
60 changes: 32 additions & 28 deletions packages/you_cli/bin/cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ main(List<String> args) async {
var runner = CommandRunner("note", "you page tools.");
runner.addCommand(
Cmd_gen(fs: fs)
..addSubcommand(Cmd_gen_all(fs: fs))..addSubcommand(Cmd_gen_routes_g_dart(fs: fs)),
..addSubcommand(Cmd_gen_all(fs: fs))
..addSubcommand(Cmd_gen_routes_g_dart(fs: fs)),
);

await runner.run(args);
Expand All @@ -38,22 +39,24 @@ main(List<String> args) async {
class CliSystem {
CliSystem({required this.pkgDir})
: fs = pkgDir.fileSystem,
pubspec = Pubspec.parseFileSync(pkgDir.childFile("pubspec.yaml"));
pubspec = Pubspec.parseFileSync(pkgDir.childFile("pubspec.yaml"))
;

Directory pkgDir;
FileSystem fs;
Pubspec pubspec;

Directory get pagesDir => pkgDir.childDirectory(_PAGES_ROOT);
RouteNode get routeRoot=> RouteNode.fromSync(routeDir);

Directory get notesDir => pkgDir.childDirectory(_NOTES_ROOT);
Directory get routeDir => pkgDir.childDirectory(_PAGES_ROOT);

Directory get notesRouteDir => pkgDir.childDirectory(_NOTES_ROOT);

Directory get libDir => pkgDir.childDirectory(_LIB_ROOT);

Stream<PageLib> pages() {
var noteRootDir = pkgDir.childDirectory(_NOTES_ROOT);
return _PAGE_GLOB.listFileSystem(fs, root: noteRootDir.path).where((e) => e is File).map((e) =>
PageLib(
return _PAGE_GLOB.listFileSystem(fs, root: noteRootDir.path).where((e) => e is File).map((e) => PageLib(
file: e as File,
pkgName: pubspec.name,
pkgDir: pkgDir,
Expand Down Expand Up @@ -104,6 +107,8 @@ class Cmd_gen_routes_g_dart extends Command {

Cmd_gen_routes_g_dart.libMode({
required this.fs,
required this.async,
required this.dir,
}) : libMode = true;

bool libMode;
Expand All @@ -121,29 +126,31 @@ class Cmd_gen_routes_g_dart extends Command {
// (context, print) async => await notes_i18n_.loadLibrary().then((_) => notes_i18n_.build(context, print))
// - async layout + page :
// notes_layout.layout((context, print) async => await notes_i18n_.loadLibrary().then((_) => notes_i18n_.build(context, print)))
String _builderExpression(PageDir node) {
String builderExpression(RouteNode node) {
if (!node.page_dart.existsSync()) {
return '';
}
String builder = '${node.flatName}_.build';
PageDir? layout = node.findLayoutSync();
RouteNode? layout = node.findLayoutSync();
if (layout != null) {
builder = "${layout.flatName}__.layout($builder)";
}
if (async) {
// return '()async{ await ${node.flatName}_.loadLibrary(); await ${node.flatName}__.loadLibrary(); return ${node.flatName}__.layout(${node.flatName}_.build); }';
return '(context,print)async=> await ${node.flatName}_.loadLibrary().then((_) => $builder(context,print))';
} else {
return builder;
}
}

String _genRouteTreeCode(PageDir node) {
String buildArg = !node.page_dart.existsSync() ? "" : ",${async ? "builderAsync" : "builder"}:${_builderExpression(node)}";
String _genRouteTreeCode(RouteNode node) {
String buildArg = !node.page_dart.existsSync() ? "" : ",${async ? "builderAsync" : "builder"}:${builderExpression(node)}";
String padding = "".padLeft(node.level, ' ');
if (node.children.isEmpty) {
return '''To("${node.dir.basename}" $buildArg)''';
return '''${padding}To("${node.dir.basename}" $buildArg) ''';
}
return '''To("${node.dir.basename}" $buildArg, children:[
${node.children.map((e) => _genRouteTreeCode(e)).map((e) => "$e,").join("")}
return '''${padding}To("${node.dir.basename}" $buildArg, children:[
${node.children.map((child) => _genRouteTreeCode(child)).map((e) => "$e,").join("\n")}
])''';
}

Expand All @@ -153,15 +160,15 @@ ${node.children.map((e) => _genRouteTreeCode(e)).map((e) => "$e,").join("")}
if (!libMode) {
String dirOpt = argResults!["dir"];
dir = fs.directory(path.absolute(dirOpt));
if (!dir.existsSync()) {
throw AssertionError("【--dir $dir】 not exists");
}
async = argResults!.flag("async");
}
if (!dir.existsSync()) {
throw AssertionError("【--dir $dir】 not exists");
}

CliSystem cli = CliSystem(pkgDir: fs.directory(dir));
var rootRoute = PageDir.fromSync(cli.pagesDir);
Iterable<PageDir> pageDirs = rootRoute.toList();
var rootRoute = RouteNode.fromSync(cli.routeDir);
Iterable<RouteNode> pageDirs = rootRoute.toList();

var nameMaxLen = pageDirs.map((e) => e.flatName.length).reduce((value, element) => value > element ? value : element);
pageDirs.where((e) => e.page_dart.existsSync()).map((pageDir) {
Expand All @@ -175,8 +182,7 @@ ${node.children.map((e) => _genRouteTreeCode(e)).map((e) => "$e,").join("")}
return """ final $varWithPadding = root.find("${routeDir.routePath}")! ; """;
}).join("\n");

Library pageImports = Library((b) =>
b
Library pageImports = Library((b) => b
..directives.addAll(
pageDirs.where((e) => e.page_dart.existsSync()).map((lib) {
if (async) {
Expand All @@ -187,8 +193,7 @@ ${node.children.map((e) => _genRouteTreeCode(e)).map((e) => "$e,").join("")}
}),
));
Library layoutImports = Library(
(b) =>
b
(b) => b
..directives.addAll(
pageDirs.where((e) => e.layout_dart.existsSync()).map((lib) {
if (async) {
Expand All @@ -205,7 +210,8 @@ ${node.children.map((e) => _genRouteTreeCode(e)).map((e) => "$e,").join("")}
String pageImportsCode = fmt.format('${pageImports.accept(dartEmitter)}');
String layoutImportsCode = fmt.format('${layoutImports.accept(dartEmitter)}');

String routeConfigCode = fmt.format("var root=${_genRouteTreeCode(rootRoute)} ;");
String routeConfigCode = "var root=${_genRouteTreeCode(rootRoute)} ;";
// routeConfigCode = fmt.format("var root=${_genRouteTreeCode(rootRoute)} ;");

String allCode = """
// Generated by https://github.com/chen56/you
Expand Down Expand Up @@ -256,8 +262,7 @@ class PageLib {
required this.file,
required this.pkgName,
required this.pkgDir,
})
: fs = file.fileSystem,
}) : fs = file.fileSystem,
libDir = pkgDir.childDirectory(_LIB_ROOT),
pagesRootDir = pkgDir.childDirectory(_PAGES_ROOT);

Expand All @@ -280,9 +285,8 @@ class PageLib {
}
var names = dir.split(path.separator).where((e) => e.isNotEmpty);
return names
.map((e) =>
e
// ignore: unnecessary_string_escapes
.map((e) => e
// ignore: unnecessary_string_escapes
.replaceAll(RegExp("^\\d+\."), "") // 1.z.about -> note_note-self
.replaceAll(".", "_")
.replaceAll("-", "_")
Expand Down
Loading

0 comments on commit 1415beb

Please sign in to comment.