From fd057ebb0585f3ed7528e856e4f83854135f6554 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 12 Dec 2021 13:52:55 +0900 Subject: [PATCH] =?UTF-8?q?build(WIP):=20=EB=B9=8C=EB=93=9C=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=EB=AC=BC=EC=9D=84=20=EC=84=9C=EB=B2=84=20=EC=A3=BC?= =?UTF-8?q?=EC=86=8C=EC=97=90=20=EA=B4=80=EA=B3=84=EC=97=86=EC=9D=B4=20?= =?UTF-8?q?=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- j_updateServer.php | 26 ++++++++--- webpack.config.cjs | 110 ++++++++++++++++++++++++--------------------- 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/j_updateServer.php b/j_updateServer.php index 50ed0f47..8542a83e 100644 --- a/j_updateServer.php +++ b/j_updateServer.php @@ -140,7 +140,7 @@ if (!$v->validate()) { $target = Util::getPost('target'); $server = basename($request['server']); - +$settingBasePath = __DIR__ . "/{$server}/d_setting/"; $allowFullUpdate = in_array('fullUpdate', $session->acl[$server] ?? []); $allowFullUpdate |= $session->userGrade >= 6; @@ -244,20 +244,28 @@ if ($server == $baseServerName) { $version = getVersion(); $gitHash = getHash(); if ( - hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.dynamic.orig.php') == - hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.php') + hash_file("sha256", $settingBasePath . 'VersionGit.dynamic.orig.php') == + hash_file("sha256", $settingBasePath . 'VersionGit.php') ) { + + if (file_exists($settingBasePath . 'VersionGit.json')) { + unlink($settingBasePath . 'VersionGit.json'); + } $result = true; } else { $result = Util::generateFileUsingSimpleTemplate( - __DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php', - __DIR__ . '/' . $server . '/d_setting/VersionGit.php', + $settingBasePath . 'VersionGit.orig.php', + $settingBasePath . 'VersionGit.php', [ 'verionGit' => $version, 'hash' => $gitHash ], true ); + file_put_contents($settingBasePath . 'VersionGit.json', Json::encode([ + 'versionGit' => $version, + 'hash' => $gitHash, + ])); } //git 업데이트했는데, package.json이 바뀌면 곤란하니까 @@ -333,14 +341,18 @@ $zip->close(); $version = getVersion($target); $gitHash = getHash($target); $result = Util::generateFileUsingSimpleTemplate( - __DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php', - __DIR__ . '/' . $server . '/d_setting/VersionGit.php', + $settingBasePath . 'VersionGit.orig.php', + $settingBasePath . 'VersionGit.php', [ 'verionGit' => $version, 'hash' => $gitHash ], true ); +file_put_contents($settingBasePath . 'VersionGit.json', Json::encode([ + 'versionGit' => $version, + 'hash' => $gitHash, +])); genJS($server); $storage->$server = [$target, $version]; diff --git a/webpack.config.cjs b/webpack.config.cjs index f887875a..a7c6900e 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -6,12 +6,41 @@ const { resolve } = require('path'); const CleanTerminalPlugin = require('clean-terminal-webpack-plugin'); const { ESBuildMinifyPlugin } = require('esbuild-loader') const webpack = require('webpack'); +const fs = require('fs'); module.exports = (env, argv) => { const target = env.target ?? 'hwe'; const mode = argv.mode ?? 'production'; const tsDir = resolve(__dirname, `${target}/ts/`); const build_exports = require(`${tsDir}/build_exports.json`); + const versionGitPath = resolve(__dirname, target, 'd_setting', 'VersionGit.json'); + + const versionValue = (() => { + if (!fs.existsSync(versionGitPath)) { + return undefined; + } + const versionInfo = JSON.parse(fs.readFileSync(versionGitPath, 'utf-8')); + return versionInfo.versionGit; + })() + const versionTarget = versionValue ?? `${target}_dynamic`; + const outputPath = resolve(__dirname, 'dist_js', versionTarget); + fs.mkdirSync(outputPath, { + recursive: true + }); + + const genBuildHook = function (oTarget) { + const checkFilePath = resolve(outputPath, `build_${oTarget}.txt`); + return function (percentage, msg) { + if (percentage == 0) { + if (fs.existsSync(checkFilePath)) { + fs.unlinkSync(checkFilePath); + } + } else if (percentage == 1) { + fs.writeFileSync(checkFilePath, new Date().toISOString(), 'utf-8'); + } + }; + }; + //TODO: esbuild에 browserslist 사용 가능하면 적용 //서버마다 ts 파일 구성이 다를 가능성이 높기 때문에 어떤 파일이 필요한지는 ts/build_exports.json을 확인한다. @@ -25,7 +54,7 @@ module.exports = (env, argv) => { } const ingame_vue = { - name: `ingame_${target}_vue`, + name: `ingame_${versionTarget}_vue`, resolve: { extensions: [".ts", ".tsx", ".vue", ".js"], alias: { @@ -39,7 +68,7 @@ module.exports = (env, argv) => { entry: entryIngameVue, output: { filename: '[name].js', - path: resolve(__dirname, `${target}/dist_js`) + path: resolve(outputPath, 'vue') }, devtool: 'source-map', optimization: { @@ -128,56 +157,27 @@ module.exports = (env, argv) => { }, { test: /\.(png|jpe?g|gif|webp)$/, - use: [ - { - loader: 'file-loader', - options: { - name: '../dist_misc/[name].[contenthash:8].[ext]' - } - } - ] + use: ['file-loader'] }, { test: /\.(svg)$/, - use: [ - { - loader: 'file-loader', - options: { - name: '../dist_misc/[name].[contenthash:8].[ext]' - } - } - ] + use: ['file-loader'] }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/, - use: [ - { - loader: 'file-loader', - options: { - name: '../dist_misc/[name].[contenthash:8].[ext]' - } - } - ] + use: ['file-loader'] }, { test: /\.(woff2?|eot|ttf|otf)$/i, - use: [ - { - loader: 'file-loader', - options: { - name: '../dist_misc/[name].[contenthash:8].[ext]' - } - } - ] + use: ['file-loader'] }, ] }, plugins: [ new CleanTerminalPlugin(), new VueLoaderPlugin(), - new MiniCssExtractPlugin({ - filename: '../dist_css/[name].css' - }), + new MiniCssExtractPlugin(), + new webpack.ProgressPlugin(genBuildHook('vue')), //new BundleAnalyzerPlugin() ], cache: { @@ -185,7 +185,7 @@ module.exports = (env, argv) => { }, }; const ingame = { - name: `ingame_${target}`, + name: `ingame_${versionTarget}`, resolve: { extensions: [".js", ".ts", ".tsx"], alias: { @@ -198,7 +198,7 @@ module.exports = (env, argv) => { entry: entryIngame, output: { filename: '[name].js', - path: resolve(__dirname, `${target}/dist_js`) + path: resolve(outputPath, 'ts') }, devtool: 'source-map', optimization: { @@ -272,9 +272,8 @@ module.exports = (env, argv) => { }, plugins: [ new CleanTerminalPlugin(), - new MiniCssExtractPlugin({ - filename: '../dist_css/[name].css' - }), + new MiniCssExtractPlugin(), + new webpack.ProgressPlugin(genBuildHook('ts')), //new BundleAnalyzerPlugin() ], cache: { @@ -287,7 +286,7 @@ module.exports = (env, argv) => { } }; const gateway = { - name: 'gateway', + name: `gateway_${versionTarget}`, resolve: { extensions: [".js", ".ts", ".tsx"], alias: { @@ -307,7 +306,7 @@ module.exports = (env, argv) => { }, output: { filename: '[name].js', - path: path.resolve(__dirname, 'dist_js'), + path: resolve(outputPath, 'gateway') }, devtool: 'source-map', optimization: { @@ -379,9 +378,8 @@ module.exports = (env, argv) => { }] }, plugins: [ - new MiniCssExtractPlugin({ - filename: '../dist_css/[name].css' - }), + new MiniCssExtractPlugin(), + new webpack.ProgressPlugin(genBuildHook('gateway')), //new BundleAnalyzerPlugin() ], cache: { @@ -389,10 +387,22 @@ module.exports = (env, argv) => { }, }; - if (target == 'hwe') { + if(env.WEBPACK_WATCH || !versionValue){ return [gateway, ingame_vue, ingame]; } - else { - return [ingame_vue, ingame]; + + const buildConfList = []; + if (target == 'hwe' && !fs.existsSync(resolve(outputPath, `build_gateway.txt`))) { + buildConfList.push(gateway); } + + if (!fs.existsSync(resolve(outputPath, `build_vue.txt`))) { + buildConfList.push(ingame_vue); + } + + if (!fs.existsSync(resolve(outputPath, `build_ts.txt`))) { + buildConfList.push(ingame); + } + + return buildConfList; }