mirror of
https://github.com/kuaifan/dootask.git
synced 2026-03-17 19:23:26 +00:00
perf: 优化开发执行脚本
This commit is contained in:
parent
112b70dcad
commit
b1f5cae663
@ -1,7 +1,7 @@
|
|||||||
APP_NAME=DooTask
|
APP_NAME=DooTask
|
||||||
APP_ENV=local
|
APP_ENV=local
|
||||||
APP_KEY=
|
APP_KEY=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=false
|
||||||
APP_SCHEME=auto
|
APP_SCHEME=auto
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
|
|||||||
@ -52,11 +52,14 @@ class IndexController extends InvokeController
|
|||||||
*/
|
*/
|
||||||
public function main()
|
public function main()
|
||||||
{
|
{
|
||||||
if (config('app.debug')) {
|
$hotFile = public_path('hot');
|
||||||
|
$manifestFile = public_path('manifest.json');
|
||||||
|
if (file_exists($hotFile)) {
|
||||||
|
$array = Base::json2array(file_get_contents($hotFile));
|
||||||
$style = null;
|
$style = null;
|
||||||
$script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . env("APP_DEV_PORT") . "/", asset_main("resources/assets/js/app.js"));
|
$script = preg_replace("/^(\/\/(.*?))(:\d+)?\//i", "$1:" . $array['APP_DEV_PORT'] . "/", asset_main("resources/assets/js/app.js"));
|
||||||
} else {
|
} else {
|
||||||
$array = Base::json2array(file_get_contents(public_path('manifest.json')));
|
$array = Base::json2array(file_get_contents($manifestFile));
|
||||||
$style = asset_main($array['resources/assets/js/app.js']['css'][0]);
|
$style = asset_main($array['resources/assets/js/app.js']['css'][0]);
|
||||||
$script = asset_main($array['resources/assets/js/app.js']['file']);
|
$script = asset_main($array['resources/assets/js/app.js']['file']);
|
||||||
}
|
}
|
||||||
|
|||||||
15
bin/auto
Executable file
15
bin/auto
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ ! -f ".env" ]; then
|
||||||
|
echo -e "配置文件不存在!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
debug=`cat .env | grep "^APP_DEBUG=" | awk -F '=' '{print $2}'`
|
||||||
|
if [ "$debug" = "true" ]; then
|
||||||
|
echo "[MODE] development"
|
||||||
|
./bin/inotify ./app
|
||||||
|
else
|
||||||
|
echo "[MODE] production"
|
||||||
|
php bin/laravels start -i
|
||||||
|
fi
|
||||||
89
bin/run
89
bin/run
@ -1,89 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class runLoader
|
|
||||||
*/
|
|
||||||
class runLoader
|
|
||||||
{
|
|
||||||
public function randString($length = 16)
|
|
||||||
{
|
|
||||||
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
||||||
$passwordstr = '';
|
|
||||||
$max = strlen($chars) - 1;
|
|
||||||
for ($i = 0; $i < $length; $i++) {
|
|
||||||
$passwordstr .= $chars[mt_rand(0, $max)];
|
|
||||||
}
|
|
||||||
return $passwordstr;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getEnv(string $key)
|
|
||||||
{
|
|
||||||
if (empty($key) || !is_string($key)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
$envPath = realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR . '.env';
|
|
||||||
if (!file_exists($envPath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$envContent = file_get_contents($envPath);
|
|
||||||
preg_match_all("/^" . $key . "\s*=\s*(.*?)$/m", $envContent, $matchs);
|
|
||||||
return $matchs[1] ?: '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function modifyEnv(array $data)
|
|
||||||
{
|
|
||||||
if (empty($data) || !is_array($data)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$envPath = realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR . '.env';
|
|
||||||
if (!file_exists($envPath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$envContent = file_get_contents($envPath);
|
|
||||||
foreach ($data as $key => $val) {
|
|
||||||
$envContent = preg_replace("/^" . $key . "\s*=\s*(.*?)$/m", $key . "=" . $val, $envContent);
|
|
||||||
}
|
|
||||||
file_put_contents($envPath, $envContent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function modifyMode($type)
|
|
||||||
{
|
|
||||||
$filePath = realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR . '/docker/php/php.conf';
|
|
||||||
if (!file_exists($filePath)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$envContent = file_get_contents($filePath);
|
|
||||||
$envContent = str_replace("#command=php bin/laravels start -i", "command=php bin/laravels start -i", $envContent);
|
|
||||||
$envContent = str_replace("#command=./bin/inotify ./app", "command=./bin/inotify ./app", $envContent);
|
|
||||||
if ($type == "dev") {
|
|
||||||
$envContent = str_replace("command=php bin/laravels start -i", "#command=php bin/laravels start -i", $envContent);
|
|
||||||
$this->modifyEnv([
|
|
||||||
'APP_DEBUG' => 'true'
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$envContent = str_replace("command=./bin/inotify ./app", "#command=./bin/inotify ./app", $envContent);
|
|
||||||
$this->modifyEnv([
|
|
||||||
'APP_DEBUG' => 'false'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
file_put_contents($filePath, $envContent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$array = getopt('', ['port:', 'mode:']);
|
|
||||||
$loader = new runLoader();
|
|
||||||
|
|
||||||
if (isset($array['mode'])) {
|
|
||||||
$loader->modifyMode($array['mode']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = [];
|
|
||||||
if (isset($array['port'])) {
|
|
||||||
$data['APP_PORT'] = $array['port'];
|
|
||||||
}
|
|
||||||
if ($data) {
|
|
||||||
$loader->modifyEnv($data);
|
|
||||||
}
|
|
||||||
27
cmd
27
cmd
@ -55,6 +55,17 @@ restart_php() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_debug() {
|
||||||
|
local debug="false"
|
||||||
|
if [[ "$1" == "true" ]] || [[ "$1" == "dev" ]] || [[ "$1" == "open" ]]; then
|
||||||
|
debug="true"
|
||||||
|
fi
|
||||||
|
if [[ "$(env_get APP_DEBUG)" != "$debug" ]]; then
|
||||||
|
env_set APP_DEBUG "$debug"
|
||||||
|
restart_php
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
check_docker() {
|
check_docker() {
|
||||||
docker --version &> /dev/null
|
docker --version &> /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@ -99,8 +110,7 @@ run_compile() {
|
|||||||
echo "<script>window.location.href=window.location.href.replace(/:\d+/, ':' + $(env_get APP_PORT))</script>" > ./index.html
|
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)
|
env_set APP_DEV_PORT $(rand 20001 30000)
|
||||||
fi
|
fi
|
||||||
run_exec php "php bin/run --mode=$type"
|
switch_debug "$type"
|
||||||
restart_php
|
|
||||||
#
|
#
|
||||||
if [ "$type" = "prod" ]; then
|
if [ "$type" = "prod" ]; then
|
||||||
rm -rf "./public/js/build"
|
rm -rf "./public/js/build"
|
||||||
@ -130,8 +140,7 @@ run_electron() {
|
|||||||
fi
|
fi
|
||||||
#
|
#
|
||||||
if [ "$argv" == "dev" ]; then
|
if [ "$argv" == "dev" ]; then
|
||||||
run_exec php "php bin/run --mode=$argv"
|
switch_debug "$argv"
|
||||||
restart_php
|
|
||||||
else
|
else
|
||||||
mkdir -p ./electron/public
|
mkdir -p ./electron/public
|
||||||
cp ./electron/index.html ./electron/public/index.html
|
cp ./electron/index.html ./electron/public/index.html
|
||||||
@ -288,7 +297,7 @@ if [ $# -gt 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
[[ -z "$(env_get APP_KEY)" ]] && run_exec php "php artisan key:generate"
|
[[ -z "$(env_get APP_KEY)" ]] && run_exec php "php artisan key:generate"
|
||||||
run_exec php "php bin/run --mode=prod"
|
switch_debug "false"
|
||||||
# 检查数据库
|
# 检查数据库
|
||||||
remaining=20
|
remaining=20
|
||||||
while [ ! -f "${cur_path}/docker/mysql/data/$(env_get DB_DATABASE)/db.opt" ]; do
|
while [ ! -f "${cur_path}/docker/mysql/data/$(env_get DB_DATABASE)/db.opt" ]; do
|
||||||
@ -384,12 +393,8 @@ if [ $# -gt 0 ]; then
|
|||||||
docker run -it --rm -v ${cur_path}:/home/node/apidoc kuaifan/apidoc -i app/Http/Controllers/Api -o public/docs
|
docker run -it --rm -v ${cur_path}:/home/node/apidoc kuaifan/apidoc -i app/Http/Controllers/Api -o public/docs
|
||||||
elif [[ "$1" == "debug" ]]; then
|
elif [[ "$1" == "debug" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
if [[ "$@" == "close" ]]; then
|
switch_debug "$@"
|
||||||
env_set APP_DEBUG "false"
|
echo "success"
|
||||||
else
|
|
||||||
env_set APP_DEBUG "true"
|
|
||||||
fi
|
|
||||||
restart_php
|
|
||||||
elif [[ "$1" == "https" ]]; then
|
elif [[ "$1" == "https" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
if [[ "$@" == "auto" ]]; then
|
if [[ "$@" == "auto" ]]; then
|
||||||
|
|||||||
@ -1,12 +1,6 @@
|
|||||||
[program:php]
|
[program:php]
|
||||||
directory=/var/www
|
directory=/var/www
|
||||||
|
command=./bin/auto
|
||||||
# 生产环境
|
|
||||||
command=php bin/laravels start -i
|
|
||||||
|
|
||||||
# 开发环境
|
|
||||||
#command=./bin/inotify ./app
|
|
||||||
|
|
||||||
numprocs=1
|
numprocs=1
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
|
|||||||
18
vite.config.js
vendored
18
vite.config.js
vendored
@ -1,4 +1,5 @@
|
|||||||
import {resolve} from "path";
|
import {resolve} from "path";
|
||||||
|
import {writeFileSync, existsSync, unlinkSync} from "fs";
|
||||||
import {spawnSync} from "child_process";
|
import {spawnSync} from "child_process";
|
||||||
import {defineConfig, loadEnv} from 'vite'
|
import {defineConfig, loadEnv} from 'vite'
|
||||||
import {createVuePlugin} from 'vite-plugin-vue2';
|
import {createVuePlugin} from 'vite-plugin-vue2';
|
||||||
@ -20,6 +21,23 @@ export default defineConfig(({command, mode}) => {
|
|||||||
const host = "0.0.0.0"
|
const host = "0.0.0.0"
|
||||||
const port = parseInt(env['APP_DEV_PORT'])
|
const port = parseInt(env['APP_DEV_PORT'])
|
||||||
|
|
||||||
|
if (command === 'serve') {
|
||||||
|
const hotFile = resolve(__dirname, 'public/hot')
|
||||||
|
const hotClean = (exit) => {
|
||||||
|
if (existsSync(hotFile)) {
|
||||||
|
unlinkSync(hotFile);
|
||||||
|
}
|
||||||
|
if (exit) {
|
||||||
|
process.exit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hotClean(false)
|
||||||
|
writeFileSync(hotFile, JSON.stringify(env));
|
||||||
|
process.on('exit', () => hotClean(true));
|
||||||
|
process.on('SIGINT', () => hotClean(true));
|
||||||
|
process.on('SIGHUP', () => hotClean(true));
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
base: basePath,
|
base: basePath,
|
||||||
publicDir: publicPath,
|
publicDir: publicPath,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user