mde / fleegix-js-javascript-toolkit
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Tree:
59c117f
fleegix-js-javascript-toolkit / Rakefile
| c3372b71 » | mde | 2006-10-08 | 1 | #!/usr/bin/ruby | |
| 2 | |||||
| a7df9378 » | mde | 2007-09-10 | 3 | $YUI_COMPRESSOR_PATH = 'lib/yuicompressor-2.1.2.jar' | |
| 3bb5ca59 » | mde | 2007-09-16 | 4 | $COMPRESSION = true | |
| 7d69f25a » | mde | 2008-01-04 | 5 | $GZIP = true | |
| 83f187be » | mde | 2006-10-08 | 6 | ||
| c3475130 » | mde | 2007-09-09 | 7 | def get_source_file_list | |
| c3372b71 » | mde | 2006-10-08 | 8 | require 'find' | |
| 9 | files = Array.new | ||||
| c3475130 » | mde | 2007-09-09 | 10 | Find.find('./src/') do |f| | |
| 11 | # Don't include .svn version snapshots or vim's .js.swp files | ||||
| 12 | if FileTest.file?(f) and not f.include? '.svn' and f.index(/\.js$/) | ||||
| c3372b71 » | mde | 2006-10-08 | 13 | files.push(f) | |
| 14 | end | ||||
| 15 | end | ||||
| 16 | files | ||||
| 17 | end | ||||
| 18 | |||||
| 80e731c4 » | mde | 2008-08-17 | 19 | def get_base_module_file_list(param) | |
| 20 | mods = [] | ||||
| 21 | if not param.nil? and param.length > 0 | ||||
| 22 | mods = param.gsub(' ', '').split(",") | ||||
| 23 | mods.each do |p| | ||||
| 24 | p.sub!(/^/, './src/') | ||||
| 25 | end | ||||
| 26 | end | ||||
| 27 | puts mods.inspect | ||||
| 28 | mods | ||||
| 29 | end | ||||
| 30 | |||||
| c3475130 » | mde | 2007-09-09 | 31 | def get_plugin_file_list(param) | |
| 32 | plugins = [] | ||||
| 33 | if not param.nil? and param.length > 0 | ||||
| 6eb84b20 » | mde | 2007-09-10 | 34 | plugins = param.gsub(' ', '').split(",") | |
| c3475130 » | mde | 2007-09-09 | 35 | plugins.each do |p| | |
| 36 | p.sub!(/^/, './plugins/') | ||||
| 37 | end | ||||
| 38 | end | ||||
| 39 | plugins | ||||
| 40 | end | ||||
| 41 | |||||
| 42 | def concat_sourcefiles(files, filename) | ||||
| 43 | dist = File.new(filename + '.uncompressed.js', 'w') | ||||
| 90afaa0a » | mde | 2006-10-08 | 44 | js_file = File.new('./src/base.js') | |
| 45 | js = js_file.readlines.join | ||||
| 46 | dist << js | ||||
| 47 | # if (typeof fleegix == 'undefined') { var fleegix = {}; } | ||||
| 48 | re = Regexp.new('\/\*.*if \(typeof fleegix == \'undefined\'\) \{ var fleegix = \{\}; \}', Regexp::MULTILINE) | ||||
| c3372b71 » | mde | 2006-10-08 | 49 | files.each do |f| | |
| 47bfdd2e » | mde | 2008-02-10 | 50 | if f != './src/base.js' | |
| 51 | js_file = File.new(f) | ||||
| 52 | js = js_file.readlines.join | ||||
| 53 | js.sub!(re, '') | ||||
| 54 | dist << js | ||||
| 55 | end | ||||
| c3372b71 » | mde | 2006-10-08 | 56 | end | |
| 57 | dist.close | ||||
| 58 | true | ||||
| 59 | end | ||||
| 60 | |||||
| c3475130 » | mde | 2007-09-09 | 61 | def compress_concat(filename) | |
| 3bb5ca59 » | mde | 2007-09-16 | 62 | msg = %x{java -jar #{ $YUI_COMPRESSOR_PATH } -o #{ filename } #{ filename }.uncompressed.js 2>&1} | |
| 63 | if not $?.success? | ||||
| 64 | puts msg | ||||
| 65 | end | ||||
| 66 | true | ||||
| 67 | end | ||||
| 68 | |||||
| 69 | def gzip_compress(filename) | ||||
| 17073df1 » | mde | 2007-09-18 | 70 | msg = %x{gzip -c #{ filename } > #{ filename }.gz 2>&1} | |
| 3bb5ca59 » | mde | 2007-09-16 | 71 | if not $?.success? | |
| 72 | puts msg | ||||
| 73 | end | ||||
| c3372b71 » | mde | 2006-10-08 | 74 | true | |
| 75 | end | ||||
| 76 | |||||
| c3475130 » | mde | 2007-09-09 | 77 | desc "This builds a compressed fleegix.js or fleegix_plugins.js for production use." | |
| c3372b71 » | mde | 2006-10-08 | 78 | task :default do | |
| a7df9378 » | mde | 2007-09-10 | 79 | profile = ENV['profile'] | |
| 80 | # Config is a saved profile | ||||
| 81 | if not profile.nil? and profile.length > 0 | ||||
| 82 | require 'json' | ||||
| 83 | file = File.new(profile) | ||||
| 84 | file = file.readlines.join | ||||
| 85 | conf = JSON.parse(file) | ||||
| 3bb5ca59 » | mde | 2007-09-16 | 86 | plugins_only = conf['plugins_only'].to_s | |
| a7df9378 » | mde | 2007-09-10 | 87 | plugins = conf['plugins'] | |
| 80e731c4 » | mde | 2008-08-17 | 88 | base_modules = conf['base_modules'] | |
| 3bb5ca59 » | mde | 2007-09-16 | 89 | compression = conf['compression'].to_s | |
| 90 | gzip = conf['gzip'].to_s | ||||
| a7df9378 » | mde | 2007-09-10 | 91 | # Otherwise look for command params | |
| 92 | else | ||||
| 93 | plugins_only = ENV['plugins_only'] | ||||
| 94 | plugins = ENV['plugins'] | ||||
| 80e731c4 » | mde | 2008-08-17 | 95 | base_modules = ENV['base_modules'] | |
| 3bb5ca59 » | mde | 2007-09-16 | 96 | compression = ENV['compression'] | |
| 97 | gzip = ENV['gzip'] | ||||
| a7df9378 » | mde | 2007-09-10 | 98 | end | |
| 99 | |||||
| 100 | if plugins_only == 'true' | ||||
| c3475130 » | mde | 2007-09-09 | 101 | plugins_only = true | |
| 102 | filename = 'fleegix_plugins.js' | ||||
| 103 | else | ||||
| 104 | plugins_only = false | ||||
| 105 | filename = 'fleegix.js' | ||||
| 106 | end | ||||
| 3bb5ca59 » | mde | 2007-09-16 | 107 | if compression.nil? | |
| 108 | compression = $COMPRESSION | ||||
| 109 | else | ||||
| 110 | compression = compression == 'false' ? false : true; | ||||
| 111 | end | ||||
| 112 | if gzip.nil? | ||||
| 113 | gzip = $GZIP | ||||
| 114 | else | ||||
| 115 | gzip = gzip == 'false' ? false : true; | ||||
| 116 | end | ||||
| 117 | |||||
| 80e731c4 » | mde | 2008-08-17 | 118 | files = [] | |
| c3475130 » | mde | 2007-09-09 | 119 | if plugins_only | |
| 80e731c4 » | mde | 2008-08-17 | 120 | files += [] | |
| 121 | elsif not base_modules.nil? and base_modules.length > 0 | ||||
| 122 | puts 'Getting list of base source files ...' | ||||
| 123 | files += get_base_module_file_list(base_modules) | ||||
| c3475130 » | mde | 2007-09-09 | 124 | else | |
| 3bb5ca59 » | mde | 2007-09-16 | 125 | puts 'Getting list of base source files ...' | |
| c3475130 » | mde | 2007-09-09 | 126 | files = get_source_file_list | |
| 127 | end | ||||
| efc35433 » | mde | 2007-09-18 | 128 | ||
| 3bb5ca59 » | mde | 2007-09-16 | 129 | if not plugins.nil? and plugins.length > 0 | |
| 130 | puts 'Getting list of plugin source files ...' | ||||
| 131 | files += get_plugin_file_list(plugins) | ||||
| 132 | end | ||||
| efc35433 » | mde | 2007-09-18 | 133 | ||
| c3475130 » | mde | 2007-09-09 | 134 | puts 'Reading and concatenating source files ...' | |
| 135 | concat_sourcefiles(files, filename) | ||||
| 3bb5ca59 » | mde | 2007-09-16 | 136 | puts 'Built ' + filename + '.uncompresed.js' | |
| 137 | |||||
| 138 | if compression | ||||
| 139 | puts 'Compressing concatenated file ...' | ||||
| 140 | compress_concat(filename) | ||||
| 141 | puts 'Built ' + filename | ||||
| 142 | end | ||||
| 143 | |||||
| 144 | if gzip | ||||
| 145 | puts 'Gzipping compressed file ...' | ||||
| 146 | gzip_compress(filename) | ||||
| 17073df1 » | mde | 2007-09-18 | 147 | puts 'Built ' + filename + '.gz' | |
| 3bb5ca59 » | mde | 2007-09-16 | 148 | end | |
| efc35433 » | mde | 2007-09-18 | 149 | ||
| 3bb5ca59 » | mde | 2007-09-16 | 150 | puts 'Done.' | |
| c3372b71 » | mde | 2006-10-08 | 151 | end | |
| c3475130 » | mde | 2007-09-09 | 152 | ||
| 153 | desc "This removes any built fleegix.js files." | ||||
| 154 | task :clean do | ||||
| a7df9378 » | mde | 2007-09-10 | 155 | %x{rm *.js* 2>&1} | |
| c3475130 » | mde | 2007-09-09 | 156 | if $?.success? | |
| 3bb5ca59 » | mde | 2007-09-16 | 157 | puts 'Removed built fleegix.js files.' | |
| c3475130 » | mde | 2007-09-09 | 158 | else | |
| 159 | puts 'No built fleegix.js files to remove.' | ||||
| 160 | end | ||||
| 161 | true | ||||
| 162 | end | ||||
| 163 | |||||
| 164 | |||||
