Skip to content

Commit

Permalink
./bake 修正
Browse files Browse the repository at this point in the history
  • Loading branch information
chen56 committed Mar 25, 2024
1 parent d85774c commit ee3845f
Showing 1 changed file with 47 additions and 37 deletions.
84 changes: 47 additions & 37 deletions n
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@ _exec() {
##########################################

bake.cmd.set --cmd _root \
--usage "./$SCRIPT_PATH [cmd] [opts] [args...]" \
--usage "./$SCRIPT_FILE [cmd] [opts] [args...]" \
--summary "flutter-note build cli." \
--description "$( cat <<-EOF
___ _ _ _ _ _ _
| __|| | _ _ | |_ | |_ ___ _ _ | \| | ___ | |_ ___
| _| | || || || _|| _|/ -_)| '_| | . |/ _ \| _|/ -_)
|_| |_| \_._| \__| \__|\___||_| |_|\_|\___/ \__|\___|
flutter-note build tools.
https://github.com/chen56/note
Samples:
./${SCRIPT_PATH} # default run "get()"
./${SCRIPT_PATH} -h # show all commands help
./${SCRIPT_PATH} -h -v # show all commands help , include internal commands
./${SCRIPT_PATH} all flutter pub get # run "flutter pub get" on all mono projects
./${SCRIPT_PATH} note flutter pub get # run "flutter pub get" on note project
Examples:
./${SCRIPT_FILE} # same as './${SCRIPT_FILE} -h'
./${SCRIPT_FILE} -h # show all commands help
./${SCRIPT_FILE} -h -v # show all commands help , include internal function
./${SCRIPT_FILE} all pwd # run "pwd" on all mono projects
./${SCRIPT_FILE} all flutter pub get # run "flutter pub get" on all mono projects
./${SCRIPT_FILE} note flutter pub get # run "flutter pub get" on note project
EOF
)"
Expand All @@ -71,10 +77,13 @@ init() {
bake.opt.set --cmd all --name "aaa" --abbr h --type bool --default false --optHelp "print help, show all commands"
bake.opt.set --cmd all --name "bbb" --abbr v --type bool --default false --optHelp "verbose, show more info, more hidden commands"
bake.opt.set --cmd all --name "ccc" --type string --default info --optHelp "log level: debug, info, error"
all.a() { echo $@; }

bake.cmd.set --cmd all --summary "<mono> run cmd on all mono project" --usage "Usage: ./$SCRIPT_PATH all [any command]"
all() {


bake.cmd.set --cmd p --summary "<mono> project set" --usage "Usage: ./$SCRIPT_FILE all [any command]"
bake.cmd.set --cmd p.all --summary "<mono> run cmd on all mono project" --usage "Usage: ./$SCRIPT_FILE all [any command]"

p.all() {
# 目录中有"pubspec.yaml"的,认为是flutter项目
# for project in $( find . -name pubspec.yaml | sed s/pubspec.yaml$//g ) ; do
# # 用括号()开启子进程执行,可以不影响当前进程的环境
Expand All @@ -89,53 +98,54 @@ all() {
(cd spaces/flutter_note && _exec "$@")
}

bake.cmd.set --cmd note --summary "<project> run cmd on note project" --usage "./$SCRIPT_PATH note [any command]"
bake.cmd.set --cmd flutter_note --summary "<project> run cmd on flutter_note project" --usage "./$SCRIPT_PATH flutter_note [any command]"
bake.cmd.set --cmd mate --usage "./$SCRIPT_PATH mate [any command]"
bake.cmd.set --cmd mate_flutter --summary "<project> run cmd on mate_flutter project" --usage "./$SCRIPT_PATH mate_flutter [any command]"
bake.cmd.set --cmd note_test --summary "<project> run cmd on note_test project" --usage "./$SCRIPT_PATH note_test [any command]"
note() (cd note && _exec "$@")
flutter_note() (cd spaces/flutter_note && _exec "$@")
mate() (cd mate && _exec "$@")
mate_flutter() (cd mate_flutter && _exec "$@")
note_test() (cd note_test && _exec "$@")
note_tools() (cd note_tools && _exec "$@")

bake.cmd.set --cmd get --usage "./$SCRIPT_PATH get" --summary "<shortcut> ./bake all flutter pub get"
bake.cmd.set --cmd p.note --summary "<project> run cmd on note project" --usage "./$SCRIPT_FILE note [any command]"
bake.cmd.set --cmd p.flutter_note --summary "<project> run cmd on flutter_note project" --usage "./$SCRIPT_FILE flutter_note [any command]"
bake.cmd.set --cmd p.mate --usage "./$SCRIPT_FILE mate [any command]"
bake.cmd.set --cmd p.mate_flutter --summary "<project> run cmd on mate_flutter project" --usage "./$SCRIPT_FILE mate_flutter [any command]"
bake.cmd.set --cmd p.note_test --summary "<project> run cmd on note_test project" --usage "./$SCRIPT_FILE note_test [any command]"
p.note() (cd note && _exec "$@")
p.flutter_note() (cd spaces/flutter_note && _exec "$@")
p.mate() (cd mate && _exec "$@")
p.mate_flutter() (cd mate_flutter && _exec "$@")
p.note_test() (cd note_test && _exec "$@")
p.note_tools() (cd note_tools && _exec "$@")

bake.cmd.set --cmd get --usage "./$SCRIPT_FILE get" --summary "<shortcut> ./bake all flutter pub get"
get() { _exec all flutter pub get; }

bake.cmd.set --cmd test --usage "./$SCRIPT_PATH test" --summary "<shortcut> run all tests in all projects"
bake.cmd.set --cmd test --usage "./$SCRIPT_FILE test" --summary "<shortcut> run all tests in all projects"
bake.cmd.set --cmd test.bake --usage "./$SCRIPT_FILE test" --summary "<shortcut> run all tests in all projects"
test() (./test/bake2_test.bash test ; _exec all flutter test ;)
test.bake() ( ./test/bake2_test.bash test ; )

# get ip only work on macos
# shellcheck disable=SC2155
# local ip=$(ifconfig -l | xargs -n1 ipconfig getifaddr) || true
run.web() { flutter_note flutter run --web-port 8888 --web-renderer html --device-id chrome "$@"; }
run.macos() { flutter_note flutter run --device-id macos "$@"; }
run.web() { p.flutter_note flutter run --web-port 8888 --web-renderer html --device-id chrome "$@"; }
run.macos() { p.flutter_note flutter run --device-id macos "$@"; }

# skwasm无法运行
build.web_skwasm() { flutter_note flutter build web -v --release --tree-shake-icons --web-renderer skwasm "$@" ; }
build.web_canvaskit() { flutter_note flutter build web -v --release --tree-shake-icons --web-renderer canvaskit "$@" ; }
build.web_html() { flutter_note flutter build web -v --release --tree-shake-icons --web-renderer html "$@" ; }
build.web_skwasm() { p.flutter_note flutter build web -v --release --tree-shake-icons --web-renderer skwasm "$@" ; }
build.web_canvaskit() { p.flutter_note flutter build web -v --release --tree-shake-icons --web-renderer canvaskit "$@" ; }
build.web_html() { p.flutter_note 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_note/build/web --port 8000
# flutter pub global activate dhttpd
# _exec flutter_note dhttpd --path ./build/web --port 8080 '--headers=Cross-Origin-Embedder-Policy=credentialless;Cross-Origin-Opener-Policy=same-origin'
preview.web() { build "$@" ; _exec flutter_note deno run --allow-env --allow-read --allow-sys --allow-net npm:http-server ./build/web --port 8000 -g --brotli; }
# _exec p.flutter_note dhttpd --path ./build/web --port 8080 '--headers=Cross-Origin-Embedder-Policy=credentialless;Cross-Origin-Opener-Policy=same-origin'
preview.web() { build "$@" ; _exec p.flutter_note deno run --allow-env --allow-read --allow-sys --allow-net npm:http-server ./build/web --port 8000 -g --brotli; }

# http-server 不支持base href设置,所以单独build,并设置base-href为"/",而github-pages的base-href必须是repository名
# build "$@"
# npx http-server ./flutter_note/build/web --port 8000
web.serve() { _exec flutter_note deno run --allow-env --allow-read --allow-sys --allow-net npm:http-server ./build/web --port 8000 -g --brotli ;}
preview.macos() ( _exec flutter_note flutter build macos -v --release --tree-shake-icons "$@"; _exec flutter_note open build/macos/Build/Products/Release/flutter_note.app ; )
web.serve() { _exec p.flutter_note deno run --allow-env --allow-read --allow-sys --allow-net npm:http-server ./build/web --port 8000 -g --brotli ;}
preview.macos() ( _exec p.flutter_note flutter build macos -v --release --tree-shake-icons "$@"; _exec p.flutter_note open build/macos/Build/Products/Release/flutter_note.app ; )

clean() { all flutter clean; rm -rf build;}
gen.all() { _exec flutter_note dart run tools/gen.dart; _exec mate_flutter dart run tools/gen_mates.dart; _exec mate_flutter dart run tools/gen_mate_icons.dart; }
gen.notes() { _exec flutter_note dart run tools/gen.dart; _exec flutter_note flutter pub get; }
gen.mate() ( _exec mate_flutter dart run tools/gen_mates.dart; _exec mate_flutter dart run tools/gen_mate_icons.dart ; )
regen() { _exec rm -f flutter_note/lib/pages.g.dart; _exec rm -rf mate_flutter/lib; gen; }
gen.all() { _exec p.flutter_note dart run tools/gen.dart; _exec p.mate_flutter dart run tools/gen_mates.dart; _exec p.mate_flutter dart run tools/gen_mate_icons.dart; }
gen.notes() { _exec p.flutter_note dart run tools/gen.dart; _exec p.flutter_note flutter pub get; }
gen.mate() ( _exec p.mate_flutter dart run tools/gen_mates.dart; _exec p.mate_flutter dart run tools/gen_mate_icons.dart ; )
regen() { _exec rm -f p.flutter_note/lib/pages.g.dart; _exec rm -rf mate_flutter/lib; gen; }

docker.build() ( _exec docker build --progress plain --tag younpc/note:latest . ; _exec mkdir -p build/flutter_note/web; _exec sh -c "docker run --rm --workdir /usr/share/nginx/html/note younpc/note tar cf - ./ | ( cd build/flutter_note/web; tar xf -)";)
docker.run() { _exec echo "note preview http://localhost:8888/note/"; _exec docker run --rm --name note -p 8888:80 -u root:root younpc/note;}
Expand Down

0 comments on commit ee3845f

Please sign in to comment.