spader 0.0.1.pre.pre → 0.0.3.pre.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,14 @@
1
- #require "spader/commands/build"
2
- #require "spader/commands/download"
3
-
4
- module Spader
5
- class Command
6
- class InvalidParametersError < StandardError; end;
7
-
8
- def execute()
9
- puts "RUNNING #{self.class}"
10
- end
11
- end
12
-
13
- require "spader/commands/generate"
14
- require "spader/commands/build"
1
+ # encoding: UTF-8
2
+
3
+ module Spader
4
+ class Command
5
+ class InvalidParametersError < StandardError; end;
6
+
7
+ def execute()
8
+ puts "RUNNING #{self.class}"
9
+ end
10
+ end
11
+
12
+ require "spader/commands/generate"
13
+ require "spader/commands/build"
15
14
  end
@@ -1,121 +1,157 @@
1
- module Spader
2
- class BuildCommand < Command
3
- attr_accessor :zip, :path, :browsers, :browser, :environment, :version, :build_info
4
-
5
- def initialize()
6
- @path = nil
7
- @zip = false
8
- @environment = "development"
9
- @version = "0.0.0"
10
- @browsers = BROWSERS
11
- @browser = nil
12
- @build_info = nil
13
- end
14
-
15
- def execute()
16
- super
17
- puts "Building #{@path} @ v#{@version}/#{@environment} for #{@browsers.length} browser(s)."
18
-
19
- if @path.nil?() || @path.empty?()
20
- puts "Path is required."
21
- raise InvalidParametersError
22
- end
23
-
24
- scss_dir = @path + "scss/"
25
- font_dir = @path + "font/"
26
- html_dir = @path + "html/"
27
- icon_dir = @path + "icon/"
28
- java_dir = @path + "js/"
29
- mani_dir = @path + "manifest/"
30
- msgs_dir = @path + "_locales/"
31
-
32
- SassC.load_paths << scss_dir
33
-
34
- dirs_in_dir(scss_dir).each do |dir|
35
- SassC.load_paths << dir
36
- end
37
-
38
- @build_info = DateTime.now().strftime("%Y-%m-%d @ %H:%M:%S")
39
-
40
- @browsers.each do |browser|
41
- @browser = browser
42
- dest_dir = @path + "dist/#{@environment}/#{browser}/"
43
-
44
- if environment == "production"
45
- dest_dir << "#{@version}/"
46
- end
47
-
48
- puts "Output dir: #{dest_dir}"
49
-
50
- if Dir.exists?(dest_dir)
51
- FileUtils.remove_dir(dest_dir)
52
- end
53
-
54
- FileUtils.mkdir_p(dest_dir)
55
-
56
- # manifest
57
- in_manifest = mani_dir + "#{browser}.json"
58
- out_manifest = dest_dir + "manifest.json"
59
- FileUtils.cp(in_manifest, out_manifest)
60
-
61
- # messages
62
- FileUtils.cp_r(msgs_dir, dest_dir + "_locales")
63
-
64
- scss_files = primary_files_in_dir(scss_dir)
65
-
66
- scss_files.each do |scss_file|
67
- puts scss_file
68
- in_filename = File.basename(scss_file)
69
- out_file = dest_dir + in_filename.gsub(".erb", "").gsub(".css", "").gsub(".scss", "")
70
- out_file << ".css"
71
- scss_data = nil
72
-
73
- if in_filename.include?(".erb")
74
- scss_data = render(scss_file)
75
- else
76
- scss_data = read_file(scss_file)
77
- end
78
-
79
- scss_data = SassC::Engine.new(scss_data, :style => :expanded).render()
80
- write_file(out_file, scss_data)
81
- end
82
-
83
- js_files = primary_files_in_dir(java_dir)
84
-
85
- js_files.each do |js_file|
86
- puts js_file
87
- in_filename = File.basename(js_file)
88
- out_file = dest_dir + in_filename.gsub(".erb", "").gsub(".js", "")
89
- out_file << ".js"
90
- js_data = nil
91
-
92
- if in_filename.include?(".erb")
93
- js_data = render(js_file)
94
- else
95
- js_data = read_file(js_file)
96
- end
97
-
98
- write_file(out_file, js_data)
99
- end
100
-
101
- html_files = primary_files_in_dir(html_dir)
102
-
103
- html_files.each do |html_file|
104
- puts html_file
105
- in_filename = File.basename(html_file)
106
- out_file = dest_dir + in_filename.gsub(".erb", "").gsub(".html", "")
107
- out_file << ".html"
108
- html_data = nil
109
-
110
- if in_filename.include?(".erb")
111
- html_data = render(html_file)
112
- else
113
- html_data = read_file(html_data)
114
- end
115
-
116
- write_file(out_file, html_data)
117
- end
118
- end
119
- end
120
- end
1
+ # encoding: UTF-8
2
+
3
+ module Spader
4
+ class BuildCommand < Command
5
+ attr_accessor :zip, :path, :browsers, :browser, :environment, :version, :build_info
6
+
7
+ def initialize()
8
+ @path = nil
9
+ @zip = false
10
+ @environment = "development"
11
+ @version = "0.0.0"
12
+ @browsers = BROWSERS
13
+ @browser = nil
14
+ @build_info = nil
15
+ end
16
+
17
+ def execute()
18
+ super
19
+ puts "Building #{@path} @ v#{@version}/#{@environment} for #{@browsers.length} browser(s)."
20
+
21
+ if @path.nil?() || @path.empty?()
22
+ puts "Path is required."
23
+ raise InvalidParametersError
24
+ end
25
+
26
+ project = Project.new().load_json(@path + "spader.json")
27
+ dist_dir = @path + "dist/"
28
+ scss_dir = @path + "scss/"
29
+ font_dir = @path + "font/"
30
+ html_dir = @path + "html/"
31
+ icon_dir = @path + "icon/"
32
+ java_dir = @path + "js/"
33
+ mani_dir = @path + "manifest/"
34
+ msgs_dir = @path + "_locales/"
35
+
36
+ SassC.load_paths << scss_dir
37
+
38
+ dirs_in_dir(scss_dir).each do |dir|
39
+ SassC.load_paths << dir
40
+ end
41
+
42
+ @build_info = DateTime.now().strftime("%Y-%m-%d @ %H:%M:%S")
43
+
44
+ @browsers.each do |browser|
45
+ @browser = browser
46
+ dest_dir = dist_dir + "#{@environment}/#{browser}/"
47
+
48
+ if environment == "production"
49
+ dest_dir << "#{@version}/"
50
+ end
51
+
52
+ puts "Output dir: #{dest_dir}"
53
+
54
+ if Dir.exists?(dest_dir)
55
+ FileUtils.remove_dir(dest_dir)
56
+ end
57
+
58
+ FileUtils.mkdir_p(dest_dir)
59
+
60
+ # manifest -- should use our Manifest class
61
+ in_manifest = mani_dir + "manifest.json.erb"
62
+ out_manifest = dest_dir + "manifest.json"
63
+ manifest_data = render(in_manifest)
64
+ manifest_data = JSON.parse(manifest_data)
65
+ manifest_data["version"] = @version
66
+
67
+ if !project.permissions.empty?()
68
+ manifest_data["permissions"] += project.permissions
69
+
70
+ if project.permissions.include?("activeTab") && !is_browser_chromal?()
71
+ manifest_data["permissions"] << "tabs"
72
+ end
73
+ end
74
+
75
+ manifest_data["permissions"].uniq!()
76
+ write_file(out_manifest, JSON.pretty_generate(manifest_data))
77
+
78
+ # messages
79
+ FileUtils.cp_r(msgs_dir, dest_dir + "_locales")
80
+
81
+ scss_files = primary_files_in_dir(scss_dir) + project.scss
82
+
83
+ scss_files.each do |scss_file|
84
+ in_filename = File.basename(scss_file)
85
+ out_file = dest_dir + in_filename.gsub(".erb", "").gsub(".css", "").gsub(".scss", "")
86
+ out_file << ".css"
87
+ scss_data = nil
88
+
89
+ if in_filename.include?(".erb")
90
+ scss_data = render(scss_file)
91
+ else
92
+ scss_data = read_file(scss_file)
93
+ end
94
+
95
+ scss_data = SassC::Engine.new(scss_data, :style => :expanded).render()
96
+ write_file(out_file, scss_data)
97
+ end
98
+
99
+ js_files = primary_files_in_dir(java_dir) + project.js
100
+
101
+ js_files.each do |js_file|
102
+ in_filename = File.basename(js_file)
103
+ out_file = dest_dir + in_filename.gsub(".erb", "").gsub(".js", "")
104
+ out_file << ".js"
105
+ js_data = nil
106
+
107
+ if in_filename.include?(".erb")
108
+ js_data = render(js_file)
109
+ else
110
+ js_data = read_file(js_file)
111
+ end
112
+
113
+ write_file(out_file, js_data)
114
+ end
115
+
116
+ html_files = primary_files_in_dir(html_dir) + project.html
117
+
118
+ html_files.each do |html_file|
119
+ in_filename = File.basename(html_file)
120
+ out_file = dest_dir + in_filename.gsub(".erb", "").gsub(".html", "")
121
+ out_file << ".html"
122
+ html_data = nil
123
+
124
+ if in_filename.include?(".erb")
125
+ html_data = render(html_file)
126
+ else
127
+ html_data = read_file(html_data)
128
+ end
129
+
130
+ write_file(out_file, html_data)
131
+ end
132
+
133
+ static_files = project.static
134
+
135
+ static_files.each do |static_file|
136
+ in_filename = File.basename(static_file)
137
+ out_file = dest_dir + in_filename
138
+ FileUtils.cp(static_file, out_file)
139
+ end
140
+
141
+ if @zip
142
+ zip_file = dist_dir + "3camelizer-#{browser}-#{@environment}-#{@version}.zip"
143
+
144
+ # this should probably prompt the user for confirmation
145
+ # or do something more helpful
146
+ if File.exists?(zip_file)
147
+ puts "Deleting existing: #{zip_file}"
148
+ FileUtils.remove(zip_file)
149
+ end
150
+
151
+ puts "Writing: #{zip_file}"
152
+ ZipFileGenerator.new(dest_dir, zip_file).write()
153
+ end
154
+ end
155
+ end
156
+ end
121
157
  end
