Skip to content

Commit a585b9e

Browse files
committed
added compiler in docker image
1 parent 5e9c9ca commit a585b9e

File tree

6 files changed

+109
-1
lines changed

6 files changed

+109
-1
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
How to Contribute
2+
=================
3+
4+
This project welcomes your contribution. There are several ways to help out:
5+
6+
* Create an [issue](https://github.com/femtopixel/docker-google-closure-compiler-api/issues/) on GitHub,
7+
if you have found a bug or have an idea for a feature
8+
* Write test cases for open bug issues
9+
* Write patches for open bug/feature issues
10+
11+
Issues
12+
------
13+
14+
* Submit an [issue](https://github.com/femtopixel/docker-google-closure-compiler-api/issues/)
15+
* Make sure it does not already exist.
16+
* Clearly describe the issue including steps to reproduce, when it is a bug.
17+
* Make sure you note the version you use.
18+
19+
Additional Resources
20+
--------------------
21+
22+
* [Existing issues](https://github.com/femtopixel/docker-google-closure-compiler-api/issues/)
23+
* [General GitHub documentation](https://help.github.com/)
24+
* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:alpine
2+
3+
MAINTAINER Jay MOULIN <jaymoulin@gmail.com>
4+
5+
COPY ./compiler.py /bin/compiler.py
6+
COPY ./entrypoint.sh /bin/entrypoint
7+
ENTRYPOINT ["/bin/entrypoint"]
8+
CMD ["/bin/compiler.py"]

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 Jay MOULIN
3+
Copyright (c) 2017 FemtoPixel
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Google Closure Compiler API - Docker Image
2+
==========================================
3+
4+
[![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)
5+
[![Bitcoin donation](https://github.com/jaymoulin/jaymoulin.github.io/raw/master/btc.png "Bitcoin donation")](https://m.freewallet.org/id/374ad82e/btc)
6+
[![Litecoin donation](https://github.com/jaymoulin/jaymoulin.github.io/raw/master/ltc.png "Litecoin donation")](https://m.freewallet.org/id/374ad82e/ltc)
7+
8+
This image allows you to Compile your JS code using [Google Closure Compiler API](https://developers.google.com/closure/compiler/) in CLI
9+
10+
Usage
11+
-----
12+
```
13+
usage: compiler.py [-h] [--js JS] [--js_output_file JS_OUTPUT_FILE]
14+
[--compilation_level {WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS,ADVANCED_OPTIMIZATIONS}]
15+
16+
optional arguments:
17+
-h, --help show this help message and exit
18+
--js JS Input file
19+
--js_output_file JS_OUTPUT_FILE
20+
Output file
21+
--compilation_level {WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS,ADVANCED_OPTIMIZATIONS}
22+
Compilation level
23+
```
24+
25+
## Default values
26+
27+
`--js` : /dev/stdin (input your code)
28+
`--js_output_file` : /dev/stdout (Prints compiled code in the shell)
29+
`--compilation_level` : WHITESPACE_ONLY
30+
31+
Docker usage
32+
------------
33+
34+
```
35+
docker run --rm -ti -v /path/to/my/file.js:/root/myfile.js femtopixel/google-closure-compiler --js /root/myfile.js
36+
```

compiler.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/local/bin/python3
2+
3+
import http.client, urllib.parse, sys, argparse
4+
5+
def main():
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument("--js", default='/dev/stdin', help="Input file")
8+
parser.add_argument("--js_output_file", default='/dev/stdout', help="Output file")
9+
parser.add_argument("--compilation_level", default='WHITESPACE_ONLY', choices=['WHITESPACE_ONLY', 'SIMPLE_OPTIMIZATIONS', 'ADVANCED_OPTIMIZATIONS'], help="Compilation level")
10+
args = parser.parse_args()
11+
js_code = open(args.js, 'r')
12+
13+
params = urllib.parse.urlencode([
14+
('js_code', js_code.read()),
15+
('compilation_level', args.compilation_level),
16+
('output_format', 'text'),
17+
('output_info', 'compiled_code'),
18+
])
19+
20+
js_code.close()
21+
headers = { "Content-type": "application/x-www-form-urlencoded" }
22+
conn = http.client.HTTPConnection('closure-compiler.appspot.com')
23+
conn.request('POST', '/compile', params, headers)
24+
response = conn.getresponse()
25+
data = response.read()
26+
output_code = open(args.js_output_file, 'w')
27+
output_code.write(data.decode("utf-8"))
28+
output_code.close()
29+
conn.close()
30+
31+
if __name__ == "__main__":
32+
main()

entrypoint.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
if [ "${1#-}" != "$1" ]; then
5+
set -- /bin/compiler.py "$@"
6+
fi
7+
8+
exec "$@"

0 commit comments

Comments
 (0)