2017-11-29 10:01:48 +00:00
|
|
|
<?php
|
|
|
|
|
2017-12-04 18:22:58 +00:00
|
|
|
$version = $this->getVersion();
|
|
|
|
|
2017-11-29 10:01:48 +00:00
|
|
|
function getUrl ($fileName)
|
|
|
|
{
|
|
|
|
if (file_exists ($fileName))
|
2017-12-04 18:22:58 +00:00
|
|
|
$mTime = '?'. strftime ('%G%m%d%H%M%S', filemtime ($fileName));
|
2017-11-29 10:01:48 +00:00
|
|
|
else
|
2017-12-04 18:22:58 +00:00
|
|
|
$mTime = '?'. $this->getVersion ();
|
2017-11-29 10:01:48 +00:00
|
|
|
|
|
|
|
return $fileName.$mTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
function js ($fileName)
|
|
|
|
{
|
|
|
|
return '<script type="text/javascript" src="'. getUrl ($fileName) .'"></script>'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function css ($fileName)
|
|
|
|
{
|
|
|
|
return '<link rel="stylesheet" type="text/css" href="'. getUrl ($fileName) .'"/>'."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function getWebpackAssets ()
|
|
|
|
{
|
|
|
|
$wpConfig = json_decode (file_get_contents ('webpack.config.json'));
|
|
|
|
$buildDir = $wpConfig->buildDir;
|
|
|
|
$devServerPort = $wpConfig->devServerPort;
|
|
|
|
|
|
|
|
$host = $_SERVER['SERVER_NAME'];
|
|
|
|
$assets = new stdClass();
|
|
|
|
|
|
|
|
if (!_DEV_MODE)
|
|
|
|
{
|
|
|
|
$wpAssets = json_decode (file_get_contents ("$buildDir/webpack-assets.json"));
|
|
|
|
|
|
|
|
$manifestJs = $wpAssets->manifest->js;
|
|
|
|
$mainJs = $wpAssets->main->js;
|
|
|
|
unset ($wpAssets->manifest);
|
|
|
|
unset ($wpAssets->main);
|
|
|
|
|
|
|
|
foreach ($wpAssets as $name => $asset)
|
|
|
|
if (property_exists ($asset, 'js'))
|
|
|
|
$assets->$name = $asset->js;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$devServerPath = "http://$host:$devServerPort/$buildDir";
|
|
|
|
$manifestJs = "$devServerPath/manifest.js";
|
|
|
|
$mainJs = "$devServerPath/main.js";
|
|
|
|
|
|
|
|
unset ($wpConfig->entry->main);
|
|
|
|
|
|
|
|
foreach ($wpConfig->entry as $asset => $files)
|
|
|
|
$assets->$asset = "$devServerPath/$asset.js";
|
|
|
|
}
|
|
|
|
|
|
|
|
$jsFiles = [];
|
|
|
|
$jsFiles[] = $manifestJs;
|
|
|
|
|
|
|
|
foreach ($assets as $jsFile)
|
|
|
|
$jsFiles[] = $jsFile;
|
|
|
|
|
|
|
|
$jsFiles[] = $mainJs;
|
|
|
|
|
|
|
|
return $jsFiles;
|
|
|
|
}
|