From a28bbafa51315583ffa9cf1b8845e769d7f0062e Mon Sep 17 00:00:00 2001 From: Takayama Fumihiko Date: Tue, 10 Sep 2024 08:16:51 +0900 Subject: [PATCH] Change build output directory to public/build dist/build --- Makefile | 10 ++++----- scripts/make_distjson.py | 6 +++--- scripts/update-dist.sh | 38 ++++++++++++++++++++++++++++++++++ scripts/update-public-build.sh | 26 ----------------------- 4 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 scripts/update-dist.sh delete mode 100644 scripts/update-public-build.sh diff --git a/Makefile b/Makefile index 71435ea..56cdd66 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: build_rules python3 scripts/lint_groups.py '../public/groups.json' - bash scripts/update-public-build.sh + bash scripts/update-dist.sh build_rules: # There are cases where only public/json needs to be updated, so it is separated into `build_rules`. @@ -23,8 +23,8 @@ rebuild: touch ../src/json/* $(MAKE) all -update-public-build: - bash scripts/update-public-build.sh +update-dist: + bash scripts/update-dist.sh -server: - /usr/bin/python3 scripts/dev_server.py +preview-server: update-dist + (cd ../dist && /usr/bin/python3 ../core/scripts/preview_server.py) diff --git a/scripts/make_distjson.py b/scripts/make_distjson.py index 756e637..b9dff51 100644 --- a/scripts/make_distjson.py +++ b/scripts/make_distjson.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -'''Update public/build/dist.json''' +'''Update dist/build/dist.json''' import contextlib import glob @@ -27,7 +27,7 @@ def check_safe_path(path): def make_distjson(): - '''Update public/build/dist.json''' + '''Update dist/build/dist.json''' with remember_cwd(): os.chdir(f'{os.path.dirname(__file__)}/../../public') @@ -131,7 +131,7 @@ def make_distjson(): capture_output=True, check=False, encoding='utf-8') groups_json['updatedAt'] = int(git.stdout.strip()) - with open('build/dist.json', 'w', encoding='utf-8') as build_groups_json_file: + with open('../dist/build/dist.json', 'w', encoding='utf-8') as build_groups_json_file: json.dump(groups_json, build_groups_json_file, ensure_ascii=False, indent=2) diff --git a/scripts/update-dist.sh b/scripts/update-dist.sh new file mode 100644 index 0000000..7280b59 --- /dev/null +++ b/scripts/update-dist.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +set -u # forbid undefined variables +set -e # forbid command failure + +cd $(dirname "$0")/../.. + +# +# Update dist.json +# + +rm -fr dist +mkdir -p dist/build +/usr/bin/python3 core/scripts/make_distjson.py + +# +# Copy json +# + +cp -R public/json dist + +# +# Update extra_descriptions +# + +cp -R public/extra_descriptions dist/build + +for f in $(find dist/build/extra_descriptions -name '*.html'); do + echo '' >"$f.tmp" + cat "$f" >>"$f.tmp" + mv "$f.tmp" "$f" +done + +# +# Copy react files +# + +cp -R core/react/dist/* dist diff --git a/scripts/update-public-build.sh b/scripts/update-public-build.sh deleted file mode 100644 index a5f702c..0000000 --- a/scripts/update-public-build.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -u # forbid undefined variables -set -e # forbid command failure - -cd $(dirname "$0")/../../public - -# -# Update dist.json -# - -rm -fr build -mkdir -p build -/usr/bin/python3 ../core/scripts/make_distjson.py - -# -# Update extra_descriptions -# - -cp -R extra_descriptions build - -for f in $(find extra_descriptions -name '*.html'); do - mkdir -p $(dirname "build/$f") - echo '' >"build/$f" - cat "$f" >>"build/$f" -done