Skip to content

Commit c59173a

Browse files
committed
Fixes #3 - add google_closure_compiler_api pypi module
1 parent 686d598 commit c59173a

File tree

11 files changed

+191
-79
lines changed

11 files changed

+191
-79
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
google_closure_compiler_api.egg-info
3+
dist

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM python:alpine
22

33
MAINTAINER Jay MOULIN <jaymoulin@gmail.com>
44

5-
COPY ./compiler.py /bin/compiler.py
5+
RUN pip install google-closure-compiler-api
66
COPY ./entrypoint.sh /bin/entrypoint
77
ENTRYPOINT ["/bin/entrypoint"]
8-
CMD ["/bin/compiler.py"]
8+
CMD ["google-closure-compiler"]

Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.PHONY: install clean check
2+
3+
test:
4+
make install
5+
twine upload -r testpypi dist/*
6+
publish:
7+
make install
8+
twine upload dist/*
9+
install:
10+
make clean
11+
make check
12+
sudo python3 setup.py sdist
13+
check:
14+
python3 setup.py check --restructuredtext
15+
build:
16+
mkdir -p build
17+
dist:
18+
mkdir -p dist
19+
clean: build dist
20+
sudo rm -Rf build/*
21+
sudo rm -Rf dist/*

README.md

Lines changed: 0 additions & 42 deletions
This file was deleted.

README.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
==========================================
2+
Google Closure Compiler API - Docker Image
3+
==========================================
4+
5+
.. image:: https://img.shields.io/github/release/femtopixel/docker-google-closure-compiler-api.svg
6+
:alt: latest release
7+
:align: left
8+
:target: http://github.com/femtopixel/docker-google-closure-compiler-api/releases
9+
.. image:: https://img.shields.io/pypi/v/google-closure-compiler-api.svg
10+
:alt: PyPI version
11+
:align: left
12+
:target: https://pypi.python.org/pypi?:action=display&name=google-closure-compiler-api
13+
.. image:: https://img.shields.io/docker/pulls/femtopixel/google-closure-compiler.svg
14+
:align: left
15+
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler/
16+
.. image:: https://img.shields.io/docker/stars/femtopixel/google-closure-compiler.svg
17+
:align: left
18+
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler/
19+
.. image:: https://img.shields.io/docker/pulls/femtopixel/google-closure-compiler-app.svg
20+
:align: left
21+
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler-app/
22+
.. image:: https://img.shields.io/docker/stars/femtopixel/google-closure-compiler-app.svg
23+
:align: left
24+
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler-app/
25+
.. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/btc.png
26+
:alt: Bitcoin donation
27+
:align: left
28+
:target: https://m.freewallet.org/id/374ad82e/btc
29+
.. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ltc.png
30+
:alt: Litecoin donation
31+
:align: left
32+
:target: https://m.freewallet.org/id/374ad82e/ltc
33+
.. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ppl.png
34+
:alt: PayPal donation
35+
:align: left
36+
:target: https://www.paypal.me/jaymoulin
37+
.. image:: https://beerpay.io/femtopixel/docker-google-closure-compiler-api/badge.svg
38+
:alt: Beerpay donation
39+
:align: left
40+
:target: https://beerpay.io/femtopixel/docker-google-closure-compiler-api
41+
42+
This image allows you to Compile your JS code using `Google Closure Compiler API <https://developers.google.com/closure/compiler/>`_ in CLI
43+
44+
Install
45+
=======
46+
47+
.. code::
48+
pip3 install google_closure_compiler_api
49+
50+
Usage
51+
=====
52+
.. code::
53+
54+
usage: compiler.py [-h] [--js JS] [--js_output_file JS_OUTPUT_FILE] [--compilation_level {WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS,ADVANCED_OPTIMIZATIONS}]
55+
56+
optional arguments:
57+
-h, --help show this help message and exit
58+
--js JS Input file
59+
--js_output_file JS_OUTPUT_FILE
60+
Output file
61+
--compilation_level {WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS,ADVANCED_OPTIMIZATIONS}
62+
Compilation level
63+
64+
65+
Default values
66+
--------------
67+
68+
- `--js` : /dev/stdin (input your code)
69+
- `--js_output_file` : /dev/stdout (Prints compiled code in the shell)
70+
- `--compilation_level` : WHITESPACE_ONLY
71+
72+
Docker usage
73+
============
74+
75+
.. code::
76+
77+
docker run --rm -ti -v /path/to/my/file.js:/root/myfile.js femtopixel/google-closure-compiler --js /root/myfile.js
78+

compiler.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -e
44
if [ "${1#-}" != "$1" ]; then
5-
set -- /bin/compiler.py "$@"
5+
set -- google-closure-compiler "$@"
66
fi
77

88
exec "$@"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
3+
"""
4+
5+
from .compiler import compile_file
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
import http.client
4+
import urllib.parse
5+
import argparse
6+
7+
__all__ = ['compile_file']
8+
9+
10+
def compile_file(input_file='/dev/stdin', out='/dev/stdout', level='WHITESPACE_ONLY', external=''):
11+
js_code = open(input_file, 'r')
12+
13+
params = urllib.parse.urlencode([
14+
('js_code', js_code.read()),
15+
('compilation_level', level),
16+
('output_format', 'text'),
17+
('output_info', 'compiled_code'),
18+
('js_externs', external),
19+
])
20+
21+
js_code.close()
22+
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
23+
conn = http.client.HTTPSConnection('closure-compiler.appspot.com')
24+
conn.request('POST', '/compile', params, headers)
25+
response = conn.getresponse()
26+
data = response.read()
27+
output_code = open(out, 'w')
28+
output_code.write(data.decode("utf-8"))
29+
output_code.close()
30+
conn.close()
31+
32+
33+
def main():
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("--js", default='/dev/stdin', help="Input file")
36+
parser.add_argument("--js_output_file", default='/dev/stdout', help="Output file")
37+
parser.add_argument("--compilation_level", default='WHITESPACE_ONLY',
38+
choices=['WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'],
39+
help="Compilation level")
40+
parser.add_argument("--js_externs", default='',
41+
help="Declare some external js vars and functions separated with semicolon")
42+
args = parser.parse_args()
43+
compile_file(args.js, args.js_output_file, args.compilation_level, args.js_externs)
44+
45+
46+
if __name__ == "__main__":
47+
main()

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.rst

0 commit comments

Comments
 (0)