vam 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 856fab8c57d914c9dd15f79ba3134291baa63c28
4
- data.tar.gz: b7f916bb26db8fa52b2749b1a269f995debf7038
3
+ metadata.gz: 21438f192cfe610da5318d736124dc28125a8cdc
4
+ data.tar.gz: e3eedbc8b35fbe958b9aba9bd36e79752078734f
5
5
  SHA512:
6
- metadata.gz: de111f95e5add288cc2bd99b399f0b8e1300505c9cd60df20b917c31271acd62295f148f77fe123c53ddb15c33d36429764be74aae3341d89e098208e103bcca
7
- data.tar.gz: 1c569fb5a9ef29fb8621c8638e79013dee2f58a8c404f4223f2d9be1d9a48174e388ebcf288567d0873a3dbfe03566fe7b3cf122ad284c20918a9975db85aa5c
6
+ metadata.gz: 6698abfbcd07645db688a3bba203bea2b93586960889d11e64b067f89b8d517a6b1fda94b796bc2de2a5710361fb86c0b6779f993dcb4ea428a06a0f04f78453
7
+ data.tar.gz: 4e9329ebbf350d8b81a7075cb5e001ea424167353852d31fb9b81d45d469719fffb6676e54140014e2b05de382be97fa3f8b1ed192eb96c218f88db119347a45
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Vam
2
2
 
3
- TODO: Write a gem description
3
+ Vendor Assets Manager
4
4
 
5
5
  ## Installation
6
6
 
data/bin/vam CHANGED
@@ -3,7 +3,3 @@
3
3
  require 'vam'
4
4
 
5
5
  Vam::CLI.start(ARGV)
6
-
7
-
8
-
9
-
data/lib/vam/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'vam/constants'
2
2
  require 'vam/dsl'
3
+ require 'vam/repo'
4
+ require 'vam/server'
3
5
 
4
6
  module Vam
5
7
  class CLI
@@ -11,6 +13,8 @@ module Vam
11
13
  case argv[0]
12
14
  when 'install'
13
15
  install
16
+ when 'scan'
17
+ scan
14
18
  when '-v'
15
19
  print_version
16
20
  else
@@ -29,9 +33,9 @@ module Vam
29
33
 
30
34
  def self.install
31
35
  vamfile = File.join Dir.pwd, 'Vamfile'
32
- vams = Dsl.evaluate vamfile, vamfile+'.lock'
36
+ dsl = Dsl.evaluate vamfile
33
37
 
34
- for vam in vams
38
+ dsl.vams.each do |vam|
35
39
  dest = File.join Dir.pwd, 'vendor', 'assets', 'components'
36
40
  vam.install dest
37
41
  end
@@ -39,5 +43,10 @@ module Vam
39
43
  end
40
44
 
41
45
 
46
+ def self.scan
47
+ dir = Dir.getwd
48
+ Repo.scan dir
49
+ end
50
+
42
51
  end
43
52
  end
data/lib/vam/dsl.rb CHANGED
@@ -1,14 +1,17 @@
1
1
  require 'vam/vam'
2
2
 
3
+ require 'jimson'
4
+
5
+
3
6
  module Vam
4
7
  class Dsl
5
8
 
6
- attr_reader :vams
9
+ attr_reader :vams, :repo
7
10
 
8
- def self.evaluate(vamfile, lockfile)
11
+ def self.evaluate(vamfile)
9
12
  dsl = new()
10
13
  dsl.eval_vamfile(vamfile)
11
- return dsl.vams
14
+ return dsl
12
15
  end
13
16
 
14
17
 
@@ -23,16 +26,22 @@ module Vam
23
26
  end
24
27
 
25
28
 
26
- def vam(name, *args, &block)
29
+ def vam(name, *args)
27
30
  options = args.last.is_a?(Hash) ? args.last.dup : {}
28
31
 
29
32
  if args.first.is_a?(String)
30
33
  options[:version] = args.first
31
34
  end
32
35
 
33
- vam = Vam.new name, options, &block
36
+ vam = Vam.new name, self, options
34
37
  @vams << vam
35
38
  end
36
39
 
40
+
41
+ def source(url)
42
+ @source = url
43
+ @repo = Repo.load url
44
+ end
45
+
37
46
  end
38
47
  end
