Skip to content

Commit

Permalink
added compiler in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Oct 26, 2017
1 parent 5e9c9ca commit a585b9e
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 1 deletion.
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
How to Contribute
=================

This project welcomes your contribution. There are several ways to help out:

* Create an [issue](https://github.com/femtopixel/docker-google-closure-compiler-api/issues/) on GitHub,
if you have found a bug or have an idea for a feature
* Write test cases for open bug issues
* Write patches for open bug/feature issues

Issues
------

* Submit an [issue](https://github.com/femtopixel/docker-google-closure-compiler-api/issues/)
* Make sure it does not already exist.
* Clearly describe the issue including steps to reproduce, when it is a bug.
* Make sure you note the version you use.

Additional Resources
--------------------

* [Existing issues](https://github.com/femtopixel/docker-google-closure-compiler-api/issues/)
* [General GitHub documentation](https://help.github.com/)
* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:alpine

MAINTAINER Jay MOULIN <jaymoulin@gmail.com>

COPY ./compiler.py /bin/compiler.py
COPY ./entrypoint.sh /bin/entrypoint
ENTRYPOINT ["/bin/entrypoint"]
CMD ["/bin/compiler.py"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Jay MOULIN
Copyright (c) 2017 FemtoPixel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Google Closure Compiler API - Docker Image
==========================================

[![latest release](https://img.shields.io/github/release/femtopixel/docker-google-closure-compiler-api.svg "latest release")](http://github.com/femtopixel/docker-google-closure-compiler-api/releases)
[![Bitcoin donation](https://github.com/jaymoulin/jaymoulin.github.io/raw/master/btc.png "Bitcoin donation")](https://m.freewallet.org/id/374ad82e/btc)
[![Litecoin donation](https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ltc.png "Litecoin donation")](https://m.freewallet.org/id/374ad82e/ltc)

This image allows you to Compile your JS code using [Google Closure Compiler API](https://developers.google.com/closure/compiler/) in CLI

Usage
-----
```
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
------------

```
docker run --rm -ti -v /path/to/my/file.js:/root/myfile.js femtopixel/google-closure-compiler --js /root/myfile.js
```
32 changes: 32 additions & 0 deletions compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/local/bin/python3

import http.client, urllib.parse, sys, argparse

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")
args = parser.parse_args()
js_code = open(args.js, 'r')

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

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

if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

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

exec "$@"

0 comments on commit a585b9e

Please sign in to comment.