install: php 단에서 npm 설치 환경 구성
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
[
|
[
|
||||||
"@babel/preset-env",
|
"@babel/preset-env",
|
||||||
{
|
{
|
||||||
"targets": "> 0.2%, not ie>8, not op_mini all",
|
|
||||||
"useBuiltIns": "usage",
|
"useBuiltIns": "usage",
|
||||||
"corejs": 3,
|
"corejs": 3,
|
||||||
"modules": false
|
"modules": false
|
||||||
|
|||||||
@@ -3,6 +3,51 @@ namespace sammo;
|
|||||||
|
|
||||||
require(__DIR__.'/../vendor/autoload.php');
|
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();
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="ko">
|
<html lang="ko">
|
||||||
|
|||||||
+59
-8
@@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace sammo;
|
namespace sammo;
|
||||||
|
|
||||||
require(__DIR__ . '/vendor/autoload.php');
|
require(__DIR__ . '/vendor/autoload.php');
|
||||||
|
|
||||||
|
set_time_limit(600);
|
||||||
|
|
||||||
function getVersion($target = null)
|
function getVersion($target = null)
|
||||||
{
|
{
|
||||||
if ($target) {
|
if ($target) {
|
||||||
@@ -28,18 +29,66 @@ function getHash($target = 'HEAD')
|
|||||||
return trim($output);
|
return trim($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
function genJS($server){
|
function genJS($server)
|
||||||
|
{
|
||||||
$command = sprintf("./node_modules/.bin/webpack build --env target=%s", escapeshellarg($server));
|
$command = sprintf("./node_modules/.bin/webpack build --env target=%s", escapeshellarg($server));
|
||||||
|
|
||||||
exec(($command), $output, $result_code);
|
exec(($command), $output, $result_code);
|
||||||
if($result_code!=0){
|
if ($result_code != 0) {
|
||||||
Json::die([
|
Json::die([
|
||||||
'result' => false,
|
'result' => 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();
|
$session = Session::requireLogin(null)->setReadOnly();
|
||||||
|
|
||||||
$request = $_POST + $_GET;
|
$request = $_POST + $_GET;
|
||||||
@@ -169,10 +218,10 @@ if ($server == $baseServerName) {
|
|||||||
$gitHash = getHash();
|
$gitHash = getHash();
|
||||||
if (
|
if (
|
||||||
hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.dynamic.orig.php') ==
|
hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.dynamic.orig.php') ==
|
||||||
hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.php')) {
|
hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.php')
|
||||||
$result = true;
|
) {
|
||||||
}
|
$result = true;
|
||||||
else{
|
} else {
|
||||||
$result = Util::generateFileUsingSimpleTemplate(
|
$result = Util::generateFileUsingSimpleTemplate(
|
||||||
__DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php',
|
__DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php',
|
||||||
__DIR__ . '/' . $server . '/d_setting/VersionGit.php',
|
__DIR__ . '/' . $server . '/d_setting/VersionGit.php',
|
||||||
@@ -184,6 +233,8 @@ if ($server == $baseServerName) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//git 업데이트했는데, package.json이 바뀌면 곤란하니까
|
||||||
|
tryNpmInstall();
|
||||||
genJS($server);
|
genJS($server);
|
||||||
|
|
||||||
if (ServConfig::$imageRequestKey) {
|
if (ServConfig::$imageRequestKey) {
|
||||||
|
|||||||
@@ -82,5 +82,10 @@
|
|||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint"
|
"lint"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"> 0.4%",
|
||||||
|
"not ie <= 11",
|
||||||
|
"not op_mini all"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ Allow from <?=$allow_ip?>
|
|||||||
<Files j_server_basic_info.php>
|
<Files j_server_basic_info.php>
|
||||||
Allow from all
|
Allow from all
|
||||||
</Files>
|
</Files>
|
||||||
<Files ~ "\.(xml|css|jpe?g|png|gif|js|pdf)$">
|
<Files ~ "\.(xml|css|jpe?g|png|gif|js|map|woff2|woff|ttf|pdf|txt)$">
|
||||||
Allow from all
|
Allow from all
|
||||||
</Files>
|
</Files>
|
||||||
<Files j_load_scenarios.php>
|
<Files j_load_scenarios.php>
|
||||||
|
|||||||
+3
-5
@@ -60,6 +60,7 @@ module.exports = (env, argv) => {
|
|||||||
extractComments: true,
|
extractComments: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
moduleIds: 'deterministic',
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
@@ -93,9 +94,6 @@ module.exports = (env, argv) => {
|
|||||||
loader: 'vue-loader',
|
loader: 'vue-loader',
|
||||||
exclude: /(node_modules)/,
|
exclude: /(node_modules)/,
|
||||||
options: {
|
options: {
|
||||||
/*transformAssetUrls: {
|
|
||||||
png: [],
|
|
||||||
},*/
|
|
||||||
hotReload: false,
|
hotReload: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -222,6 +220,7 @@ module.exports = (env, argv) => {
|
|||||||
extractComments: true,
|
extractComments: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
moduleIds: 'deterministic',
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [{
|
||||||
@@ -232,7 +231,6 @@ module.exports = (env, argv) => {
|
|||||||
options: {
|
options: {
|
||||||
presets: [
|
presets: [
|
||||||
['@babel/preset-env', {
|
['@babel/preset-env', {
|
||||||
"targets": "> 0.2%, not ie>8, not op_mini all",
|
|
||||||
"useBuiltIns": "usage",
|
"useBuiltIns": "usage",
|
||||||
"corejs": 3,
|
"corejs": 3,
|
||||||
"modules": false
|
"modules": false
|
||||||
@@ -299,6 +297,7 @@ module.exports = (env, argv) => {
|
|||||||
extractComments: true,
|
extractComments: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
moduleIds: 'deterministic',
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [{
|
rules: [{
|
||||||
@@ -309,7 +308,6 @@ module.exports = (env, argv) => {
|
|||||||
options: {
|
options: {
|
||||||
presets: [
|
presets: [
|
||||||
['@babel/preset-env', {
|
['@babel/preset-env', {
|
||||||
"targets": "> 0.2%, not ie>8, not op_mini all",
|
|
||||||
"useBuiltIns": "usage",
|
"useBuiltIns": "usage",
|
||||||
"corejs": 3,
|
"corejs": 3,
|
||||||
"modules": false
|
"modules": false
|
||||||
|
|||||||
Reference in New Issue
Block a user