From 0c9b553591d550d1437594fc8326b06c79d9d087 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 24 Feb 2023 12:19:03 +0800 Subject: [PATCH] no message --- app/Http/Controllers/IndexController.php | 12 +++---- cmd | 42 +++++++++++++----------- resources/views/main.blade.php | 19 ++++++++--- vite.config.js | 9 ++++- 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index 96e79ae12..23993ddcd 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -52,18 +52,18 @@ class IndexController extends InvokeController */ public function main() { - $scripts = []; if (config('app.debug')) { - $src = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . env("APP_DEV_PORT") . "/", asset_main("resources/assets/js/app.js")); - $scripts[] = ""; + $style = null; + $script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . env("APP_DEV_PORT") . "/", asset_main("resources/assets/js/app.js")); } else { $array = Base::json2array(file_get_contents(public_path('manifest.json'))); - $scripts[] = ""; - $scripts[] = ""; + $style = asset_main($array['resources/assets/js/app.js']['css'][0]); + $script = asset_main($array['resources/assets/js/app.js']['file']); } return response()->view('main', [ 'version' => Base::getVersion(), - 'script' => implode("\n", $scripts), + 'style' => $style, + 'script' => $script, ])->header('Link', "<" . url('manifest.txt') . ">; rel=\"prefetch\""); } diff --git a/cmd b/cmd index 2041ae57e..85aecc148 100755 --- a/cmd +++ b/cmd @@ -41,10 +41,15 @@ rand_string() { fi } -supervisorctl_restart() { - local RES=`run_exec php "supervisorctl update $1"` +restart_php() { + local RES=`run_exec php "supervisorctl update php"` if [ -z "$RES" ]; then - run_exec php "supervisorctl restart $1" + RES=`run_exec php "supervisorctl restart php"` + fi + local IN=`echo $RES | grep "ERROR"` + if [[ "$IN" != "" ]]; then + $COMPOSE stop php + $COMPOSE start php else echo -e "$RES" fi @@ -95,13 +100,13 @@ run_compile() { env_set APP_DEV_PORT $(rand 20001 30000) fi run_exec php "php bin/run --mode=$type" - supervisorctl_restart php + restart_php # if [ "$type" = "prod" ]; then rm -rf "./public/js/build" - npx vite build + npx vite build -- fromcmd else - npx vite + npx vite -- fromcmd fi } @@ -120,18 +125,17 @@ run_electron() { if [ -d "./electron/dist" ]; then rm -rf "./electron/dist" fi - if [ -d "./electron/public" ] && [ "$argv" != "--nobuild" ]; then + if [ -d "./electron/public" ]; then rm -rf "./electron/public" fi - mkdir -p ./electron/public - cp ./electron/index.html ./electron/public/index.html # - if [ "$argv" != "dev" ] && [ "$argv" != "--nobuild" ]; then - npx vite build -- --env --electron - fi if [ "$argv" == "dev" ]; then run_exec php "php bin/run --mode=$argv" - supervisorctl_restart php + restart_php + else + mkdir -p ./electron/public + cp ./electron/index.html ./electron/public/index.html + npx vite build -- fromcmd electron fi node ./electron/build.js $argv } @@ -304,7 +308,7 @@ if [ $# -gt 0 ]; then # 设置初始化密码 res=`run_exec mariadb "sh /etc/mysql/repassword.sh"` $COMPOSE up -d - supervisorctl_restart php + restart_php echo -e "${OK} ${GreenBG} 安装完成 ${Font}" echo -e "地址: http://${GreenBG}127.0.0.1:$(env_get APP_PORT)${Font}" echo -e "$res" @@ -316,7 +320,7 @@ if [ $# -gt 0 ]; then git pull run_exec php "composer update" run_exec php "php artisan migrate" - supervisorctl_restart php + restart_php $COMPOSE up -d elif [[ "$1" == "uninstall" ]]; then shift 1 @@ -350,14 +354,14 @@ if [ $# -gt 0 ]; then elif [[ "$1" == "url" ]]; then shift 1 env_set APP_URL "$1" - supervisorctl_restart php + restart_php echo -e "${OK} ${GreenBG} 修改成功 ${Font}" elif [[ "$1" == "env" ]]; then shift 1 if [ -n "$1" ]; then env_set $1 "$2" fi - supervisorctl_restart php + restart_php echo -e "${OK} ${GreenBG} 修改成功 ${Font}" elif [[ "$1" == "repassword" ]]; then shift 1 @@ -385,7 +389,7 @@ if [ $# -gt 0 ]; then else env_set APP_DEBUG "true" fi - supervisorctl_restart php + restart_php elif [[ "$1" == "https" ]]; then shift 1 if [[ "$@" == "auto" ]]; then @@ -393,7 +397,7 @@ if [ $# -gt 0 ]; then else env_set APP_SCHEME "true" fi - supervisorctl_restart php + restart_php elif [[ "$1" == "artisan" ]]; then shift 1 e="php artisan $@" && run_exec php "$e" diff --git a/resources/views/main.blade.php b/resources/views/main.blade.php index 7cc2f6001..57c33bd30 100755 --- a/resources/views/main.blade.php +++ b/resources/views/main.blade.php @@ -11,12 +11,24 @@ {{ config('app.name', 'WebPage') }} + @if($style) + + @endif @@ -37,7 +49,6 @@ -{!! $script !!} - + diff --git a/vite.config.js b/vite.config.js index edb9c55cf..b3908c7f3 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,13 +1,20 @@ import {resolve} from "path"; +import {spawnSync} from "child_process"; import {defineConfig, loadEnv} from 'vite' import {createVuePlugin} from 'vite-plugin-vue2'; import vitePluginRequire from 'vite-plugin-require' import vitePluginFileCopy from 'vite-plugin-file-copy'; const argv = process.argv; -const isElectron = argv.includes('--electron'); +const isCmd = argv.includes('fromcmd'); +const isElectron = argv.includes('electron'); const publicPath = isElectron ? 'electron/public' : 'public'; +if (!isCmd) { + spawnSync("npx", [resolve(__dirname, 'cmd'), argv.includes("build") ? "build" : "dev"], {stdio: "inherit"}); + process.exit() +} + export default defineConfig(({command, mode}) => { const env = loadEnv(mode, process.cwd(), '') const host = "0.0.0.0"