phun-ky / patsy

A CLI based build system for frontend developers
MIT License
7 stars 2 forks source link

Base grunt tasks on this file #1

Closed phun-ky closed 11 years ago

phun-ky commented 12 years ago

PATH = 'javascript/mustaches'; TMP = 'tmp'; COMPRESS_FILES = false; #Should be true when releasing a version

desc 'update git repo from upstream repository' task :up do sh('git stash') sh('git svn rebase') sh('git stash apply') end

desc 'fix issue commit' task :f => [:pack]do sh("git commit -am'resolves issue NBP-#{ENV['m']}'" ) end

desc 'send up code changes to upstream repository' task :c => [:up] do sh('git add -u') sh("git commit -m'#{ENV['m']}'" ) sh('git svn rebase') sh('git svn dcommit') end

task :default =>[:mustache]

desc "make mustache templates" task :mustache do src = 'SB.extend({templates: {'; length = Dir[PATH+'/*.mustache'].length;

 Dir[PATH+'/*.mustache'].each do |f|
    file = File.open(f, 'rb').read();
    file.gsub!(/\n|\r|\t|\s\s/, '')
    src += '"'+File.basename(f).gsub(/\.mustache/, '')+ '"' + " : '" + file + "',";
 end
src += '"done":true}});';
File.open('javascript/mustaches/templates.js', 'wb'){|io| io.write(src) }
puts "Saved " + length.to_s + ' templates'

end

desc "Pack all css" task :css do css = [ [COMPRESS_FILES, "css/jquery-ui.css"], [COMPRESS_FILES, "css/edb/master.css"], [COMPRESS_FILES, "css/stb/main.css"], [COMPRESS_FILES, "css/stb/defaults.css"], [COMPRESS_FILES, "css/stb/tables.css"], [COMPRESS_FILES, "css/stb/navigation.css"], [COMPRESS_FILES, "css/master.css"],
[COMPRESS_FILES, "css/budget.css"]
].map do |pack, file| if(pack) puts "compressing #{file}" java -jar js/bin/yuicompressor-2.4.2.jar #{file} else puts "reading #{file}" IO.read(file) end end File.open('css/all.css', 'w'){|io| io.write(css.join("\n"))}

end

desc "Pack all external javascript files" task :ext do packMe = true js = [ [COMPRESS_FILES, 'js/ext/jquery-1.7.min.js' ], [COMPRESS_FILES, 'js/ext/json2.js' ], [COMPRESS_FILES, 'js/ext/excanvas.js' ], [COMPRESS_FILES, 'js/ext/highcharts.src.js' ], [COMPRESS_FILES, 'js/ext/thejit.js' ], [COMPRESS_FILES, 'js/ext/date-nb-NO.js' ], [COMPRESS_FILES, 'js/ext/jquery.bbq.js' ], [COMPRESS_FILES, 'js/ext/waypoints.js' ], [COMPRESS_FILES, 'js/ext/jquery.cookie.js' ],

[COMPRESS_FILES, 'js/ext/modernizr.js' ],

[COMPRESS_FILES,    'js/ext/jquery.autoGrowInput.js'            ],
[COMPRESS_FILES,    'js/ext/jquery-ui-1.8.x.js'                     ],
[COMPRESS_FILES,    'js/ext/jquery.ui.datepicker-no.js'     ],
[COMPRESS_FILES,    'js/ext/underscore-min.js'                      ],
[COMPRESS_FILES,    'js/ext/handlebars.js'                              ],
[COMPRESS_FILES,    'js/ext/mustache.js'                                    ],
[COMPRESS_FILES,    'js/ext/jquery.tiptip.js'                           ],
[COMPRESS_FILES,    'js/ext/stb_sdc_100706.js'                      ]
].map do |pack, file| 
if(pack)
  puts "compressing #{file}"
  `java -jar js/bin/yuicompressor-2.4.2.jar #{file}`
else
  puts "reading #{file}"
  IO.read(file)
end

end File.open('js/min/ext.js', 'w'){|io| io.write(js.join("\n"))} end

