gokart 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +0 -0
- data/README.md +0 -0
- data/assets/Gemfile +24 -0
- data/assets/Guardfile +37 -0
- data/assets/Rakefile +5 -0
- data/assets/config.rb +24 -0
- data/assets/spec/javascripts/support/jasmine.yml +76 -0
- data/assets/spec/javascripts/support/jasmine_config.rb +23 -0
- data/assets/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/assets/src/server/http_handler.go +139 -0
- data/assets/src/server/main.go +31 -0
- data/assets/src/server/my_test.go +13 -0
- data/assets/src/server/templates.go +42 -0
- data/assets/src/www/app/coffee/application.js.coffee +6 -0
- data/assets/src/www/app/coffee/helpers/properties.js.coffee +19 -0
- data/assets/src/www/app/coffee/libs/deferred.js.coffee +92 -0
- data/assets/src/www/app/coffee/libs/logger.js.coffee +40 -0
- data/assets/src/www/app/coffee/libs/mod_loader.js.coffee +44 -0
- data/assets/src/www/app/coffee/main.js.coffee +10 -0
- data/assets/src/www/app/partials/index.html +92 -0
- data/assets/src/www/app/sass/application.css.scss +136 -0
- data/assets/src/www/app/templates/application.gotmpl +2 -0
- data/assets/src/www/app/templates/base.gotmpl.erb +31 -0
- data/assets/src/www/app/templates/home.gotmpl +30 -0
- data/assets/src/www/spec/coffee/deferred-spec.coffee +202 -0
- data/assets/src/www/spec/coffee/mocks.coffee +137 -0
- data/assets/src/www/spec/coffee/mod_loader-spec.coffee +45 -0
- data/assets/src/www/spec/coffee/properties-spec.coffee +21 -0
- data/assets/tasks/app.rake +34 -0
- data/assets/tasks/jasmine.rake +8 -0
- data/assets/tasks/server.rake +58 -0
- data/assets/tasks/www.rake +162 -0
- data/bin/gokart +28 -0
- data/lib/gokart/base.rb +59 -0
- data/lib/gokart/environment.rb +39 -0
- data/lib/gokart/version.rb +3 -0
- data/lib/gokart.rb +8 -0
- metadata +253 -0
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            describe 'Module Loader Spec', ->
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              beforeEach ->
         | 
| 4 | 
            +
                modLoader.clearAll()
         | 
| 5 | 
            +
                return
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              it 'should be defined as a global object', ->
         | 
| 8 | 
            +
                expect(modLoader).toBeDefined()
         | 
| 9 | 
            +
                return
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              it 'should be able to define a new module', ->
         | 
| 12 | 
            +
                modLoader.define 'testmod-1', (require, exports)->
         | 
| 13 | 
            +
                  return
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                expect(modLoader.isDefined('testmod-1')).toBe(true)
         | 
| 16 | 
            +
                return
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              it 'should be able to define a new module with exports', ->
         | 
| 19 | 
            +
                modLoader.define 'testmod-1', (require, exports)->
         | 
| 20 | 
            +
                  exports.isLoaded = true
         | 
| 21 | 
            +
                  return
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                exports = modLoader.require 'testmod-1'
         | 
| 24 | 
            +
                expect(exports).toBeDefined()
         | 
| 25 | 
            +
                expect(exports.isLoaded).toBe(true)
         | 
| 26 | 
            +
                return
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              it 'should only load a module once and cache the exports', ->
         | 
| 29 | 
            +
                numLoaded = 0
         | 
| 30 | 
            +
                modLoader.define 'testmod-1', (require, exports)->
         | 
| 31 | 
            +
                  numLoaded++
         | 
| 32 | 
            +
                  exports.isLoaded = true
         | 
| 33 | 
            +
                  return
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                exports = modLoader.require 'testmod-1'
         | 
| 36 | 
            +
                expect(exports).toBeDefined()
         | 
| 37 | 
            +
                expect(exports.isLoaded).toBe(true)
         | 
| 38 | 
            +
                expect(numLoaded).toBe(1)
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                exports = modLoader.require 'testmod-1'
         | 
| 41 | 
            +
                expect(exports).toBeDefined()
         | 
| 42 | 
            +
                expect(exports.isLoaded).toBe(true)
         | 
