lib/vbsmin.rb
# Minify a VBScript file (make a minified copy: file.min.vbs)
# @param filepath [String] Path to the VBS file to minify
# @return [String] Path of the minified file
Minify a VBScript file (make a minified copy: file.min.vbs)
Minify a VBScript file ( make a minified copy : file . min . vbs )
def minify(filepath)
    @original_filepath = filepath
    input_lines = IO.readlines(filepath).length
    File.open(min_ext, 'w') do |output|
      File.foreach(filepath).with_index(1) do |line, i|
        eol = ':' 
        line = inline_comment(line)
        line.strip!
        line = '' if line[0] == "'" || line[0..2].upcase == 'REM'
        line = internal_space(line)
        line[-1] = '' && eol = '' if line[-2..] == ' _'
        unless line.empty?
          output.write(line)
          output.write(eol) unless i == input_lines
        end
      end
    end
    calc_size
    return @min_filepath
  end
def minify ( filepath ) @original_filepath = filepath input_lines = IO . readlines ( filepath ) . length File . open ( min_ext , 'w' ) do | output | File . foreach ( filepath ) . with_index ( 1 ) do | line , i | eol = ':' line = inline_comment ( line ) line . strip! line = '' if line [ 0 ] == "'" || line [ 0 .. 2 ] . upcase == 'REM' line = internal_space ( line ) line [ - 1 ] = '' && eol = '' if line [ - 2 .. ] == ' _' unless line . empty? output . write ( line ) output . write ( eol ) unless i == input_lines end end end calc_size return @min_filepath end
Minify a VBScript file (make a minified copy: file.min.vbs)
Minify a VBScript file ( make a minified copy : file . min . vbs )
# Count number of line of input # File streaming # End of file char # Remove inline comment (must be before whitespace striping) # Remove leading and trailing whitespaces: null, horizontal tab, line feed, # vertical tab, form feed, carriage return, space # Remove comments except inline ones (must be after whitespace striping) # Remove space when several spaces between two keywords # Remove line splitting # Write processed line unless it is a blank line or the last line
Path of the minified file
Path of the minified file
String
filepath
Path to the VBS file to minify
Path to the VBS file to minify