cdnget 0.1.0 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9204fce30417104ddfeb1a49af1c1e770c630cc1
4
- data.tar.gz: 1e9dc0c2d1fba34882a0dd5c6fc26a8ccc6edb57
3
+ metadata.gz: 1a718ec89571144e9875b5a5c56bd3d44fdd81f5
4
+ data.tar.gz: ea19fd364267826d4228a01caef8a4ebbb394cf1
5
5
  SHA512:
6
- metadata.gz: 087992a00501a6d1f3dd179a741b708eed1c80266666c0a61f8465325d2c7f0f7592ecc8015c3edb7e0987613a811e92fba0e4b7ecdb058a54b68f3f8a0b6f43
7
- data.tar.gz: 1bed28d10dc90f2e2ab241178dc74a9762a866efe5860f31c2eab01a4f6377978653756932ddd8a2a170bbd9061fa3a77a78ecb5493dbf05b48ce0fdf76a27ce
6
+ metadata.gz: e4e17f3ec24c1d84314890c7f54414e36365a75ee2a5478235be2410a80d97e319617a0e880d851a4acb9ef80282cdb1656ab3cae227304d34d67382a19083d7
7
+ data.tar.gz: 2e84dda3e1866b128e526e8949555f1ca90ee3a28c5465323140fdb55b40df4542b6189eafce04665ff677b8a995d1707001c80908c86238dceeb4ea3e9e2c2b
@@ -0,0 +1,14 @@
1
+ Changes
2
+ =======
3
+
4
+
5
+ Release 0.2.0 (2016-07-11)
6
+ --------------------------
7
+
8
+ * Update to follow change of CDNJS website
9
+
10
+
11
+ Release 0.1.0 (2016-01-13)
12
+ --------------------------
13
+
14
+ * First release
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  CDNget
2
2
  ======
3
3
 
4
- ($Release: 0.1.0 $)
4
+ ($Release: 0.2.0 $)
5
5
 
6
6
  CDNget is a utility script to download files from CDNJS, jsDelivr or Google.
7
7
 
@@ -13,7 +13,7 @@ Install
13
13
 
14
14
  Or:
15
15
 
16
- $ curl -sO https://github.com/kwatch/cdnget/raw/ruby-release/bin/cdnget
16
+ $ curl -sLo cdnget bit.ly/cdnget_rb
17
17
  $ chmod a+x cdnget
18
18
  $ sudo cp cdnget /usr/local/bin
19
19
 
@@ -37,6 +37,12 @@ Usage
37
37
  jquery.js jquery.min.js jquery.min.map
38
38
 
39
39
 
40
+ Todo
41
+ ----
42
+
43
+ * [_] change to call api.cdnjs.com
44
+
45
+
40
46
  Copyright and License
41
47
  ---------------------
42
48
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ###
4
4
 
5
- RELEASE = '$Release: 0.1.0 $'.split()[1]
5
+ RELEASE = '$Release: 0.2.0 $'.split()[1]
6
6
  COPYRIGHT = 'copyright(c) 2016 kuwata-lab.com all rights reserved'
7
7
  LICENSE = 'MIT License'
8
8
 
@@ -40,7 +40,7 @@ end
40
40
  desc "run test scripts"
41
41
  task :test do
42
42
  #sh "ruby -r minitest/autorun test/*_test.rb"
43
- run "ruby test/#{PROJECT}_test.rb"
43
+ run "ruby -I ./lib test/#{PROJECT}_test.rb"
44
44
  end
45
45
 
46
46
 
@@ -137,7 +137,7 @@ task :publish do
137
137
  if $stdin.gets() =~ /[yY]/
138
138
  run "gem push #{gem}"
139
139
  run "git push -u origin `git rev-parse --abbrev-ref HEAD`"
140
- run "git push -f origin ruby-release"
140
+ run "git push -f origin HEAD:ruby-release"
141
141
  run "git tag ruby-#{ver}"
142
142
  run "git push --tags"
143
143
  end
data/bin/cdnget CHANGED
@@ -24,7 +24,7 @@ require 'fileutils'
24
24
  module CDNGet