| 43 | 
            +
                expect(numLoaded).toBe(1)
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                return
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            describe 'Properties generator', ->
         | 
| 2 | 
            +
              Properties = modLoader.require 'helpers/properties'
         | 
| 3 | 
            +
              
         | 
| 4 | 
            +
              it 'should be able to add properties to a object', ->
         | 
| 5 | 
            +
                obj = {}
         | 
| 6 | 
            +
                Properties.add obj,
         | 
| 7 | 
            +
                  val1: {value:'test 1 value',static:true}
         | 
| 8 | 
            +
                  val2: {value: 'test 2 value'}
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                expect(obj.__auto__val1).toBe('test 1 value')
         | 
| 11 | 
            +
                expect(obj.val1()).toBe('test 1 value')
         | 
| 12 | 
            +
                expect(obj.__auto__val2).toBe('test 2 value')
         | 
| 13 | 
            +
                expect(obj.val2()).toBe('test 2 value')
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                obj.val1('failed value')
         | 
| 16 | 
            +
                expect(obj.val1()).toBe('test 1 value')
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                obj.val2('failed value 2')
         | 
| 19 | 
            +
                expect(obj.val2()).toBe('failed value 2')
         | 
| 20 | 
            +
                return
         | 
| 21 | 
            +
              return
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            namespace :app do
         | 
| 3 | 
            +
              desc 'Default action to perform, builds the app then runs it'
         | 
| 4 | 
            +
              task :default => [:start]
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              desc 'Builds build app source files'
         | 
| 7 | 
            +
              task :build => ['www:build', 'server:build']
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              desc 'Cleans the build paths for build parts of the app'
         | 
| 10 | 
            +
              task :clean => [:stop, 'www:clean', 'server:clean']
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              desc 'Cleans the build paths then builds are source files'
         | 
| 13 | 
            +
              task :rebuild => [:clean, :build]
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              desc 'Runs the test units for build source files'
         | 
| 16 | 
            +
              task :test => ['www:test', 'server:test']
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              desc 'Stops and restarts the server'
         | 
| 19 | 
            +
              task :restart => [:stop, :start]
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              desc 'Builds the app if needed, and starts it'
         | 
| 22 | 
            +
              task :start => [:build, 'server:start']
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              desc 'Builds the app if wth debug, and starts it'
         | 
| 25 | 
            +
              task :startdebug => [:build, 'server:startdebug']
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              desc 'Stops the server if it was running'
         | 
| 28 | 
            +
              task :stop => ['server:stop']
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              desc 'Runs the guard command within bundler'
         | 
| 31 | 
            +
              task :guard => [:rebuild] do
         | 
| 32 | 
            +
                `bundle exec guard`
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,58 @@ | |
| 1 | 
            +
            require 'rake'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            namespace :app do
         | 
| 4 | 
            +
              namespace :server do
         | 
| 5 | 
            +
                task :init do
         | 
| 6 | 
            +
                  dirs = []
         | 
| 7 | 
            +
                  dirs << GO_BUILD_PATH
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  dirs.each do |path|
         | 
| 10 | 
            +
                    begin
         | 
| 11 | 
            +
                      FileUtils::mkdir_p(path) if (!FileTest::directory?(path))
         | 
| 12 | 
            +
                    rescue
         | 
| 13 | 
            +
                      puts "Failed to create directory #{path}"
         | 
| 14 | 
            +
                    end
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                desc 'Builds the existing source'
         | 
| 19 | 
            +
                task :build => [:init] do
         | 
| 20 | 
            +
                  `GOPATH="#{ROOT}" go install #{GO_APP_NAME} 1>&2`
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                desc 'Cleans the build path'
         | 
| 24 | 
            +
                task :clean do
         | 
| 25 | 
            +
                  paths = []
         | 
| 26 | 
            +
                  paths << File.join(GO_BUILD_PATH, 'server')
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  paths.each do |path|
         | 
| 29 | 
            +
                    begin
         | 
| 30 | 
            +
                      FileUtils::rm_rf path
         | 
| 31 | 
            +
                    rescue
         | 
| 32 | 
            +
                      puts "Failed to clean server's #{path}"
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                desc 'Runs the test units for the source files'
         | 
| 38 | 
            +
                task :test => [:build] do
         | 
| 39 | 
            +
                	`GOPATH="#{ROOT}" go test #{GO_APP_NAME} 1>&2`
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                desc 'Runs the server, killing old instance if there was one.'
         | 
