Skip to content

Commit

Permalink
api thinking
Browse files Browse the repository at this point in the history
update bake script
  • Loading branch information
chen56 committed Apr 17, 2024
1 parent 226219e commit 8f71268
Show file tree
Hide file tree
Showing 34 changed files with 372 additions and 314 deletions.
66 changes: 29 additions & 37 deletions bake
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ SCRIPT_FILE="$(basename "$SCRIPT_PATH")"
# 进入脚本所在目录,这样上下文就是本项目了
cd "$SCRIPT_DIR" || exit 200

upgrade_bake(){
bake.upgrade(){
mkdir -p "$SCRIPT_DIR/vendor"
echo "$SCRIPT_PATH -> upgrade_bake ▶︎【curl -o $SCRIPT_DIR/bake.bash https://github.com/chen56/bake/raw/main/bake.bash】"
echo "$SCRIPT_PATH -> bake.upgrade ▶︎【curl -o $SCRIPT_DIR/bake.bash https://github.com/chen56/bake/raw/main/bake.bash】"
curl -L -o "$SCRIPT_DIR/vendor/bake.bash" https://github.com/chen56/bake/raw/main/bake.bash ;
}
if ! [[ -f "$SCRIPT_DIR/vendor/bake.bash" ]]; then
upgrade_bake
bake.upgrade
fi

# include common script
Expand All @@ -28,50 +28,48 @@ source "$SCRIPT_DIR/vendor/bake.bash"
##########################################

declare -A _pkgs=(
["bake"]="$SCRIPT_DIR"
["learn_dart"]="$SCRIPT_DIR/notes/learn_dart"
["note"]="$SCRIPT_DIR/"
["note"]="$SCRIPT_DIR"
["note_dart"]="$SCRIPT_DIR/packages/note_dart"
["flutter"]="$SCRIPT_DIR/notes/flutter_core"
["qwik"]="$SCRIPT_DIR/notes/qwik"
["shell"]="$SCRIPT_DIR/notes/shell"
)

bake.cmd --cmd pkgs --desc "<mono> mono project manage: ./$SCRIPT_FILE pkgs <ls|run>"
pkgs.ls(){
ls(){
for pkg in ${!_pkgs[*]} ; do
echo "$pkg:${_pkgs[$pkg]}"
done
}

bake.cmd --cmd pkgs.run --desc "<mono> run cmd on all pkg,Usage: ./$SCRIPT_FILE pkgs run [any cmd]"
pkgs.run(){
run(){
for pkg in ${!_pkgs[*]} ; do
# 子shell内执行,防止环境感染
( cd "${_pkgs[$pkg]}" || exit 200 ; _run "$@" ; )
done
}

# 运行所用项目的某子命令
# Usage: pkgs._run_subcmd <subcmd>
# Example: pkgs._run_subcmd clean
# Usage: _run_on_all_package <subcmd>
# Example: _run_on_all_package clean
# run => note.clean
# mate.clean
# flutter.clean
# ...
pkgs._run_subcmd() {
_run_on_all_package() {
local subcmd="$1"
if [[ "$subcmd" == "" ]] ; then
echo "缺subcmd参数 Usage:pkgs._run_subcmd <subcmd>";
echo "缺subcmd参数 Usage:_run_on_all_package <subcmd>";
return 100;
fi
for pkg in "${!_pkgs[@]}"; do
if _func_exists "$pkg.$subcmd" ; then "$pkg.$subcmd" ; fi
done
}




# run一条命令,先print上下文信息,再执行
# Usage: _run <some cmd>
# Example:
Expand Down Expand Up @@ -103,8 +101,6 @@ _func_exists(){
fi
}



##########################################
# app cmd script
# 应用的命令脚本
Expand Down Expand Up @@ -143,54 +139,50 @@ Examples:
EOF
)"


note.run() { _run "$@";}
note.install() ( note.run dart pub get;)
note.clean() ( note.run rm -rf build;note.run rm -rf .dart_tool; )
note.upgrade() ( note.run dart pub upgrade ;)
note.test() ( note.run dart test;)
note.build() ( note.run dart compile exe bin/notecli.dart ;)

note_dart.run() ( cd packages/note_dart || return 200 && _run "$@")
note_dart.install() ( note_dart.run flutter pub get)
note_dart.clean() ( note_dart.run flutter clean; rm -rf build;)
note_dart.upgrade() ( note.run flutter pub upgrade ;)
note_dart.test() ( note_dart.run flutter test;)

flutter.run() ( cd notes/flutter_core && _run "$@")
flutter.install() ( flutter.run flutter pub get)
flutter.clean() ( flutter.run flutter clean; rm -rf build;)
flutter.gen() ( flutter.run dart run bin/gen.dart; )
flutter.upgrade() ( flutter.run flutter pub upgrade ;)
flutter.build() {
flutter.run flutter build web -v --release --tree-shake-icons --web-renderer html "$@" ;
}
flutter.build_macos() { flutter.run flutter build macos -v --release --tree-shake-icons "$@"; }
flutter.build_web_skwasm() { flutter.run flutter build web -v --release --tree-shake-icons --web-renderer skwasm "$@" ; }
flutter.build_web_canvaskit() { flutter.run flutter build web -v --release --tree-shake-icons --web-renderer canvaskit "$@" ; }
# get ip only work on macos
# shellcheck disable=SC2155
# local ip=$(ifconfig -l | xargs -n1 ipconfig getifaddr) || true
flutter.dev_web() { flutter.run flutter run --web-port 8888 --web-renderer html --device-id chrome "$@"; }
flutter.dev() { flutter.run flutter run --device-id macos "$@"; }
flutter.dev_web() { flutter.run flutter run --web-port 8888 --web-renderer html --device-id chrome "$@"; }
# skwasm无法运行
flutter.build_macos() { flutter.run flutter build macos -v --release --tree-shake-icons "$@"; }
flutter.build_web_skwasm() { flutter.run flutter build web -v --release --tree-shake-icons --web-renderer skwasm "$@" ; }
flutter.build_web_canvaskit() { flutter.run flutter build web -v --release --tree-shake-icons --web-renderer canvaskit "$@" ; }
flutter.build() {
flutter.run flutter build web -v --release --tree-shake-icons --web-renderer html "$@" ;
}
# http-server 不支持base href设置,所以单独build,并设置base-href为"/",而github-pages的base-href必须是repository名
# npx http-server ./flutter_core/build/web --port 8000
# flutter pub global activate dhttpd
# run p.flutter_core dhttpd --path ./build/web --port 8080 '--headers=Cross-Origin-Embedder-Policy=credentialless;Cross-Origin-Opener-Policy=same-origin'
flutter.preview() { flutter.run deno run --allow-env --allow-read --allow-sys --allow-net npm:http-server ./build/web --port 8000 -g --brotli; }
flutter.gen() ( dart run bin/notecli.dart gen --dir notes/flutter_core/ ; ) # mate_flutter.gen;暂时不用了

install(){ pkgs._run_subcmd install; }

upgrade() {
upgrade_bake;
}


# 执行 note.test、mate.test等命令
test() { pkgs._run_subcmd test; }
clean() { pkgs._run_subcmd clean; }

gen.all() ( dart run bin/notecli.dart gen --dir notes/flutter_core/ ; ) # mate_flutter.gen;暂时不用了
gen.clean() ( flutter.run rm -f ./lib/pages.g.dart; ) # 暂时不用了 _run rm -rf mate_flutter/lib;
install() { _run_on_all_package install; }
get() { _run_on_all_package install; }
upgrade() { _run_on_all_package upgrade;}
clean() { _run_on_all_package clean; }
test() { _run_on_all_package test; }
gen() { _run_on_all_package gen; }

# github 发布时使用,参考[.github/workflows/*.yaml]
docker.build() (
_run docker build --progress plain --tag younpc/note:latest . ;
_run mkdir -p build/flutter_core/web;
Expand Down
15 changes: 12 additions & 3 deletions notes/flutter_core/lib/notes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ import 'package:flutter_core/notes/Improve_app/RepaintBoundary/note.dart' deferr
import 'package:flutter_core/notes/Improve_app/RepaintBoundary/note.g.dart' as Improve_app_RepaintBoundary_g;
import 'package:flutter_core/notes/Improve_app/web_optimization/note.dart' deferred as Improve_app_web_optimization_;
import 'package:flutter_core/notes/Improve_app/web_optimization/note.g.dart' as Improve_app_web_optimization_g;
import 'package:flutter_core/notes/layout/box_layout/constraints/note.dart' deferred as layout_box_layout_constraints_;
import 'package:flutter_core/notes/layout/box_layout/constraints/note.g.dart' as layout_box_layout_constraints_g;
import 'package:flutter_core/notes/layout/note.dart' deferred as layout_;
import 'package:flutter_core/notes/layout/note.g.dart' as layout_g;
import 'package:flutter_core/notes/layout/old/layout/note.dart' deferred as layout_old_layout_;
import 'package:flutter_core/notes/layout/old/layout/note.g.dart' as layout_old_layout_g;
import 'package:flutter_core/notes/layout/responsive_design/note.dart' deferred as layout_responsive_design_;
import 'package:flutter_core/notes/layout/responsive_design/note.g.dart' as layout_responsive_design_g;
import 'package:flutter_core/notes/media&assets&file/assets/note.dart' deferred as media_assets_file_assets_;
import 'package:flutter_core/notes/media&assets&file/assets/note.g.dart' as media_assets_file_assets_g;
import 'package:flutter_core/notes/media&assets&file/file/note.dart' deferred as media_assets_file_file_;
Expand Down Expand Up @@ -97,8 +105,6 @@ import 'package:flutter_core/notes/x.note_inside/note_test_self/nobody/note.dart
import 'package:flutter_core/notes/x.note_inside/note_test_self/nobody/note.g.dart' as x_note_inside_note_test_self_nobody_g;
import 'package:flutter_core/notes/x.note_inside/note_test_self/note.dart' deferred as x_note_inside_note_test_self_;
import 'package:flutter_core/notes/x.note_inside/note_test_self/note.g.dart' as x_note_inside_note_test_self_g;
import 'package:flutter_core/notes/x.note_inside/note_test_self/temp/note.dart' deferred as x_note_inside_note_test_self_temp_;
import 'package:flutter_core/notes/x.note_inside/note_test_self/temp/note.g.dart' as x_note_inside_note_test_self_temp_g;
import 'package:flutter_core/notes/x.note_inside/research_parameterized_example/note.dart' deferred as x_note_inside_research_parameterized_example_;
import 'package:flutter_core/notes/x.note_inside/research_parameterized_example/note.g.dart' as x_note_inside_research_parameterized_example_g;

Expand All @@ -109,6 +115,10 @@ abstract class BaseNotes {
return rootroot.put(path,noteInfo,deferredPageBuilder);
}
final Note research_remote_view = put("/research/remote_view",research_remote_view_g.noteInfo(), (note) async => note.loadPage(builder:await research_remote_view_.loadLibrary().then((value) => research_remote_view_.build)));
final Note layout_old_layout = put("/layout/old/layout",layout_old_layout_g.noteInfo(), (note) async => note.loadPage(builder:await layout_old_layout_.loadLibrary().then((value) => layout_old_layout_.build)));
final Note layout_box_layout_constraints = put("/layout/box_layout/constraints",layout_box_layout_constraints_g.noteInfo(), (note) async => note.loadPage(builder:await layout_box_layout_constraints_.loadLibrary().then((value) => layout_box_layout_constraints_.build)));
final Note layout_responsive_design = put("/layout/responsive_design",layout_responsive_design_g.noteInfo(), (note) async => note.loadPage(builder:await layout_responsive_design_.loadLibrary().then((value) => layout_responsive_design_.build)));
final Note layout = put("/layout",layout_g.noteInfo(), (note) async => note.loadPage(builder:await layout_.loadLibrary().then((value) => layout_.build)));
final Note navigation = put("/navigation",navigation_g.noteInfo(), (note) async => note.loadPage(builder:await navigation_.loadLibrary().then((value) => navigation_.build)));
final Note state_vanilla_state = put("/state/1.vanilla_state",state_vanilla_state_g.noteInfo(), (note) async => note.loadPage(builder:await state_vanilla_state_.loadLibrary().then((value) => state_vanilla_state_.build)));
final Note state = put("/state",state_g.noteInfo(), (note) async => note.loadPage(builder:await state_.loadLibrary().then((value) => state_.build)));
Expand All @@ -135,7 +145,6 @@ abstract class BaseNotes {
final Note x_note_inside_research_parameterized_example = put("/x.note_inside/research_parameterized_example",x_note_inside_research_parameterized_example_g.noteInfo(), (note) async => note.loadPage(builder:await x_note_inside_research_parameterized_example_.loadLibrary().then((value) => x_note_inside_research_parameterized_example_.build)));
final Note x_note_inside_mockup_content = put("/x.note_inside/mockup_content",x_note_inside_mockup_content_g.noteInfo(), (note) async => note.loadPage(builder:await x_note_inside_mockup_content_.loadLibrary().then((value) => x_note_inside_mockup_content_.build)));
final Note x_note_inside_welcome = put("/x.note_inside/1.welcome",x_note_inside_welcome_g.noteInfo(), (note) async => note.loadPage(builder:await x_note_inside_welcome_.loadLibrary().then((value) => x_note_inside_welcome_.build)));
final Note x_note_inside_note_test_self_temp = put("/x.note_inside/note_test_self/temp",x_note_inside_note_test_self_temp_g.noteInfo(), (note) async => note.loadPage(builder:await x_note_inside_note_test_self_temp_.loadLibrary().then((value) => x_note_inside_note_test_self_temp_.build)));
final Note x_note_inside_note_test_self_nobody = put("/x.note_inside/note_test_self/nobody",x_note_inside_note_test_self_nobody_g.noteInfo(), (note) async => note.loadPage(builder:await x_note_inside_note_test_self_nobody_.loadLibrary().then((value) => x_note_inside_note_test_self_nobody_.build)));
final Note x_note_inside_note_test_self = put("/x.note_inside/note_test_self",x_note_inside_note_test_self_g.noteInfo(), (note) async => note.loadPage(builder:await x_note_inside_note_test_self_.loadLibrary().then((value) => x_note_inside_note_test_self_.build)));
final Note widgets_specific_widgets_input = put("/widgets/specific_widgets/input",widgets_specific_widgets_input_g.noteInfo(), (note) async => note.loadPage(builder:await widgets_specific_widgets_input_.loadLibrary().then((value) => widgets_specific_widgets_input_.build)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ noteInfo() => (
(
cellType: 'body',
offset: 166,
end: 2410,
end: 2409,
specialNodes: <({
String nodeType,
int end,
Expand All @@ -29,8 +29,8 @@ noteInfo() => (
/// ()
(
cellType: 'tail',
offset: 2410,
end: 4440,
offset: 2409,
end: 4439,
specialNodes: <({
String nodeType,
int end,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import 'package:flutter/material.dart';
import 'package:note_dart/note.dart';

build(BuildContext context, Pen print) {
print(Layer(title: const Text("布局"), style: const ContentLayout(maxColumn: 3), () {
print(Layer(title: const Text("box布局"), style: const ContentLayout(maxColumn: 3), () {
print(Layer(title: const Text("box布局 box布局.Column vs ListView"), style: const ContentLayout(maxColumn: 3), () {
print(const Text(""));
}));
}));
print(Layer(title: const Text("slaver布局"), style: const ContentLayout(maxColumn: 3), () {
print(const Text(""));
}));
}));



Layer(title: const Text("slaver布局"), style: const ContentLayout(maxColumn: 3), () {
Layer(title: const Text("box布局 box布局.Column vs ListView"), style: const ContentLayout(maxColumn: 3), () {
print(const Text(""));
});
Layer(title: const Text("box布局 box布局.Column vs ListView"), style: const ContentLayout(maxColumn: 3), () {
print(const Text(""));
});
});



}

void noUse(Pen print) {
var i = 1;
print.runInCurrentCell((print) {
print(i);
});

print.level(
title: const Text("1"),
style: const ContentLayout(
maxColumn: 3,
), () {
print(const Text("2"));
});

{
// ignore: unused_element
void x({Text title = const Text("ss")}) {
// 特殊语句
print.runInCurrentCell((print) {
print(i);
});
}

();

group(const Text("ss"), () {
// 特殊语句
print.runInCurrentCell((print) {
print(i);
});
});
print.level(
title: const Text("布局"),
style: const ContentLayout(
maxColumn: 3,
),
null)(() {
print.level(title: const Text("box布局"), style: const ContentLayout(maxColumn: 3), null)(() {
print.level(title: const Text("box布局.Column vs ListView"), style: const ContentLayout(maxColumn: 3), null)(() {
print(const Text(""));
});
});
print.level(null, title: const Text("slaver布局"), style: const ContentLayout(maxColumn: 3))(() {
print(const Text(""));
});
});
}
}

void group(Text text, Null Function() param1) {}

extension X on Pen {
XX level(Function()? block, {Text title = const Text(""), ContentLayout style = const ContentLayout()}) {
return XX(block, title: title, style: style);
}
}

class Layer extends StatelessWidget {
Layer(dynamic block, {super.key, Pen? print, Text title = const Text(""), Widget? textBox, ContentLayout style = const ContentLayout(), List<Widget> children = const <Widget>[]}) {
if (print != null) print(this);
}

@override
Widget build(BuildContext context) {
// TODO: implement build
throw UnimplementedError();
}
}

class XX {
Function()? block;
Text title;
ContentLayout style;

XX(this.block, {required this.title, required this.style});

call(Function() block) {}
}

class ContentLayout {
final int maxColumn;

const ContentLayout({this.maxColumn = 1});
}
Loading

0 comments on commit 8f71268

Please sign in to comment.