Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parser.print_usage()
exit(-1)
namespace = options.namespace
headerPath = arguments[0]
sourcePath = arguments[1]
inputPaths = arguments[2:]
headerFile = open(headerPath, 'w')
print('namespace {0:s} {{'.format(namespace), file=headerFile)
sourceFile = open(sourcePath, 'w')
print('#include "{0:s}"'.format(os.path.basename(headerPath)), file=sourceFile)
print('namespace {0:s} {{'.format(namespace), file=sourceFile)
jsm = JavascriptMinify()
for inputFileName in inputPaths:
inputStream = io.FileIO(inputFileName)
outputStream = StringIO()
if not options.no_minify:
jsm.minify(inputStream, outputStream)
characters = outputStream.getvalue()
else:
characters = inputStream.read()
size = len(characters)
variableName = os.path.splitext(os.path.basename(inputFileName))[0]
print('extern const char {0:s}JavaScript[{1:d}];'.format(variableName, size), file=headerFile)
print('const char {0:s}JavaScript[{1:d}] = {{'.format(variableName, size), file=sourceFile)
def get_js_minified(self, codestr):
ins = StringIO(codestr)
outs = StringIO()
JavascriptMinify().minify(ins, outs)
min_js = outs.getvalue()
if len(min_js) > 0 and min_js[0] == '\n':
min_js = min_js[1:]
return re.sub(r'(\n|\r)+','', min_js)
def get_minified_js_str(self, js):
ins = StringIO(js)
outs = StringIO()
JavascriptMinify().minify(ins, outs)
str = outs.getvalue()
if len(str) > 0 and str[0] == '\n':
str = str[1:]
str = re.sub(r'(\n|\r)+','', str)
return str
def run(self):
try:
import jsmin
except:
pass
djanalytics_js_in = open('djanalytics/templates/djanalytics.js')
djanalytics_js_out = open('djanalytics/templates/djanalytics.js.min', 'w')
try:
jsmin.JavascriptMinify(djanalytics_js_in, djanalytics_js_out).minify()
finally:
djanalytics_js_in.close()
djanalytics_js_out.close()
# all copies or substantial portions of the Software.
#·
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import sys, os, glob
from jsmin import JavascriptMinify
for f in sys.argv[1:]:
with open(f, 'r') as js:
minifier = JavascriptMinify(js, sys.stdout)
minifier.minify()
sys.stdout.write('\n')
def get_minified_js_str(self, js):
ins = StringIO(js)
outs = StringIO()
JavascriptMinify().minify(ins, outs)
min_js = outs.getvalue()
if len(min_js) > 0 and min_js[0] == '\n':
min_js = min_js[1:]
min_js = re.sub(r'(\n|\r)+','', min_js)
return min_js
def open(self):
output = BytesIO()
minify = JavascriptMinify(self._file.open(), output, quote_chars="'\"`")
minify.minify()
output.seek(0)
if not self._verify_command:
return output
input_source = self._file.open().read()
output_source = output.getvalue()
with NamedTemporaryFile() as fh1, NamedTemporaryFile() as fh2:
fh1.write(input_source)
fh2.write(output_source)
fh1.flush()
fh2.flush()
try:
def minify_js(file_path, src):
"""Returns a minified version of the given JavaScript source string."""
in_str = StringIO(src)
out_str = StringIO()
JavascriptMinify().minify(in_str, out_str)
src = out_str.getvalue()
in_str.close()
out_str.close()
return src
def output(self, _in, out, **kw):
JavascriptMinify().minify(_in, out)