Skip to content

Commit

Permalink
Fixes #3 - add google_closure_compiler_api pypi module
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Nov 12, 2017
1 parent 686d598 commit c59173a
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 79 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
google_closure_compiler_api.egg-info
dist
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM python:alpine

MAINTAINER Jay MOULIN <jaymoulin@gmail.com>

COPY ./compiler.py /bin/compiler.py
RUN pip install google-closure-compiler-api
COPY ./entrypoint.sh /bin/entrypoint
ENTRYPOINT ["/bin/entrypoint"]
CMD ["/bin/compiler.py"]
CMD ["google-closure-compiler"]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY: install clean check

test:
make install
twine upload -r testpypi dist/*
publish:
make install
twine upload dist/*
install:
make clean
make check
sudo python3 setup.py sdist
check:
python3 setup.py check --restructuredtext
build:
mkdir -p build
dist:
mkdir -p dist
clean: build dist
sudo rm -Rf build/*
sudo rm -Rf dist/*
42 changes: 0 additions & 42 deletions README.md

This file was deleted.

78 changes: 78 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
==========================================
Google Closure Compiler API - Docker Image
==========================================

.. image:: https://img.shields.io/github/release/femtopixel/docker-google-closure-compiler-api.svg
:alt: latest release
:align: left
:target: http://github.com/femtopixel/docker-google-closure-compiler-api/releases
.. image:: https://img.shields.io/pypi/v/google-closure-compiler-api.svg
:alt: PyPI version
:align: left
:target: https://pypi.python.org/pypi?:action=display&name=google-closure-compiler-api
.. image:: https://img.shields.io/docker/pulls/femtopixel/google-closure-compiler.svg
:align: left
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler/
.. image:: https://img.shields.io/docker/stars/femtopixel/google-closure-compiler.svg
:align: left
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler/
.. image:: https://img.shields.io/docker/pulls/femtopixel/google-closure-compiler-app.svg
:align: left
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler-app/
.. image:: https://img.shields.io/docker/stars/femtopixel/google-closure-compiler-app.svg
:align: left
:target: https://hub.docker.com/r/femtopixel/google-closure-compiler-app/
.. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/btc.png
:alt: Bitcoin donation
:align: left
:target: https://m.freewallet.org/id/374ad82e/btc
.. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ltc.png
:alt: Litecoin donation
:align: left
:target: https://m.freewallet.org/id/374ad82e/ltc
.. image:: https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ppl.png
:alt: PayPal donation
:align: left
:target: https://www.paypal.me/jaymoulin
.. image:: https://beerpay.io/femtopixel/docker-google-closure-compiler-api/badge.svg
:alt: Beerpay donation
:align: left
:target: https://beerpay.io/femtopixel/docker-google-closure-compiler-api

This image allows you to Compile your JS code using `Google Closure Compiler API <https://developers.google.com/closure/compiler/>`_ in CLI

Install
=======

.. code::
pip3 install google_closure_compiler_api
Usage
=====
.. code::
usage: compiler.py [-h] [--js JS] [--js_output_file JS_OUTPUT_FILE] [--compilation_level {WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS,ADVANCED_OPTIMIZATIONS}]
optional arguments:
-h, --help show this help message and exit
--js JS Input file
--js_output_file JS_OUTPUT_FILE
Output file
--compilation_level {WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS,ADVANCED_OPTIMIZATIONS}
Compilation level
Default values
--------------

- `--js` : /dev/stdin (input your code)
- `--js_output_file` : /dev/stdout (Prints compiled code in the shell)
- `--compilation_level` : WHITESPACE_ONLY

Docker usage
============

.. code::
docker run --rm -ti -v /path/to/my/file.js:/root/myfile.js femtopixel/google-closure-compiler --js /root/myfile.js
34 changes: 0 additions & 34 deletions compiler.py

This file was deleted.

2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

exec "$@"
5 changes: 5 additions & 0 deletions google_closure_compiler_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
"""

from .compiler import compile_file
47 changes: 47 additions & 0 deletions google_closure_compiler_api/compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python

import http.client
import urllib.parse
import argparse

__all__ = ['compile_file']


def compile_file(input_file='/dev/stdin', out='/dev/stdout', level='WHITESPACE_ONLY', external=''):
js_code = open(input_file, 'r')

params = urllib.parse.urlencode([
('js_code', js_code.read()),
('compilation_level', level),
('output_format', 'text'),
('output_info', 'compiled_code'),
('js_externs', external),
])

js_code.close()
headers = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
conn = http.client.HTTPSConnection('closure-compiler.appspot.com')
conn.request('POST', '/compile', params, headers)
response = conn.getresponse()
data = response.read()
output_code = open(out, 'w')
output_code.write(data.decode("utf-8"))
output_code.close()
conn.close()


def main():
parser = argparse.ArgumentParser()
parser.add_argument("--js", default='/dev/stdin', help="Input file")
parser.add_argument("--js_output_file", default='/dev/stdout', help="Output file")
parser.add_argument("--compilation_level", default='WHITESPACE_ONLY',
choices=['WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'],
help="Compilation level")
parser.add_argument("--js_externs", default='',
help="Declare some external js vars and functions separated with semicolon")
args = parser.parse_args()
compile_file(args.js, args.js_output_file, args.compilation_level, args.js_externs)


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.rst
32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

setup(
name='google_closure_compiler_api',
python_requires=">=3",
version='0.1.4',
packages=find_packages(),
long_description=open("README.rst", 'r').read(),
author="Jay MOULIN",
author_email="jaymoulin@gmail.com",
description="Google closure compiler CLI API",
include_package_data=True,
url='http://github.com/femtopixel/docker-google-closure-compiler-api',
classifiers=[
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Multimedia :: Sound/Audio",
],
entry_points={
'console_scripts': [
'google-closure-compiler = google_closure_compiler_api.compiler:main',
],
},
license="MIT",
)

0 comments on commit c59173a

Please sign in to comment.