jsdm 0.4.2 → 0.4.3
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/Rakefile +2 -1
- data/bin/jsdm +87 -0
- data/lib/jsdm.rb +23 -3
- data/lib/jsdm/errors.rb +1 -1
- metadata +11 -5
data/Rakefile
CHANGED
@@ -11,11 +11,12 @@ spec = Gem::Specification.new do |s|
|
|
11
11
|
s.files = Dir['{lib,doc,bin,ext}/**/*'].delete_if { |f|
|
12
12
|
/\/rdoc(\/|$)/i.match f
|
13
13
|
} + %w(Rakefile README.rdoc)
|
14
|
+
s.executables = Dir['bin/*'].map(&File.method(:basename))
|
14
15
|
s.require_path = 'lib'
|
15
16
|
s.has_rdoc = true
|
16
17
|
s.rubyforge_project = 'jsdm'
|
17
18
|
s.homepage = 'http://www.github.com/retiman/jsdm'
|
18
|
-
s.version = '0.4.
|
19
|
+
s.version = '0.4.3'
|
19
20
|
s.summary = 'Javascript dependency manager'
|
20
21
|
s.description = <<-EOF
|
21
22
|
Use #require statements to declare dependencies in JavaScript and let JSDM
|
data/bin/jsdm
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << 'lib'
|
4
|
+
|
5
|
+
require 'jsdm'
|
6
|
+
require 'optparse'
|
7
|
+
require 'pp'
|
8
|
+
|
9
|
+
options = {
|
10
|
+
:load_path => ['.']
|
11
|
+
}
|
12
|
+
|
13
|
+
optparse = OptionParser.new do |opts|
|
14
|
+
opts.banner = 'Usage: jsdm [options] path1 path2 path3'
|
15
|
+
|
16
|
+
opts.on(
|
17
|
+
'-e',
|
18
|
+
'--extension EXTENSION',
|
19
|
+
'Process files ending in .EXTENSION'
|
20
|
+
) do |extension|
|
21
|
+
if extension.nil?
|
22
|
+
puts opts
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
options[:extension] = extension
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on(
|
29
|
+
'-c',
|
30
|
+
'--comment-pattern PATTERN',
|
31
|
+
'Process comments matching regex PATTERN'
|
32
|
+
) do |pattern|
|
33
|
+
if pattern.nil?
|
34
|
+
puts opts
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
options[:comment_pattern] = Regexp.new(pattern)
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on(
|
41
|
+
'-r',
|
42
|
+
'--require-pattern',
|
43
|
+
'Process require directives matching regex PATTERN'
|
44
|
+
) do |pattern|
|
45
|
+
if pattern.nil?
|
46
|
+
puts opts
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
options[:require_pattern] = Regexp.new(pattern)
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.on(
|
53
|
+
'-R',
|
54
|
+
'--randomize',
|
55
|
+
'Randomize files beforehand'
|
56
|
+
) do
|
57
|
+
options[:randomize] = true
|
58
|
+
options[:sort] = false
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on(
|
62
|
+
'-S',
|
63
|
+
'--sort',
|
64
|
+
'Sort files beforehand'
|
65
|
+
) do
|
66
|
+
options[:randomize] = false
|
67
|
+
options[:sort] = true
|
68
|
+
end
|
69
|
+
|
70
|
+
opts.on('-h', '--help', 'Display this screen') do
|
71
|
+
puts opts
|
72
|
+
exit
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
optparse.parse!
|
77
|
+
options[:load_path] = ARGV unless ARGV.empty?
|
78
|
+
|
79
|
+
begin
|
80
|
+
sources = JSDM.new(options).sources
|
81
|
+
exit if sources.empty?
|
82
|
+
sources.each { |s| puts s }
|
83
|
+
rescue JSDM::CircularDependencyError => e
|
84
|
+
puts e.message
|
85
|
+
rescue JSDM::UnsatisfiableDependencyError => e
|
86
|
+
puts e.message
|
87
|
+
end
|
data/lib/jsdm.rb
CHANGED
@@ -26,9 +26,28 @@ class JSDM
|
|
26
26
|
:manager,
|
27
27
|
:resolver
|
28
28
|
|
29
|
+
# Options: randomize sort load_path extension comment_pattern require_pattern
|
30
|
+
#
|
31
|
+
# Examples:
|
32
|
+
#
|
33
|
+
# # Looks for both .js and .jsm extensions in the current directory
|
34
|
+
# JSDM.new :extension => '{js,jsm}'
|
35
|
+
#
|
36
|
+
# # Looks for JavaScript files in two different directories
|
37
|
+
# JSDM.new :load_path => %w(some/path some/other/path)
|
38
|
+
#
|
39
|
+
# # Sorts the JavaScript files beforehand; ensures a unique ordering of
|
40
|
+
# # dependencies, even if you've made a mistake in specifying the require
|
41
|
+
# # statements
|
42
|
+
# JSDM.new :sort => true
|
43
|
+
#
|
44
|
+
# # Randomizes the JavaScript files beforehand; hopefully ensures that you
|
45
|
+
# # will get an error from improperly specifying dependencies
|
46
|
+
# JSDM.new :randomize => true
|
29
47
|
def initialize(opts = {})
|
30
48
|
defaults = {
|
31
|
-
:randomize =>
|
49
|
+
:randomize => false,
|
50
|
+
:sort => true,
|
32
51
|
:load_path => '.',
|
33
52
|
:extension => 'js',
|
34
53
|
:comment_pattern => Preprocessor.comment_pattern,
|
@@ -57,8 +76,9 @@ class JSDM
|
|
57
76
|
self.sources = options[:load_path].map { |path|
|
58
77
|
Dir[File.join(path, '**', "*.#{options[:extension]}")]
|
59
78
|
}.flatten
|
60
|
-
self.sources = sources.sort
|
61
|
-
self.
|
79
|
+
self.sources = sources.sort if options[:sort]
|
80
|
+
self.sources = sources.sort_by { rand } if options[:randomize]
|
81
|
+
self.preprocessor = Preprocessor.new sources, options
|
62
82
|
self.manager = DependencyManager.new sources
|
63
83
|
self.resolver = DependencyResolver.new options[:load_path]
|
64
84
|
self.requires = preprocessor.process
|
data/lib/jsdm/errors.rb
CHANGED
@@ -39,7 +39,7 @@ class JSDM
|
|
39
39
|
private :source=, :dep=
|
40
40
|
|
41
41
|
def initialize(source, dep)
|
42
|
-
msg = "File #{source} has unsatisfiable
|
42
|
+
msg = "File #{source} has one or more unsatisfiable dependencies:\n" +
|
43
43
|
" #{dep}"
|
44
44
|
self.source = source
|
45
45
|
self.dep = dep
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsdm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
9
|
+
- 3
|
10
|
+
version: 0.4.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Min Huang
|
@@ -20,8 +21,8 @@ dependencies: []
|
|
20
21
|
|
21
22
|
description: " Use #require statements to declare dependencies in JavaScript and let JSDM\n resolve the dependencies for you.\n"
|
22
23
|
email: min.huang@alumni.usc.edu
|
23
|
-
executables:
|
24
|
-
|
24
|
+
executables:
|
25
|
+
- jsdm
|
25
26
|
extensions: []
|
26
27
|
|
27
28
|
extra_rdoc_files: []
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- lib/jsdm/dependency_resolver.rb
|
38
39
|
- doc/LICENSE
|
39
40
|
- doc/REFERENCES
|
41
|
+
- bin/jsdm
|
40
42
|
- Rakefile
|
41
43
|
- README.rdoc
|
42
44
|
has_rdoc: true
|
@@ -49,23 +51,27 @@ rdoc_options: []
|
|
49
51
|
require_paths:
|
50
52
|
- lib
|
51
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
52
55
|
requirements:
|
53
56
|
- - ">="
|
54
57
|
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
55
59
|
segments:
|
56
60
|
- 0
|
57
61
|
version: "0"
|
58
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
59
64
|
requirements:
|
60
65
|
- - ">="
|
61
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
62
68
|
segments:
|
63
69
|
- 0
|
64
70
|
version: "0"
|
65
71
|
requirements: []
|
66
72
|
|
67
73
|
rubyforge_project: jsdm
|
68
|
-
rubygems_version: 1.3.
|
74
|
+
rubygems_version: 1.3.7
|
69
75
|
signing_key:
|
70
76
|
specification_version: 3
|
71
77
|
summary: Javascript dependency manager
|