| 43 | 
            +
                task :start, [:port, :static] => [:stop] do |t, args|
         | 
| 44 | 
            +
                  args.with_defaults(:port => 8080, :static => :true)
         | 
| 45 | 
            +
                  `./bin/#{GO_APP_NAME} -port=#{args[:port]} -static=#{args[:static]} -tmpl="#{TMPL_BUILD_PATH}" -www="#{MIN_WWW_PATH}"`
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                desc 'Runs the server, killing old instance if there was one.'
         | 
| 49 | 
            +
                task :startdebug, [:port] => [:stop] do |t, args|
         | 
| 50 | 
            +
                  args.with_defaults(:port => 8080, :static => :true)
         | 
| 51 | 
            +
                  `./bin/#{GO_APP_NAME} -port=#{args[:port]} -debug=true -static=true -tmpl="#{TMPL_BUILD_PATH}" -www="#{DEBUG_WWW_PATH}"`
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                desc 'Stops the server if it was running'
         | 
| 55 | 
            +
                task :stop do
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
              end
         | 
| 58 | 
            +
            end
         | 
| @@ -0,0 +1,162 @@ | |
| 1 | 
            +
            require 'fileutils'
         | 
| 2 | 
            +
            require 'coffee_script'
         | 
| 3 | 
            +
            require 'sass'
         | 
| 4 | 
            +
            require 'yui/compressor'
         | 
| 5 | 
            +
            require 'uglifier'
         | 
| 6 | 
            +
            require 'sprockets'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            sprockets = (Sprockets::Environment.new(ROOT) { |env| env.logger = Logger.new(STDOUT) })
         | 
| 9 | 
            +
            sprockets.append_path WWW_SRC_VENDOR_PATH.join('css').to_s
         | 
| 10 | 
            +
            sprockets.append_path WWW_SRC_APP_PATH.join('sass').to_s
         | 
| 11 | 
            +
            sprockets.append_path WWW_SRC_VENDOR_PATH.join('js').to_s
         | 
| 12 | 
            +
            sprockets.append_path WWW_SRC_APP_PATH.join('coffee').to_s
         | 
| 13 | 
            +
            sprockets.append_path WWW_SRC_APP_PATH.join('templates').to_s
         | 
| 14 | 
            +
            # Note: Requires JVM for YUI
         | 
| 15 | 
            +
            sprockets.css_compressor = YUI::CssCompressor.new
         | 
| 16 | 
            +
            sprockets.js_compressor  = Uglifier.new(mangle: true)
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            # Add the go template mime type/extension so we can specify the directive processors in them
         | 
| 19 | 
            +
            sprockets.register_mime_type('text/gotmpl', '.gotmpl')
         | 
| 20 | 
            +
            sprockets.register_processor('text/gotmpl', Sprockets::DirectiveProcessor)
         | 
| 21 | 
            +
             | 
| 22 | 
            +
             | 
| 23 | 
            +
            desc 'Iterates over the input directory building a list of coffee files to compile'
         | 
| 24 | 
            +
            def coffee(inDir, outDir)
         | 
| 25 | 
            +
              Dir.glob("#{inDir}/**/*.coffee").each do |file|
         | 
| 26 | 
            +
                outFile = file.partition(inDir)[2]
         | 
| 27 | 
            +
                next if (outFile.empty?)
         | 
| 28 | 
            +
                outFile.sub!(/coffee$/, 'js')
         | 
| 29 | 
            +
                coffee_compile(file, outDir+outFile)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
            end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            desc 'Compiles the coffee script file and writes it to the out'
         | 
| 34 | 
            +
            def coffee_compile(inFile, outFile)
         | 
| 35 | 
            +
              begin
         | 
| 36 | 
            +
                File.delete(outFile) if (FileTest::file?(outFile))
         | 
| 37 | 
            +
                FileUtils::mkdir_p(File.dirname(outFile)) if (!FileTest::directory?(File.dirname(outFile)))
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                f = File.new(outFile, "w")
         | 
| 40 | 
            +
                f.write(CoffeeScript.compile(File.read(inFile)))
         | 
| 41 | 
            +
                f.close()
         | 
| 42 | 
            +
              rescue
         | 
| 43 | 
            +
                puts "Failed to compile #{inFile} to #{outFile}"
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            namespace :app do
         | 