@@ -1,63 +1,67 @@
1
- require "spader/command"
2
-
3
- module Spader
4
- class GenerateCommand < Command
5
- attr_accessor :path, :title
6
-
7
- def execute()
8
- super
9
- puts "Generating \"#{@title}\" into #{@path}"
10
-
11
- if @path.nil?() || @path.empty?() || @title.nil?() || @title.empty?()
12
- puts "Path and Title are required."
13
- raise InvalidParametersError
14
- end
15
-
16
- project = Project.generate(@path, :title => @title)
17
-
18
- if Dir.exists?(project.path)
19
- puts "Removing existing dir..."
20
- FileUtils.remove_dir(project.path)
21
- end
22
-
23
- FileUtils.mkdir_p(project.path)
24
-
25
- project.save_json(project.path + "spader.json")
26
-
27
- new_dirs = [
28
- "_locales/en",
29
- "dist/development",
30
- "dist/production",
31
- "font",
32
- "html",
33
- "icon",
34
- "js",
35
- "manifest",
36
- "promo",
37
- "scss",
38
- "txt",
39
- ]
40
-
41
- new_dirs.each do |new_dir|
42
- FileUtils.mkdir_p(project.path + new_dir)
43
- end
44
-
45
- FileUtils.touch(project.path + "txt/README.md")
46
-
47
- messages = Messages.generate(project.title)
48
- messages.save_json(project.path + "_locales/en/messages.json")
49
-
50
- manifest = Manifest.generate()
51
-
52
- BROWSERS.each do |browser|
53
- if browser == "chrome"
54
- manifest.document["update_url"] = "http://clients2.google.com/service/update2/crx"
55
- else
56
- manifest.document.delete("update_url")
57
- end
58
-
59
- manifest.save_json(project.path + "manifest/#{browser}.json")
60
- end
61
- end
62
- end
1
+ # encoding: UTF-8
2
+
3
+ require "spader/command"
4
+
5
+ module Spader
6
+ class GenerateCommand < Command
7
+ attr_accessor :path, :title
8
+
9
+ def execute()
10
+ super
11
+ puts "Generating \"#{@title}\" into #{@path}"
12
+
13
+ if @path.nil?() || @path.empty?() || @title.nil?() || @title.empty?()
14
+ puts "Path and Title are required."
15
+ raise InvalidParametersError
16
+ end
17
+
18
+ project = Project.generate(@path, :title => @title)
19
+
20
+ if Dir.exists?(project.path)
21
+ puts "Removing existing dir..."
22
+ FileUtils.remove_dir(project.path)
23
+ end
24
+
25
+ FileUtils.mkdir_p(project.path)
26
+
27
+ project.save_json(project.path + "spader.json")
28
+
29
+ new_dirs = [
30
+ "_locales/en",
31
+ "font",
32
+ "html",
33
+ "icon",
34
+ "js",
35
+ "manifest",
36
+ "promo",
37
+ "scss",
38
+ "txt",
39
+ ]
40
+
41
+ Spader::ENVIRONMENTS.each do |env|
42
+ new_dirs << "dist/#{env}"
43
+ end
44
+
45
+ new_dirs.each do |new_dir|
46
+ FileUtils.mkdir_p(project.path + new_dir)
47
+ end
48
+
49
+ FileUtils.touch(project.path + "txt/README.md")
50
+
51
+ messages = Messages.generate(project.title)
52
+ messages.save_json(project.path + "_locales/en/messages.json")
53
+
54
+ manifest = Manifest.generate()
55
+
56
+ #BROWSERS.each do |browser|
57
+ #if browser == "chrome"
58
+ # manifest.document["update_url"] = "http://clients2.google.com/service/update2/crx"
59
+ #else
60
+ # manifest.document.delete("update_url")
61
+ #end
62
+
63
+ manifest.save_json(project.path + "manifest/manifest.json.erb")
64
+ # end
65
+ end
66
+ end
63
67
  end
@@ -1,23 +1,25 @@
1
- module Spader
2
- require "spader/util"
3
-
4
- class Document
5
- attr_accessor :document
6
-
7
- def initialize()
8
- @document = {}
9
- end
10
-
11
- def load_json(path)
12
- @document = JSON.parse(read_file(path))
13
- end
14
-
15
- def save_json(path)
16
- write_file(path, JSON.pretty_generate(@document))
17
- end
18
- end
19
-
20
- require "spader/documents/project"
21
- require "spader/documents/manifest"
22
- require "spader/documents/messages"
1
+ # encoding: UTF-8
2
+
3
+ module Spader
4
+ require "spader/util"
5
+
6
+ class Document
7
+ attr_accessor :document
8
+
9
+ def initialize()
10
+ @document = {}
11
+ end
12
+
13
+ def load_json(path)
14
+ @document = JSON.parse(read_file(path))
15
+ end
16
+
17
+ def save_json(path)
18
+ write_file(path, JSON.pretty_generate(@document))
19
+ end
20
+ end
21
+
22
+ require "spader/documents/project"
23
+ require "spader/documents/manifest"
24
+ require "spader/documents/messages"
23
25
  end