Skip to content

Commit

Permalink
new Makefile to meet jslibrary scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
dealfonso committed Oct 22, 2023
1 parent b0a4f67 commit 225921c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 13 deletions.
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@ LIBRARY_NAME := $(if $(LIBRARY_NAME),$(LIBRARY_NAME),$(current_dir))
DIST_FOLDER := $(if $(DIST_FOLDER),$(DIST_FOLDER),dist)
FILENAME = $(DIST_FOLDER)/$(LIBRARY_NAME)

DEPENDS =
DEPENDS_FOLDER = ./depends
DEP_FILES = $(foreach fd, $(DEPENDS), $(DEPENDS_FOLDER)/$(fd)/dist/$(fd).module.js)

PRE =
POST =
FILES = src/*.js

build: rawfile
build: rawfile depends
mkdir -p $(DIST_FOLDER)
cat $(DEP_FILES) $(FILENAME).raw.js | uglifyjs -e exports:window | js-beautify -t -s 1 -m 1 -j -n | cat notice - > $(FILENAME).full.js
cat $(DEP_FILES) $(FILENAME).raw.js | uglifyjs -e exports:window -b | js-beautify -t -s 1 -m 1 -j -n | cat notice - > $(FILENAME).js
cat $(DEP_FILES) $(FILENAME).raw.js | uglifyjs -e exports:window --toplevel --module -m | cat notice.min - > $(FILENAME).min.js
cat $(DEP_FILES) $(FILENAME).raw.js | uglifyjs -e exports:window --compress passes=3,dead_code=true,toplevel=true --toplevel --module -m -- | cat notice.min - > $(FILENAME).compress.js

module: rawfile depends
mkdir -p $(DIST_FOLDER)
cat $(FILENAME).raw.js | uglifyjs -e window,document:window,document | js-beautify -t -s 1 -m 1 -j -n | cat notice - > $(FILENAME).full.js
cat $(FILENAME).raw.js | uglifyjs -e window,document:window,document -b | js-beautify -t -s 1 -m 1 -j -n | cat notice - > $(FILENAME).js
cat $(FILENAME).raw.js | uglifyjs -e window,document:window,document --toplevel --module -m | cat notice.min - > $(FILENAME).min.js
cat $(FILENAME).raw.js | uglifyjs -e window,document:window,document --compress passes=3,dead_code=true,toplevel=true --toplevel --module -m -- | cat notice.min - > $(FILENAME).compress.js
( cat notice; echo 'if (typeof imports === "undefined") { var imports = {}; }' ; cat $(DEP_FILES) $(FILENAME).raw.js | uglifyjs -e exports:imports | js-beautify -t -s 1 -m 1 -j -n ) > $(FILENAME).module.js

rawfile: $(FILES) $(PRE) $(POST)
mkdir -p $(DIST_FOLDER)
cat $(PRE) $(FILES) $(POST) > $(FILENAME).raw.js

depends: $(DEPENDS)
echo $(DEPENDS) $(DEP_FILES)

clean:
rm -f $(FILENAME).raw.js $(FILENAME).full.js $(FILENAME).min.js $(FILENAME).js $(FILENAME).compress.js
if [ -d $(DIST_FOLDER) ] && [ -z "$(ls -A $(DIST_FOLDER))" ]; then rm -r $(DIST_FOLDER); fi
rm -f $(FILENAME).raw.js $(FILENAME).full.js $(FILENAME).min.js $(FILENAME).js $(FILENAME).compress.js $(FILENAME).module.js
if [ -d $(DIST_FOLDER) ] && [ -z "$(ls -A $(DIST_FOLDER))" ]; then rm -r $(DIST_FOLDER); fi

cleanall: clean
for fd in $(DEPENDS); do $(MAKE) -C $(DEPENDS_FOLDER)/$$fd clean; done

$(DEPENDS): FORCE
$(MAKE) -C $(DEPENDS_FOLDER)/$@ module

FORCE:
2 changes: 1 addition & 1 deletion dist/dom2object.compress.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions dist/dom2object.full.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
SOFTWARE.
*/

(function (window, document) {
(function (exports) {
"use strict";

function DOMToObject(el, acquireChildrenFromAnonymous = false) {
if (typeof el === "string") {
el = document.querySelector(el)
Expand Down Expand Up @@ -98,6 +100,7 @@
acquireChildren(proxy)
}
}
return true
}
});
acquireChildren(proxy);
Expand All @@ -119,4 +122,4 @@
};
DOMToObject.version = "0.9.0";
window.DOM2Object = DOMToObject
})(window, document);
})(window);
7 changes: 5 additions & 2 deletions dist/dom2object.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
SOFTWARE.
*/

(function (window, document) {
(function (exports) {
"use strict";

function DOMToObject(el, acquireChildrenFromAnonymous = false) {
if (typeof el === "string") {
el = document.querySelector(el);
Expand Down Expand Up @@ -98,6 +100,7 @@
acquireChildren(proxy);
}
}
return true;
}
});
acquireChildren(proxy);
Expand All @@ -119,4 +122,4 @@
};
DOMToObject.version = "0.9.0";
window.DOM2Object = DOMToObject;
})(window, document);
})(window);
2 changes: 1 addition & 1 deletion dist/dom2object.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/dom2object.raw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/**
* Builds a Proxy for the given DOM element, so that it can be accessed as an object, but if each of the HTML elements has an id, it can be accessed by that id.
* e.g.
Expand Down Expand Up @@ -115,6 +117,7 @@ function DOMToObject(el, acquireChildrenFromAnonymous = false) {
acquireChildren(proxy);
}
}
return true;
}
});

Expand Down

0 comments on commit 225921c

Please sign in to comment.