| 48 | 
            +
              namespace :www do
         | 
| 49 | 
            +
                task :init do
         | 
| 50 | 
            +
                  paths = []
         | 
| 51 | 
            +
                  paths << MIN_WWW_PATH.join('js')
         | 
| 52 | 
            +
                  paths << MIN_WWW_PATH.join('css')
         | 
| 53 | 
            +
                  paths << MIN_WWW_PATH.join('images')
         | 
| 54 | 
            +
                  paths << MIN_WWW_PATH.join('partials')
         | 
| 55 | 
            +
                  paths << DEBUG_WWW_PATH.join('js')
         | 
| 56 | 
            +
                  paths << DEBUG_WWW_PATH.join('css')
         | 
| 57 | 
            +
                  paths << DEBUG_WWW_PATH.join('images')
         | 
| 58 | 
            +
                  paths << DEBUG_WWW_PATH.join('partials')
         | 
| 59 | 
            +
                  paths << TMPL_BUILD_PATH
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  paths.each do |path|
         | 
| 62 | 
            +
                    begin
         | 
| 63 | 
            +
                      FileUtils::mkdir_p(path) if (!FileTest::directory?(path))
         | 
| 64 | 
            +
                    rescue
         | 
| 65 | 
            +
                      puts "Failed to create directory #{path}"
         | 
| 66 | 
            +
                    end
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                task :spec_coffee do
         | 
| 71 | 
            +
                  coffee "#{WWW_SRC_SPEC_PATH}/coffee", WWW_SPEC_PATH.to_s
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                task :images do
         | 
| 75 | 
            +
                  from  = WWW_SRC_APP_PATH.join('images')
         | 
| 76 | 
            +
                  to    = DEBUG_WWW_PATH
         | 
| 77 | 
            +
                  begin
         | 
| 78 | 
            +
                    FileUtils::cp_r from, to
         | 
| 79 | 
            +
                  rescue
         | 
| 80 | 
            +
                    puts "Failed to copy directory #{from} to #{to}"
         | 
| 81 | 
            +
                  end
         | 
| 82 | 
            +
                end
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                task :partials do
         | 
| 85 | 
            +
                  from = WWW_SRC_APP_PATH.join('partials')
         | 
| 86 | 
            +
                  to   = DEBUG_WWW_PATH
         | 
| 87 | 
            +
                  begin
         | 
| 88 | 
            +
                    FileUtils::cp_r from, to
         | 
| 89 | 
            +
                  rescue
         | 
| 90 | 
            +
                    puts "Failed to copy directory #{from} to #{to}"
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                task :vendor do
         | 
| 95 | 
            +
                  from = "#{WWW_SRC_VENDOR_PATH}/images"
         | 
| 96 | 
            +
                  to   = DEBUG_WWW_PATH.join('vendor', 'images')
         | 
| 97 | 
            +
                  begin
         | 
| 98 | 
            +
                    FileUtils::cp_r from, to
         | 
| 99 | 
            +
                  rescue
         | 
| 100 | 
            +
                    puts "Failed to copy directory #{from} to #{to}"
         | 
| 101 | 
            +
                  end
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                desc 'Compiles the asset files into those usable by the browser'
         | 
| 105 | 
            +
                task :compile  do
         | 
| 106 | 
            +
                  ASSET_BUNDLES.each do |bundle|
         | 
| 107 | 
            +
                    assets = sprockets.find_asset(bundle)
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                    # drop all extentions except the first
         | 
| 110 | 
            +
                    realname = assets.pathname.basename.to_s.split(".")[0..1].join(".")
         | 
| 111 | 
            +
                    prefix = File.extname(realname).split('.').last
         | 
| 112 | 
            +
                    outfile = MIN_WWW_PATH.join(prefix, realname)
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                    assets.write_to(outfile)
         | 
| 115 | 
            +
                    assets.write_to("#{outfile}.gz")
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                    # For each asset in the bundle write them to the debug output
         | 
| 118 | 
            +
                    assets.to_a.each do |asset|
         | 
| 119 | 
            +
                      # strip filename.css.foo.bar.css multiple extensions, but maintain the base directory of the file
         | 
| 120 | 
            +
                      realname = asset.pathname.basename.to_s.split(".")[0..1].join(".")
         | 
