mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-10 09:52:53 +00:00
feat: 优化开发环境配置
This commit is contained in:
parent
9419ddd174
commit
123c74de46
1
.github/workflows/publish.yml
vendored
1
.github/workflows/publish.yml
vendored
@ -4,7 +4,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- "pro"
|
||||
- "dev"
|
||||
|
||||
jobs:
|
||||
check-version:
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -32,6 +32,9 @@ vars.yaml
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
|
||||
# Development file
|
||||
/index.html
|
||||
|
||||
# Testing
|
||||
.phpunit.result.cache
|
||||
test.*
|
||||
|
||||
@ -61,6 +61,10 @@ class IndexController extends InvokeController
|
||||
$array = Base::json2array(file_get_contents($hotFile));
|
||||
$style = null;
|
||||
$script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . $array['APP_DEV_PORT'] . "/", asset_main("resources/assets/js/app.js"));
|
||||
$proxyUri = Base::liveEnv('VSCODE_PROXY_URI');
|
||||
if (is_string($proxyUri) && preg_match('/^https?:\/\//i', $proxyUri)) {
|
||||
$script = preg_replace('/^(https?:\/\/|\/\/)[^\/]+/', rtrim($proxyUri, '/'), $script, 1);
|
||||
}
|
||||
} else {
|
||||
$array = Base::json2array(file_get_contents($manifestFile));
|
||||
$style = asset_main($array['resources/assets/js/app.js']['css'][0]);
|
||||
|
||||
@ -3073,4 +3073,61 @@ class Base
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时读取 .env 配置(不受配置缓存影响)
|
||||
* @param string $key 配置键名
|
||||
* @param mixed $default 默认值
|
||||
* @return mixed
|
||||
*/
|
||||
public static function liveEnv($key, $default = null)
|
||||
{
|
||||
$envFile = base_path('.env');
|
||||
if (!file_exists($envFile)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$envContent = file_get_contents($envFile);
|
||||
$lines = explode("\n", $envContent);
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
|
||||
// 跳过注释和空行
|
||||
if (empty($line) || str_starts_with($line, '#')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 解析 KEY=VALUE
|
||||
if (str_contains($line, '=')) {
|
||||
[$envKey, $envValue] = explode('=', $line, 2);
|
||||
$envKey = trim($envKey);
|
||||
|
||||
if ($envKey === $key) {
|
||||
$envValue = trim($envValue);
|
||||
|
||||
// 移除引号
|
||||
if (preg_match('/^(["\'])(.*)\1$/', $envValue, $matches)) {
|
||||
$envValue = $matches[2];
|
||||
}
|
||||
|
||||
// 处理布尔值
|
||||
$lowerValue = strtolower($envValue);
|
||||
if ($lowerValue === 'true') {
|
||||
return true;
|
||||
}
|
||||
if ($lowerValue === 'false') {
|
||||
return false;
|
||||
}
|
||||
if ($lowerValue === 'null' || $lowerValue === '(null)') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $envValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
22
cmd
22
cmd
@ -119,6 +119,14 @@ switch_debug() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查是否有sudo
|
||||
check_sudo() {
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
error "请使用 sudo 运行此脚本"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 检查docker、docker-compose
|
||||
check_docker() {
|
||||
docker --version &> /dev/null
|
||||
@ -175,7 +183,15 @@ web_build() {
|
||||
fi
|
||||
if [ "$type" = "dev" ]; then
|
||||
echo "<script>window.location.href=window.location.href.replace(/:\d+/, ':' + $(env_get APP_PORT))</script>" > ./index.html
|
||||
env_set APP_DEV_PORT $(rand 20001 30000)
|
||||
if [ -z "$(env_get APP_DEV_PORT)" ]; then
|
||||
env_set APP_DEV_PORT $(rand 20001 30000)
|
||||
fi
|
||||
if [ -n "${VSCODE_PROXY_URI:-}" ]; then
|
||||
APP_REAL_URI=$(TARGET_PORT="$(env_get APP_PORT)" node -p "process.env.VSCODE_PROXY_URI.replace(/\{\{port\}\}/g, process.env.TARGET_PORT || '')")
|
||||
VSCODE_PROXY_URI=$(APP_DEV_PORT="$(env_get APP_DEV_PORT)" node -p "process.env.VSCODE_PROXY_URI.replace(/\{\{port\}\}/g, process.env.APP_DEV_PORT || '')")
|
||||
echo "<script>window.location.href='${APP_REAL_URI}'</script>" > ./index.html
|
||||
fi
|
||||
env_set VSCODE_PROXY_URI "${VSCODE_PROXY_URI:-}"
|
||||
fi
|
||||
switch_debug "$type"
|
||||
#
|
||||
@ -479,7 +495,8 @@ handle_install() {
|
||||
for vol in "${volumes[@]}"; do
|
||||
tmp_path="${WORK_DIR}/${vol}"
|
||||
mkdir -p "${tmp_path}"
|
||||
chmod -R 775 "${tmp_path}"
|
||||
find "${tmp_path}" -type d -exec chmod 775 {} \;
|
||||
|
||||
rm -f "${tmp_path}/dootask.lock"
|
||||
cmda="${cmda} -v ${tmp_path}:/usr/share/${vol}"
|
||||
cmdb="${cmdb} touch /usr/share/${vol}/dootask.lock &&"
|
||||
@ -644,6 +661,7 @@ handle_update() {
|
||||
|
||||
# 卸载函数
|
||||
handle_uninstall() {
|
||||
check_sudo
|
||||
# 确认卸载
|
||||
echo -e "${RedBG}警告:此操作将永久删除以下内容:${Font}"
|
||||
echo "- 数据库"
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
<body>
|
||||
|
||||
|
||||
<div id="app" data-preload="false">
|
||||
<div id="app" data-preload="init">
|
||||
<div class="app-view-loading no-dark-content">
|
||||
<div>
|
||||
<div>PAGE LOADING</div>
|
||||
|
||||
@ -1 +0,0 @@
|
||||
<script>window.location.href=window.location.href.replace(/:\d+/, ':' + 2222)</script>
|
||||
2
resources/assets/js/app.js
vendored
2
resources/assets/js/app.js
vendored
@ -2,6 +2,8 @@ const isElectron = !!(window && window.process && window.process.type && window.
|
||||
const isEEUIApp = window && window.navigator && /eeui/i.test(window.navigator.userAgent);
|
||||
const isSoftware = isElectron || isEEUIApp;
|
||||
|
||||
document.getElementById("app")?.setAttribute("data-preload", "false");
|
||||
|
||||
import {languageName, switchLanguage as $L} from "./language";
|
||||
import {isLocalHost} from "./components/Replace/utils";
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
<body>
|
||||
|
||||
@extends('ie')
|
||||
<div id="app" data-preload="false">
|
||||
<div id="app" data-preload="init">
|
||||
<div class="app-view-loading no-dark-content">
|
||||
<div>
|
||||
<div>PAGE LOADING</div>
|
||||
|
||||
15
vite.config.js
vendored
15
vite.config.js
vendored
@ -22,6 +22,7 @@ export default defineConfig(({command, mode}) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const host = "0.0.0.0"
|
||||
const port = parseInt(env['APP_DEV_PORT'])
|
||||
const proxy_uri = env['VSCODE_PROXY_URI']
|
||||
|
||||
if (command === 'serve') {
|
||||
const hotFile = path.resolve(__dirname, 'public/hot')
|
||||
@ -80,6 +81,17 @@ export default defineConfig(({command, mode}) => {
|
||||
})
|
||||
}
|
||||
|
||||
const serverHmr = {}
|
||||
if (/^https?:\/\//i.test(proxy_uri)) {
|
||||
const proxyUri = new URL(proxy_uri)
|
||||
if (proxyUri) {
|
||||
Object.assign(serverHmr, {
|
||||
host: proxyUri.host,
|
||||
clientPort: proxyUri.port || (/^https/.test(proxy_uri) ? 443 : 80)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
base: basePath,
|
||||
publicDir: publicPath,
|
||||
@ -98,7 +110,8 @@ export default defineConfig(({command, mode}) => {
|
||||
'**/language/**',
|
||||
'**/electron/**',
|
||||
]
|
||||
}
|
||||
},
|
||||
hmr: serverHmr
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user