update css_compress
This commit is contained in:
parent
02aaaf793d
commit
4fbe411b13
@ -24,10 +24,24 @@ def countnl(str, start, end):
|
|||||||
if (str[i] == '\n'): cnt = cnt+1;
|
if (str[i] == '\n'): cnt = cnt+1;
|
||||||
return cnt;
|
return cnt;
|
||||||
|
|
||||||
|
def comment_remover(text):
|
||||||
|
def replacer(match):
|
||||||
|
s = match.group(0)
|
||||||
|
if s.startswith('/'):
|
||||||
|
return " " # note: a space and not an empty string
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
pattern = re.compile(
|
||||||
|
r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
|
||||||
|
re.DOTALL | re.MULTILINE
|
||||||
|
)
|
||||||
|
return re.sub(pattern, replacer, text)
|
||||||
|
|
||||||
fsource = str.replace(sys.argv[1], '\\', '/') # scss
|
fsource = str.replace(sys.argv[1], '\\', '/') # scss
|
||||||
finput = str.replace(sys.argv[2], '\\', '/') # css
|
finput = str.replace(sys.argv[2], '\\', '/') # css
|
||||||
foutput = str.replace(sys.argv[3], '\\', '/') # min.css
|
foutput = str.replace(sys.argv[3], '\\', '/') # min.css
|
||||||
ftemp = '__temp_compresss_py_yui.tmp.css';
|
ftemp1 = '__temp_compresss_py_1.tmp.css';
|
||||||
|
ftemp2 = '__temp_compresss_py_2.tmp.css';
|
||||||
|
|
||||||
print('======== INPUT ========');
|
print('======== INPUT ========');
|
||||||
print();
|
print();
|
||||||
@ -37,9 +51,30 @@ print(foutput);
|
|||||||
print();
|
print();
|
||||||
print();
|
print();
|
||||||
|
|
||||||
|
print('======== DELETE OLD DATA ========');
|
||||||
|
if os.path.isfile(finput):
|
||||||
|
try:
|
||||||
|
os.remove(finput);
|
||||||
|
print(finput + ' deleted')
|
||||||
|
except e:
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
print(finput + ' does not exist')
|
||||||
|
if os.path.isfile(foutput):
|
||||||
|
try:
|
||||||
|
os.remove(foutput);
|
||||||
|
print(foutput + ' deleted')
|
||||||
|
except e:
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
print(foutput + ' does not exist')
|
||||||
|
print();
|
||||||
|
print();
|
||||||
|
|
||||||
|
|
||||||
print('======== CALL SCSS ========');
|
print('======== CALL SCSS ========');
|
||||||
out = subprocess.run(['scss.bat', '--no-cache', '--update', fsource + ':' + finput], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
out = subprocess.run(['ruby', 'scss', '--style=expanded', '--no-cache', '--update', fsource + ':' + finput], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
print('> scss.bat --no-cache --update ' + fsource + ':' + finput)
|
print('> scss.bat --style=expanded --no-cache --update ' + fsource + ':' + finput)
|
||||||
print('STDOUT:')
|
print('STDOUT:')
|
||||||
print(out.stdout.decode('utf-8'))
|
print(out.stdout.decode('utf-8'))
|
||||||
print('STDERR:')
|
print('STDERR:')
|
||||||
@ -48,10 +83,25 @@ print(out.stderr.decode('utf-8'))
|
|||||||
print('')
|
print('')
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
|
print('======== CLEANUP COMMENTS ========');
|
||||||
|
with open(finput, 'r') as tf:
|
||||||
|
data1 = tf.read()
|
||||||
|
print(str(len(data1)) + ' characters read from ' + os.path.basename(finput))
|
||||||
|
|
||||||
|
data1 = comment_remover(data1)
|
||||||
|
print('Comments in css removed');
|
||||||
|
|
||||||
|
with open(ftemp1, "w") as tf:
|
||||||
|
tf.write(data1)
|
||||||
|
print(str(len(data1)) + ' characters written to ' + ftemp1)
|
||||||
|
|
||||||
|
print('')
|
||||||
|
print('')
|
||||||
|
|
||||||
|
|
||||||
print('======== CALL YUI ========');
|
print('======== CALL YUI ========');
|
||||||
out = subprocess.run(['java', '-jar', 'yuicompressor.jar', '--verbose', finput, '-o', ftemp], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
out = subprocess.run(['java', '-jar', 'yuicompressor.jar', '--verbose', ftemp1, '-o', ftemp2], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
print('> java -jar yuicompressor.jar --verbose "'+finput+'" -o "'+ftemp+'"')
|
print('> java -jar yuicompressor.jar --verbose "'+finput+'" -o "'+ftemp2+'"')
|
||||||
print('STDOUT:');
|
print('STDOUT:');
|
||||||
print(out.stdout.decode('utf-8'))
|
print(out.stdout.decode('utf-8'))
|
||||||
print('STDERR:');
|
print('STDERR:');
|
||||||
@ -61,17 +111,19 @@ print('')
|
|||||||
print('')
|
print('')
|
||||||
|
|
||||||
print('======== READ ========');
|
print('======== READ ========');
|
||||||
with open(ftemp, 'r') as tf:
|
with open(ftemp2, 'r') as tf:
|
||||||
data = tf.read()
|
data = tf.read()
|
||||||
print(str(len(data)) + ' characters read from ' + ftemp)
|
print(str(len(data)) + ' characters read from ' + ftemp2)
|
||||||
|
|
||||||
print('')
|
print('')
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
print('======== REM ========');
|
print('======== REM ========');
|
||||||
try:
|
try:
|
||||||
os.remove(ftemp);
|
os.remove(ftemp1);
|
||||||
print(ftemp + ' deleted')
|
print(ftemp1 + ' deleted')
|
||||||
|
os.remove(ftemp2);
|
||||||
|
print(ftemp2 + ' deleted')
|
||||||
except e:
|
except e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@ -118,4 +170,19 @@ with open(foutput, "w") as tf:
|
|||||||
|
|
||||||
print('')
|
print('')
|
||||||
print('')
|
print('')
|
||||||
|
|
||||||
|
print('======== REMOVE MAP ========');
|
||||||
|
if os.path.isfile(finput + '.map'):
|
||||||
|
try:
|
||||||
|
os.remove(finput + '.map');
|
||||||
|
print(finput + '.map' + ' deleted')
|
||||||
|
except e:
|
||||||
|
print(e)
|
||||||
|
else:
|
||||||
|
print(finput + '.map' + ' does not exist')
|
||||||
|
|
||||||
|
print('')
|
||||||
|
print('')
|
||||||
|
|
||||||
|
|
||||||
print('Finished.')
|
print('Finished.')
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
|
||||||
version = ">= 0.a"
|
version = ">= 3.a"
|
||||||
|
|
||||||
if ARGV.first
|
if ARGV.first
|
||||||
str = ARGV.first
|
str = ARGV.first
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
|
||||||
@"C:\TOOLS\Ruby\bin\ruby.exe" "C:/TOOLS/Ruby/bin/scss" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
|
||||||
GOTO :EOF
|
|
||||||
:WinNT
|
|
||||||
@"C:\TOOLS\Ruby\bin\ruby.exe" "%~dpn0" %*
|
|
Loading…
Reference in New Issue
Block a user