From 827fa9372538c329705fdfbb4ca697486e499eab Mon Sep 17 00:00:00 2001 From: JoseluCross Date: Mon, 26 Jun 2017 17:06:00 +0200 Subject: [PATCH] Create project --- README.md | 7 +++++ data/supported.json | 3 ++ doc/REQUIREMENTS.md | 3 ++ src/minithunder.py | 72 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 README.md create mode 100644 data/supported.json create mode 100644 doc/REQUIREMENTS.md create mode 100644 src/minithunder.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f8e33d --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +MiniThunder += +Minimize project to production +- +### Requeriment: +* slimit +* rcssmin diff --git a/data/supported.json b/data/supported.json new file mode 100644 index 0000000..53bfece --- /dev/null +++ b/data/supported.json @@ -0,0 +1,3 @@ +{ + "supported": ["css"] +} \ No newline at end of file diff --git a/doc/REQUIREMENTS.md b/doc/REQUIREMENTS.md new file mode 100644 index 0000000..79975a6 --- /dev/null +++ b/doc/REQUIREMENTS.md @@ -0,0 +1,3 @@ +# Require +* [slimit](https://github.com/rspivak/slimit) +* [rcssmin](http://opensource.perlig.de/rcssmin) \ No newline at end of file diff --git a/src/minithunder.py b/src/minithunder.py new file mode 100644 index 0000000..dc5a1df --- /dev/null +++ b/src/minithunder.py @@ -0,0 +1,72 @@ +#!/usr/bin/python3 + +import os +import json + +from sys import argv as _ +from shutil import copyfile +from rcssmin import cssmin + +VERSION="0.1.0.0" +FORMATS={} +with open('../data/supported.json') as data: + FORMATS = json.load(data) + +def copyStructure(originalPath, finalPath): + if not os.path.isdir(originalPath): + raise Exception("The origin directory " + originalPath + " not exists") + + if not os.path.exists(finalPath): + os.makedirs(finalPath) + elif not os.path.isdir(finalPath): + raise Exception("The path " + finalPath + " exists but isn't a directory") + elif not os.listdir(finalPath) == []: + raise Exception("The folder " + finalPath + " is not empty") + startCopy(originalPath, finalPath) + + +def startCopy(origin, final): + originList = os.listdir(origin) + for i in originList: + part = i.split('.') + if os.path.isdir(origin+"/"+i): + os.makedirs(final+"/"+i) + startCopy(origin+"/"+i, final+"/"+i) + elif not part[len(part)-1] in FORMATS["supported"]: + copyfile(origin+"/"+i, final+"/"+i) + else: + minimizeFile(origin+"/"+i,final+"/"+i,part[len(part)-1]) + +def minimizeFile(source, production, format): + input = open(source, "r") + output = open(production, "w") + if format == "js": + output.write(jsmin(input.read(), mangle=True, mangle_toplevel=True)) + elif format == "css": + output.write(cssmin(input.read(), keep_bang_comments=True)) + + + +def main(): + if len(_) == 1 or _[1] == "-h": + help() + elif _[1] == "-v": + version() + elif _[1] == "-m" and len(_) == 4: + copyStructure(_[2], _[3]) + else: + help() + +def help(): + print("Usage of minithunder:") + print("---------------------") + print("-h: show help") + print("-v: show version") + print("-m : Minimize project to production") + +def version(): + print("MiniThunder - Prepare your software to production") + print("Version: "+VERSION) + +if __name__ == "__main__": + main()