| 121 | 
            +
                      outPath = DEBUG_WWW_PATH.join(prefix, File.dirname(asset.logical_path))
         | 
| 122 | 
            +
                      FileUtils::mkdir_p(outPath) if (!FileTest::directory?(outPath))
         | 
| 123 | 
            +
                      asset.write_to(outPath.join(realname))
         | 
| 124 | 
            +
                    end
         | 
| 125 | 
            +
                  end
         | 
| 126 | 
            +
                end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
                desc 'Compiles the go template files and concats them'
         | 
| 129 | 
            +
                task :compile_templates  do
         | 
| 130 | 
            +
                  assets = sprockets.find_asset("application.gotmpl")
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                  # drop all extentions except the first
         | 
| 133 | 
            +
                  realname = assets.pathname.basename.to_s.split(".")[0..1].join(".")
         | 
| 134 | 
            +
                  outfile = TMPL_BUILD_PATH.join(realname)
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                  assets.write_to(outfile)
         | 
| 137 | 
            +
                end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                desc 'Builds the existing source'
         | 
| 140 | 
            +
                task :build => [:init,:compile,:compile_templates,:spec_coffee,:images,:partials]
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                desc 'Cleans the build path'
         | 
| 143 | 
            +
                task :clean do
         | 
| 144 | 
            +
                  paths = []
         | 
| 145 | 
            +
                  paths << ASSETS_PATH
         | 
| 146 | 
            +
                  paths << TMPL_BUILD_PATH
         | 
| 147 | 
            +
                  paths << Dir.glob("#{WWW_SPEC_PATH}/*.js")
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                  paths.each do |path|
         | 
| 150 | 
            +
                    begin
         | 
| 151 | 
            +
                      FileUtils::rm_rf path
         | 
| 152 | 
            +
                    rescue
         | 
| 153 | 
            +
                      puts "Failed to clean www's #{path}"
         | 
| 154 | 
            +
                    end
         | 
| 155 | 
            +
                  end
         | 
| 156 | 
            +
                end
         | 
| 157 | 
            +
             | 
| 158 | 
            +
                desc 'Runs the test units for the source files'
         | 
| 159 | 
            +
                task :test => [:build, 'jasmine:ci']
         | 
| 160 | 
            +
             | 
| 161 | 
            +
              end
         | 
| 162 | 
            +
            end
         | 
    
        data/bin/gokart
    ADDED
    
    | @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'gokart'
         | 
| 4 | 
            +
            require 'pathname'
         | 
| 5 | 
            +
            require 'open3'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
             | 
| 8 | 
            +
            root = Pathname(File.dirname(__FILE__)).join('../')
         | 
| 9 | 
            +
            app_name = ARGV[0]
         | 
| 10 | 
            +
            gokart = Gokart::Environment.new(root, app_name)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            unless gokart.app_name_valid?
         | 
| 13 | 
            +
              exit(-1)
         | 
| 14 | 
            +
            end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            unless gokart.build_app
         | 
| 17 | 
            +
            	$stderr.puts "Failed to build the gokart app #{app_name}"
         | 
| 18 | 
            +
            	exit(-1)
         | 
| 19 | 
            +
            end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            Dir.chdir(app_name)
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            Open3.popen3('bundle install') do | i, o, e |
         | 
| 24 | 
            +
              while (out = o.gets || err = e.gets) 
         | 
| 25 | 
            +
              	$stdout.puts out unless out.nil?
         | 
| 26 | 
            +
              	$stderr.puts err unless err.nil?
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
    
        data/lib/gokart/base.rb
    ADDED
    
    | @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            require 'fileutils'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Gokart
         | 
| 4 | 
            +
              attr_reader :app_name, :app_parent_path, :app_base_path, :assets_path
         | 
| 5 | 
            +
              attr_accessor :logger
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              class Base
         | 
| 8 | 
            +
                # 
         | 
| 9 | 
            +
              	def app_name_valid?
         | 
| 10 | 
            +
                  unless File.stat(@app_parent_path).readable?
         | 
| 11 | 
            +
                  	@logger.fatal("App parent directory is not readable")
         | 
| 12 | 
            +
                  	return false
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
                  unless File.stat(@app_parent_path).writable?
         | 
| 15 | 
            +
                  	@logger.fatal("App parent directory is not writable")
         | 
