From 403ad5827412fed4f916f472a99ba68f78d44d84 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Wed, 17 Feb 2021 14:32:03 +0000 Subject: [PATCH] move all scripts to scripts/ --- .goreleaser.yml | 10 +-- Makefile | 12 ++-- config/config-base.json | 24 ------- embed.py | 68 ------------------- embed/README.md | 1 + embed/external.go | 20 ++++++ embed/internal.go | 38 +++++++++++ package.json | 1 + mail/generate.py => scripts/compile_mjml.py | 2 +- scripts/embed.py | 22 ++++++ .../enumerate_config.py | 0 {config => scripts}/generate_ini.py | 0 version.py => scripts/version.py | 0 13 files changed, 94 insertions(+), 104 deletions(-) delete mode 100755 embed.py create mode 100644 embed/README.md create mode 100644 embed/external.go create mode 100644 embed/internal.go rename mail/generate.py => scripts/compile_mjml.py (96%) create mode 100755 scripts/embed.py rename config/fixconfig.py => scripts/enumerate_config.py (100%) rename {config => scripts}/generate_ini.py (100%) rename version.py => scripts/version.py (100%) diff --git a/.goreleaser.yml b/.goreleaser.yml index d0acc5e..eb89483 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,16 +17,16 @@ before: - cp node_modules/remixicon/fonts/remixicon.css node_modules/remixicon/fonts/remixicon.woff2 data/web/css/ - cp -r html data/ - cp -r lang data/ - - python3 config/fixconfig.py -i config/config-base.json -o data/config-base.json - - python3 config/generate_ini.py -i config/config-base.json -o data/config-default.ini - - python3 mail/generate.py -o data/ - - python3 version.py {{.Version}} version.go + - python3 scripts/enumerate_config.py -i config/config-base.json -o data/config-base.json + - python3 scripts/generate_ini.py -i config/config-base.json -o data/config-default.ini + - python3 scripts/compile_mjml.py -o data/ + - python3 scripts/version.py {{.Version}} - npx esbuild --bundle ts/admin.ts --outfile=./data/web/js/admin.js --minify - npx esbuild --bundle ts/form.ts --outfile=./data/web/js/form.js --minify - npx esbuild --bundle ts/setup.ts --outfile=./data/web/js/setup.js --minify - go get -u github.com/swaggo/swag/cmd/swag - swag init -g main.go - - python3 embed.py internal + - python3 scripts/embed.py internal builds: - dir: ./ env: diff --git a/Makefile b/Makefile index 33bb3d2..1281c65 100644 --- a/Makefile +++ b/Makefile @@ -18,13 +18,13 @@ npm: configuration: $(info Fixing config-base) -mkdir -p data - python3 config/fixconfig.py -i config/config-base.json -o data/config-base.json + python3 scripts/enumerate_config.py -i config/config-base.json -o data/config-base.json $(info Generating config-default.ini) - python3 config/generate_ini.py -i config/config-base.json -o data/config-default.ini + python3 scripts/generate_ini.py -i config/config-base.json -o data/config-default.ini email: $(info Generating email html) - python3 mail/generate.py -o data/ + python3 scripts/compile_mjml.py -o data/ typescript: $(info compiling typescript) @@ -48,7 +48,7 @@ swagger: swag init -g main.go version: - python3 version.py auto version.go + python3 scripts/version.py auto compile: $(info Downloading deps) @@ -84,10 +84,10 @@ copy: cp -r lang data/ embed: - python embed.py internal + python scripts/embed.py internal noembed: - python embed.py external + python scripts/embed.py external -mkdir -p build $(info copying internal data into build/) cp -r data build/ diff --git a/config/config-base.json b/config/config-base.json index a64625b..1d6a6d3 100644 --- a/config/config-base.json +++ b/config/config-base.json @@ -821,30 +821,6 @@ "value": "", "description": "Location of stored Ombi user template." }, - "user_template": { - "name": "User Template (Deprecated)", - "required": false, - "requires_restart": true, - "type": "text", - "value": "", - "description": "Deprecated in favor of User Profiles. Location of stored user policy template (json)." - }, - "user_configuration": { - "name": "userConfiguration (Deprecated)", - "required": false, - "requires_restart": true, - "type": "text", - "value": "", - "description": "Deprecated in favor of User Profiles. Location of stored user configuration template (used for setting homescreen layout) (json)" - }, - "user_displayprefs": { - "name": "displayPreferences (Deprecated)", - "required": false, - "requires_restart": true, - "type": "text", - "value": "", - "description": "Deprecated in favor of User Profiles. Location of stored displayPreferences template (also used for homescreen layout) (json)" - }, "user_profiles": { "name": "User Profiles", "required": false, diff --git a/embed.py b/embed.py deleted file mode 100755 index d420031..0000000 --- a/embed.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/python -import sys -import argparse - -parser = argparse.ArgumentParser() -parser.add_argument("embed", metavar="||", type=str) -trues = ["true", "internal", "yes", "y"] -falses = ["false", "external", "no", "n"] - -EMBED = parser.parse_args().embed - -with open("embed.go", "w") as f: - if EMBED in trues: - f.write("""package main -import ( - "embed" - "io/fs" - "log" -) - -//go:embed data data/html data/web data/web/css data/web/js -var loFS embed.FS - -//go:embed lang/common lang/admin lang/email lang/form lang/setup -var laFS embed.FS - -var langFS rewriteFS -var localFS rewriteFS - -type rewriteFS struct { - fs embed.FS - prefix string -} - -func (l rewriteFS) Open(name string) (fs.File, error) { return l.fs.Open(l.prefix + name) } -func (l rewriteFS) ReadDir(name string) ([]fs.DirEntry, error) { return l.fs.ReadDir(l.prefix + name) } -func (l rewriteFS) ReadFile(name string) ([]byte, error) { return l.fs.ReadFile(l.prefix + name) } -func FSJoin(elem ...string) string { - out := "" - for _, v := range elem { out += v + "/" } - return out[:len(out)-1] -} - -func loadFilesystems() { - langFS = rewriteFS{laFS, "lang/"} - localFS = rewriteFS{loFS, "data/"} - log.Println("Using internal storage") -}""") - elif EMBED in falses: - f.write("""package main -import ( - "io/fs" - "os" - "log" - "path/filepath" -) - -var localFS fs.FS -var langFS fs.FS - -func FSJoin(elem ...string) string { return filepath.Join(elem...) } - -func loadFilesystems() { - log.Println("Using external storage") - executable, _ := os.Executable() - localFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data")) - langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data", "lang")) -}""") diff --git a/embed/README.md b/embed/README.md new file mode 100644 index 0000000..5055915 --- /dev/null +++ b/embed/README.md @@ -0,0 +1 @@ +`scripts/embed.py [internal/external]` will copy the respective file into the main directory. If internal, `//go:embed` is used to embed the `data/` directory in the binary. If external, `os.DirFS` is used to access the `data/` directory, which should be placed next to the executable. diff --git a/embed/external.go b/embed/external.go new file mode 100644 index 0000000..611f4b0 --- /dev/null +++ b/embed/external.go @@ -0,0 +1,20 @@ +package main + +import ( + "io/fs" + "log" + "os" + "path/filepath" +) + +var localFS fs.FS +var langFS fs.FS + +func FSJoin(elem ...string) string { return filepath.Join(elem...) } + +func loadFilesystems() { + log.Println("Using external storage") + executable, _ := os.Executable() + localFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data")) + langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data", "lang")) +} diff --git a/embed/internal.go b/embed/internal.go new file mode 100644 index 0000000..365f515 --- /dev/null +++ b/embed/internal.go @@ -0,0 +1,38 @@ +package main + +import ( + "embed" + "io/fs" + "log" +) + +//go:embed data data/html data/web data/web/css data/web/js +var loFS embed.FS + +//go:embed lang/common lang/admin lang/email lang/form lang/setup +var laFS embed.FS + +var langFS rewriteFS +var localFS rewriteFS + +type rewriteFS struct { + fs embed.FS + prefix string +} + +func (l rewriteFS) Open(name string) (fs.File, error) { return l.fs.Open(l.prefix + name) } +func (l rewriteFS) ReadDir(name string) ([]fs.DirEntry, error) { return l.fs.ReadDir(l.prefix + name) } +func (l rewriteFS) ReadFile(name string) ([]byte, error) { return l.fs.ReadFile(l.prefix + name) } +func FSJoin(elem ...string) string { + out := "" + for _, v := range elem { + out += v + "/" + } + return out[:len(out)-1] +} + +func loadFilesystems() { + langFS = rewriteFS{laFS, "lang/"} + localFS = rewriteFS{loFS, "data/"} + log.Println("Using internal storage") +} diff --git a/package.json b/package.json index 2ea8a8d..b9425a4 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "homepage": "https://github.com/hrfee/jfa-go#readme", "dependencies": { "a17t": "^0.4.0", + "esbuild": "^0.8.46", "lodash": "^4.17.19", "mjml": "^4.8.0", "remixicon": "^2.5.0", diff --git a/mail/generate.py b/scripts/compile_mjml.py similarity index 96% rename from mail/generate.py rename to scripts/compile_mjml.py index f5c7f37..589fd46 100755 --- a/mail/generate.py +++ b/scripts/compile_mjml.py @@ -16,7 +16,7 @@ def runcmd(cmd): return proc.communicate() -local_path = Path(__file__).resolve().parent +local_path = Path("mail") for mjml in [f for f in local_path.iterdir() if f.is_file() and "mjml" in f.suffix]: print(f"Compiling {mjml.name}") diff --git a/scripts/embed.py b/scripts/embed.py new file mode 100755 index 0000000..c1c75ff --- /dev/null +++ b/scripts/embed.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +import shutil +import sys +from pathlib import Path + +external = ["false", "external", "no", "n"] + +with open("embed.go", "w") as f: + choice = "" + try: + choice = sys.argv[1] + except IndexError: + pass + folder = Path("embed") + if choice in external: + embed = False + shutil.copy(folder / "external.go", "embed.go") + print("Embedding disabled. \"data\" must be placed alongside the executable.") + else: + shutil.copy(folder / "internal.go", "embed.go") + print("Embedding enabled.") + diff --git a/config/fixconfig.py b/scripts/enumerate_config.py similarity index 100% rename from config/fixconfig.py rename to scripts/enumerate_config.py diff --git a/config/generate_ini.py b/scripts/generate_ini.py similarity index 100% rename from config/generate_ini.py rename to scripts/generate_ini.py diff --git a/version.py b/scripts/version.py similarity index 100% rename from version.py rename to scripts/version.py