From 656245ce6a103fe948dec3619a4069690e61fb7f Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 8 Sep 2021 23:50:38 +0900 Subject: [PATCH] =?UTF-8?q?install:=20php=20=EB=8B=A8=EC=97=90=EC=84=9C=20?= =?UTF-8?q?npm=20=EC=84=A4=EC=B9=98=20=ED=99=98=EA=B2=BD=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .babelrc | 1 - f_install/install.php | 45 +++++++++++++++++ j_updateServer.php | 67 +++++++++++++++++++++++--- package.json | 5 ++ src/sammo/templates/block_htaccess.php | 2 +- webpack.config.cjs | 8 ++- 6 files changed, 113 insertions(+), 15 deletions(-) diff --git a/.babelrc b/.babelrc index c6e7c612..a5154ce5 100644 --- a/.babelrc +++ b/.babelrc @@ -3,7 +3,6 @@ [ "@babel/preset-env", { - "targets": "> 0.2%, not ie>8, not op_mini all", "useBuiltIns": "usage", "corejs": 3, "modules": false diff --git a/f_install/install.php b/f_install/install.php index 9fc504b3..1332dd00 100644 --- a/f_install/install.php +++ b/f_install/install.php @@ -3,6 +3,51 @@ namespace sammo; require(__DIR__.'/../vendor/autoload.php'); +set_time_limit(600); + +function tryNpmInstall() +{ + $npmResultPath = '../npm_recent.json.log'; + $packageJsonPath = '../package.json'; + $packageJsonLockPath = '../package-lock.json'; + + $packageJsonHash = hash_file('sha512', $packageJsonPath); + $timestamp = time(); + if (file_exists($npmResultPath) && file_exists($packageJsonLockPath)) { + do { + $result = json_decode(file_get_contents($npmResultPath)); + $oldJsonHash = $result->packageJsonHash; + $oldTimestamp = $result->updateTimestamp; + + //1. package.json 파일이 다르면 업데이트. + if ($packageJsonHash != $oldJsonHash) { + break; + } + + //2. package-lock.json 업데이트가 2주를 초과했다면 업데이트. + if($oldTimestamp + 60*60*24*14 < $timestamp){ + break; + } + + //그것도 아니라면 업데이트하지 않겠다. + return; + } while (0); + } + + exec("npm install", $output, $result_code); + if ($result_code != 0) { + Json::die([ + 'result' => false, + 'reason' => $output + ]); + } + + file_put_contents($npmResultPath, json_encode([ + 'packageJsonHash'=>$packageJsonHash, + 'updateTimestamp'=>$timestamp, + ])); +} +tryNpmInstall(); ?> diff --git a/j_updateServer.php b/j_updateServer.php index 04335b8a..319b7c28 100644 --- a/j_updateServer.php +++ b/j_updateServer.php @@ -1,9 +1,10 @@ false, - 'reason'=>$output + 'reason' => $output ]); } } +function tryNpmInstall() +{ + $npmResultPath = './npm_recent.json.log'; + $packageJsonPath = './package.json'; + $packageJsonLockPath = './package-lock.json'; + + $packageJsonHash = hash_file('sha512', $packageJsonPath); + $timestamp = time(); + if (file_exists($npmResultPath) && file_exists($packageJsonLockPath)) { + do { + $result = json_decode(file_get_contents($npmResultPath)); + $oldJsonHash = $result->packageJsonHash; + $oldTimestamp = $result->updateTimestamp; + + //1. package.json 파일이 다르면 업데이트. + if ($packageJsonHash != $oldJsonHash) { + break; + } + + //2. package-lock.json 업데이트가 2주를 초과했다면 업데이트. + if($oldTimestamp + 60*60*24*14 < $timestamp){ + break; + } + + //그것도 아니라면 업데이트하지 않겠다. + return; + } while (0); + } + + exec("npm install", $output, $result_code); + if ($result_code != 0) { + Json::die([ + 'result' => false, + 'reason' => $output + ]); + } + + file_put_contents($npmResultPath, json_encode([ + 'packageJsonHash'=>$packageJsonHash, + 'updateTimestamp'=>$timestamp, + ])); +} + +//묻고 따지지 않고 일단 npm install은 시도한다. +//hwe 업데이트인 경우에만 한번 더 부른다. + +tryNpmInstall(); $session = Session::requireLogin(null)->setReadOnly(); $request = $_POST + $_GET; @@ -169,10 +218,10 @@ if ($server == $baseServerName) { $gitHash = getHash(); if ( hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.dynamic.orig.php') == - hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.php')) { - $result = true; - } - else{ + hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.php') + ) { + $result = true; + } else { $result = Util::generateFileUsingSimpleTemplate( __DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php', __DIR__ . '/' . $server . '/d_setting/VersionGit.php', @@ -184,6 +233,8 @@ if ($server == $baseServerName) { ); } + //git 업데이트했는데, package.json이 바뀌면 곤란하니까 + tryNpmInstall(); genJS($server); if (ServConfig::$imageRequestKey) { diff --git a/package.json b/package.json index 65a6c448..ed0069d1 100644 --- a/package.json +++ b/package.json @@ -82,5 +82,10 @@ }, "pre-commit": [ "lint" + ], + "browserslist": [ + "> 0.4%", + "not ie <= 11", + "not op_mini all" ] } diff --git a/src/sammo/templates/block_htaccess.php b/src/sammo/templates/block_htaccess.php index ea90c6ad..2e53daee 100644 --- a/src/sammo/templates/block_htaccess.php +++ b/src/sammo/templates/block_htaccess.php @@ -31,7 +31,7 @@ Allow from Allow from all - + Allow from all diff --git a/webpack.config.cjs b/webpack.config.cjs index 186a119d..e62854be 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -60,6 +60,7 @@ module.exports = (env, argv) => { extractComments: true, }), ], + moduleIds: 'deterministic', }, module: { rules: [ @@ -93,9 +94,6 @@ module.exports = (env, argv) => { loader: 'vue-loader', exclude: /(node_modules)/, options: { - /*transformAssetUrls: { - png: [], - },*/ hotReload: false, } }, @@ -222,6 +220,7 @@ module.exports = (env, argv) => { extractComments: true, }), ], + moduleIds: 'deterministic', }, module: { rules: [{ @@ -232,7 +231,6 @@ module.exports = (env, argv) => { options: { presets: [ ['@babel/preset-env', { - "targets": "> 0.2%, not ie>8, not op_mini all", "useBuiltIns": "usage", "corejs": 3, "modules": false @@ -299,6 +297,7 @@ module.exports = (env, argv) => { extractComments: true, }), ], + moduleIds: 'deterministic', }, module: { rules: [{ @@ -309,7 +308,6 @@ module.exports = (env, argv) => { options: { presets: [ ['@babel/preset-env', { - "targets": "> 0.2%, not ie>8, not op_mini all", "useBuiltIns": "usage", "corejs": 3, "modules": false