25
25
 
26
26
 
27
- RELEASE = '$Release: 0.1.0 $'.split()[1]
27
+ RELEASE = '$Release: 0.2.0 $'.split()[1]
28
28
 
29
29
  CLASSES = []
30
30
 
@@ -143,12 +143,14 @@ module CDNGet
143
143
  def find(library)
144
144
  validate(library, nil)
145
145
  html = fetch("https://cdnjs.com/libraries/#{library}", library)
146
+ flagment = html.split(/<select class=".*?version-selector.*?"/, 2).last
147
+ flagment = flagment.split(/<\/select>/, 2).first
146
148
  versions = []
147
- html.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
149
+ flagment.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
148
150
  versions << ver
149
151
  end
150
152
  desc = tags = nil
151
- if html =~ /<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
153
+ if html =~ /<\/p>\s*<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
152
154
  desc = $1
153
155
  tags = $2
154
156
  end
@@ -163,14 +165,13 @@ module CDNGet
163
165
  def get(library, version)
164
166
  validate(library, version)
165
167
  html = fetch("https://cdnjs.com/libraries/#{library}/#{version}", library)
166
- baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}"
167
- urls = []
168
+ baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}/"
169
+ basepat = Regexp.escape("#{library}/#{version}")
168
170
  files = []
