jake 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-07-04
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ bin/jake
6
+ lib/jake.rb
7
+ lib/jake/build.rb
8
+ lib/jake/buildable.rb
9
+ lib/jake/package.rb
10
+ lib/jake/bundle.rb
11
+ test/test_jake.rb
data/README.txt ADDED
@@ -0,0 +1,114 @@
1
+ = Jake
2
+
3
+ * http://github.com/jcoglan/jake
4
+
5
+ == Description
6
+
7
+ Jake is a tool for building JavaScript library packages from source code. It allows
8
+ builds to be specified using simple YAML files, and provides a command-line tool for
9
+ generating package files. It also allows ERB to be embedded in JavaScript source code
10
+ so that build data or new code can be generated during the build process.
11
+
12
+ == Features
13
+
14
+ * Easy automated builds of JavaScript packages with a single command
15
+ * Uses lightweight YAML to specify files and compression options
16
+ * Compression is configurable both globally and per-package
17
+ * Multiple builds with different compression setups
18
+ * Headers such as copyright information can be injected into all build files
19
+ * ERB can be used to inject code at build time using Ruby functions
20
+
21
+ == Usage
22
+
23
+ Jake builds are configured using a YAML file and (optionally) a 'Jakefile' containing
24
+ helper methods for use with Jake's ERB features. You place a file called <tt>jake.yml</tt>
25
+ in the root directory of your project (you will run the +jake+ command from this
26
+ directory). If you use a Jakefile, place this in the same directory.
27
+
28
+ This example <tt>jake.yml</tt> demonstrates the layout of the file:
29
+
30
+ --
31
+ source_directory: src
32
+ build_directory: dist
33
+ header: COPYRIGHT
34
+ packer:
35
+ shrink_vars: true
36
+ private: true
37
+ base62: true
38
+
39
+ packages:
40
+ foo: foo
41
+
42
+ bar:
43
+ - bar_file1
44
+ - bar_file2
45
+
46
+ baz:
47
+ directory: baz
48
+ header: COPYRIGHT
49
+ packer:
50
+ base62: false
51
+ files:
52
+ - model
53
+ - view
54
+ - controller
55
+
56
+ bundles:
57
+ my_lib:
58
+ - foo
59
+ - bar
60
+ - baz
61
+
62
+ This configuration would match a project layed out as follows:
63
+
64
+ - dist/
65
+ - bar.js
66
+ - baz.js
67
+ - foo.js
68
+ - my_lib.js
69
+ - src/
70
+ - baz/
71
+ - controller.js
72
+ - COPYRIGHT
73
+ - model.js
74
+ - view.js
75
+ - bar_file1.js
76
+ - bar_file2.js
77
+ - foo.js
78
+ - COPYRIGHT
79
+ - jake.yml
80
+
81
+ == Requirements
82
+
83
+ * Rubygems
84
+ * Oyster
85
+ * PackR
86
+
87
+ == Installation
88
+
89
+ * sudo gem install jake -y
90
+
91
+ == License
92
+
93
+ (The MIT License)
94
+
95
+ Copyright (c) 2008 James Coglan
96
+
97
+ Permission is hereby granted, free of charge, to any person obtaining
98
+ a copy of this software and associated documentation files (the
99
+ 'Software'), to deal in the Software without restriction, including
100
+ without limitation the rights to use, copy, modify, merge, publish,
101
+ distribute, sublicense, and/or sell copies of the Software, and to
102
+ permit persons to whom the Software is furnished to do so, subject to
103
+ the following conditions:
104
+
105
+ The above copyright notice and this permission notice shall be
106
+ included in all copies or substantial portions of the Software.
107
+
108
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
109
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
110
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
111
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
112
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
113
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
114
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/jake.rb'
6
+
7
+ Hoe.new('jake', Jake::VERSION) do |p|
8
+ # p.rubyforge_name = 'jakex' # if different than lowercase project name
9
+ p.developer('James Coglan', 'jcoglan@googlemail.com')
10
+ p.extra_deps = %w(oyster packr)
11
+ end
12
+
13
+ # vim: syntax=Ruby
data/bin/jake ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'oyster'
4
+ require 'jake'
5
+
6
+ spec = Oyster.spec do
7
+ name 'jake -- automated build tool for JavaScript projects'
8
+
9
+ synopsis <<-EOS
10
+ jake [--force] [DIR]
11
+ EOS
12
+
13
+ description <<-EOS
14
+ Jake builds JavaScript library packages from source code using PackR and
15
+ ERB. Use --force to force a rebuild of files deemed up-to-date. DIR specifies
16
+ where to find the jake.yml configuration file, by default this is set to the
17
+ current working directory.
18
+ EOS
19
+
20
+ flag :force, :default => false,
21
+ :desc => 'Force a rebuild even if files are up-to-date'
22
+
23
+ author 'James Coglan <jcoglan@googlemail.com>'
24
+ end
25
+
26
+ begin; opts = spec.parse
27
+ rescue Oyster::HelpRendered; exit
28
+ end
29
+
30
+ Jake.build(File.expand_path(opts[:unclaimed].first || '.'), opts[:force])
31
+
data/lib/jake/build.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+
4
+ module Jake
5
+ class Build
6
+
7
+ DEFAULT_LAYOUT = 'together'
8
+
9
+ attr_reader :helper, :builds
10
+
11
+ def initialize(dir, config = nil)
12
+ @dir = File.expand_path(dir)
13
+ @helper = Helper.new
14
+
15
+ path = "#{dir}/#{CONFIG_FILE}"
16
+ @config = Jake.symbolize_hash( config || YAML.load(File.read(path)) )
17
+
18
+ helpers = "#{dir}/#{HELPER_FILE}"
19
+ load helpers if File.file?(helpers)
20
+
21
+ @builds = @config[:builds] || {:src => false, :min => @config[:packer]}
22
+
23
+ @packages = @config[:packages].inject({}) do |pkgs, (name, conf)|
24
+ pkgs[name] = Package.new(self, name, conf)
25
+ pkgs
26
+ end
27
+
28
+ @bundles = (@config[:bundles] || {}).inject({}) do |pkgs, (name, conf)|
29
+ pkgs[name] = Bundle.new(self, name, conf)
30
+ pkgs
31
+ end
32
+ end
33
+
34
+ def force!
35
+ @forced = true
36
+ end
37
+
38
+ def forced?
39
+ !!@forced
40
+ end
41
+
42
+ def package(name)
43
+ @packages[name.to_sym]
44
+ end
45
+
46
+ def run!
47
+ @packages.each { |name, pkg| pkg.write! }
48
+ @bundles.each { |name, pkg| pkg.write! }
49
+ @helper.after_build(self) if @helper.respond_to? :after_build
50
+ end
51
+
52
+ def build_directory
53
+ "#{ @dir }/#{ @config[:build_directory] || '.' }"
54
+ end
55
+
56
+ def source_directory
57
+ "#{ @dir }/#{ @config[:source_directory] || '.' }"
58
+ end
59
+
60
+ def header
61
+ @config[:header] ?
62
+ Jake.read("#{ source_directory }/#{ @config[:header] }") :
63
+ ""
64
+ end
65
+
66
+ def packer_settings(build_name)
67
+ @builds[build_name] || false
68
+ end
69
+
70
+ def layout
71
+ @config[:layout] || DEFAULT_LAYOUT
72
+ end
73
+
74
+ end
75
+ end
76
+
@@ -0,0 +1,69 @@
1
+ require 'fileutils'
2
+ require 'packr'
3
+
4
+ module Jake
5
+ class Buildable
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(build, name, config)
10
+ @build, @name = build, name
11
+ @config = case config
12
+ when Hash then config
13
+ when String then {:files => [config]}
14
+ when Array then {:files => config}
15
+ end
16
+ @code = {}
17
+ end
18
+
19
+ def directory
20
+ "#{ @build.source_directory }/#{ @config[:directory] }"
21
+ end
22
+
23
+ def build_path(build_name)
24
+ @build.layout == 'together' ?
25
+ "#{ @build.build_directory }/#{ @name }-#{ build_name }.js" :
26
+ "#{ @build.build_directory }/#{ build_name }/#{ @name }.js"
27
+ end
28
+
29
+ def build_needed?(name)
30
+ return true if @build.forced?
31
+ path = build_path(name)
32
+ return true unless File.file?(path)
33
+ build_time = File.mtime(path)
34
+ files.any? { |path| File.mtime(path) > build_time }
35
+ end
36
+
37
+ def header
38
+ @config[:header] ?
39
+ Jake.read("#{ directory }/#{ @config[:header] }") :
40
+ @build.header
41
+ end
42
+
43
+ def packer_settings(build_name)
44
+ global = @build.packer_settings(build_name)
45
+ local = @config[:packer]
46
+ return false if global == false or local == false
47
+ {}.merge(global || {}).merge(local || {})
48
+ end
49
+
50
+ def write!
51
+ puts "Package #{@name}..."
52
+
53
+ @build.builds.each do |name, settings|
54
+ next unless build_needed?(name)
55
+
56
+ @build.helper.build = name
57
+ path = build_path(name)
58
+ FileUtils.mkdir_p(File.dirname(path))
59
+ File.open(path, 'wb') { |f| f.write( (header + "\n\n" + code(name)).strip ) }
60
+
61
+ size = (File.size(path)/1024.0).ceil
62
+ path = path.sub(@build.build_directory, '')
63
+ puts " -- build '#{ name }' created #{ path }, #{ size } kb"
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+
@@ -0,0 +1,18 @@
1
+ module Jake
2
+ class Bundle < Buildable
3
+
4
+ def files
5
+ @config[:files].map { |pkg| @build.package(pkg).files }.flatten
6
+ end
7
+
8
+ def source
9
+ @source ||= @config[:files].map { |pkg| @build.package(pkg).source }.join("\n\n\n")
10
+ end
11
+
12
+ def code(name)
13
+ @code[name] ||= @config[:files].map { |pkg| @build.package(pkg).code(name) }.join("\n\n\n")
14
+ end
15
+
16
+ end
17
+ end
18
+
@@ -0,0 +1,31 @@
1
+ require 'erb'
2
+
3
+ module Jake
4
+ class Package < Buildable
5
+
6
+ def files
7
+ @config[:files].map do |path|
8
+ path = "#{ directory }/#{ path }"
9
+ File.file?(path) ? path : "#{ path }.js"
10
+ end
11
+ end
12
+
13
+ def source
14
+ @source ||= files.map { |path| Jake.read(path) }.join("\n\n\n")
15
+ end
16
+
17
+ def code(name)
18
+ return @code[name] if @code[name]
19
+ settings = packer_settings(name)
20
+ output = ERB.new(source).result(@build.helper.get_binding)
21
+ @code[name] = settings ? Packr.pack(output, settings) : output
22
+ end
23
+
24
+ def header
25
+ reqs = @config[:requires] || []
26
+ [super, *reqs.map { |r| "// @require #{r}" }].join("\n")
27
+ end
28
+
29
+ end
30
+ end
31
+
data/lib/jake.rb ADDED
@@ -0,0 +1,43 @@
1
+ module Jake
2
+ VERSION = '0.9.0'
3
+
4
+ CONFIG_FILE = 'jake.yml'
5
+ HELPER_FILE = 'Jakefile'
6
+
7
+ def self.build(path, force = false)
8
+ build = Build.new(path)
9
+ build.force! if force
10
+ build.run!
11
+ end
12
+
13
+ def self.read(path)
14
+ path = File.expand_path(path)
15
+ path = File.file?(path) ? path : ( File.file?("#{path}.js") ? "#{path}.js" : nil )
16
+ path and File.read(path).strip
17
+ end
18
+
19
+ def self.symbolize_hash(hash, deep = true)
20
+ hash.inject({}) do |output, (key, value)|
21
+ value = Jake.symbolize_hash(value) if deep and value.is_a?(Hash)
22
+ output[(key.to_sym rescue key) || key] = value
23
+ output
24
+ end
25
+ end
26
+
27
+ class Helper
28
+ attr_accessor :build
29
+ def get_binding; binding; end
30
+ end
31
+ end
32
+
33
+ require File.dirname(__FILE__) + '/jake/build'
34
+ require File.dirname(__FILE__) + '/jake/buildable'
35
+ require File.dirname(__FILE__) + '/jake/package'
36
+ require File.dirname(__FILE__) + '/jake/bundle'
37
+
38
+ def jake(name, &block)
39
+ Jake::Helper.class_eval do
40
+ define_method(name, &block)
41
+ end
42
+ end
43
+
data/test/test_jake.rb ADDED
File without changes
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - James Coglan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-09-11 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oyster
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: packr
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.7.0
44
+ version:
45
+ description: Jake is a tool for building JavaScript library packages from source code. It allows builds to be specified using simple YAML files, and provides a command-line tool for generating package files. It also allows ERB to be embedded in JavaScript source code so that build data or new code can be generated during the build process.
46
+ email:
47
+ - jcoglan@googlemail.com
48
+ executables:
49
+ - jake
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.txt
56
+ files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - README.txt
60
+ - Rakefile
61
+ - bin/jake
62
+ - lib/jake.rb
63
+ - lib/jake/build.rb
64
+ - lib/jake/buildable.rb
65
+ - lib/jake/package.rb
66
+ - lib/jake/bundle.rb
67
+ - test/test_jake.rb
68
+ has_rdoc: true
69
+ homepage: http://github.com/jcoglan/jake
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.txt
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: jake
91
+ rubygems_version: 1.2.0
92
+ signing_key:
93
+ specification_version: 2
94
+ summary: Jake is a tool for building JavaScript library packages from source code
95
+ test_files:
96
+ - test/test_jake.rb