Pārlūkot izejas kodu

Update makefile to join files in order, Fix for Safari

Safari is not yet advanced enough to have default function argument
values.
Weiyi Lou 10 gadi atpakaļ
vecāks
revīzija
9a21bc6ba3
3 mainītis faili ar 26 papildinājumiem un 17 dzēšanām
  1. 21 14
      Makefile
  2. 1 0
      css/style.css
  3. 4 3
      js/pgsh.js

+ 21 - 14
Makefile

@@ -1,24 +1,31 @@
-# Title
+# vim: set sw=2 ts=2 sts=2 et tw=80 fmr={{{,}}} fdl=0 fdm=marker:
+# pgs-cli build.
+
+.PHONY: help dist
 
 # Auto-Documenting Section. Displays a target list with `##` descriptions.
 help:
 	@grep -E '^[a-zA-Z_-]+:.*## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "%-15s %s\n", $$1, $$2}'
-.PHONY: help dist
 
 dist: ## Create a distribution for live usage
-	@mkdir -p dist/{css,js,tags}
-	@echo "combining css"
-	@cat css/vendor/* > dist/css/app.css
-	@cat css/style.css >> dist/css/app.css
-	@echo "combining javascript"
-	@cat js/vendor/* > dist/js/app.js
-	@cat js/pgsh.js >> dist/js/app.js
-	@echo "copying riot tags"
+	# --- Create Folders ---
+	@mkdir -p dist/css dist/js dist/tags
+	# --- Combine CSS ---
+	@for file in $$(cat css/app.css | sed "$(CSS_FILES)"); do \
+		cat css/$$file >> dist/css/app.css; \
+	done
+	# --- Combine Javascript ---
+	@for file in $$(grep "$(JS_TAGS)" index.html | sed "$(JS_FILES)"); do \
+		cat $$file >> dist/js/app.js; \
+	done
+	# --- Copy Riot Tags ---
 	@cp tags/*.tag dist/tags/
-	@echo "adjusting index.html"
+	# --- Modify Index Page ---
 	@sed "/$(JS_TAGS)/D" index.html | sed "s|$(APPJS_PH)|$(APPJS_TAG)|" > dist/index.html
-	@echo "all done!"
+	@echo "All Done!"
 
-JS_TAGS = <script.*type='text\/javascript'
+CSS_FILES = s|@import.*[\'\"]\(.*\)[\'\"].*|\1|
+JS_TAGS = <script .*src=[\'\"].*\.js[\'\"]
+JS_FILES = s|.*src=[\'\"]\(.*\.js\)[\'\"].*|\1|
 APPJS_PH = <!-- appjsplaceholder -->
-APPJS_TAG = <script type='text/javascript' src='js/app.js'><\/script>
+APPJS_TAG = <script type='text/javascript' src='js/app.js'></script>

+ 1 - 0
css/style.css

@@ -1,3 +1,4 @@
+/* pgs-cli styles */
 * {
   color: #DDD;
   font-family: 'Courier New', Courier, Monospace;

+ 4 - 3
js/pgsh.js

@@ -254,9 +254,10 @@ function pgsh(ev) {
   }
 
   // Check if a path exists in the tree
-  var pathExists = function(path, file = false) {
+  var pathExists = function(path, isFile) {
+    var isFile = typeof isFile !== 'undefined' ? isFile : false; // Old way, for Safari.
     var parts = path.trim().split('/')
-    var fname = file ? parts.pop() : ''
+    var fname = isFile ? parts.pop() : ''
     var tree = self.tree
     for (var i = 0; i < parts.length; i++) {
       var part = parts[i]
@@ -268,7 +269,7 @@ function pgsh(ev) {
       }
       tree = tree[part]
     }
-    if (file && !(tree.hasOwnProperty(fname) && typeof tree[fname] === 'string')) {
+    if (isFile && !(tree.hasOwnProperty(fname) && typeof tree[fname] === 'string')) {
       return false
     }
     return true