desc "Pack all javascript files" task :pack => [:mustache] do puts '###### PACKING JS #######' js = [

External scripts

[COMPRESS_FILES, 'js/min/ext.js'],
    # JS Core extensions
[COMPRESS_FILES,    'js/src/extensions.js'],
    # STB developed scripts
     #CORE FUNCTIONALITY
[COMPRESS_FILES,    'js/src/core.js'                                ],
[COMPRESS_FILES,    'js/src/mittforbruk.js'                 ],
[COMPRESS_FILES,    'js/src/economies.js'                       ],
[COMPRESS_FILES,    'js/src/browser.js'                         ],
[COMPRESS_FILES,    'js/src/colors.js'                          ],
[COMPRESS_FILES,    'js/src/templates.js'                       ],
[COMPRESS_FILES,    'js/src/utils.js'                               ],
[COMPRESS_FILES,    'js/src/formatters.js'                  ],
[COMPRESS_FILES,    'js/src/api.js'                                 ],
[COMPRESS_FILES,    'js/src/callbacks.js'                       ],
[COMPRESS_FILES,    'js/src/fn.js'                                  ],
[COMPRESS_FILES,    'js/src/handlers.js'                        ],
[COMPRESS_FILES,    'js/src/history.js'                         ],
[COMPRESS_FILES,    'js/src/options.js'                         ],
[COMPRESS_FILES,    'js/src/events.js'                          ],
[COMPRESS_FILES,    'js/src/organize.js'                        ],
[COMPRESS_FILES,    'js/src/datamining.js'                  ],
[COMPRESS_FILES,    'js/src/datatraversal.js'               ],
[COMPRESS_FILES,    'js/src/categorizing.js'                ],
     #MODULES
[COMPRESS_FILES,    'js/src/crumb.js'                               ],
[COMPRESS_FILES,    'js/src/autocomplete.js'                ],
[COMPRESS_FILES,    'js/src/datepicker.js'                  ],
[COMPRESS_FILES,    'js/src/accounts.js'                        ],
[COMPRESS_FILES,    'js/src/search.js'                          ],
[COMPRESS_FILES,    'js/src/table.js'                               ],
[COMPRESS_FILES,    'js/src/list.js'                                ],
[COMPRESS_FILES,    'js/src/treemap.js'                         ],
    #SERVICES
[COMPRESS_FILES,    'js/src/index.js'                               ],
[COMPRESS_FILES,    'js/src/transactions.js'                ],
[COMPRESS_FILES,    'js/src/categories.js'                  ],
[COMPRESS_FILES,    'js/src/barChart.js'                        ],
[COMPRESS_FILES,    'js/src/inout.js'                               ],
[COMPRESS_FILES,    'js/src/budget.js'                          ]
    ].map do |pack, file| 
if(pack)
  puts "compressing #{file}"
  `java -jar js/bin/yuicompressor-2.4.2.jar #{file}`
else
  puts "reading #{file}"
  IO.read(file)

end end File.open('js/min/SB.js', 'w'){|io| io.write(js.join("\n"))} end

desc 'Replace Tabs with spaces' task :tabs do puts '###### TABS #######' Dir['*/'].each do |f| puts File.basename(f) next if File.directory?(f) source = File.open(f, 'rb').read case File.extname(f) when '.js', '.css', '.html', '.sass', '.mustache' next if File.dirname(f).match(/ext/) source.gsub!(/\t/, ' ') end File.open("#{File.dirname(f)}/#{File.basename(f)}", 'wb') {|io| io.write(source)} end end

desc 'strip console logs' task :strip => [:tabs] do puts '###### STRIPPING CONSOLE CALLS #######' rm_rf(TMP) mkdirp(TMP) Dir[PATH+'/*/_.js'].each do |f| next if File.directory?(f) || File.basename(f) =~ /(min.|tests.|pack.|compiled.)/ source = File.open(f, 'rb').read file = File.basename(f) stripped = source stripped = source.gsub(/SB.(time|log)(.*?)[)\;\n]/, '') File.open(TMP+'/'+file, 'w'){|io| io.write(stripped)} end end task :r => [:mustache, :pack] do puts('Aaayay') end

desc 'Compile less files (windows OS)' task :lessCompile do puts '###### COMPILE css/.less => css/.css#######' count = 0 Dir['css/*.less'].each do |f| next if File.directory?(f) sh('cscript bin/lessc.wsf ' +f + ' ' +File.dirname(f) +'/' + File.basename(f,'.less') + '.css -compress') count =+ 1 puts(File.basename(f) + ' => ' + File.basename(f,'.less') + '.css') end puts('Total files compiled: ' +count.to_s) end

desc 'Compile less files (windows OS) and run rake' task :lessCompileRake => [:lessCompile, :css, :pack]

phun-ky commented 11 years ago

Closing issue to sift out all features into different issues