169
- rexp = %r`>(#{Regexp.escape(baseurl)}/([^<]+))<\/p>`
170
- html.scan(%r`>(#{Regexp.escape(baseurl)}/([^<]+))<\/p>`) do |url, file|
171
- urls << url .gsub(/&#x2F;/, '/')
171
+ html.scan(%r`>#{basepat}/([^<]+)<\/p>`) do |file,|
172
172
  files << file.gsub(/&#x2F;/, '/')
173
173
  end
174
+ urls = files.collect {|s| baseurl + s }
174
175
  return {
175
176
  name: library,
176
177
  version: version,
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |o|
4
4
  o.name = "cdnget"
5
- o.version = '$Release: 0.1.0 $'.split()[1]
5
+ o.version = '$Release: 0.2.0 $'.split()[1]
6
6
  o.authors = ["makoto kuwata"]
7
7
  o.email = ["kwa@kuwata-lab.com"]
8
8
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |o|
12
12
  o.license = "MIT"
13
13
 
14
14
  o.files = Dir[*%w[
15
- README.md MIT-LICENSE Rakefile cdnget.gemspec
15
+ README.md CHANGES.md MIT-LICENSE Rakefile cdnget.gemspec
16
16
  lib/**/*.rb
17
17
  bin/cdnget
18
18
  test/**/*_test.rb
@@ -24,7 +24,7 @@ require 'fileutils'
24
24
  module CDNGet
25
25
 
26
26
 
27
- RELEASE = '$Release: 0.1.0 $'.split()[1]
27
+ RELEASE = '$Release: 0.2.0 $'.split()[1]
28
28
 
29
29
  CLASSES = []
30
30
 
@@ -143,12 +143,14 @@ module CDNGet
143
143
  def find(library)
144
144
  validate(library, nil)
145
145
  html = fetch("https://cdnjs.com/libraries/#{library}", library)
146
+ flagment = html.split(/<select class=".*?version-selector.*?"/, 2).last
147
+ flagment = flagment.split(/<\/select>/, 2).first
146
148
  versions = []
147
- html.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
149
+ flagment.scan(/<option value="([^"]+)" *(?:selected)?>/) do |ver,|
148
150
  versions << ver
149
151
  end
150
152
  desc = tags = nil
151
- if html =~ /<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
153
+ if html =~ /<\/p>\s*<p>(.*?)<\/p>\s*<em>(.*?)<\/em>/
152
154
  desc = $1
153
155
  tags = $2
154
156
  end
@@ -163,14 +165,13 @@ module CDNGet
163
165
  def get(library, version)
164
166
  validate(library, version)
165
167
  html = fetch("https://cdnjs.com/libraries/#{library}/#{version}", library)
166
- baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}"
167
- urls = []
168
+ baseurl = "https://cdnjs.cloudflare.com/ajax/libs/#{library}/#{version}/"
169
+ basepat = Regexp.escape("#{library}/#{version}")
168
170
  files = []
169
- rexp = %r`>(#{Regexp.escape(baseurl)}/([^<]+))<\/p>`
170
- html.scan(%r`>(#{Regexp.escape(baseurl)}/([^<]+))<\/p>`) do |url, file|
171
- urls << url .gsub(/&#x2F;/, '/')
171
+ html.scan(%r`>#{basepat}/([^<]+)<\/p>`) do |file,|
172
172
  files << file.gsub(/&#x2F;/, '/')
173
173
  end
174
+ urls = files.collect {|s| baseurl + s }
174
175
  return {
175
176
  name: library,
176
177
  version: version,
@@ -311,14 +311,19 @@ END
311
311
 
312
312
  it "(cdnjs) lists files containing subdirectory." do
313
313
  expected = <<END
314
- name: jqueryui
315
- version: 1.9.2
314
+ name: jquery-jcrop
315
+ version: 0.9.12
316
316
  urls:
317
- - https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.2/i18n/jquery-ui-i18n.js
318
- - https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.2/i18n/jquery-ui-i18n.min.js
319
- - https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js
317
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/Jcrop.gif
318
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.css
319
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css
320
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.js
321
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js
322
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.color.js
323
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.color.min.js
324
+ - https://cdnjs.cloudflare.com/ajax/libs/jquery-jcrop/0.9.12/js/jquery.min.js
320
325
  END
321
- actual = CDNGet::Main.new().run("cdnjs", "jqueryui", "1.9.2")
326
+ actual = CDNGet::Main.new().run("cdnjs", "jquery-jcrop", "0.9.12")
322
327
  ok {actual} == expected
323
328
  end
324
329
 
@@ -373,42 +378,74 @@ END
373
378
  tmpdir = "tmpdir1"
374
379
  Dir.mkdir(tmpdir)
375
380
  expected = <<END
376
- #{tmpdir}/jqueryui/1.9.2/i18n/jquery-ui-i18n.js ... Done (70,146 byte)
377
- #{tmpdir}/jqueryui/1.9.2/i18n/jquery-ui-i18n.min.js ... Done (54,926 byte)
378
- #{tmpdir}/jqueryui/1.9.2/jquery-ui.min.js ... Done (237,802 byte)
381
+ #{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif ... Done (329 byte)
382
+ #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css ... Done (3,280 byte)
383
+ #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css ... Done (2,102 byte)
384
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
385
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
386
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js ... Done (16,142 byte)
387
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js ... Done (6,845 byte)
388
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js ... Done (93,068 byte)
379
389
  END
380
390
  begin
381
391
  sout, serr = capture_io() do
382
- actual = CDNGet::Main.new().run("cdnjs", "jqueryui", "1.9.2", tmpdir)
392
+ actual = CDNGet::Main.new().run("cdnjs", "jquery-jcrop", "0.9.12", tmpdir)
383
393
  end
384
- ok {"#{tmpdir}/jqueryui/1.9.2/i18n/jquery-ui-i18n.js" }.file_exist?
385
- ok {"#{tmpdir}/jqueryui/1.9.2/i18n/jquery-ui-i18n.min.js"}.file_exist?
386
- ok {"#{tmpdir}/jqueryui/1.9.2/jquery-ui.min.js" }.file_exist?
394
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif" }.file_exist?
395
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css" }.file_exist?
396
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css" }.file_exist?
397
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js" }.file_exist?
398
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js" }.file_exist?
399
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js" }.file_exist?
400
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js" }.file_exist?
401
+ ok {"#{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js" }.file_exist?
387
402
  ok {sout} == expected
388
403
  ensure
389
404
  FileUtils.rm_r(tmpdir)
390
405
  end
391
406
  end
392
407
 
393
- def _do_download_test3(cdn_code)
408
+ def _do_download_test3(cdn_code, libname)
394
409
  tmpdir = "tmpdir1"
395
410
  Dir.mkdir(tmpdir)
396
- expected = <<END
397
- #{tmpdir}/jqueryui/1.9.2/i18n/jquery-ui-i18n.js ... Done (70,146 byte)
398
- #{tmpdir}/jqueryui/1.9.2/i18n/jquery-ui-i18n.min.js ... Done (54,926 byte)
399
- #{tmpdir}/jqueryui/1.9.2/jquery-ui.min.js ... Done (237,802 byte)
411
+ case libname
412
+ when "jquery"
413
+ version = "2.2.4"
414
+ if cdn_code == "google"
415
+ expected = <<END
416
+ #{tmpdir}/jquery/2.2.4/jquery.min.js ... Done (85,578 byte)
417
+ END
418
+ else
419
+ expected = <<END
420
+ #{tmpdir}/jquery/2.2.4/jquery.js ... Done (257,551 byte)
421
+ #{tmpdir}/jquery/2.2.4/jquery.min.js ... Done (85,578 byte)
422
+ #{tmpdir}/jquery/2.2.4/jquery.min.map ... Done (129,572 byte)
423
+ END
424
+ end
425
+ when "jquery-jcrop"
426
+ version = "0.9.12"
427
+ expected = <<END
428
+ #{tmpdir}/jquery-jcrop/0.9.12/css/Jcrop.gif ... Done (329 byte)
429
+ #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.css ... Done (3,280 byte)
430
+ #{tmpdir}/jquery-jcrop/0.9.12/css/jquery.Jcrop.min.css ... Done (2,102 byte)
431
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.js ... Done (42,434 byte)
432
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.Jcrop.min.js ... Done (15,892 byte)
433
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.js ... Done (16,142 byte)
434
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.color.min.js ... Done (6,845 byte)
435
+ #{tmpdir}/jquery-jcrop/0.9.12/js/jquery.min.js ... Done (93,068 byte)
400
436
  END
437
+ end
401
438
  begin
402
- path = "#{tmpdir}/jqueryui/1.9.2"
439
+ path = "#{tmpdir}/#{libname}/#{version}"
403
440
  # 1st
404
441
  sout, serr = capture_io() do
405
- actual = CDNGet::Main.new().run("cdnjs", "jqueryui", "1.9.2", tmpdir)
442
+ actual = CDNGet::Main.new().run(cdn_code, libname, version, tmpdir)
406
443
  end
407
444
  ok {serr} == ""
408
445
  ok {sout} == expected
409
446
  # 2nd
410
447
  sout, serr = capture_io() do
411
- actual = CDNGet::Main.new().run("cdnjs", "jqueryui", "1.9.2", tmpdir)
448
+ actual = CDNGet::Main.new().run(cdn_code, libname, version, tmpdir)
412
449
  end
413
450
  ok {serr} == ""
414
451
  ok {sout} == expected.gsub(/\n/, " (Unchanged)\n")
@@ -417,7 +454,6 @@ END
417
454
  end
418
455
  end
419
456
 
420
-
421
457
  it "(cdnjs) downloads files into dir." do
422
458
  _do_download_test1("cdnjs")
423
459
  end
@@ -443,15 +479,15 @@ END
443
479
  end
444
480
 
445
481
  it "(cdnjs) doesn't override existing files when they are identical to downloaded files." do
446
- _do_download_test3("cdnjs")
482
+ _do_download_test3("cdnjs", "jquery-jcrop")
447
483
  end
448
484
 
449
485
  it "(google) doesn't override existing files when they are identical to downloaded files." do
450
- _do_download_test3("google")
486
+ _do_download_test3("google", "jquery")
451
487
  end
452
488
 
453
489
  it "(jsdelivr) doesn't override existing files when they are identical to downloaded files." do
454
- _do_download_test3("jsdelivr")
490
+ _do_download_test3("jsdelivr", "jquery")
455
491
  end
456
492
 
457
493
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdnget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - makoto kuwata
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-23 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -46,6 +46,7 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - CHANGES.md
49
50
  - MIT-LICENSE
50
51
  - README.md
51
52
  - Rakefile