data/lib/vam/repo.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'open-uri'
2
+
3
+ module Vam
4
+
5
+ class Repo
6
+
7
+ attr_accessor :repo_url
8
+
9
+ def initialize
10
+ @repo_url = ''
11
+ @vendors = {}
12
+ end
13
+
14
+
15
+ def latest_version(name)
16
+ @vendors[name].keys.sort[0]
17
+ end
18
+
19
+
20
+ def files(name, version)
21
+ @vendors[name][version].collect do |e|
22
+ {
23
+ dir: File.dirname(e),
24
+ filename: File.basename(e),
25
+ url: File.join(repo_url, name, version, e)
26
+ }
27
+ end
28
+ end
29
+
30
+
31
+ def add(name, version, rpath)
32
+ unless @vendors.include? name
33
+ @vendors[name] = {}
34
+ end
35
+
36
+ unless @vendors[name].include? version
37
+ @vendors[name][version] = []
38
+ end
39
+
40
+ if rpath.is_a? Array
41
+ @vendors[name][version] = rpath
42
+ else
43
+ @vendors[name][version] << rpath
44
+ end
45
+ end
46
+
47
+
48
+ def self.scan(dir)
49
+ repo = Repo.new
50
+ Dir.glob(File.join dir, '*').each do |s|
51
+ name = File.basename(s)
52
+
53
+ Dir.glob(File.join s, '*').each do |v|
54
+ version = File.basename(v)
55
+ files = Dir.glob(File.join v, '/**/*').collect { |e| e.slice!("#{v}/"); e }
56
+ repo.add name, version, files
57
+ end
58
+ end
59
+
60
+ Repo.dump dir, repo
61
+ end
62
+
63
+
64
+ def self.load(repo_url)
65
+ repo = Marshal.load open(File.join(repo_url, 'repo'))
66
+ repo.repo_url = repo_url
67
+ repo
68
+ end
69
+
70
+
71
+ def self.dump(dir, repo)
72
+ File.open(File.join(dir, 'repo'), 'w') {|f| f.write(Marshal.dump repo)}
73
+ end
74
+
75
+ end
76
+
77
+ end
data/lib/vam/server.rb ADDED
@@ -0,0 +1,29 @@
1
+ require 'jimson'
2
+
3
+ module Vam
4
+
5
+ class VamServer
6
+
7
+ class Handler
8
+ extend Jimson::Handler
9
+ def sum(a,b)
10
+ a + b
11
+ end
12
+ end
13
+
14
+
15
+ def initialize(host, port)
16
+ @host = host
17
+ @port = port
18
+ end
19
+
20
+
21
+ def start
22
+ server = Jimson::Server.new(Handler.new, host: @host, port: @port, server: 'thin')
23
+ server.start
24
+ end
25
+
26
+
27
+ end
28
+
29
+ end
data/lib/vam/vam.rb CHANGED
@@ -1,158 +1,79 @@
1
1
  require 'fileutils'
2
2
  require 'colorize'
3
3
  require 'vam/constants'
4
+ require 'open-uri'
5
+ require 'pp'
4
6
 
5
7
  module Vam
6
8
 
7
9
  class Vam
8
10
 
9
- def initialize(name, options, &block)
10
- @name = name
11
+ SNAPSHOT = 'SNAPSHOT'
11
12
 
12
- @tmproot = "#{VAMROOT}/#{@name}"
13
+ def initialize(name, dsl, options)
14
+ @name = name
15
+ @dsl = dsl
13
16
 
14
17
  @urls = []
15
- @locals = []
16
18
 
17
19
  if options.include?(:version)
18
20
  @version = options[:version]
21
+ else
22
+ @version = @dsl.repo.latest_version @name
19
23
  end
20
24
 
21
- if options.include?(:github)
22
- @git = "https://github.com/#{options[:github]}.git"
23
- elsif options.include?(:git)
24
- @git = options[:git]
25
- end
26
-
27
- if options.include?(:tag)
28
- @tag = options[:tag]
29
- end
30
-
31
- instance_eval &block
32
-
33
- end
34
-
35
-
36
- def url(url, main: true)
37
- unless ['.css', '.js'].include? File.extname(url)
38
- main = false
39
- end
40
-
41
- filename = main ? 'index'+File.extname(url) : File.basename(url)
42
- @urls << {url: url, filename: filename}
43
- end
25
+ @files = @dsl.repo.files @name, @version
44
26
 
27
+ tmproot = "#{VAMROOT}/#{@name}"
28
+ @vroot = File.join tmproot, @version
29
+ @vroot_tmp = File.join tmproot, ".tmp-#{@version}"
45
30
 
46
- def local(local, main: false)
47
- filename = main ? 'index'+File.extname(local) : File.basename(local)
48
- @locals << {local: local, filename: filename}
49
31
  end
50
32
 
51
33
 
52
34
  def install(dest)
53
35
  puts "===Install #{@name}===".colorize(:blue)
