jsus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGELOG +4 -0
  2. data/LICENSE +0 -0
  3. data/Manifest +36 -0
  4. data/README +6 -0
  5. data/Rakefile +13 -0
  6. data/TODO +0 -0
  7. data/bin/jsus +10 -0
  8. data/jsus.gemspec +44 -0
  9. data/lib/jsus.rb +43 -0
  10. data/lib/jsus/bundler.rb +39 -0
  11. data/lib/jsus/package.rb +122 -0
  12. data/lib/jsus/source_file.rb +42 -0
  13. data/spec/data/Basic/README +10 -0
  14. data/spec/data/Basic/app/javascripts/Orwik/Source/Library/Color.js +16 -0
  15. data/spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js +20 -0
  16. data/spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.js +19 -0
  17. data/spec/data/Basic/app/javascripts/Orwik/Source/Widget/Widget.js +16 -0
  18. data/spec/data/Basic/app/javascripts/Orwik/package.yml +12 -0
  19. data/spec/data/OutsideDependencies/README +24 -0
  20. data/spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.Extras.js +16 -0
  21. data/spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.js +16 -0
  22. data/spec/data/OutsideDependencies/app/javascripts/Core/Source/Native/Hash.js +13 -0
  23. data/spec/data/OutsideDependencies/app/javascripts/Core/package.yml +12 -0
  24. data/spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Library/Color.js +16 -0
  25. data/spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js +20 -0
  26. data/spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.js +19 -0
  27. data/spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Widget.js +19 -0
  28. data/spec/data/OutsideDependencies/app/javascripts/Orwik/package.yml +12 -0
  29. data/spec/data/bad_test_source_one.js +3 -0
  30. data/spec/data/bad_test_source_two.js +1 -0
  31. data/spec/data/test_source_one.js +20 -0
  32. data/spec/lib/jsus/bundler_spec.rb +46 -0
  33. data/spec/lib/jsus/package_spec.rb +84 -0
  34. data/spec/lib/jsus/source_file_spec.rb +33 -0
  35. data/spec/spec.opts +4 -0
  36. data/spec/spec_helper.rb +7 -0
  37. metadata +158 -0
@@ -0,0 +1,4 @@
1
+ = JsBundler Changelog
2
+
3
+ == Version 0.1.0
4
+ * Initial release
data/LICENSE ADDED
File without changes
@@ -0,0 +1,36 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ TODO
7
+ bin/jsus
8
+ jsus.gemspec
9
+ lib/jsus.rb
10
+ lib/jsus/bundler.rb
11
+ lib/jsus/package.rb
12
+ lib/jsus/source_file.rb
13
+ spec/data/Basic/README
14
+ spec/data/Basic/app/javascripts/Orwik/Source/Library/Color.js
15
+ spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js
16
+ spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.js
17
+ spec/data/Basic/app/javascripts/Orwik/Source/Widget/Widget.js
18
+ spec/data/Basic/app/javascripts/Orwik/package.yml
19
+ spec/data/OutsideDependencies/README
20
+ spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.Extras.js
21
+ spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.js
22
+ spec/data/OutsideDependencies/app/javascripts/Core/Source/Native/Hash.js
23
+ spec/data/OutsideDependencies/app/javascripts/Core/package.yml
24
+ spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Library/Color.js
25
+ spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js
26
+ spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.js
27
+ spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Widget.js
28
+ spec/data/OutsideDependencies/app/javascripts/Orwik/package.yml
29
+ spec/data/bad_test_source_one.js
30
+ spec/data/bad_test_source_two.js
31
+ spec/data/test_source_one.js
32
+ spec/lib/jsus/bundler_spec.rb
33
+ spec/lib/jsus/package_spec.rb
34
+ spec/lib/jsus/source_file_spec.rb
35
+ spec/spec.opts
36
+ spec/spec_helper.rb
data/README ADDED
@@ -0,0 +1,6 @@
1
+ = What is it?
2
+ Ruby implementation of javascript packager / dependency resolver.
3
+ More info at: http://github.com/Inviz/Javascript-bundler
4
+
5
+ = License
6
+ MIT
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+ Echoe.new('jsus', '0.1.0') do |g|
5
+ g.description = "Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info."
6
+ g.url = "http://github.com/markiz/jsus"
7
+ g.author = "Markiz, idea by Inviz (http://github.com/Inviz)"
8
+ g.email = "markizko@gmail.com"
9
+ g.ignore_pattern = ["nbproject/**/*", 'spec/*/public/**/*']
10
+ g.runtime_dependencies = ["activesupport", "json_pure", "rgl"]
11
+ g.development_dependencies = ["rake"]
12
+ g.use_sudo = false
13
+ end
data/TODO ADDED
File without changes
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'jsus'
4
+
5
+ unless ARGV.length == 2
6
+ puts "SYNOPSYS: jsus <input_directory_with_packages> <output_directory_for_packages>"
7
+ exit
8
+ else
9
+ Jsus::Bundler.new(ARGV[0]).compile(ARGV[1])
10
+ end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{jsus}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Markiz, idea by Inviz (http://github.com/Inviz)"]
9
+ s.date = %q{2010-06-03}
10
+ s.default_executable = %q{jsus}
11
+ s.description = %q{Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info.}
12
+ s.email = %q{markizko@gmail.com}
13
+ s.executables = ["jsus"]
14
+ s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "TODO", "bin/jsus", "lib/jsus.rb", "lib/jsus/bundler.rb", "lib/jsus/package.rb", "lib/jsus/source_file.rb"]
15
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README", "Rakefile", "TODO", "bin/jsus", "lib/jsus.rb", "lib/jsus/bundler.rb", "lib/jsus/package.rb", "lib/jsus/source_file.rb", "spec/data/Basic/README", "spec/data/Basic/app/javascripts/Orwik/Source/Library/Color.js", "spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js", "spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.js", "spec/data/Basic/app/javascripts/Orwik/Source/Widget/Widget.js", "spec/data/Basic/app/javascripts/Orwik/package.yml", "spec/data/OutsideDependencies/README", "spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.Extras.js", "spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.js", "spec/data/OutsideDependencies/app/javascripts/Core/Source/Native/Hash.js", "spec/data/OutsideDependencies/app/javascripts/Core/package.yml", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Library/Color.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Widget.js", "spec/data/OutsideDependencies/app/javascripts/Orwik/package.yml", "spec/data/bad_test_source_one.js", "spec/data/bad_test_source_two.js", "spec/data/test_source_one.js", "spec/lib/jsus/bundler_spec.rb", "spec/lib/jsus/package_spec.rb", "spec/lib/jsus/source_file_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "jsus.gemspec"]
16
+ s.homepage = %q{http://github.com/markiz/jsus}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Jsus", "--main", "README"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{jsus}
20
+ s.rubygems_version = %q{1.3.6}
21
+ s.summary = %q{Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info.}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
29
+ s.add_runtime_dependency(%q<json_pure>, [">= 0"])
30
+ s.add_runtime_dependency(%q<rgl>, [">= 0"])
31
+ s.add_development_dependency(%q<rake>, [">= 0"])
32
+ else
33
+ s.add_dependency(%q<activesupport>, [">= 0"])
34
+ s.add_dependency(%q<json_pure>, [">= 0"])
35
+ s.add_dependency(%q<rgl>, [">= 0"])
36
+ s.add_dependency(%q<rake>, [">= 0"])
37
+ end
38
+ else
39
+ s.add_dependency(%q<activesupport>, [">= 0"])
40
+ s.add_dependency(%q<json_pure>, [">= 0"])
41
+ s.add_dependency(%q<rgl>, [">= 0"])
42
+ s.add_dependency(%q<rake>, [">= 0"])
43
+ end
44
+ end
@@ -0,0 +1,43 @@
1
+ require 'yaml'
2
+ require 'pathname'
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'active_support/ordered_hash'
6
+ require 'rgl/adjacency'
7
+ require 'rgl/topsort'
8
+
9
+ require 'jsus/source_file'
10
+ require 'jsus/package'
11
+ require 'jsus/bundler'
12
+
13
+ module Jsus
14
+ # Shortcut for Bundler.new
15
+ def self.new(*args, &block)
16
+ Bundler.new(*args, &block)
17
+ end
18
+
19
+ # Topological sort for packages and source files
20
+ def self.topsort(items)
21
+ graph = RGL::DirectedAdjacencyGraph.new
22
+ provides_hash = {}
23
+ # init vertices
24
+ items.each do |item|
25
+ graph.add_vertex(item)
26
+ item.provides.each do |provides|
27
+ provides_hash[provides] = item
28
+ end
29
+ end
30
+ # init edges
31
+ items.each do |item|
32
+ item.dependencies.each do |dependency|
33
+ if required_item = provides_hash[dependency]
34
+ graph.add_edge(required_item, item)
35
+ end
36
+ end
37
+ end
38
+ result = []
39
+ graph.topsort_iterator.each { |item| result << item }
40
+ result
41
+ end
42
+
43
+ end
@@ -0,0 +1,39 @@
1
+ module Jsus
2
+ class Bundler
3
+ def initialize(directory)
4
+ Dir[File.join(directory, "**", "package.yml")].each do |package_name|
5
+ path = Pathname.new(package_name)
6
+ Dir.chdir path.parent.parent.to_s do
7
+ package = Package.new(path.parent.relative_path_from(path.parent.parent).to_s)
8
+ self.packages << package
9
+ end
10
+ end
11
+ calculate_requirement_order
12
+ end
13
+
14
+
15
+ attr_writer :packages
16
+ def packages
17
+ @packages ||= []
18
+ end
19
+
20
+ attr_accessor :required_files
21
+
22
+ def compile(directory)
23
+ FileUtils.mkdir_p(directory)
24
+ Dir.chdir directory do
25
+ packages.each do |package|
26
+ package.compile(package.relative_directory)
27
+ package.generate_tree(package.relative_directory)
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ protected
34
+ def calculate_requirement_order
35
+ @packages = Jsus.topsort(packages)
36
+ @required_files = @packages.map {|p| p.required_files }.flatten
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,122 @@
1
+ module Jsus
2
+ class Package
3
+ # Constructors
4
+ def initialize(directory)
5
+ self.relative_directory = Pathname.new(directory).relative_path_from(Pathname.new(".")).to_s
6
+ self.directory = File.expand_path(directory)
7
+ self.header = YAML.load_file(File.join(directory, 'package.yml'))
8
+ Dir.chdir(directory) do
9
+ files.each do |source|
10
+ source_files << SourceFile.from_file(source)
11
+ end
12
+ end
13
+ calculate_requirement_order
14
+ end
15
+
16
+
17
+ # Public API
18
+ attr_accessor :relative_directory
19
+ attr_accessor :directory
20
+
21
+ attr_writer :header
22
+ def header
23
+ @header ||= {}
24
+ end
25
+
26
+ def name
27
+ header["name"] ||= ""
28
+ end
29
+
30
+ def filename
31
+ header["filename"] ||= name + ".js"
32
+ end
33
+
34
+ def provides
35
+ @provides ||= provides!
36
+ end
37
+
38
+ def provides!
39
+ source_files.map {|source| source.provides }.flatten
40
+ end
41
+
42
+ def files
43
+ header["files"] = header["sources"] || header["files"] || []
44
+ end
45
+
46
+ alias_method :sources, :files
47
+
48
+ def dependencies
49
+ @dependencies ||= dependencies!
50
+ end
51
+
52
+ def dependencies!
53
+ source_files.map {|source| source.dependencies }.flatten.compact.uniq - provides!
54
+ end
55
+
56
+ def description
57
+ header["description"] ||= ""
58
+ end
59
+
60
+ attr_accessor :required_files
61
+
62
+ def compile(directory = ".")
63
+ FileUtils.mkdir_p directory
64
+ Dir.chdir(directory) do
65
+ File.open(filename, "w") do |resulting_file|
66
+ required_files.each do |required_file|
67
+ resulting_file.puts(IO.read(required_file))
68
+ end
69
+ end
70
+ generate_scripts_info(".")
71
+ end
72
+ end
73
+
74
+ def generate_tree(directory = ".", filename = "tree.json")
75
+ FileUtils.mkdir_p(directory)
76
+ result = ActiveSupport::OrderedHash.new
77
+ source_files.each do |source|
78
+ components = File.dirname(source.relative_filename).split(File::SEPARATOR)
79
+ components.delete("Source")
80
+ components << File.basename(source.filename, ".js")
81
+ node = result
82
+ components.each do |component|
83
+ node[component] ||= ActiveSupport::OrderedHash.new
84
+ node = node[component]
85
+ end
86
+ node["desc"] = source.description
87
+ node["requires"] = source.dependencies
88
+ node["provides"] = source.provides
89
+ end
90
+ Dir.chdir(directory) do
91
+ File.open(filename, "w") { |resulting_file| resulting_file << JSON.pretty_generate(result) }
92
+ end
93
+ end
94
+
95
+ def generate_scripts_info(directory = ".", filename = "scripts.json")
96
+ Dir.chdir(directory) do
97
+ result = {}
98
+ result[name] = {}
99
+ result[name]["desc"] = description
100
+ result[name]["requires"] = dependencies
101
+ result[name]["provides"] = provides
102
+ File.open(filename, "w") { |resulting_file| resulting_file << JSON.pretty_generate(result) }
103
+ end
104
+ end
105
+
106
+ protected
107
+
108
+ attr_writer :source_files
109
+ def source_files
110
+ @source_files ||= []
111
+ @source_files.compact!
112
+ @source_files
113
+ end
114
+
115
+ def calculate_requirement_order
116
+ self.source_files = Jsus.topsort(source_files)
117
+ self.required_files = source_files.map {|f| f.filename}
118
+ end
119
+
120
+
121
+ end
122
+ end
@@ -0,0 +1,42 @@
1
+ module Jsus
2
+ class SourceFile
3
+ attr_accessor :header
4
+ attr_accessor :relative_filename
5
+ attr_accessor :filename
6
+ # constructors
7
+
8
+ def self.from_file(filename)
9
+ if File.exists?(filename)
10
+ source = File.read(filename) # TODO: read only first several lines of file
11
+ yaml_data = source.match(%r(^/\*\s*(---.*?)\*/)m)
12
+ if (yaml_data && yaml_data[1] && header = YAML.load(yaml_data[1]))
13
+ result = new
14
+ result.header = header
15
+ result.relative_filename = filename
16
+ result.filename = File.expand_path(filename)
17
+ result
18
+ else
19
+ # puts "WARNING: file #{filename} has invalid format (should be YAML)"
20
+ nil
21
+ end
22
+ else
23
+ # puts "WARNING: file #{filename} does not exist"
24
+ nil
25
+ end
26
+ end
27
+
28
+ # Public API
29
+ def dependencies
30
+ header["requires"] ||= []
31
+ end
32
+
33
+ def provides
34
+ header["provides"] ||= []
35
+ end
36
+
37
+ def description
38
+ header["description"] ||= ""
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ SUMMARY:
2
+ A basic example of packing up a single package.
3
+
4
+ LOGIC:
5
+ Everything compiles into one file.
6
+ Two additional files are created: scripts.json (contains information about packed file) and tree.json (full per-file description)
7
+
8
+ SYNTAX:
9
+ bundle Orwik -i app/javascripts/ -o public/javascripts
10
+ #=> [public/javascripts/Orwik/Source/orwik.js, public/javascripts/Orwik/Source/scripts.js, public/javascripts/Orwik/Source/tree.js]
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+
4
+ script: Color.js
5
+
6
+ description: A library to work with colors
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Valerio Proietti
12
+
13
+ provides: [Color]
14
+
15
+ ...
16
+ */
@@ -0,0 +1,20 @@
1
+ /*
2
+ ---
3
+
4
+ script: Input.Color.js
5
+
6
+ description: Cool colorpicker for everyone to enjoy
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Yaroslaff Fedin
12
+
13
+ requires:
14
+ - Input
15
+ - Color
16
+
17
+ provides: [Input.Color]
18
+
19
+ ...
20
+ */
@@ -0,0 +1,19 @@
1
+ /*
2
+ ---
3
+
4
+ script: Input.js
5
+
6
+ description: Basic input class
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Yaroslaff Fedin
12
+
13
+ requires:
14
+ - Widget
15
+
16
+ provides: [Input]
17
+
18
+ ...
19
+ */
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+
4
+ script: Widget.js
5
+
6
+ description: An abstract class for all your widgets out there.
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Yaroslaff Fedin
12
+
13
+ provides: [Widget]
14
+
15
+ ...
16
+ */
@@ -0,0 +1,12 @@
1
+ name: orwik
2
+ filename: orwik.js
3
+ web: http://orwik.com
4
+ description: Orwik widgets and essensial things
5
+ license: MIT-Style License, http://mootools.net/license
6
+ copyright: 2008-2010 Yaroslaff Fedin http://orwik.com/people/inviz
7
+ authors: Orwik team, http://developers.orwik.com
8
+ sources:
9
+ - "Source/Widget/Widget.js"
10
+ - "Source/Widget/Input/Input.js"
11
+ - "Source/Widget/Input/Input.Color.js" #Files are unsorted. Figure out the order please
12
+ - "Source/Library/Color.js"
@@ -0,0 +1,24 @@
1
+ SUMMARY:
2
+ Example of a package having dependencies in another package.
3
+ Includes sample results for two ways of handling the situation:
4
+
5
+ SEPARATE PACKAGES
6
+ SYNTAX:
7
+ bundle Orwik -i app/javascripts/ -o public/javascripts
8
+ #=> [public/javascripts/Orwik/Source/orwik.js, public/javascripts/Orwik/Source/tree.json, public/javascripts/Orwik/Source/scripts.json]
9
+
10
+ bundle Core -i app/javascripts/ -o public/javascripts
11
+ #=> [public/javascripts/Core/Source/orwik.js, public/javascripts/Core/Source/tree.json, public/javascripts/Core/Source/scripts.json]
12
+
13
+ LOGIC:
14
+ Each of the packages gets compiled in its own directory.
15
+ Resulting file of orwik package retains all dependencies to Core package.
16
+
17
+ ONE-FILE COMPILATION
18
+ SYNTAX:
19
+ bundle Orwik -i app/javascripts/ -o public/javascripts --with-dependencies
20
+ #=> [public/javascripts/Orwik/Compiled/orwik.js, public/javascripts/Orwik/Compiled/tree.json, public/javascripts/Orwik/Compiled/scripts.json]
21
+
22
+ LOGIC:
23
+ All files from Core that Orwik needs are compiled into resulting file.
24
+ Dependencies are resolved and removed from the tree.
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+
4
+ script: Class.Extras.js
5
+
6
+ description: Contains Utility Classes that can be implemented into your own Classes to ease the execution of many common tasks.
7
+
8
+ license: MIT-style license.
9
+
10
+ requires:
11
+ - /Class
12
+
13
+ provides: [Chain, Events, Options]
14
+
15
+ ...
16
+ */
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+
4
+ script: Class.js
5
+
6
+ description: Contains the Class Function for easily creating, extending, and implementing reusable Classes.
7
+
8
+ license: MIT-style license.
9
+
10
+ requires:
11
+ - /Hash
12
+
13
+ provides: [Class]
14
+
15
+ ...
16
+ */
@@ -0,0 +1,13 @@
1
+ /*
2
+ ---
3
+
4
+ script: Hash.js
5
+
6
+ description: Contains Hash Prototypes. Provides a means for overcoming the JavaScript practical impossibility of extending native Objects.
7
+
8
+ license: MIT-style license.
9
+
10
+ provides: [Hash]
11
+
12
+ ...
13
+ */
@@ -0,0 +1,12 @@
1
+ name: "core"
2
+ exports: "mootools-core.js"
3
+ web: "[mootools.net](http://mootools.net)"
4
+ description: "MooTools, The JavaScript framework"
5
+ license: "[MIT License](http://mootools.net/license.txt)"
6
+ copyright: "&copy; [MooTools](http://mootools.net)"
7
+ authors: "[The MooTools development team](http://mootools.net/developers)"
8
+ version: "1.2.4"
9
+ files:
10
+ - "Source/Source/Class/Class.js"
11
+ - "Source/Source/Class/Class.Extras.js"
12
+ - "Source/Source/Native/Hash.js"
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+
4
+ script: Color.js
5
+
6
+ description: A library to work with colors
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Valerio Proietti
12
+
13
+ provides: [Color]
14
+
15
+ ...
16
+ */
@@ -0,0 +1,20 @@
1
+ /*
2
+ ---
3
+
4
+ script: Input.Color.js
5
+
6
+ description: Cool colorpicker for everyone to enjoy
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Yaroslaff Fedin
12
+
13
+ requires:
14
+ - Input
15
+ - Color
16
+
17
+ provides: [Input.Color]
18
+
19
+ ...
20
+ */
@@ -0,0 +1,19 @@
1
+ /*
2
+ ---
3
+
4
+ script: Input.js
5
+
6
+ description: Basic input class
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Yaroslaff Fedin
12
+
13
+ requires:
14
+ - Widget
15
+
16
+ provides: [Input]
17
+
18
+ ...
19
+ */
@@ -0,0 +1,19 @@
1
+ /*
2
+ ---
3
+
4
+ script: Widget.js
5
+
6
+ description: An abstract class for all your widgets out there.
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Yaroslaff Fedin
12
+
13
+ requires:
14
+ - core/Class
15
+
16
+ provides: [Widget]
17
+
18
+ ...
19
+ */
@@ -0,0 +1,12 @@
1
+ name: orwik
2
+ filename: orwik.js
3
+ web: http://orwik.com
4
+ description: Orwik widgets and essensial things
5
+ license: MIT-Style License, http://mootools.net/license
6
+ copyright: 2008-2010 Yaroslaff Fedin http://orwik.com/people/inviz
7
+ authors: Orwik team, http://developers.orwik.com
8
+ files:
9
+ - "Source/Widget/Widget.js"
10
+ - "Source/Widget/Input/Input.js"
11
+ - "Source/Widget/Input/Input.Color.js" #Files are unsorted. Figure out the order please
12
+ - "Source/Library/Color.js"
@@ -0,0 +1,3 @@
1
+ /*
2
+ That is a great javascript tool for doing incredible things
3
+ */
@@ -0,0 +1 @@
1
+ // Something for nothing, lol
@@ -0,0 +1,20 @@
1
+ /*
2
+ ---
3
+
4
+ script: Color.js
5
+
6
+ description: A library to work with colors
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Valerio Proietti
12
+
13
+ provides: [Color]
14
+
15
+ ...
16
+ */
17
+
18
+ var TestSourceOne = new Class({
19
+
20
+ });
@@ -0,0 +1,46 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Jsus::Bundler do
4
+ subject { Jsus::Bundler.new(input_dir) }
5
+ let(:input_dir) { "spec/data/Basic/app/javascripts" }
6
+ let(:output_dir) { "spec/data/Basic/public/javascripts" }
7
+ before(:each) { cleanup }
8
+ after(:all) { cleanup }
9
+ context "initialization" do
10
+ context "from a directory" do
11
+ subject { Jsus::Bundler.new("spec/data/Basic/") }
12
+ it "should load packages" do
13
+ subject.packages.map {|p| p.name}.should == ["orwik"]
14
+ subject.packages.map {|p| p.relative_directory }.should == ["Orwik"]
15
+ end
16
+ end
17
+ end
18
+
19
+ describe "#required_files" do
20
+ it "should return an array with correctly sorted required files" do
21
+ files = subject.required_files
22
+ color_index = files.find_index {|f| f =~ /\/Color.js/}
23
+ input_index = files.find_index {|f| f =~ /\/Input.js/}
24
+ input_color_index = files.find_index {|f| f =~ /\/Input.Color.js/}
25
+ color_index.should < input_color_index
26
+ input_index.should < input_color_index
27
+ end
28
+ end
29
+
30
+ describe "#compile" do
31
+ it "should generate scripts.json file with all the dependencies and provides for each package" do
32
+ subject.compile(output_dir)
33
+ File.exists?("#{output_dir}/Orwik/scripts.json").should be_true
34
+ end
35
+
36
+ it "should generate js file for each package" do
37
+ subject.compile(output_dir)
38
+ File.exists?("#{output_dir}/Orwik/orwik.js").should be_true
39
+ end
40
+
41
+ it "should generate tree.json file for each package" do
42
+ subject.compile(output_dir)
43
+ File.exists?("#{output_dir}/Orwik/tree.json").should be_true
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec/spec_helper'
2
+ require 'json'
3
+
4
+ describe Jsus::Package do
5
+ subject { Jsus::Package.new(input_dir) }
6
+ let(:input_dir) { "spec/data/Basic/app/javascripts/Orwik"}
7
+ let(:output_dir) { "spec/data/Basic/public/javascripts/Orwik" }
8
+ before(:each) { cleanup }
9
+ after(:all) { cleanup }
10
+ context "initialization" do
11
+ let(:input_dir) { "spec/data/OutsideDependencies/app/javascripts/Orwik" }
12
+ let(:output_dir) { "spec/data/OutsideDependencies/public/javascripts/Orwik" }
13
+ context "from a directory" do
14
+ it "should load header from package.yml" do
15
+ subject.name.should == "orwik"
16
+ subject.filename.should == "orwik.js"
17
+ end
18
+
19
+ it "should set provided modules from source files" do
20
+ subject.provides.should have_exactly(4).items
21
+ subject.provides.should include("Color", "Input", "Input.Color", "Widget")
22
+ end
23
+
24
+ it "should set up outside dependencies" do
25
+ subject.dependencies.should == ['core/Class']
26
+ end
27
+
28
+ it "should set directory and relative directory fields" do
29
+ subject.directory.should == File.expand_path(input_dir)
30
+ subject.relative_directory.should == input_dir
31
+ end
32
+
33
+ it "should set up required files in correct order" do
34
+ required_files = subject.required_files
35
+ input_index = required_files.index {|s| s=~ /\/Input.js$/}
36
+ color_index = required_files.index {|s| s=~ /\/Color.js$/}
37
+ input_color_index = required_files.index {|s| s=~ /\/Input.Color.js$/}
38
+ input_index.should < input_color_index
39
+ color_index.should < input_color_index
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#compile" do
45
+ it "should create a merged js package from given files" do
46
+ subject.compile(output_dir)
47
+ File.exists?("#{output_dir}/orwik.js").should be_true
48
+ compiled_content = IO.read("#{output_dir}/orwik.js")
49
+ required_files = Dir["#{input_dir}/**/*.js"].map {|f| IO.read(f) }
50
+ required_files.each {|f| compiled_content.should include(f)}
51
+ end
52
+
53
+ it "should create scripts.json file containing all the info about the package" do
54
+ subject.compile(output_dir)
55
+ File.exists?("#{output_dir}/scripts.json").should be_true
56
+ info = JSON.parse(IO.read("#{output_dir}/scripts.json"))
57
+ info = info["orwik"]
58
+ info["provides"].should have_exactly(4).items
59
+ info["provides"].should include("Color", "Widget", "Input", "Input.Color")
60
+ end
61
+ end
62
+
63
+ describe "#generate_tree" do
64
+ it "should create a json file containing tree information and dependencies" do
65
+ subject.generate_tree(output_dir)
66
+ File.exists?("#{output_dir}/tree.json").should be_true
67
+ tree = JSON.parse(IO.read("#{output_dir}/tree.json"))
68
+ tree["Library"]["Color"]["provides"].should == ["Color"]
69
+ tree["Widget"]["Widget"]["provides"].should == ["Widget"]
70
+ tree["Widget"]["Input"]["Input"]["requires"].should == ["Widget"]
71
+ tree["Widget"]["Input"]["Input"]["provides"].should == ["Input"]
72
+ tree["Widget"]["Input"]["Input.Color"]["requires"].should have_exactly(2).elements
73
+ tree["Widget"]["Input"]["Input.Color"]["requires"].should include("Input", "Color")
74
+ tree["Widget"]["Input"]["Input.Color"]["provides"].should == ["Input.Color"]
75
+ end
76
+
77
+ it "should allow different filenames" do
78
+ subject.generate_tree(output_dir, "structure.json")
79
+ File.exists?("#{output_dir}/structure.json").should be_true
80
+ tree = JSON.parse(IO.read("#{output_dir}/structure.json"))
81
+ tree["Library"]["Color"]["provides"].should == ["Color"]
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe Jsus::SourceFile do
4
+ before(:each) { cleanup }
5
+ after(:all) { cleanup }
6
+ context "initialization" do
7
+ context "from file" do
8
+ subject { Jsus::SourceFile.from_file('spec/data/test_source_one.js') }
9
+ it "should parse json header" do
10
+ subject.dependencies.should == []
11
+ subject.provides.should == ["Color"]
12
+ subject.description.should == "A library to work with colors"
13
+ end
14
+
15
+ it "should set filename field to expanded file name" do
16
+ subject.filename.should == File.expand_path("spec/data/test_source_one.js")
17
+ end
18
+
19
+ context "when format is invalid" do
20
+ it "should return nil" do
21
+ Jsus::SourceFile.from_file('spec/data/bad_test_source_one.js').should == nil
22
+ Jsus::SourceFile.from_file('spec/data/bad_test_source_two.js').should == nil
23
+ end
24
+ end
25
+
26
+ context "when file does not exist" do
27
+ it "should return nil" do
28
+ Jsus::SourceFile.from_file('spec/data/non-existant-file.js').should == nil
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,7 @@
1
+ require 'lib/jsus'
2
+
3
+ # cleanup compiled stuff
4
+ def cleanup
5
+ `rm -rf spec/data/Basic/public`
6
+ `rm -rf spec/data/OutsideDependencies/public`
7
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jsus
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Markiz, idea by Inviz (http://github.com/Inviz)
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-03 00:00:00 +04:00
18
+ default_executable: jsus
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: json_pure
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :runtime
43
+ version_requirements: *id002
44
+ - !ruby/object:Gem::Dependency
45
+ name: rgl
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ type: :runtime
55
+ version_requirements: *id003
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ prerelease: false
59
+ requirement: &id004 !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ type: :development
67
+ version_requirements: *id004
68
+ description: Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info.
69
+ email: markizko@gmail.com
70
+ executables:
71
+ - jsus
72
+ extensions: []
73
+
74
+ extra_rdoc_files:
75
+ - CHANGELOG
76
+ - LICENSE
77
+ - README
78
+ - TODO
79
+ - bin/jsus
80
+ - lib/jsus.rb
81
+ - lib/jsus/bundler.rb
82
+ - lib/jsus/package.rb
83
+ - lib/jsus/source_file.rb
84
+ files:
85
+ - CHANGELOG
86
+ - LICENSE
87
+ - Manifest
88
+ - README
89
+ - Rakefile
90
+ - TODO
91
+ - bin/jsus
92
+ - lib/jsus.rb
93
+ - lib/jsus/bundler.rb
94
+ - lib/jsus/package.rb
95
+ - lib/jsus/source_file.rb
96
+ - spec/data/Basic/README
97
+ - spec/data/Basic/app/javascripts/Orwik/Source/Library/Color.js
98
+ - spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js
99
+ - spec/data/Basic/app/javascripts/Orwik/Source/Widget/Input/Input.js
100
+ - spec/data/Basic/app/javascripts/Orwik/Source/Widget/Widget.js
101
+ - spec/data/Basic/app/javascripts/Orwik/package.yml
102
+ - spec/data/OutsideDependencies/README
103
+ - spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.Extras.js
104
+ - spec/data/OutsideDependencies/app/javascripts/Core/Source/Class/Class.js
105
+ - spec/data/OutsideDependencies/app/javascripts/Core/Source/Native/Hash.js
106
+ - spec/data/OutsideDependencies/app/javascripts/Core/package.yml
107
+ - spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Library/Color.js
108
+ - spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.Color.js
109
+ - spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Input/Input.js
110
+ - spec/data/OutsideDependencies/app/javascripts/Orwik/Source/Widget/Widget.js
111
+ - spec/data/OutsideDependencies/app/javascripts/Orwik/package.yml
112
+ - spec/data/bad_test_source_one.js
113
+ - spec/data/bad_test_source_two.js
114
+ - spec/data/test_source_one.js
115
+ - spec/lib/jsus/bundler_spec.rb
116
+ - spec/lib/jsus/package_spec.rb
117
+ - spec/lib/jsus/source_file_spec.rb
118
+ - spec/spec.opts
119
+ - spec/spec_helper.rb
120
+ - jsus.gemspec
121
+ has_rdoc: true
122
+ homepage: http://github.com/markiz/jsus
123
+ licenses: []
124
+
125
+ post_install_message:
126
+ rdoc_options:
127
+ - --line-numbers
128
+ - --inline-source
129
+ - --title
130
+ - Jsus
131
+ - --main
132
+ - README
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ segments:
140
+ - 0
141
+ version: "0"
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ segments:
147
+ - 1
148
+ - 2
149
+ version: "1.2"
150
+ requirements: []
151
+
152
+ rubyforge_project: jsus
153
+ rubygems_version: 1.3.6
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: Packager/compiler for js-files that resolves dependencies and can compile everything into one file, providing all the neccessary meta-info.
157
+ test_files: []
158
+