rego-js-builder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ gem "rdoc"
14
+ gem "rego-ruby-ext"
15
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Alex
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # rego-js-builder
2
+
3
+ Build tasks for git js projects.
4
+
5
+ # Release notes
6
+
7
+ * 0.0.1 - first release
8
+
9
+ # Contributing to rego-js-builder
10
+
11
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
12
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
13
+ * Fork the project
14
+ * Start a feature/bugfix branch
15
+ * Commit and push until you are happy with your contribution
16
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
17
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
18
+
19
+ # Copyright
20
+
21
+ Copyright (c) 2011 Alex Tkachev. See LICENSE.txt for
22
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "rego-js-builder"
18
+ gem.homepage = "http://github.com/alextk/rego-js-builder"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Build tasks for git js projects}
21
+ gem.description = %Q{Build tasks for git js projects}
22
+ gem.email = "tkachev.alex@gmail.com"
23
+ gem.authors = ["Alex Tkachev"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ RDoc::Task.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "rego-js-builder #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,82 @@
1
+ require 'yaml'
2
+
3
+ class JsProjectBuilder
4
+ attr_reader :name, :description,
5
+ :dist_file_name, :dist_file_path, :dist_min_file_path, :dist_pack_file_path
6
+
7
+ def initialize(options = {})
8
+ @options = {:dist_dir => 'dist', :license_file => 'license.txt', :version_file_path => 'version.yml'}.update(options)
9
+
10
+ @name = @options[:name]
11
+ @description = @options[:description]
12
+ @dist_file_name = @options[:file_name]
13
+ @dist_file_path = File.join(dist_dir, dist_file_name)
14
+ @dist_min_file_path = @dist_file_path.ext('min.js')
15
+ @dist_pack_file_path = @dist_file_path.ext('pack.js')
16
+
17
+ @version_yml = YAML::load(File.open(@options[:version_file_path]))
18
+ end
19
+
20
+ def dist_dir
21
+ @options[:dist_dir]
22
+ end
23
+
24
+ def js_files
25
+ @options[:js_files]
26
+ end
27
+
28
+ def license_file
29
+ @options[:license_file]
30
+ end
31
+
32
+ def version
33
+ @version_yml['version']
34
+ end
35
+
36
+ def build_number
37
+ @version_yml['build_number']
38
+ end
39
+
40
+ def bump_version(type)
41
+ index = {:major => 0, :minor => 1, :patch => 2}[type]
42
+
43
+ arr = version.split('.').collect{|s| s.to_i }
44
+ arr[index]+=1
45
+ @version_yml['version'] = arr.join('.')
46
+
47
+ write_version_file
48
+
49
+ version
50
+ end
51
+
52
+ def bump_build_number
53
+ @version_yml['build_number'] += 1
54
+ @version_yml['built_at'] = Time.now.strftime('%a %m %b %Y %H:%M:%S')
55
+ write_version_file
56
+ build_number
57
+ end
58
+
59
+ # join given files into single target file.
60
+ # if include_license_file is true (by default) then license file will be added to the head of the target file
61
+ def join_files(target_file, files, include_license_file = true)
62
+ files.insert(0, license_file) if include_license_file
63
+
64
+ existing_files = files.existing
65
+ if existing_files.length != files.length
66
+ raise "ERROR: The following files are missing: \n#{files.select{|f| !existing_files.include?(f) }.join("\n")}"
67
+ end
68
+
69
+ File.open(target_file, 'w') do |f|
70
+ files.each do |fname|
71
+ f.puts File.read(fname)
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+ private
78
+ def write_version_file
79
+ File.open(@options[:version_file_path], 'w'){|f| f.write(@version_yml.to_yaml) }
80
+ end
81
+
82
+ end
@@ -0,0 +1,117 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ class JsProjectBuilder
5
+
6
+ class Tasks < ::Rake::TaskLib
7
+ attr_reader :project_builder
8
+
9
+ def initialize(project_builder)
10
+ @project_builder = project_builder
11
+ define
12
+ end
13
+
14
+ private
15
+ def define
16
+ task :default => [:clobber, :pack]
17
+
18
+ directory project_builder.dist_dir
19
+
20
+ task :clobber do
21
+ rm_r project_builder.dist_dir, :force => true
22
+ end
23
+
24
+ desc 'Prepare the project for build (destination directory and update licence file)'
25
+ task :prepare => project_builder.dist_dir do
26
+ File.open(project_builder.license_file, 'w+') do |f|
27
+ license_tpl = File.read(File.join('build', project_builder.license_file.ext('.tpl.txt')))
28
+ project_builder.bump_build_number
29
+ f.puts license_tpl.interpolate(
30
+ :project_name => project_builder.name,
31
+ :project_description => project_builder.description,
32
+ :project_version => project_builder.version,
33
+ :build_number => project_builder.build_number,
34
+ :date => Time.now.strftime('%d %b %Y %H:%M:%S')
35
+ )
36
+ end
37
+ end
38
+
39
+ desc 'Join all javascript files into one joined file with version and license at the head'
40
+ task :js => :prepare do
41
+ puts "Building single js file: #{project_builder.dist_file_name}"
42
+
43
+ files = FileList[project_builder.js_files]
44
+ project_builder.join_files(project_builder.dist_file_path, files)
45
+ end
46
+
47
+ desc 'Run JSHint checks on the joined javsacript file (runs via nodejs)'
48
+ task :hint => :js do
49
+ puts "Running JSHint on #{project_builder.dist_file_name} ..."
50
+ sh "node build/tools/jshint-check.js #{project_builder.dist_file_path}" do |ok, output|
51
+ ok or fail "Error running jshint on #{project_builder.dist_file_path}. \n #{output}"
52
+ end
53
+ end
54
+
55
+ desc 'Compress js, remove all comments add copyright notice to the head of the file (runs via nodejs with uglify script)'
56
+ task :min => :js do
57
+ puts "Minifying: creating #{project_builder.dist_file_name.ext('min.js')}..."
58
+ tmp_min_file = File.join(project_builder.dist_dir, 'tmp.min.js')
59
+ sh "node build/tools/uglify.js --unsafe -o #{tmp_min_file} #{project_builder.dist_file_path}" do |ok, output|
60
+ ok or fail "Error running uglify on #{project_builder.dist_file_path}. \n #{output}"
61
+ end
62
+
63
+ project_builder.join_files(project_builder.dist_min_file_path, FileList[tmp_min_file])
64
+ File.delete(tmp_min_file)
65
+ end
66
+
67
+ desc 'Run rhino server and pack minified js file into even smaller size. add copyright notice at the start'
68
+ task :pack => :min do
69
+ pack_min_file = File.join(project_builder.dist_dir, 'tmp.min.js')
70
+
71
+ puts "Packing: creating #{project_builder.dist_pack_file_path}..."
72
+ sh "java -jar build/tools/rhino.jar build/tools/packer.js #{project_builder.dist_min_file_path} #{pack_min_file}" do |ok, output|
73
+ ok or fail "Error packing #{project_builder.dist_min_file_path}. \n #{output}"
74
+ end
75
+
76
+ project_builder.join_files(project_builder.dist_pack_file_path, FileList[pack_min_file])
77
+ File.delete(pack_min_file)
78
+ end
79
+
80
+ namespace :version do
81
+ desc "Displays the current version"
82
+ task :current do
83
+ puts "Current version: #{project_builder.version} (build #{project_builder.build_number})"
84
+ end
85
+
86
+ namespace :bump do
87
+ desc "Bump the major version by 1"
88
+ task :major => 'version:current' do
89
+ project_builder.bump_version(:major)
90
+ puts "Updated version: #{project_builder.version}"
91
+ end
92
+
93
+ desc "Bump the a minor version by 1"
94
+ task :minor => 'version:current' do
95
+ project_builder.bump_version(:minor)
96
+ puts "Updated version: #{project_builder.version}"
97
+ end
98
+
99
+ desc "Bump the patch version by 1"
100
+ task :patch => 'version:current' do
101
+ project_builder.bump_version(:patch)
102
+ puts "Updated version: #{project_builder.version}"
103
+ end
104
+
105
+ desc 'Bump the build number by 1'
106
+ task :build_number => 'version:current' do
107
+ project_builder.bump_build_number
108
+ puts "Updated build number: #{project_builder.build_number}"
109
+ end
110
+ end
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,4 @@
1
+ ['js_project_builder', 'js_project_builder_tasks'].each do |file_name|
2
+ require File.join(File.dirname(__FILE__), file_name)
3
+ end
4
+
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rego-js-builder"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alex Tkachev"]
12
+ s.date = "2011-12-02"
13
+ s.description = "Build tasks for git js projects"
14
+ s.email = "tkachev.alex@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/js_project_builder.rb",
28
+ "lib/js_project_builder_tasks.rb",
29
+ "lib/rego-js-builder.rb",
30
+ "rego-js-builder.gemspec",
31
+ "spec/rego-js-builder_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/alextk/rego-js-builder"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "Build tasks for git js projects"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
49
+ s.add_development_dependency(%q<rego-ruby-ext>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ s.add_dependency(%q<rdoc>, [">= 0"])
56
+ s.add_dependency(%q<rego-ruby-ext>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<rdoc>, [">= 0"])
64
+ s.add_dependency(%q<rego-ruby-ext>, [">= 0"])
65
+ end
66
+ end
67
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "RegoJsBuilder" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'rego-js-builder'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rego-js-builder
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Alex Tkachev
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-02 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 0
31
+ version: 2.3.0
32
+ version_requirements: *id001
33
+ name: rspec
34
+ prerelease: false
35
+ type: :development
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ version_requirements: *id002
49
+ name: bundler
50
+ prerelease: false
51
+ type: :development
52
+ - !ruby/object:Gem::Dependency
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 7
59
+ segments:
60
+ - 1
61
+ - 6
62
+ - 4
63
+ version: 1.6.4
64
+ version_requirements: *id003
65
+ name: jeweler
66
+ prerelease: false
67
+ type: :development
68
+ - !ruby/object:Gem::Dependency
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ version_requirements: *id004
79
+ name: rcov
80
+ prerelease: false
81
+ type: :development
82
+ - !ruby/object:Gem::Dependency
83
+ requirement: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ version_requirements: *id005
93
+ name: rdoc
94
+ prerelease: false
95
+ type: :development
96
+ - !ruby/object:Gem::Dependency
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ version_requirements: *id006
107
+ name: rego-ruby-ext
108
+ prerelease: false
109
+ type: :development
110
+ description: Build tasks for git js projects
111
+ email: tkachev.alex@gmail.com
112
+ executables: []
113
+
114
+ extensions: []
115
+
116
+ extra_rdoc_files:
117
+ - LICENSE.txt
118
+ - README.md
119
+ files:
120
+ - .document
121
+ - .rspec
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - VERSION
127
+ - lib/js_project_builder.rb
128
+ - lib/js_project_builder_tasks.rb
129
+ - lib/rego-js-builder.rb
130
+ - rego-js-builder.gemspec
131
+ - spec/rego-js-builder_spec.rb
132
+ - spec/spec_helper.rb
133
+ homepage: http://github.com/alextk/rego-js-builder
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ requirements: []
160
+
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.10
163
+ signing_key:
164
+ specification_version: 3
165
+ summary: Build tasks for git js projects
166
+ test_files: []
167
+