Explorar el Código

Build script updated to allow remote js files to be local

Andrew Collington hace 3 años
padre
commit
4fe73e0ef8
Se han modificado 5 ficheros con 27 adiciones y 9 borrados
  1. 2 3
      .gitignore
  2. 4 1
      README.md
  3. 17 1
      build/build.php
  4. 2 2
      build/template.phps
  5. 2 2
      index.php

+ 2 - 3
.gitignore

@@ -1,11 +1,10 @@
-/status.js
-/src/status.js
 /.idea
 /.module-cache
 /node_modules
+/vendor
 /package-lock.json
 /build/*
 !/build/template.phps
 !/build/build.php
 !/build/_frontend
-/vendor
+/*.js

+ 4 - 1
README.md

@@ -104,7 +104,7 @@ $opcache = (new Service([
 ]))->handle();
 ```
 
-## Changing the look
+## Building it yourself
 
 The interface has been split up to allow you to easily change the colours of the gui, or even the core components, should you wish.
 
@@ -125,6 +125,8 @@ The build process will create a compiled css file at `build/interface.css` and t
 
 The core PHP template used in the build process, and that acts to pass various bits of data to the ReactJS side of things, is located at `build/template.phps`.  If you wanted to update the version of ReactJS used, or how the wrapper html is structured, then this would be the file you'd want to update. 
 
+The template includes a few remote js files.  If you want to make those local (for example, you have CSP policies in place and the remote urls are not whitelisted), then you can use the `-l` or `--local-js` flags when building, such as `php ./build/build.php -l`.  This will fetch the remote script files and put them in the root of the repo, adjusting the links in the built `index.php` file to point to the local copies.  If you want to build it again with remote files, run the command again without the flag.
+
 ## The interface
 
 ### Overview
@@ -176,6 +178,7 @@ Also, if you choose to invalidate any files or reset the cache it will do this w
 **Version 3.4.0**\
 * Added new `datetime_format` config option for flexible formatting of date/time values
 * Added the cached file's `modified` date/time to the output (when the file was either added or updated)
+* You can now build the `index.php` file with the js files local rather than remote urls
 * Added PR#83 from @Stevemoretz
 
 **Version 3.3.1**\

+ 17 - 1
build/build.php

@@ -9,6 +9,8 @@
  * @license MIT, https://acollington.mit-license.org/
  */
 
+$options = getopt('l', ['local-js']);
+$makeJsLocal = (isset($options['l']) || isset($options['local-js']));
 $parentPath = dirname(__DIR__);
 
 if (!file_exists($parentPath . '/node_modules')) {
@@ -25,12 +27,26 @@ echo "🚀 Creating single build file\n";
 $template = trim(file_get_contents(__DIR__ . '/template.phps'));
 $jsOutput = trim(file_get_contents(__DIR__ . '/interface.js'));
 $cssOutput = trim(file_get_contents(__DIR__ . '/interface.css'));
-$phpOutput = trim(join('', array_slice(file($parentPath . '/src/Opcache/Service.php'), 3)));
+$phpOutput = trim(implode('', array_slice(file($parentPath . '/src/Opcache/Service.php'), 3)));
 $output = str_replace(
     ['{{JS_OUTPUT}}', '{{CSS_OUTPUT}}', '{{PHP_OUTPUT}}'],
     [$jsOutput, $cssOutput, $phpOutput],
     $template
 );
+if ($makeJsLocal) {
+    echo "🔗 Making js links local\n";
+    $jsTags = [];
+    $matched = preg_match_all('!<script src="([^"]*)"></script>!', $output, $jsTags);
+    if ($matched) {
+        foreach ($jsTags[1] as $jsUrl) {
+            $jsFile = basename($jsUrl);
+            $jsFilePath = $parentPath . '/' . $jsFile;
+            file_put_contents($jsFilePath, file_get_contents('https:' . $jsUrl));
+            $output = str_replace($jsUrl, $jsFile, $output);
+        }
+    }
+}
+
 file_put_contents($parentPath . '/index.php', $output);
 
 echo "💯 Done!\n";

+ 2 - 2
build/template.phps

@@ -62,7 +62,7 @@ $opcache = (new Service($options))->handle();
 
 ?>
 <!DOCTYPE html>
-<html>
+<html lang="en">
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width,initial-scale=1.0">
@@ -70,7 +70,7 @@ $opcache = (new Service($options))->handle();
     <script src="//unpkg.com/react/umd/react.production.min.js"></script>
     <script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
     <script src="//unpkg.com/axios/dist/axios.min.js"></script>
-    <style type="text/css">
+    <style>
         {{CSS_OUTPUT}}
     </style>
 </head>

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 2
index.php


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio