Browse Source

Reorganisation done

Godzil 6 years ago
parent
commit
37167cd17f

+ 4 - 2
.gitignore

@@ -1,2 +1,4 @@
-*.gz
-
+dist/*.gz
+dist/*.lua
+dist/*.html
+venv/

+ 87 - 17
Makefile

@@ -3,40 +3,110 @@
 ######################################################################
 
 # Path to nodemcu-uploader (https://github.com/kmpm/nodemcu-uploader)
-NODEMCU-UPLOADER=../nodemcu-uploader/nodemcu-uploader.py
+export NODEMCU-UPLOADER=$(CURDIR)/uploader/nodemcu-uploader.py
 
 # Serial port
-PORT=/dev/ttyUSB0
-SPEED=115200
+export PORT=/dev/ttyUSB0
+export SPEED=115200
 
-NODEMCU-COMMAND=$(NODEMCU-UPLOADER) -b $(SPEED) --start_baud $(SPEED) -p $(PORT) upload
+export NODEMCU-COMMAND=$(NODEMCU-UPLOADER) -b $(SPEED) --start_baud $(SPEED) -p $(PORT) upload
+
+export PYTHON=$(CURDIR)/venv/bin/python
 
 ######################################################################
 
-HTTP_FILES := $(wildcard http/*)
-LUA_FILES := $(wildcard *.lua)
+SRC_LUA_FILES := $(wildcard src/*.lua)
+SRC_HTML_FILES := $(wildcard src/*.html)
+SRC_JS_FILES := $(wildcard src/*.js)
+SRC_ICO_FILES := $(wildcard src/*.ico)
+
+EXAMPLE_FILES := $(wildcard examples/*.html) $(wildcard examples/*.lua)
+
+DIST := dist
+DIST_FILES = $(wildcard $(DIST)/*.gz) $(wildcard $(DIST)/*.lua)
 
 # Print usage
 usage:
 	@echo "make upload FILE:=<file>  to upload a specific file (i.e make upload FILE:=init.lua)"
-	@echo "make upload_http          to upload files to be served"
+	@echo "make upload_webide        to upload webide"
+	@echo "make upload_webide        to upload examples"
 	@echo "make upload_server        to upload the server code and init.lua"
 	@echo "make upload_all           to upload all"
 	@echo $(TEST)
 
+prepare: httpserver/Makefile patchserver
+
+# make sure that the submodules are fetch
+httpserver/Makefile:
+	@echo Preparing submodules...
+	@git submodule init
+	@git submodule update
+	
+# Patch httpserver makefile for upload and init
+patchserver: httpserver/makefile.patched httpserver/init.patched
+
+httpserver/makefile.patched: patchs/httpserver_makefile.patch httpserver/Makefile
+	@echo Patching httpserver makefile...
+	@if [ -e $@ ]; then patch -p1 -R < $?; fi
+	@patch -p1 < $?
+	@touch ${@}
+	
+httpserver/init.patched: patchs/httpserver_init.patch httpserver/httpserver-compile.lua
+	@echo Patching httpserver scripts...
+	@if [ -e $@ ]; then patch -p1 -R < $?; fi
+	@patch -p1 < $?
+	@touch ${@}
+	
+httpserver/httpserver-start.lua:
+	@echo Replace httpserver init.lua by ${@}
+	@mv httpserver/init.lua ${@}
+
+
+install: compress copy_lua
+	
+# Compress files
+compress: compress_html compress_js compress_ico
+
+compress_html: $(SRC_HTML_FILES)
+	@echo Compression HTML files
+	@cp $^ $(DIST)/
+	@gzip -9 -f $(DIST)/*.html
+	
+compress_js: $(SRC_JS_FILES)
+	@echo Compression JS files
+	cp $^ $(DIST)/
+	gzip -9 -f $(DIST)/*.js
+	
+compress_ico: $(SRC_ICO_FILES)
+	@echo Compression ICO files
+	cp $^ $(DIST)/
+	gzip -9 -f $(DIST)/*.ico
+
+copy_lua: $(SRC_LUA_FILES)
+	cp $^ $(DIST)/
+	
+venv: prepare venv/bin/activate
+venv/bin/activate: uploader/test_requirements.txt
+	@test -d venv || virtualenv venv --python=python3
+	@venv/bin/pip install -Ur $<
+	@touch venv/bin/activate
+
 # Upload one files only
-upload:
-	@python $(NODEMCU-COMMAND) $(FILE)
+upload: prepare venv
+	@$(PYTHON) $(NODEMCU-COMMAND) $(FILE)
 
-# Upload HTTP files only
-upload_http: $(HTTP_FILES)
-	@python $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
+# Upload webide
+upload_webide: $(DIST_FILES) prepare venv install
+	@$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
 
+# Upload examples files
+upload_examples: $(EXAMPLES_FILES) prepare venv
+	@$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
+	
+	
 # Upload httpserver lua files (init and server module)
-upload_server: $(LUA_FILES)
-	@python $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
+upload_server: prepare patchserver venv httpserver/Makefile
+	@make -C httpserver upload_server
 
 # Upload all
-upload_all: $(LUA_FILES) $(HTTP_FILES)
-	@python $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
-
+upload_all: upload_server upload_webide upload_examples

BIN
bin/addons.js.gz


BIN
bin/codemirror.js.gz


BIN
bin/favicon.ico.gz


BIN
bin/index.html.gz


BIN
bin/index.js.gz


BIN
bin/modes.js.gz


+ 0 - 0
dist/.keep


+ 12 - 0
patchs/httpserver_init.patch

@@ -0,0 +1,12 @@
+diff --git a/httpserver-compile.lua b/httpserver-compile.lua
+index 29b49a5..4cff883 100644
+--- a/httpserver-compile.lua
++++ b/httpserver-compile.lua
+@@ -25,6 +25,7 @@ local serverFiles = {
+    'httpserver-request.lua',
+    'httpserver-static.lua',
+    'httpserver-wifi.lua',
++   'httpserver-start.lua',
+ }
+ for i, f in ipairs(serverFiles) do compileAndRemoveIfNeeded(f) end
+ 

+ 47 - 0
patchs/httpserver_makefile.patch

@@ -0,0 +1,47 @@
+diff --git a/Makefile b/Makefile
+index a03055b..c1f17d4 100644
+--- a/Makefile
++++ b/Makefile
+@@ -3,13 +3,16 @@
+ ######################################################################
+ 
+ # Path to nodemcu-uploader (https://github.com/kmpm/nodemcu-uploader)
+-NODEMCU-UPLOADER=../nodemcu-uploader/nodemcu-uploader.py
++NODEMCU-UPLOADER?=../nodemcu-uploader/nodemcu-uploader.py
+ 
+ # Serial port
+-PORT=/dev/cu.SLAB_USBtoUART
+-SPEED=115200
++PORT?=/dev/cu.SLAB_USBtoUART
+ 
+-NODEMCU-COMMAND=$(NODEMCU-UPLOADER) -b $(SPEED) --start_baud $(SPEED) -p $(PORT) upload
++SPEED?=115200
++
++NODEMCU-COMMAND?=$(NODEMCU-UPLOADER) -b $(SPEED) --start_baud $(SPEED) -p $(PORT) upload
++
++PYTHON?=python3
+ 
+ ######################################################################
+ 
+@@ -26,17 +29,17 @@ usage:
+ 
+ # Upload one files only
+ upload:
+-	@python $(NODEMCU-COMMAND) $(FILE)
++	@$(PYTHON) $(NODEMCU-COMMAND) $(FILE)
+ 
+ # Upload HTTP files only
+ upload_http: $(HTTP_FILES)
+-	@python $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
++	@$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
+ 
+ # Upload httpserver lua files (init and server module)
+ upload_server: $(LUA_FILES)
+-	@python $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
++	@$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
+ 
+ # Upload all
+ upload_all: $(LUA_FILES) $(HTTP_FILES)
+-	@python $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
++	@$(PYTHON) $(NODEMCU-COMMAND) $(foreach f, $^, $(f))
+ 

+ 17 - 0
src/init.lua

@@ -0,0 +1,17 @@
+-- Compile webide files
+if file.exists("httpserver-compile.lc") then
+   dofile("httpserver-compile.lc")
+else
+   dofile("httpserver-compile.lua")
+end
+
+if file.exists("startup.lua") then
+   dofile("startup.lua")
+end
+
+-- Run httpserver
+if file.exists("httpserver-start.lc") then
+   dofile("httpserver-start.lc")
+else
+   dofile("httpserver-start.lua")
+end

+ 1 - 0
src/startup.lua

@@ -0,0 +1 @@
+-- Put here what you want to be loaded at startup (like driver initialisations)

+ 21 - 0
src/webide-compile.lua

@@ -0,0 +1,21 @@
+-- webide-compile.lua
+-- Based on nodemcu-httpserver httpserver-compile.lua
+
+local compileAndRemoveIfNeeded = function(f)
+   if file.open(f) then
+      file.close()
+      print('Compiling:', f)
+      node.compile(f)
+      file.remove(f)
+      collectgarbage()
+   end
+end
+
+local webideFiles = {
+   'file-api.lua',
+}
+for i, f in ipairs(webideFiles) do compileAndRemoveIfNeeded(f) end
+
+compileAndRemoveIfNeeded = nil
+webideFiles = nil
+collectgarbage()