Skip to content

Instantly share code, notes, and snippets.

@mattmccray
Created March 1, 2013 03:06
Show Gist options
  • Select an option

  • Save mattmccray/5062189 to your computer and use it in GitHub Desktop.

Select an option

Save mattmccray/5062189 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'thor'
require 'sprockets'
require 'fileutils'
def require_engine(name)
begin
require name
puts " o #{name} enabled"
rescue LoadError
puts " x #{name} disabled"
end
end
require_engine 'sprockets-commonjs'
require_engine 'coffee-script'
require_engine 'eco'
require_engine 'ejs'
require_engine 'less'
require_engine 'sass'
require_engine 'stylus'
require_engine 'stylus/sprockets'
class Sprocketizr < Thor
desc "build", "generates dist .js files"
def build
puts "Generating files..."
here= "#{ File.expand_path './' }/"
# puts "#{here}"
env= _build_env
env.each_file do |path|
rpath= path.to_s.gsub(here, '')
# puts " - #{ rpath }"
opath= rpath.split('/')
folder= opath.shift
if opath.length == 1 and %w(src source).include? folder
npath= opath.join('/')
npath= npath.split('.')
while npath.length > 2
npath.pop
end
npath= npath.join('.')
puts " - #{ rpath } -> build/#{npath}"
src= env[path]
unless src.nil?
# puts src.inspect
FileUtils.mkdir_p File.expand_path "#{here}/build"
File.open File.expand_path("#{here}/build/#{npath}"), 'w' do |f|
f.write src.to_s
end
else
puts "Couldn't load src for #{rpath}"
end
end
end
# puts env.entries
# puts env['app'].to_s
puts "Done."
end
desc "serve", "start build server"
def serve
puts "Starting server..."
env= _build_env
end
no_tasks do
def _build_env
environment = Sprockets::Environment.new
environment.append_path 'src'
environment.append_path 'source'
environment.append_path 'etc'
environment.append_path 'components'
environment.append_path 'vendor'
environment.append_path 'lib'
if defined? Stylus
Stylus.setup(environment)
Stylus.use :nib
end
environment
end
end
end
Sprocketizr.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment