jsus 0.2.3 → 0.2.4

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/CHANGELOG CHANGED
@@ -1,4 +1,14 @@
1
1
  = Jsus Changelog
2
+ == Version 0.2.4
3
+ * Replacements feature
4
+ * Postprocessing feature
5
+ See jsus-examples repo or features dir for more information.
6
+
7
+ == Version 0.2.3
8
+ * Minor CLI reworkings:
9
+ * Deprecated -i and -o options (use plain arguments now)
10
+ * Restored generate-includes customizable root option
11
+
2
12
  == Version 0.2.2
3
13
  * Fixed dupes in structure json files
4
14
 
data/README CHANGED
@@ -1,6 +1,61 @@
1
- = What is it?
1
+ What is it?
2
+ =============
3
+
2
4
  Ruby implementation of javascript packager / dependency resolver.
3
- More info at: http://github.com/Inviz/Javascript-bundler
4
5
 
5
- = License
6
- Public Domain, original authorship still belongs to me, Mark Abramov (markiz).
6
+ Why?
7
+ ====
8
+
9
+ As a javascript programmer, you often need to split your code into
10
+ multiple files. When you have 50+ different modules / libraries, you
11
+ need some way to resolve complex dependencies and package all you need
12
+ and nil you don't. Jsus is an utility that allows you to do just that:
13
+ package your libraries into one piece with all dependencies included.
14
+
15
+ Features
16
+ ========
17
+
18
+ * Jsus works with mootools-style packages. That means you specify a
19
+ package.yml / package.json file with package structure for every
20
+ library/bigger module you have. Source files should also have special
21
+ headers denoting their requirements and what they provide.
22
+ * Jsus automatically resolves dependencies, so you don't have to worry about
23
+ order issues or anything else.
24
+ * Jsus allows you to make "extensions". Extension is a monkey-patch you can
25
+ apply to any other library. Because sometimes you want to make project-specific
26
+ change to a library you don't have control over and you want to be able to
27
+ update this library without applying manual patches from their source.
28
+ * Jsus uses [murdoc](https://github.com/markiz/murdoc) for doccu style docs
29
+ generation.
30
+ * Jsus generates special json files denoting source and resulting project
31
+ structure which can be useful for later introspection.
32
+ * Jsus can also generate a special js file with loader for your dependencies,
33
+ so that you don't need to repackage everything during development cycle.
34
+
35
+ Examples
36
+ ========
37
+
38
+ * For simple examples, take a look at: https://github.com/markiz/jsus-examples
39
+ * You can try it yourself on mootools-core:
40
+ * Get mootools-core from https://github.com/mootools/mootools-core
41
+ * `cd mootools-core`
42
+ * `jsus . Output`
43
+ * Look at what Output directory contains
44
+
45
+ Plans
46
+ =====
47
+
48
+ These are rather long-term, for when I get to have time and mood to do those:
49
+ * Rails integration
50
+ * npm packages support
51
+
52
+ NB:
53
+ * I don't have any particular roadmap or plans for more features
54
+ * However, I am open for any suggestions
55
+ * Bonus points for suggestions with pull-requests
56
+
57
+
58
+ License
59
+ =======
60
+
61
+ Public Domain, details in UNLICENSE file.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
data/bin/jsus CHANGED
@@ -16,26 +16,26 @@ start_time = Time.now
16
16
  options = {}
17
17
  cli = OptionParser.new do |opts|
18
18
  opts.banner = "jsus #{Jsus.version}. Usage: jsus [options] <input_dir> <output_dir>"
19
-
19
+
20
20
  opts.on('-i', '--input-directory [DIR]', '[DEPRECATED] path to input directory ') do |dir|
21
21
  $stderr.puts "DEPRECATION NOTICE: please do not use -i command-line argument"
22
22
  options[:input_dir] = dir
23
23
  end
24
-
24
+
25
25
  opts.on('-o', '--input-directory [DIR]', '[DEPRECATED] path to output directory ') do |dir|
26
26
  $stderr.puts "DEPRECATION NOTICE: please do not use -o command-line argument"
27
27
  options[:output_dir] = dir
28
28
  end
29
-
29
+
30
30
  opts.on('-d', '--with-dependencies [DEPS]', 'path to directory containing dependency packages') do |dir|
31
31
  options[:deps_dir] = dir
32
32
  end
33
-
33
+
34
34
  opts.on('-g', '--generate-includes [ROOT]', 'generates includes.js file that you may use for ad-hoc requiring of dependencies, defaults to output directory') do |dir|
35
35
  options[:generate_includes] = true
36
36
  options[:includes_root] = dir
37
37
  end
38
-
38
+
39
39
  opts.on('--generate-docs [*CLASSES]', Array, "generate docs for some of the sources. When given empty array, defaults to /**/*") do |docs|
40
40
  if !docs
41
41
  options[:documented_classes] = ["/**/*"]
@@ -43,15 +43,19 @@ cli = OptionParser.new do |opts|
43
43
  options[:documented_classes] = docs
44
44
  end
45
45
  end
46
-
46
+
47
47
  opts.on('--no-syntax-highlight', 'if you turned on docs generation, it will use syntax highlighting by default. This option prevents it') do
48
48
  options[:no_syntax_highlight] = true
49
49
  end
50
-
50
+
51
51
  opts.on('--validate-with [*VALIDATORS]', Array, 'performs a check against some of the validators. Available validators: mooforge') do |validators|
52
52
  options[:validators] = (validators || []).map {|v| v.downcase }
53
53
  end
54
-
54
+
55
+ opts.on('--postproc [*PROCESSORS]', Array, 'performs postprocessing. Available postprocs:\n* moocompat12 -- removes mootools 1.2compat tags and their contents\n* mooltIE8 -- removes mootools ltIE8 compat tags and their contents') do |postprocs|
56
+ options[:postproc] = postprocs
57
+ end
58
+
55
59
  opts.on_tail('-v', '--verbose', 'verbose mode, shows various debug messages') do
56
60
  options[:verbose] = true
57
61
  end
@@ -59,17 +63,17 @@ cli = OptionParser.new do |opts|
59
63
  opts.on_tail('-b', '--benchmark', 'shows time spent on various stages') do
60
64
  options[:benchmark] = true
61
65
  end
62
-
66
+
63
67
  opts.on_tail('--without-scripts-info', 'do not generate scripts.json') do
64
68
  options[:without_scripts_info] = true
65
69
  end
66
-
70
+
67
71
  opts.on_tail('--without-tree-info', 'do not generate tree.json') do
68
72
  options[:without_tree_info] = true
69
73
  end
70
-
71
-
72
-
74
+
75
+
76
+
73
77
  opts.on_tail('-h', '--help', 'Show this message') do
74
78
  puts opts
75
79
  exit
@@ -86,9 +90,9 @@ if !(options[:input_dir] && options[:output_dir])
86
90
  end
87
91
 
88
92
  compile_start_time = Time.now
89
-
93
+
90
94
  Jsus.verbose = options[:verbose]
91
-
95
+
92
96
  pool_load_start_time = Time.now
93
97
  pool = if options[:deps_dir]
94
98
  Jsus::Pool.new(options[:deps_dir])
@@ -100,7 +104,27 @@ pool_load_finish_time = Time.now
100
104
  package = Jsus::Package.new(options[:input_dir], :pool => pool)
101
105
  package.include_dependencies!
102
106
  output_dir = options[:output_dir]
103
- package.compile(output_dir)
107
+
108
+ package_content = package.compile(nil)
109
+
110
+ if options[:postproc]
111
+ options[:postproc].each do |processor|
112
+ case processor.strip
113
+ when /^moocompat12$/i
114
+ package_content.gsub!(/\/\/<1.2compat>.*?\/\/<\/1.2compat>/m, '')
115
+ package_content.gsub!(/\/\*<1.2compat>\*\/.*?\/\*<\/1.2compat>\*\//m, '')
116
+ when /^mooltie8$/i
117
+ package_content.gsub!(/\/\/<ltIE8>.*?\/\/<\/ltIE8>/m, '')
118
+ package_content.gsub!(/\/\*<ltIE8>\*\/.*?\/\*<\/ltIE8>\*\//m, '')
119
+ else
120
+ $stderr.puts "Unknown post-processor: #{processor}"
121
+ end
122
+ end
123
+ end
124
+ FileUtils.mkdir_p(output_dir)
125
+ package_filename = File.join(output_dir, package.filename)
126
+ File.open(package_filename, 'w') {|f| f << package_content }
127
+
104
128
  package.generate_scripts_info(output_dir) unless options[:without_scripts_info]
105
129
  package.generate_tree(output_dir) unless options[:without_tree_info]
106
130
 
@@ -118,6 +142,8 @@ validators_map = {"mooforge" => Jsus::Validator::Mooforge}
118
142
  end
119
143
  end
120
144
 
145
+ # Postprocs, sort of hack
146
+
121
147
  # Hack, hack, hack >:E
122
148
  if options[:generate_includes]
123
149
  includes_root = options[:includes_root] || output_dir
@@ -0,0 +1,75 @@
1
+ Feature: postprocessing
2
+ In order to leave unneccessary compatibility code out, I should be able to
3
+ use postprocessing feature.
4
+
5
+ Scenario: compat12
6
+ When I run "jsus Postprocessing/MootoolsCompat12 tmp --postproc moocompat12"
7
+ Then the following files should exist:
8
+ | tmp/package.js |
9
+ And file "tmp/package.js" should contain
10
+ """
11
+ /*
12
+ ---
13
+
14
+ script: Core.js
15
+
16
+ description: Mootools fake core
17
+
18
+ license: MIT-style license
19
+
20
+ authors:
21
+ - Valerio Proietti
22
+
23
+ provides: [Core]
24
+
25
+ ...
26
+ */
27
+ """
28
+ And file "tmp/package.js" should not contain
29
+ """
30
+ <1.2compat>
31
+ """
32
+ And file "tmp/package.js" should not contain
33
+ """
34
+ var compatible12 = true;
35
+ """
36
+ And file "tmp/package.js" should contain
37
+ """
38
+ var incompatible = true;
39
+ """
40
+
41
+ Scenario: mooltIE8
42
+ When I run "jsus Postprocessing/MootoolsLtIE8 tmp --postproc mooltIE8"
43
+ Then the following files should exist:
44
+ | tmp/package.js |
45
+ And file "tmp/package.js" should contain
46
+ """
47
+ /*
48
+ ---
49
+
50
+ script: Core.js
51
+
52
+ description: Mootools fake core
53
+
54
+ license: MIT-style license
55
+
56
+ authors:
57
+ - Valerio Proietti
58
+
59
+ provides: [Core]
60
+
61
+ ...
62
+ */
63
+ """
64
+ And file "tmp/package.js" should not contain
65
+ """
66
+ <ltIE8>
67
+ """
68
+ And file "tmp/package.js" should not contain
69
+ """
70
+ var compatibleIE8 = true;
71
+ """
72
+ And file "tmp/package.js" should contain
73
+ """
74
+ var incompatible = true;
75
+ """
@@ -0,0 +1,72 @@
1
+ Feature: replacements
2
+ In order to monkeypatch other libraries, I should be able to replace some
3
+ of the files.
4
+
5
+ Scenario: monkeypatch for external dependency
6
+ When I run "jsus Replacements tmp -d Replacements"
7
+ Then the following files should exist:
8
+ | tmp/package.js |
9
+ And file "tmp/package.js" should contain
10
+ """
11
+ /*
12
+ ---
13
+
14
+ script: MootooolsCore.js
15
+
16
+ description: Replaced mootools core
17
+
18
+ license: MIT-style license
19
+
20
+ authors:
21
+ - Mark Abramov
22
+
23
+ provides:
24
+ - More
25
+
26
+ replaces: Mootools/Core
27
+
28
+ ...
29
+ */
30
+ """
31
+ And file "tmp/package.js" should contain
32
+ """
33
+ /*
34
+ ---
35
+
36
+ script: Color.js
37
+
38
+ description: A library to work with colors
39
+
40
+ license: MIT-style license
41
+
42
+ authors:
43
+ - Valerio Proietti
44
+
45
+ requires:
46
+ - Mootools/Core
47
+
48
+ provides: [Color]
49
+
50
+ ...
51
+ */
52
+ """
53
+ And file "tmp/package.js" should not contain
54
+ """
55
+ /*
56
+ ---
57
+
58
+ script: Core.js
59
+
60
+ description: Mootools fake core
61
+
62
+ license: MIT-style license
63
+
64
+ authors:
65
+ - Valerio Proietti
66
+
67
+ provides: [Core]
68
+
69
+ ...
70
+ */
71
+ """
72
+ And file "tmp/package.js" should have "MootooolsCore.js" before "script: Color.js"
@@ -0,0 +1,25 @@
1
+ /*
2
+ ---
3
+
4
+ script: Core.js
5
+
6
+ description: Mootools fake core
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Valerio Proietti
12
+
13
+ provides: [Core]
14
+
15
+ ...
16
+ */
17
+
18
+
19
+ //<1.2compat>
20
+ var compatible12 = true;
21
+ var a, b;
22
+ if (a < b) window.alert("Bugaga");
23
+ //</1.2compat>
24
+
25
+ var incompatible = true;
@@ -0,0 +1,8 @@
1
+ name: Mootools
2
+ filename: package.js
3
+ web: http://github.com/markiz/jsus
4
+ description: Mootools fork which is going to be postprocessed. This one has its compat features removed.
5
+ license: Public Domain, http://unlicense.org/UNLICENSE
6
+ authors: Mark Abramov (http://github.com/markiz)
7
+ sources:
8
+ - "Source/Core.js"
@@ -0,0 +1,25 @@
1
+ /*
2
+ ---
3
+
4
+ script: Core.js
5
+
6
+ description: Mootools fake core
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Valerio Proietti
12
+
13
+ provides: [Core]
14
+
15
+ ...
16
+ */
17
+
18
+
19
+ //<ltIE8>
20
+ var compatibleIE8 = true;
21
+ var a, b;
22
+ if (a < b) window.alert("Bugaga");
23
+ //</ltIE8>
24
+
25
+ var incompatible = true;
@@ -0,0 +1,8 @@
1
+ name: Mootools
2
+ filename: package.js
3
+ web: http://github.com/markiz/jsus
4
+ description: Mootools fork which is going to be postprocessed. This one has its ltIE8 features removed.
5
+ license: Public Domain, http://unlicense.org/UNLICENSE
6
+ authors: Mark Abramov (http://github.com/markiz)
7
+ sources:
8
+ - "Source/Core.js"
@@ -0,0 +1,16 @@
1
+ /*
2
+ ---
3
+
4
+ script: Core.js
5
+
6
+ description: Mootools fake core
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Valerio Proietti
12
+
13
+ provides: [Core]
14
+
15
+ ...
16
+ */
@@ -0,0 +1,8 @@
1
+ name: Mootools
2
+ filename: mootools.js
3
+ web: http://mootools.net
4
+ description: Fake mootools package
5
+ license: Public Domain, http://unlicense.org/UNLICENSE
6
+ authors: mootools authors
7
+ sources:
8
+ - "Source/Core.js"
@@ -0,0 +1,19 @@
1
+ /*
2
+ ---
3
+
4
+ script: MootooolsCore.js
5
+
6
+ description: Replaced mootools core
7
+
8
+ license: MIT-style license
9
+
10
+ authors:
11
+ - Mark Abramov
12
+
13
+ provides:
14
+ - More
15
+
16
+ replaces: Mootools/Core
17
+
18
+ ...
19
+ */
@@ -0,0 +1,8 @@
1
+ name: Mootools Fork
2
+ filename: moofork.js
3
+ web: http://github.com/markiz/jsus
4
+ description: Mootools fork containing replacement files
5
+ license: Public Domain, http://unlicense.org/UNLICENSE
6
+ authors: Mark Abramov (http://github.com/markiz)
7
+ sources:
8
+ - "Replacements/MootoolsCore.js"
@@ -0,0 +1,19 @@
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
+ requires:
14
+ - Mootools/Core
15
+
16
+ provides: [Color]
17
+
18
+ ...
19
+ */
@@ -0,0 +1,8 @@
1
+ name: Package
2
+ filename: package.js
3
+ web: http://github.com/markiz/jsus
4
+ description: Jsus package linked to externally replaced library
5
+ license: Public Domain, http://unlicense.org/UNLICENSE
6
+ authors: Mark Abramov (http://github.com/markiz)
7
+ sources:
8
+ - "Source/Library/Color.js"
@@ -19,6 +19,13 @@ Then /^file "(.*?)" should contain$/ do |filename, content|
19
19
  end
20
20
  end
21
21
 
22
+
23
+ Then /^file "(.*?)" should not contain$/ do |filename, content|
24
+ Dir.chdir DATA_DIR do
25
+ File.read(filename).should_not include(content)
26
+ end
27
+ end
28
+
22
29
  Then /^file "(.*?)" should contain valid JSON$/i do |filename|
23
30
  Dir.chdir DATA_DIR do
24
31
  json = nil
data/jsus.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{jsus}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mark Abramov"]
12
- s.date = %q{2011-02-11}
12
+ s.date = %q{2011-02-20}
13
13
  s.default_executable = %q{jsus}
14
14
  s.description = %q{Javascript packager and dependency resolver}
15
15
  s.email = %q{markizko@gmail.com}
@@ -37,6 +37,8 @@ Gem::Specification.new do |s|
37
37
  "features/command-line/extensions.feature",
38
38
  "features/command-line/external_dependency_resolution.feature",
39
39
  "features/command-line/json_package.feature",
40
+ "features/command-line/postproc.feature",
41
+ "features/command-line/replacements.feature",
40
42
  "features/command-line/structure_json.feature",
41
43
  "features/data/Basic/Source/Library/Color.js",
42
44
  "features/data/Basic/Source/Widget/Input/Input.Color.js",
@@ -64,6 +66,16 @@ Gem::Specification.new do |s|
64
66
  "features/data/JsonPackage/Source/Library/Color.js",
65
67
  "features/data/JsonPackage/Source/Widget/Input/Input.Color.js",
66
68
  "features/data/JsonPackage/package.json",
69
+ "features/data/Postprocessing/MootoolsCompat12/Source/Core.js",
70
+ "features/data/Postprocessing/MootoolsCompat12/package.yml",
71
+ "features/data/Postprocessing/MootoolsLtIE8/Source/Core.js",
72
+ "features/data/Postprocessing/MootoolsLtIE8/package.yml",
73
+ "features/data/Replacements/Mootools/Source/Core.js",
74
+ "features/data/Replacements/Mootools/package.yml",
75
+ "features/data/Replacements/MootoolsFork/Replacements/MootoolsCore.js",
76
+ "features/data/Replacements/MootoolsFork/package.yml",
77
+ "features/data/Replacements/Source/Library/Color.js",
78
+ "features/data/Replacements/package.yml",
67
79
  "features/data/tmp2/package.js",
68
80
  "features/data/tmp2/scripts.json",
69
81
  "features/data/tmp2/tree.json",
@@ -97,6 +109,8 @@ Gem::Specification.new do |s|
97
109
  "spec/data/ChainDependencies/app/javascripts/Hash/package.yml",
98
110
  "spec/data/ChainDependencies/app/javascripts/Mash/Source/Mash.js",
99
111
  "spec/data/ChainDependencies/app/javascripts/Mash/package.yml",
112
+ "spec/data/ClassReplacement/Source/Class.js",
113
+ "spec/data/ClassReplacement/package.yml",
100
114
  "spec/data/DependenciesWildcards/app/javascripts/Class/Source/Class.js",
101
115
  "spec/data/DependenciesWildcards/app/javascripts/Class/package.yml",
102
116
  "spec/data/DependenciesWildcards/app/javascripts/Hash/Source/Hash.js",
data/lib/jsus/package.rb CHANGED
@@ -116,7 +116,8 @@ module Jsus
116
116
 
117
117
  # Compiles source files and linked external source files into a given category.
118
118
  def compile(directory = ".")
119
- Packager.new(*(source_files.to_a + linked_external_dependencies.to_a)).pack(File.join(directory, filename))
119
+ fn = directory ? File.join(directory, filename) : nil
120
+ Packager.new(*(source_files.to_a + linked_external_dependencies.to_a)).pack(fn)
120
121
  end
121
122
 
122
123
  # Generates tree structure for files in package into a json file.
@@ -148,8 +149,10 @@ module Jsus
148
149
  # Looks up all the external dependencies in the pool.
149
150
  def include_dependencies!
150
151
  source_files.each do |source|
151
- deps = pool.lookup_dependencies(source).to_a - @source_files.to_a
152
- linked_external_dependencies << deps if pool
152
+ if pool
153
+ deps = pool.lookup_dependencies(source).to_a - @source_files.to_a
154
+ linked_external_dependencies << deps
155
+ end
153
156
  end
154
157
  end
155
158
 
data/lib/jsus/pool.rb CHANGED
@@ -4,7 +4,7 @@
4
4
  # * Resolve dependencies
5
5
  # * Look up extensions
6
6
  #
7
- #
7
+ #
8
8
 
9
9
 
10
10
  module Jsus
@@ -15,7 +15,7 @@ module Jsus
15
15
  #
16
16
  # Basic constructor.
17
17
  #
18
- # Accepts an optional directory argument, when it is set, it looks up for
18
+ # Accepts an optional directory argument, when it is set, it looks up for
19
19
  # packages from the given directory and if it finds any, adds them to the pool.
20
20
  #
21
21
  # Directory is considered a Package directory if it contains +package.yml+ file.
@@ -28,9 +28,9 @@ module Jsus
28
28
  end
29
29
  flush_cache!
30
30
  end
31
-
32
-
33
- #
31
+
32
+
33
+ #
34
34
  # An array containing all the packages in the pool. Unordered.
35
35
  #
36
36
  def packages
@@ -38,7 +38,7 @@ module Jsus
38
38
  end
39
39
 
40
40
  #
41
- # Container with all the sources in the pool. It is actually ordered in case you
41
+ # Container with all the sources in the pool. It is actually ordered in case you
42
42
  # want to include ALL the source files from the pool.
43
43
  #
44
44
  def sources
@@ -46,16 +46,17 @@ module Jsus
46
46
  end
47
47
 
48
48
  #
49
- # Looks up for a file providing given tag or tag key.
49
+ # Looks up for a file replacing or providing given tag or tag key.
50
+ # Replacement file gets priority.
50
51
  #
51
52
  # If given a source file, returns the input.
52
53
  #
53
54
  def lookup(source_or_key)
54
55
  case source_or_key
55
56
  when String
56
- provides_map[Tag[source_or_key]]
57
+ lookup(Tag[source_or_key])
57
58
  when Tag
58
- provides_map[source_or_key]
59
+ replacement_map[source_or_key] || provides_map[source_or_key]
59
60
  when SourceFile
60
61
  source_or_key
61
62
  else
@@ -63,7 +64,7 @@ module Jsus
63
64
  "given #{source_or_key.inspect}, an instance of #{source_or_key.class.name}."
64
65
  end
65
66
  end
66
-
67
+
67
68
 
68
69
  #
69
70
  # Looks up for dependencies for given file recursively.
@@ -118,6 +119,8 @@ module Jsus
118
119
  end
119
120
  provides_map[p] = source
120
121
  end
122
+
123
+ replacement_map[source.replaces] = source if source.replaces if source.replaces
121
124
  end
122
125
  when source_or_sources_or_package.kind_of?(Package)
123
126
  package = source_or_sources_or_package
@@ -140,13 +143,13 @@ module Jsus
140
143
 
141
144
  (Array.instance_methods - self.instance_methods).each {|m| delegate m, :to => :sources }
142
145
  # Private API
143
-
144
- #
146
+
147
+ #
145
148
  # Looks up direct dependencies for the given source_file or provides tag.
146
149
  # You probably will find yourself using #include_dependencies instead.
147
150
  # This method caches results locally, use flush_cache! to drop.
148
151
  #
149
- def lookup_direct_dependencies(source_or_source_key)
152
+ def lookup_direct_dependencies(source_or_source_key)
150
153
  source = lookup(source_or_source_key)
151
154
  @cached_dependencies[source] ||= lookup_direct_dependencies!(source)
152
155
  end
@@ -162,7 +165,7 @@ module Jsus
162
165
  puts "#{source.filename} is missing #{dependency.is_a?(SourceFile) ? dependency.filename : dependency.to_s}"
163
166
  end
164
167
  result
165
- end.flatten
168
+ end.flatten.map {|tag| lookup(tag) }
166
169
  else
167
170
  []
168
171
  end
@@ -173,7 +176,7 @@ module Jsus
173
176
  # Returs a tree, containing all the sources
174
177
  #
175
178
  def source_tree
176
- @source_tree ||= Tree.new
179
+ @source_tree ||= Tree.new
177
180
  end
178
181
 
179
182
  #
@@ -194,7 +197,7 @@ module Jsus
194
197
  source_tree.insert("/" + File.basename(source.filename), source)
195
198
  end
196
199
  source.provides.each do |tag|
197
- provides_tree.insert("/" + tag.to_s, source)
200
+ provides_tree.insert("/" + tag.to_s, tag)
198
201
  end
199
202
  end
200
203
 
@@ -207,5 +210,9 @@ module Jsus
207
210
  def extensions_map # :nodoc:
208
211
  @extensions_map ||= Hash.new{|hash, key| hash[key] = [] }
209
212
  end
213
+
214
+ def replacement_map # :nodoc:
215
+ @replacement_map ||= {}
216
+ end
210
217
  end
211
218
  end
@@ -128,6 +128,13 @@ module Jsus
128
128
  provides.map {|p| p.name(options)}
129
129
  end
130
130
 
131
+ #
132
+ # Returns a tag for replaced file, if any
133
+ #
134
+ def replaces
135
+ @replaces
136
+ end
137
+
131
138
 
132
139
  #
133
140
  # Returns a tag for source file, which this one is an extension for.
@@ -213,6 +220,7 @@ module Jsus
213
220
  @provides = [@header["provides"] || []].flatten
214
221
  @provides.map! {|tag_name| Tag.new(tag_name, :package => package) }
215
222
  @extends = (@header["extends"] && !@header["extends"].empty?) ? Tag.new(@header["extends"]) : nil
223
+ @replaces = @header["replaces"] ? Tag.new(@header["replaces"]) : nil
216
224
  end
217
225
 
218
226
  def content=(new_value) # :nodoc:
@@ -0,0 +1,14 @@
1
+ /*
2
+ ---
3
+
4
+ script: Class.js
5
+
6
+ description: Contains replacement for class
7
+
8
+ license: MIT-style license.
9
+
10
+ replaces: Class/Class
11
+
12
+
13
+ ...
14
+ */
@@ -0,0 +1,8 @@
1
+ name: Class
2
+ filename: class.js
3
+ description: Class class
4
+ license: MIT-Style License, http://mootools.net/license
5
+ copyright: Somebody
6
+ authors: Someone
7
+ sources:
8
+ - Source/Class.js
@@ -61,6 +61,18 @@ describe Jsus::Package do
61
61
  required_files = Dir["#{input_dir}/**/*.js"].map {|f| IO.read(f) }
62
62
  required_files.each {|f| compiled_content.should include(f)}
63
63
  end
64
+
65
+ context "when given nil" do
66
+ it "should not raise errors" do
67
+ lambda { subject.compile(nil) }.should_not raise_error
68
+ end
69
+
70
+ it "should return a string with compiled content" do
71
+ compiled_content = subject.compile(nil)
72
+ required_files = Dir["#{input_dir}/**/*.js"].map {|f| IO.read(f) }
73
+ required_files.each {|f| compiled_content.should include(f)}
74
+ end
75
+ end
64
76
  end
65
77
 
66
78
  describe "#generate_scripts_info" do
@@ -66,6 +66,13 @@ describe Jsus::Pool do
66
66
  it "should allow tags" do
67
67
  subject.lookup(Jsus::Tag["Class/Class"]).should == sources[1]
68
68
  end
69
+
70
+ it "should return replacements whenever possible" do
71
+ pkg = Jsus::Package.new("spec/data/ClassReplacement", :pool => subject)
72
+ subject << pkg.source_files
73
+ subject.lookup("Class/Class").should == pkg.source_files[0]
74
+ subject.lookup(Jsus::Tag["Class/Class"]).should == pkg.source_files[0]
75
+ end
69
76
  end
70
77
 
71
78
  describe "#lookup_direct_dependencies" do
@@ -154,7 +161,11 @@ describe Jsus::Pool do
154
161
  subject { Jsus::Pool.new(input_dir) }
155
162
 
156
163
  it "should return a tree with all the source elements in it" do
157
- subject.provides_tree.glob("/Core/Class")[0].value.should be_a(Jsus::SourceFile)
164
+ subject.provides_tree.glob("/Core/Class")[0].value.should == Jsus::Tag["Core/Class"]
165
+ end
166
+
167
+ it "should allow wildcards" do
168
+ subject.provides_tree.glob("/Core/*")[0].value.should == Jsus::Tag["Core/Class"]
158
169
  end
159
170
  end
160
171
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mark Abramov
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-11 00:00:00 +03:00
17
+ date: 2011-02-20 00:00:00 -05:00
18
18
  default_executable: jsus
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -149,6 +149,8 @@ files:
149
149
  - features/command-line/extensions.feature
150
150
  - features/command-line/external_dependency_resolution.feature
151
151
  - features/command-line/json_package.feature
152
+ - features/command-line/postproc.feature
153
+ - features/command-line/replacements.feature
152
154
  - features/command-line/structure_json.feature
153
155
  - features/data/Basic/Source/Library/Color.js
154
156
  - features/data/Basic/Source/Widget/Input/Input.Color.js
@@ -176,6 +178,16 @@ files:
176
178
  - features/data/JsonPackage/Source/Library/Color.js
177
179
  - features/data/JsonPackage/Source/Widget/Input/Input.Color.js
178
180
  - features/data/JsonPackage/package.json
181
+ - features/data/Postprocessing/MootoolsCompat12/Source/Core.js
182
+ - features/data/Postprocessing/MootoolsCompat12/package.yml
183
+ - features/data/Postprocessing/MootoolsLtIE8/Source/Core.js
184
+ - features/data/Postprocessing/MootoolsLtIE8/package.yml
185
+ - features/data/Replacements/Mootools/Source/Core.js
186
+ - features/data/Replacements/Mootools/package.yml
187
+ - features/data/Replacements/MootoolsFork/Replacements/MootoolsCore.js
188
+ - features/data/Replacements/MootoolsFork/package.yml
189
+ - features/data/Replacements/Source/Library/Color.js
190
+ - features/data/Replacements/package.yml
179
191
  - features/data/tmp2/package.js
180
192
  - features/data/tmp2/scripts.json
181
193
  - features/data/tmp2/tree.json
@@ -209,6 +221,8 @@ files:
209
221
  - spec/data/ChainDependencies/app/javascripts/Hash/package.yml
210
222
  - spec/data/ChainDependencies/app/javascripts/Mash/Source/Mash.js
211
223
  - spec/data/ChainDependencies/app/javascripts/Mash/package.yml
224
+ - spec/data/ClassReplacement/Source/Class.js
225
+ - spec/data/ClassReplacement/package.yml
212
226
  - spec/data/DependenciesWildcards/app/javascripts/Class/Source/Class.js
213
227
  - spec/data/DependenciesWildcards/app/javascripts/Class/package.yml
214
228
  - spec/data/DependenciesWildcards/app/javascripts/Hash/Source/Hash.js
@@ -285,7 +299,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
285
299
  requirements:
286
300
  - - ">="
287
301
  - !ruby/object:Gem::Version
288
- hash: -1946463697476242454
302
+ hash: 1044450339509570766
289
303
  segments:
290
304
  - 0
291
305
  version: "0"