54
-
55
- @dest = dest
56
- puts @dest
57
-
58
- dest = File.join dest, @name
59
- FileUtils.mkdir_p dest unless File.exist? dest
60
-
61
- if @git
62
- clone_git @git
63
-
64
- for local in @locals
65
- install_local dest, local, @tmproot
66
- end
67
-
68
- end
69
-
70
- for url in @urls
71
- install_url dest, url
72
- end
73
-
74
- @dest = nil
75
-
76
- end
77
-
78
-
79
- def install_local(dest, local, root)
80
- local_path = File.join root, local[:local]
81
-
82
- if File.directory? local_path
83
- for f in Dir.glob File.join(local_path, '*')
84
- FileUtils.cp_r f, dest
85
- end
86
- patch_dir dest
36
+ if cached?
37
+ download
87
38
  else
88
- of = File.join dest, local[:filename]
89
- FileUtils.cp local_path, of
90
- patch of
39
+ puts 'Using cache...'
91
40
  end
41
+ copy File.join(dest, @name)
92
42
  end
93
43
 
94
44
 
95
- def clone_git(git)
96
- if File.directory? @tmproot
97
- `cd #{@tmproot};git pull`
98
- else
99
- `git clone --depth=1 #{git} #{@tmproot}`
100
- end
101
-
45
+ def cached?
46
+ File.directory? @vroot
102
47
  end
103
48
 
104
49
 
105
- def install_url(dest, url)
106
- unless @version
107
- d = File.join @tmproot, '_default_'
108
- FileUtils.mkdir_p d
109
- of = File.join d, url[:filename]
110
- `rm #{of}`
111
- else
112
- d = File.join @tmproot, @version
113
- FileUtils.mkdir_p d
114
- of = File.join d, url[:filename]
115
- end
116
-
117
- df = File.join dest, url[:filename]
118
-
119
- unless File.exist? of
120
- `wget --no-check-certificate #{url[:url]} -O #{of}`
121
- of = patch of
122
- end
123
-
124
- FileUtils.cp of, df
125
- end
50
+ def download
51
+ FileUtils.mkdir_p @vroot_tmp
126
52
 
53
+ @files.each do |file|
54
+ dir = File.join @vroot_tmp, file[:dir]
55
+ FileUtils.mkdir_p dir
56
+ df = File.join dir, file[:filename]
127
57
 
128
- def patch_dir(dir)
129
- for of in Dir.glob("#{dir}/**/*.css")
130
- patch of
58
+ open File.join(df), 'wb' do |s|
59
+ puts "Download #{file[:url]}"
60
+ s << open(file[:url]).read
61
+ end
131
62
  end
63
+
64
+ FileUtils.move @vroot_tmp, @vroot
132
65
  end
133
66
 
134
67
 
135
- def patch(of)
136
- unless of.end_with? '.css'
137
- return of
138
- end
139
- pof = of + '.scss'
140
- content = File.read of, encoding: 'utf-8'
141
- cwd = Dir.getwd
142
- Dir.chdir File.dirname(of)
143
- content = content.gsub /url\('?([\w|\.|\/|#|\?]+)'?\)/ do |m|
144
- location = File.expand_path $1
145
- location = location[@dest.length+1..-1]
146
- "asset-url('#{location}')"
68
+ def copy(dest)
69
+ if Dir.exist? dest
70
+ FileUtils.rm_r dest
71
+ FileUtils.mkdir_p dest
147
72
  end
148
- Dir.chdir cwd
149
73
 
150
- File.open pof, 'w:utf-8' do |f|
151
- f.write content
152
- end
153
- File.delete of
154
- pof
74
+ FileUtils.cp_r "#{@vroot}/.", dest
155
75
  end
156
76
 
77
+
157
78
  end
158
79
  end
data/lib/vam/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vam
2
- VERSION = "0.0.4"
2
+ VERSION = '1.0.0'
3
3
  end
data/vam.gemspec CHANGED
@@ -4,19 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'vam/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "vam"
7
+ spec.name = 'vam'
8
8
  spec.version = Vam::VERSION
9
9
  spec.authors = ['Xingjian Xu']
10
10
  spec.email = ['dotswing@gmail.com']
11
11
  spec.summary = %q{Vendor assets managment}
12
12
  spec.description = %q{Vendor assets managment tool}
13
- spec.homepage = "http://github.com/dotswing/vam"
14
- spec.license = "MIT"
13
+ spec.homepage = 'http://github.com/dotswing/vam'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake', '~> 10.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xingjian Xu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2014-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,8 @@ files:
70
70
  - lib/vam/cli.rb
71
71
  - lib/vam/constants.rb
72
72
  - lib/vam/dsl.rb
73
+ - lib/vam/repo.rb
74
+ - lib/vam/server.rb
73
75
  - lib/vam/vam.rb
74
76
  - lib/vam/version.rb
75
77
  - vam.gemspec