| 16 | 
            +
                  	return false
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                  if Dir.exist?(@app_base_path)
         | 
| 19 | 
            +
                  	@logger.fatal("App #{@app_name} directory already exists")
         | 
| 20 | 
            +
                  	return false
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
                  return true
         | 
| 23 | 
            +
              	end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              	def build_app
         | 
| 26 | 
            +
                  return false unless create_dirs()
         | 
| 27 | 
            +
                  return false unless copy_files()
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  return true
         | 
| 30 | 
            +
              	end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                def create_dirs
         | 
| 33 | 
            +
                    directories().each() do |dir|
         | 
| 34 | 
            +
                      begin
         | 
| 35 | 
            +
                        FileUtils::mkdir_p dir
         | 
| 36 | 
            +
                      rescue Exception => e
         | 
| 37 | 
            +
                        @logger.fatal "Failed to create directory #{dir}, because #{e}"
         | 
| 38 | 
            +
                        return false
         | 
| 39 | 
            +
                      end
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
                  return true
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def copy_files
         | 
| 45 | 
            +
                    Dir.glob(@assets_path.join("**","*")).each() do | inFile |
         | 
| 46 | 
            +
                      begin
         | 
| 47 | 
            +
                        outFile = inFile.partition(@assets_path.to_s)[2]
         | 
| 48 | 
            +
                        next if outFile.empty? || FileTest::directory?(inFile)
         | 
| 49 | 
            +
                        FileUtils::cp inFile, @app_base_path.to_s()+outFile
         | 
| 50 | 
            +
                      rescue Exception => e
         | 
| 51 | 
            +
                        @logger.fatal "Failed to copy #{outFile} to #{@app_base_path}, because #{e}"
         | 
| 52 | 
            +
                        return false
         | 
| 53 | 
            +
                      end
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  return true
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
| @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            require 'gokart/base'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'pathname'
         | 
| 4 | 
            +
            require 'logger'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module Gokart
         | 
| 7 | 
            +
              class Environment < Base
         | 
| 8 | 
            +
              	def initialize(root, app_name)
         | 
| 9 | 
            +
              	  @logger = Logger.new($stderr)
         | 
| 10 | 
            +
              	  @logger.level = Logger::FATAL
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              	  @app_parent_path = Pathname(Dir.pwd.to_s)
         | 
| 13 | 
            +
              	  @app_base_path = @app_parent_path.join(app_name)
         | 
| 14 | 
            +
              	  @app_name = app_name
         | 
| 15 | 
            +
              	  @assets_path = Pathname(root).join('assets')
         | 
| 16 | 
            +
              	end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                def directories
         | 
| 19 | 
            +
                  paths = [
         | 
| 20 | 
            +
                    Pathname(@app_base_path).join('bin'),
         | 
| 21 | 
            +
                    Pathname(@app_base_path).join('lib'),
         | 
| 22 | 
            +
                    Pathname(@app_base_path).join('spec','javascripts','support'),
         | 
| 23 | 
            +
                    Pathname(@app_base_path).join('src','server'),
         | 
| 24 | 
            +
                    Pathname(@app_base_path).join('src','www','app','coffee','helpers'),
         | 
| 25 | 
            +
                    Pathname(@app_base_path).join('src','www','app','coffee','libs'),
         | 
| 26 | 
            +
                    Pathname(@app_base_path).join('src','www','app','coffee'),
         | 
| 27 | 
            +
                    Pathname(@app_base_path).join('src','www','app','images'),
         | 
| 28 | 
            +
                    Pathname(@app_base_path).join('src','www','app','partials'),
         | 
| 29 | 
            +
                    Pathname(@app_base_path).join('src','www','app','sass'),
         | 
| 30 | 
            +
                    Pathname(@app_base_path).join('src','www','app','templates'),
         | 
| 31 | 
            +
                    Pathname(@app_base_path).join('src','www','spec','coffee'),
         | 
| 32 | 
            +
                    Pathname(@app_base_path).join('src','www','vendor','css'),
         | 
| 33 | 
            +
                    Pathname(@app_base_path).join('src','www','vendor','images'),
         | 
| 34 | 
            +
                    Pathname(@app_base_path).join('src','www','vendor','js'),
         | 
| 35 | 
            +
                    Pathname(@app_base_path).join('tasks'),
         | 
| 36 | 
            +
                  ]
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         |