From 954fa4bf82e92b8493a3829075ccfceb3c55c3e3 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 13 Aug 2025 00:53:44 +0200 Subject: [PATCH] Add "setup" script - install deps - create env files --- package.json | 8 +++++--- tools/scripts/setupEnvFiles.ts | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 tools/scripts/setupEnvFiles.ts diff --git a/package.json b/package.json index 5961f43e..4b2a5e86 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,11 @@ "type": "module", "scripts": { "ci": "yarn install --frozen-lockfile", - "dev": "vite", - "preview": "vite preview", - "build": "vite build", + "setup-env-files": "tsx tools/scripts/setupEnvFiles.ts", + "setup": "yarn ci && yarn setup-env-files", + "dev": "yarn setup && vite", + "preview": "yarn setup vite preview", + "build": "yarn setup vite build", "test": "node -e \"console.log('imagine')\"", "build-md5": "find build -type f | sort | xargs md5sum | awk '{ print $1 }' | tr -d '\n' | md5sum| awk '{ print $1 }' > buildZip/md5sum ", "build-zip": "cd build && rev=$(git rev-list HEAD --count) && echo r$rev > revision && zip -9 -r ../buildZip/Suwayomi-WebUI-r$rev *", diff --git a/tools/scripts/setupEnvFiles.ts b/tools/scripts/setupEnvFiles.ts new file mode 100644 index 00000000..2d780007 --- /dev/null +++ b/tools/scripts/setupEnvFiles.ts @@ -0,0 +1,37 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +import fs from 'fs'; +import * as path from 'path'; + +const filesToCreate: { id: string; templatePath: string; targetPath: string }[] = [ + { + id: 'root env', + templatePath: path.resolve(import.meta.dirname, '../../.env.template'), + targetPath: path.resolve(import.meta.dirname, '../../.env'), + }, +]; + +filesToCreate.forEach(({ id, templatePath, targetPath }) => { + if (!fs.existsSync(templatePath)) { + console.warn( + `(id= ${id}) .env.template not found. Cannot create .env file. (template: ${templatePath}, target: ${targetPath})`, + ); + return; + } + + if (fs.existsSync(targetPath)) { + console.log( + `(id= ${id}) .env file already exists. Skipping. (template: ${templatePath}, target: ${targetPath})`, + ); + return; + } + + fs.copyFileSync(templatePath, targetPath); + console.log(`(id= ${id}) .env file created from .env.template. (template: ${templatePath}, target: ${targetPath})`); +});