capucine 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -7
- data/README.md +318 -23
- data/Rakefile +5 -9
- data/VERSION +1 -1
- data/bin/capucine +6 -2
- data/capucine-logo-mini.png +0 -0
- data/capucine.gemspec +32 -16
- data/content/{templates/capucine.yaml → default.yaml} +5 -5
- data/content/options.yaml +11 -0
- data/content/shared/capucine.yaml +2 -2
- data/content/shared/index.html +2 -2
- data/content/shared/public/js/app.js +1 -1
- data/content/shared/sass/_main.scss +1 -1
- data/content/shared/sass/screen.scss +4 -2
- data/content/templates/cmd_help.erb +8 -17
- data/lib/capucine.rb +68 -9
- data/lib/cdnjs.rb +71 -0
- data/lib/coffeescript.rb +36 -30
- data/lib/compass-sass.rb +51 -53
- data/lib/incloudr.rb +44 -43
- data/lib/npm.rb +21 -0
- data/lib/settings.rb +42 -55
- data/lib/tools.rb +167 -31
- data/lor +32 -0
- data/spec/capucine/capucine_spec.rb +179 -0
- data/spec/capucine/coffee_spec.rb +9 -0
- data/spec/capucine/incloudr_spec.rb +80 -0
- data/spec/capucine_coffee.yaml +30 -0
- data/spec/capucine_incloudr.yaml +6 -0
- data/spec/capucine_incloudr2.yaml +8 -0
- data/spec/capucine_incloudr3.yaml +6 -0
- data/spec/spec.rake +13 -0
- data/spec/spec_helper.rb +1 -0
- data/templates/README.md +10 -0
- data/templates/sinatra.yaml +30 -0
- metadata +54 -25
- data/Gemfile.lock +0 -49
- data/lib/commands.rb +0 -43
- data/lib/watch.rb +0 -39
@@ -1,44 +1,35 @@
|
|
1
|
-
Capucine - <%= config %>
|
1
|
+
Capucine - <%= config %>
|
2
2
|
Usage:
|
3
3
|
|
4
4
|
Configure your preferences in capucine.yaml
|
5
5
|
|
6
|
-
$ capucine [
|
7
|
-
|
8
|
-
Options:
|
6
|
+
$ capucine [command]
|
9
7
|
|
10
|
-
|
11
|
-
If not name specified, this will create the folder : capucine/
|
8
|
+
Commands:
|
12
9
|
|
10
|
+
new [name] - Create a new project
|
11
|
+
If not name specified, this will create the folder : capucine/
|
13
12
|
init - Initialize a project in current folder (simply add a capucine.yaml file)
|
14
|
-
|
15
13
|
compile [path/to/config] - Compile .sass, .coffee, .erb files (just once)
|
16
|
-
|
17
14
|
watch [path/to/config] - Compile .sass, .coffee, .erb files (run the watcher).
|
18
|
-
|
19
15
|
help - Print this message
|
20
16
|
|
21
17
|
Shortcuts:
|
22
18
|
|
23
19
|
n = new
|
24
|
-
|
25
20
|
i = init
|
26
|
-
|
27
21
|
c = compile
|
28
|
-
|
29
22
|
w = watch
|
30
|
-
|
31
23
|
h = help
|
32
24
|
|
33
25
|
Informations:
|
34
|
-
|
26
|
+
|
35
27
|
Github - https://github.com/damln/Capucine
|
36
28
|
Documentation - http://capucine.dln.name
|
37
|
-
|
38
|
-
|
29
|
+
|
39
30
|
Author:
|
40
31
|
|
41
32
|
Name - Damian Le Nouaillle
|
42
33
|
Site - http://dln.name
|
43
34
|
Twitter - @damln ( http://twitter.com/damln )
|
44
|
-
|
35
|
+
|
data/lib/capucine.rb
CHANGED
@@ -1,14 +1,73 @@
|
|
1
|
-
require
|
1
|
+
%w{settings coffeescript compass-sass incloudr tools}.each {|lib| require "#{lib}.rb"}
|
2
2
|
|
3
3
|
module Capucine
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
class Main
|
5
|
+
|
6
|
+
attr_accessor :settings
|
7
|
+
attr_accessor :coffee
|
8
|
+
attr_accessor :sass
|
9
|
+
attr_accessor :incloudr
|
10
|
+
attr_accessor :tools
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self.settings = Capucine::Settings.new
|
14
|
+
self.tools = Capucine::Tools.new(self)
|
15
|
+
self.sass = Capucine::CompassSass.new(self)
|
16
|
+
self.coffee = Capucine::CoffeeScript.new(self)
|
17
|
+
self.incloudr = Capucine::Incloudr.new(self)
|
18
|
+
return self
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_command(command)
|
22
|
+
# command = ['c', '/path/to/file.yaml']
|
23
|
+
# command = ['c:sass', '/path/to/file.yaml']
|
24
|
+
# ...
|
25
|
+
|
26
|
+
run = command[0].to_s.split(':') # Rake like capucine compile:sass
|
27
|
+
config_or_name = command[1] # second part (the capucine.yaml file or template name/url)
|
28
|
+
|
29
|
+
main = run[0] # c, w, compile, watch, new, init
|
30
|
+
run.shift # all, coffee, sass or incloudr | sinatra, wordpress, etc ...
|
31
|
+
scope = run # all, coffee, sass or incloudr | sinatra, wordpress, etc ...
|
32
|
+
|
33
|
+
if %w{i init}.include?(main)
|
34
|
+
self.tools.init(scope[0], config_or_name)
|
35
|
+
|
36
|
+
elsif %w{n new}.include?(main)
|
37
|
+
self.tools.new_project(scope[0], config_or_name)
|
38
|
+
self.tools.compile
|
39
|
+
|
40
|
+
elsif %w{c compile}.include?(main)
|
41
|
+
self.settings.set_user_config_file(config_or_name)
|
42
|
+
self.tools.compile(scope[0])
|
43
|
+
|
44
|
+
elsif %w{j js}.include?(main)
|
45
|
+
self.settings.set_user_config_file(config_or_name)
|
46
|
+
self.tools.js(scope, config_or_name)
|
47
|
+
|
48
|
+
elsif %w{w watch}.include?(main)
|
49
|
+
self.settings.set_user_config_file(config_or_name)
|
50
|
+
self.tools.watch(scope[0])
|
51
|
+
|
52
|
+
elsif %w{cl clean}.include?(main)
|
53
|
+
self.settings.set_user_config_file(config_or_name)
|
54
|
+
self.tools.clean
|
55
|
+
|
56
|
+
elsif %w{u update}.include?(main)
|
57
|
+
self.settings.set_user_config_file(config_or_name)
|
58
|
+
self.tools.update
|
59
|
+
|
60
|
+
else
|
61
|
+
self.help
|
62
|
+
end
|
63
|
+
|
64
|
+
return self
|
65
|
+
end
|
66
|
+
|
67
|
+
def help
|
68
|
+
puts 'HELP'
|
69
|
+
end
|
70
|
+
|
11
71
|
end
|
12
72
|
|
13
|
-
module_function :new, :settings
|
14
73
|
end
|
data/lib/cdnjs.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Capucine
|
5
|
+
class CDNJS
|
6
|
+
attr_accessor :result
|
7
|
+
|
8
|
+
@@cdnjsroot_github = 'https://raw.github.com/cdnjs/cdnjs/master/ajax/libs/'
|
9
|
+
@@cdnjsroot = 'http://cdnjs.cloudflare.com/ajax/libs/'
|
10
|
+
@@cdnjs = 'http://www.cdnjs.com/packages.json'
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(lib_name, version = nil, content = true)
|
14
|
+
|
15
|
+
return false unless lib_name
|
16
|
+
@result = {}
|
17
|
+
|
18
|
+
cdnjs_url_pkg = "#{@@cdnjsroot_github}#{lib_name}/package.json"
|
19
|
+
raw_content = nil
|
20
|
+
|
21
|
+
begin
|
22
|
+
distant = open(cdnjs_url_pkg).read
|
23
|
+
rescue => e
|
24
|
+
@result[:error] = e; return
|
25
|
+
end
|
26
|
+
content = JSON.parse(distant)
|
27
|
+
|
28
|
+
version = version || content['version']
|
29
|
+
version = version.to_s
|
30
|
+
|
31
|
+
filename = content['filename']
|
32
|
+
|
33
|
+
raw_file_url = "#{@@cdnjsroot}#{lib_name}/#{version}/#{filename}"
|
34
|
+
|
35
|
+
if content
|
36
|
+
begin
|
37
|
+
raw_content = open(raw_file_url).read
|
38
|
+
rescue => e
|
39
|
+
@result[:error] = e; return
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
@result = {
|
44
|
+
:lib => lib_name,
|
45
|
+
:version => version,
|
46
|
+
:file_url => raw_file_url,
|
47
|
+
:content => raw_content,
|
48
|
+
:response => content,
|
49
|
+
}
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.get_all
|
54
|
+
content = JSON.parse open(@@cdnjs).read
|
55
|
+
return content['packages']
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.search(query)
|
59
|
+
results = []
|
60
|
+
|
61
|
+
self.get_all.each do |lib|
|
62
|
+
if lib['name'] =~ /#{query}/
|
63
|
+
results.push(lib)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
return results
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/coffeescript.rb
CHANGED
@@ -1,38 +1,54 @@
|
|
1
1
|
module Capucine
|
2
|
-
class
|
2
|
+
class CoffeeScript
|
3
3
|
require 'packr'
|
4
4
|
require 'coffee-script'
|
5
|
-
require 'fssm'
|
6
5
|
|
7
|
-
def
|
8
|
-
|
6
|
+
def initialize(capucine)
|
7
|
+
@cap = capucine
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_once(file = nil)
|
11
|
+
|
12
|
+
unless file
|
13
|
+
files = Dir.glob(File.join @cap.settings.working_dir, @cap.settings.conf['coffeescript_output_dir'], '*')
|
14
|
+
FileUtils.rm_r files
|
15
|
+
self.compile_dir @cap.settings.conf['coffeescript_files_dir'], @cap.settings.conf['coffeescript_output_dir']
|
16
|
+
else
|
17
|
+
self.compile_dir file, @cap.settings.conf['coffeescript_output_dir']
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "[coffee] - Compiled"
|
21
|
+
end
|
22
|
+
|
23
|
+
def compile_dir(input, output)
|
9
24
|
|
10
25
|
if File.extname(input) == '.coffee'
|
11
26
|
coffee_files = input
|
12
27
|
else
|
13
|
-
coffee_files = File.join settings.working_dir, input, "**/**.coffee"
|
28
|
+
coffee_files = File.join @cap.settings.working_dir, input, "**/**.coffee"
|
14
29
|
end
|
15
30
|
|
16
31
|
Dir.glob(coffee_files).each do |file_coffee_o|
|
17
32
|
|
18
33
|
file_coffee = File.expand_path file_coffee_o
|
19
|
-
base_in_dir = File.join settings.working_dir, input
|
34
|
+
base_in_dir = File.join @cap.settings.working_dir, input
|
35
|
+
|
36
|
+
relative_path = file_coffee.gsub(File.join(@cap.settings.working_dir, @cap.settings.conf['coffeescript_files_dir'] ),'')
|
20
37
|
|
21
|
-
relative_path = file_coffee.gsub(File.join(Capucine.settings.working_dir, Capucine.settings.config['coffeescript_files_dir'] ),'')
|
22
38
|
relative_path = relative_path.gsub(/\.coffee$/, '.js')
|
23
39
|
relative_path_min = relative_path.gsub(/\.js$/, '.min.js')
|
24
40
|
|
25
|
-
file_out = File.join settings.working_dir, output, relative_path
|
26
|
-
file_out_min = File.join settings.working_dir, output, relative_path_min
|
41
|
+
file_out = File.join @cap.settings.working_dir, output, relative_path
|
42
|
+
file_out_min = File.join @cap.settings.working_dir, output, relative_path_min
|
27
43
|
|
28
44
|
relative_coffee_file = file_coffee.gsub(base_in_dir, '')
|
29
45
|
|
30
|
-
opts = {:bare => settings.
|
46
|
+
opts = {:bare => @cap.settings.conf['coffeescript_bare']}
|
31
47
|
coffee_output_min = ""
|
32
48
|
|
33
49
|
error = false
|
34
50
|
begin
|
35
|
-
coffee_output = CoffeeScript.compile(File.read(file_coffee), opts)
|
51
|
+
coffee_output = ::CoffeeScript.compile(File.read(file_coffee), opts)
|
36
52
|
rescue Exception => e
|
37
53
|
error = true
|
38
54
|
message = "#{e.message}"
|
@@ -57,37 +73,26 @@ module Capucine
|
|
57
73
|
|
58
74
|
end
|
59
75
|
|
60
|
-
def self.run_once file = nil
|
61
|
-
settings = Capucine.settings
|
62
76
|
|
63
|
-
|
64
|
-
|
65
|
-
FileUtils.rm_r files
|
66
|
-
self.compile_dir settings.config['coffeescript_files_dir'], settings.config['coffeescript_output_dir']
|
77
|
+
def run_watch
|
78
|
+
require 'fssm'
|
67
79
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
80
|
+
files_to_lookat = File.join @cap.settings.working_dir, @cap.settings.conf['coffeescript_files_dir']
|
81
|
+
js_generated_dir = File.join @cap.settings.working_dir, @cap.settings.conf['coffeescript_output_dir']
|
71
82
|
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.proc_watch
|
76
|
-
settings = Capucine.settings
|
77
|
-
|
78
|
-
files_to_lookat = File.join settings.working_dir, settings.config['coffeescript_files_dir']
|
79
|
-
js_generated_dir = File.join settings.working_dir, settings.config['coffeescript_output_dir']
|
83
|
+
coffee = @cap.coffee
|
80
84
|
|
81
85
|
coffee_thread = Thread.new {
|
86
|
+
|
82
87
|
FSSM.monitor(files_to_lookat, :directories => true) do
|
83
88
|
update do |b, r|
|
84
89
|
file = File.join b, r
|
85
|
-
|
90
|
+
coffee.run_once file if File.extname(r) == '.coffee' # COFFEE
|
86
91
|
end
|
87
92
|
|
88
93
|
create do |b, r|
|
89
94
|
file = File.join b, r
|
90
|
-
|
95
|
+
coffee.run_once file if File.extname(r) == '.coffee' # COFFEE
|
91
96
|
end
|
92
97
|
|
93
98
|
delete do |b, r|
|
@@ -116,6 +121,7 @@ module Capucine
|
|
116
121
|
|
117
122
|
return coffee_thread
|
118
123
|
|
124
|
+
|
119
125
|
end
|
120
126
|
|
121
127
|
end
|
data/lib/compass-sass.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
1
|
module Capucine
|
2
2
|
class CompassSass
|
3
|
+
attr_accessor :tmp_config
|
3
4
|
|
4
|
-
def
|
5
|
+
def initialize(capucine)
|
6
|
+
@cap = capucine
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_once
|
10
|
+
self.update_config
|
11
|
+
self.import_css if @cap.settings.conf['sass_import_css']
|
12
|
+
|
13
|
+
command = "compile --quiet --config \"#{@tmp_config}\" \"#{@cap.settings.working_dir}\""
|
14
|
+
self.exec_compass(command)
|
15
|
+
puts "[compass] - Compiled"
|
16
|
+
end
|
17
|
+
|
18
|
+
def update_plugins gems
|
5
19
|
return if not gems
|
6
20
|
gems.each do |plugin|
|
7
21
|
begin
|
@@ -12,20 +26,25 @@ module Capucine
|
|
12
26
|
end
|
13
27
|
end
|
14
28
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
29
|
+
def update_config
|
30
|
+
require 'tempfile'
|
31
|
+
require 'digest/md5'
|
32
|
+
|
33
|
+
template_file = File.join @cap.settings.content_dir, 'templates', 'compass_config.erb'
|
19
34
|
|
20
|
-
|
35
|
+
md5 = Digest::MD5.hexdigest(@cap.settings.working_dir.to_s)
|
36
|
+
tmp = Tempfile.new('capucine_'+md5)
|
37
|
+
@tmp_config = tmp.path
|
38
|
+
|
39
|
+
@cap.settings.conf['compass_plugins_list'] = []
|
21
40
|
plugins_gems = []
|
22
41
|
|
23
|
-
plugins = settings.
|
42
|
+
plugins = @cap.settings.conf['compass_plugins']
|
24
43
|
|
25
44
|
if plugins.size > 0
|
26
45
|
plugins.each do |p|
|
27
46
|
p = p.split('|')
|
28
|
-
settings.
|
47
|
+
@cap.settings.conf['compass_plugins_list'].push p[0]
|
29
48
|
if p[1]
|
30
49
|
plugins_gems.push p[1]
|
31
50
|
else
|
@@ -35,75 +54,54 @@ module Capucine
|
|
35
54
|
end
|
36
55
|
end
|
37
56
|
|
38
|
-
|
39
|
-
result = Capucine::Tools.render_template template_file, config_
|
57
|
+
result = @cap.tools.render_template template_file, @cap.settings.conf
|
40
58
|
|
41
|
-
f = File.open(
|
59
|
+
f = File.open(@tmp_config, 'w')
|
42
60
|
f.write(result)
|
43
61
|
f.close
|
44
62
|
|
45
63
|
self.update_plugins plugins_gems
|
46
|
-
end
|
47
64
|
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
# rb_files.each do |file|
|
52
|
-
# require "#{file}"
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# end
|
65
|
+
return tmp.path
|
66
|
+
end
|
56
67
|
|
57
|
-
def
|
68
|
+
def import_css
|
58
69
|
|
59
|
-
|
60
|
-
|
61
|
-
output_dir= File.join s.working_dir, s.config['sass_import_output_dir']
|
70
|
+
import_dir = File.join @cap.settings.working_dir, @cap.settings.conf['sass_import_css_dir']
|
71
|
+
output_dir= File.join @cap.settings.working_dir, @cap.settings.conf['sass_import_output_dir']
|
62
72
|
|
63
73
|
Dir.mkdir(import_dir) if not File.directory?(import_dir)
|
64
74
|
Dir.mkdir(output_dir) if not File.directory?(output_dir)
|
65
75
|
|
66
|
-
formats =
|
76
|
+
formats = @cap.settings.conf['sass_import_formats'].split
|
67
77
|
from_format = formats[0]
|
68
78
|
to_format = formats[2]
|
69
79
|
|
70
80
|
command = "sass-convert -R --from #{from_format} --to #{to_format} \"#{import_dir}\" \"#{output_dir}\""
|
71
81
|
system(command)
|
72
|
-
|
82
|
+
@cap.tools.archive_file import_dir
|
73
83
|
|
74
84
|
end
|
75
85
|
|
76
|
-
def
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
86
|
+
def exec_compass compass_args, system = true
|
87
|
+
if not system
|
88
|
+
require 'compass'
|
89
|
+
require 'compass/exec'
|
90
|
+
return Compass::Exec::SubCommandUI.new(compass_args).run!
|
91
|
+
else
|
92
|
+
return system("compass #{compass_args}")
|
93
|
+
end
|
84
94
|
end
|
85
95
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
# path_compass = Gem.loaded_specs['compass'].full_gem_path
|
90
|
-
# ENV['PATH'] = "#{path_compass}:#{Capucine.settings.gem_dir}:#{ENV['PATH']}"
|
91
|
-
# end
|
96
|
+
def run_watch
|
97
|
+
conf = self.update_config
|
98
|
+
self.import_css if @cap.settings.conf['sass_import_css']
|
92
99
|
|
93
|
-
|
94
|
-
|
95
|
-
config_file = File.join Capucine.settings.working_dir, '.compass.rb'
|
96
|
-
compass_args = ['watch', '--config', config_file, Capucine.settings.working_dir]
|
97
|
-
proc_watch = Thread.new {
|
98
|
-
self.exec_compass compass_args
|
99
|
-
}
|
100
|
-
return proc_watch
|
101
|
-
end
|
100
|
+
compass_args = ['watch', '--config', conf, @cap.settings.working_dir]
|
101
|
+
compass_args = compass_args.join(' ')
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
require 'compass/exec'
|
106
|
-
Compass::Exec::SubCommandUI.new(compass_args).run!
|
103
|
+
proc_watch = Thread.new { self.exec_compass compass_args }
|
104
|
+
return proc_watch
|
107
105
|
end
|
108
106
|
|
109
107
|
end
|
data/lib/incloudr.rb
CHANGED
@@ -1,50 +1,64 @@
|
|
1
1
|
module Capucine
|
2
2
|
class Incloudr
|
3
|
+
|
4
|
+
require 'cdnjs.rb'
|
5
|
+
require 'npm.rb'
|
6
|
+
|
3
7
|
require 'open-uri'
|
4
8
|
require 'fileutils'
|
5
|
-
require 'json'
|
6
9
|
require 'packr'
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
+
def initialize(capucine)
|
12
|
+
@cap = capucine
|
13
|
+
end
|
11
14
|
|
12
|
-
def
|
13
|
-
files =
|
15
|
+
def run_once
|
16
|
+
files = @cap.settings.conf['incloudr_libs']
|
14
17
|
return false if files.length == 0
|
15
|
-
|
18
|
+
|
19
|
+
dir = File.join(@cap.settings.working_dir, @cap.settings.conf['incloudr_output_dir'])
|
16
20
|
FileUtils.rm_r dir if File.exist?(dir)
|
17
21
|
FileUtils.mkdir_p dir
|
18
22
|
|
19
23
|
@file = nil
|
24
|
+
|
20
25
|
files.each {|file| self.pack file}
|
21
26
|
puts "[incloudr] - Packaged"
|
22
27
|
end
|
23
28
|
|
24
|
-
def
|
29
|
+
def pack file
|
30
|
+
|
25
31
|
@file = file
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@file['type'] = 'cdnjs'
|
31
|
-
else
|
32
|
-
@file['type'] = 'npm' unless @file['source'] # NPM
|
33
|
-
end
|
33
|
+
@file['version'] = @file['version'].to_s if @file['version']
|
34
|
+
@file['type'] = @file['type'] || 'cdnjs'
|
35
|
+
@file['type'] = 'url' if @file['source']
|
34
36
|
|
35
|
-
@file['
|
37
|
+
name = @file['file_name'] || @file['name']
|
36
38
|
|
37
|
-
@
|
38
|
-
@
|
39
|
+
@dir = @cap.settings.working_dir
|
40
|
+
@conf = @cap.settings.conf
|
41
|
+
|
42
|
+
@output = File.join(@dir, @conf['incloudr_output_dir'], name.gsub(/$/, '.js'))
|
43
|
+
@output_min = File.join(@dir, @conf['incloudr_output_dir'], name.gsub(/$/, '.min.js'))
|
39
44
|
|
40
45
|
self.cdnjs if @file['type'] == 'cdnjs'
|
41
46
|
self.url if @file['type'] == 'url'
|
42
|
-
# self.npm
|
47
|
+
# self.npm if @file['type'] == 'npm'
|
43
48
|
end
|
44
49
|
|
50
|
+
def url raw_content = nil
|
51
|
+
if not raw_content
|
52
|
+
begin
|
53
|
+
content = open(@file['source']).read
|
54
|
+
rescue => e
|
55
|
+
puts "Error"
|
56
|
+
return e
|
57
|
+
end
|
58
|
+
else
|
59
|
+
content = raw_content
|
60
|
+
end
|
45
61
|
|
46
|
-
def self.url raw_content = nil
|
47
|
-
content = raw_content || open(@file['source']).read
|
48
62
|
content_min = ""
|
49
63
|
content_min << Packr.pack(content)
|
50
64
|
|
@@ -57,34 +71,21 @@ module Capucine
|
|
57
71
|
f2.close
|
58
72
|
end
|
59
73
|
|
74
|
+
def cdnjs
|
75
|
+
api = Capucine::CDNJS.new(@file['name'], @file['version'], content = false)
|
60
76
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
raw_file_url = "#{@@cdnjsroot}#{@file['name']}/#{version}/#{filename}"
|
67
|
-
raw_content = open(raw_file_url).read
|
68
|
-
self.url raw_content
|
77
|
+
if not api.result[:error]
|
78
|
+
self.url api.result[:content]
|
79
|
+
else
|
80
|
+
puts "Error on #{@file['name']}"
|
81
|
+
end
|
69
82
|
end
|
70
83
|
|
71
|
-
def
|
72
|
-
#
|
73
|
-
# version = file['version'] || infos['dist-tags']['lastest']
|
74
|
-
# lib = infos['versions'][version]
|
75
|
-
# tarball_url = lib['dist']['tarball']
|
76
|
-
|
77
|
-
# tarball = open(tarball_url).read
|
78
|
-
|
79
|
-
# p version
|
84
|
+
def npm
|
85
|
+
# TODO !
|
80
86
|
|
81
87
|
end
|
82
88
|
|
83
|
-
def self.list
|
84
|
-
content = JSON.parse open(@@cdnjs).read
|
85
|
-
packages = content['packages']
|
86
|
-
packages.each {|p| puts "#{p['name']}\n"}
|
87
|
-
end
|
88
89
|
|
89
90
|
end
|
90
91
|
end
|
data/lib/npm.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'zlib'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'json'
|
5
|
+
require 'packr'
|
6
|
+
|
7
|
+
module Capucine
|
8
|
+
class NPM
|
9
|
+
@@noderoot = 'http://registry.npmjs.org/'
|
10
|
+
|
11
|
+
def initialise(lib_name)
|
12
|
+
infos = JSON.parse open("#{@@noderoot}#{file['name']}").read
|
13
|
+
version = file['version'] || infos['dist-tags']['lastest']
|
14
|
+
lib = infos['versions'][version]
|
15
|
+
tarball_url = lib['dist']['tarball']
|
16
|
+
|
17
|
+
# tarball = open(tarball_url).read
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|