architecture-js 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -0,0 +1,152 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "architecture-js"
8
+ s.version = "0.5.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dayton Nolan"]
12
+ s.date = "2012-05-27"
13
+ s.description = "Architecture.js helps you generate scaffolding, manage third-party packages, compile, and compress your application."
14
+ s.email = "daytonn@gmail.com"
15
+ s.executables = ["architect"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".DS_Store",
22
+ ".document",
23
+ ".rvmrc",
24
+ ".travis.yml",
25
+ "AUTHORS",
26
+ "Gemfile",
27
+ "Gemfile.lock",
28
+ "HELP",
29
+ "LICENSE.txt",
30
+ "README.md",
31
+ "Rakefile",
32
+ "VERSION",
33
+ "architecture-js.gemspec",
34
+ "bin/architect",
35
+ "docs/docco.css",
36
+ "lib/architecture-js.rb",
37
+ "lib/architecture-js/architect.rb",
38
+ "lib/architecture-js/blueprint.rb",
39
+ "lib/architecture-js/dependencies.rb",
40
+ "lib/architecture-js/generator.rb",
41
+ "lib/architecture-js/helpers.rb",
42
+ "lib/architecture-js/notification.rb",
43
+ "lib/architecture-js/watcher.rb",
44
+ "lib/sprockets/CHANGELOG",
45
+ "lib/sprockets/LICENSE",
46
+ "lib/sprockets/README.markdown",
47
+ "lib/sprockets/lib/sprockets.rb",
48
+ "lib/sprockets/lib/sprockets/concatenation.rb",
49
+ "lib/sprockets/lib/sprockets/environment.rb",
50
+ "lib/sprockets/lib/sprockets/error.rb",
51
+ "lib/sprockets/lib/sprockets/pathname.rb",
52
+ "lib/sprockets/lib/sprockets/preprocessor.rb",
53
+ "lib/sprockets/lib/sprockets/secretary.rb",
54
+ "lib/sprockets/lib/sprockets/source_file.rb",
55
+ "lib/sprockets/lib/sprockets/source_line.rb",
56
+ "lib/sprockets/lib/sprockets/version.rb",
57
+ "lib/sprockets/test/fixtures/assets/images/script_with_assets/one.png",
58
+ "lib/sprockets/test/fixtures/assets/images/script_with_assets/two.png",
59
+ "lib/sprockets/test/fixtures/assets/stylesheets/script_with_assets.css",
60
+ "lib/sprockets/test/fixtures/constants.yml",
61
+ "lib/sprockets/test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js",
62
+ "lib/sprockets/test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js",
63
+ "lib/sprockets/test/fixtures/multiline_comments_should_be_removed_by_default.js",
64
+ "lib/sprockets/test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js",
65
+ "lib/sprockets/test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js",
66
+ "lib/sprockets/test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js",
67
+ "lib/sprockets/test/fixtures/requiring_the_current_file_should_do_nothing.js",
68
+ "lib/sprockets/test/fixtures/src/constants.yml",
69
+ "lib/sprockets/test/fixtures/src/foo.js",
70
+ "lib/sprockets/test/fixtures/src/foo/bar.js",
71
+ "lib/sprockets/test/fixtures/src/foo/foo.js",
72
+ "lib/sprockets/test/fixtures/src/script_with_assets.js",
73
+ "lib/sprockets/test/fixtures/src/script_with_comments.js",
74
+ "lib/sprockets/test/test_concatenation.rb",
75
+ "lib/sprockets/test/test_environment.rb",
76
+ "lib/sprockets/test/test_helper.rb",
77
+ "lib/sprockets/test/test_pathname.rb",
78
+ "lib/sprockets/test/test_preprocessor.rb",
79
+ "lib/sprockets/test/test_secretary.rb",
80
+ "lib/sprockets/test/test_source_file.rb",
81
+ "lib/sprockets/test/test_source_line.rb",
82
+ "repository/modjs/plugins/jquery-elements.js",
83
+ "spec/.DS_Store",
84
+ "spec/architect_spec.rb",
85
+ "spec/architecture-js_spec.rb",
86
+ "spec/blueprint_spec.rb",
87
+ "spec/fixtures/.DS_Store",
88
+ "spec/fixtures/_hidden.js",
89
+ "spec/fixtures/compiled_src.js",
90
+ "spec/fixtures/compressed.blueprint",
91
+ "spec/fixtures/compressed.js",
92
+ "spec/fixtures/ejs.ejs",
93
+ "spec/fixtures/env-test.js",
94
+ "spec/fixtures/existing.blueprint",
95
+ "spec/fixtures/lib1.js",
96
+ "spec/fixtures/lib1_compressed.js",
97
+ "spec/fixtures/lib2.js",
98
+ "spec/fixtures/lib2_compressed.js",
99
+ "spec/fixtures/myapp.blueprint",
100
+ "spec/fixtures/src_file.js",
101
+ "spec/fixtures/templates/env_template.js",
102
+ "spec/fixtures/templates/test_template_one.js",
103
+ "spec/fixtures/templates/test_template_two.js",
104
+ "spec/fixtures/test_blueprint.rb",
105
+ "spec/fixtures/test_template_options.js",
106
+ "spec/fixtures/test_template_two.js",
107
+ "spec/fixtures/underscore_template.js",
108
+ "spec/fixtures/update.blueprint",
109
+ "spec/fixtures/update.js",
110
+ "spec/generator_spec.rb",
111
+ "spec/helpers_spec.rb",
112
+ "spec/notification_spec.rb",
113
+ "spec/spec_helper.rb",
114
+ "templates/blank.js"
115
+ ]
116
+ s.homepage = "https://github.com/daytonn/architecture-js"
117
+ s.licenses = ["MIT"]
118
+ s.require_paths = ["lib"]
119
+ s.rubygems_version = "1.8.21"
120
+ s.summary = "architecture.js is a command line application to dynamically build and manage complex javascript applications."
121
+
122
+ if s.respond_to? :specification_version then
123
+ s.specification_version = 3
124
+
125
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
126
+ s.add_runtime_dependency(%q<listen>, [">= 0"])
127
+ s.add_runtime_dependency(%q<jsmin>, ["~> 1.0.1"])
128
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
129
+ s.add_development_dependency(%q<bundler>, [">= 0"])
130
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
131
+ s.add_runtime_dependency(%q<jsmin>, [">= 0"])
132
+ s.add_runtime_dependency(%q<listen>, [">= 0"])
133
+ else
134
+ s.add_dependency(%q<listen>, [">= 0"])
135
+ s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
136
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
137
+ s.add_dependency(%q<bundler>, [">= 0"])
138
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
139
+ s.add_dependency(%q<jsmin>, [">= 0"])
140
+ s.add_dependency(%q<listen>, [">= 0"])
141
+ end
142
+ else
143
+ s.add_dependency(%q<listen>, [">= 0"])
144
+ s.add_dependency(%q<jsmin>, ["~> 1.0.1"])
145
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
146
+ s.add_dependency(%q<bundler>, [">= 0"])
147
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
148
+ s.add_dependency(%q<jsmin>, [">= 0"])
149
+ s.add_dependency(%q<listen>, [">= 0"])
150
+ end
151
+ end
152
+
@@ -36,6 +36,8 @@ module Architect
36
36
 
37
37
  if @command
38
38
  self.send @command unless @command =~ /^-/
39
+ else
40
+ help
39
41
  end
40
42
 
41
43
  end
@@ -60,23 +62,6 @@ module Architect
60
62
 
61
63
  def generate
62
64
  project_path = File.expand_path(Dir.getwd)
63
-
64
- # Go up to 10 levels up to look for the project config file
65
- # This is not optimal but is probably the easiest way to allow
66
- # generating templates in project sub-folders given we need to
67
- # read the blueprint file to get the templates
68
- 10.times do
69
- config_file = ArchitectureJS::get_config_file(project_path)
70
-
71
- unless config_file
72
- path_array = project_path.split(File::SEPARATOR)
73
- path_array.pop # push the last dir off the stack
74
- project_path = path_array.join(File::SEPARATOR)
75
- else
76
- break
77
- end
78
- end
79
-
80
65
  project = ArchitectureJS::Blueprint.new_from_config(project_path)
81
66
 
82
67
  config = {
@@ -85,8 +70,14 @@ module Architect
85
70
  filename: @args[1],
86
71
  options: @template_options
87
72
  }
88
-
89
- project.generator.generate config
73
+ begin
74
+ project.generator.generate config
75
+ rescue Exception => e
76
+ puts e.message
77
+ puts "Be sure you ran the command correctly (architect generate <template> <filename> [options])"
78
+ puts "Available templates:"
79
+ project.generator.templates.each { |k,v| puts " - #{k}" }
80
+ end
90
81
  end
91
82
 
92
83
  def compile
@@ -100,38 +91,43 @@ module Architect
100
91
  path ||= Dir.getwd
101
92
  path = File.expand_path(path)
102
93
 
103
- puts ArchitectureJS::Notification.log "architect is watching for changes. Press Ctrl-C to stop."
104
94
  project = ArchitectureJS::Blueprint::new_from_config(path)
105
95
  project.update
106
-
107
- Listen.to(path, :filter => /\.jst?$/, :ignore => /#{project.config[:build_dir]}|spec|test/) do |modified, added, removed|
108
- if modified.length > 0
109
-
110
- modified.each do |f|
111
- file = File.basename(f)
112
- puts ArchitectureJS::Notification.event "change detected in #{file}"
113
- project.config.read if f.match(/blueprint$/)
114
- end
115
-
116
- project.update
117
- end
118
-
119
- if added.length > 0
120
- added.each do |f|
121
- file = File.basename(f)
122
- puts ArchitectureJS::Notification.event "#{file} created"
96
+ listener = project.watch
97
+
98
+ command = 'start'
99
+ puts ArchitectureJS::Notification.log "architect is watching for changes. Type 'quit' or 'exit' to stop."
100
+ while not command =~ /exit|quit/
101
+ print ArchitectureJS::Notification.prompt
102
+ command = gets.chomp
103
+ case command
104
+ when /exit|quit/
105
+ listener.stop
106
+ when /src_files/
107
+ puts project.src_files.join("\n")
108
+ when /templates/
109
+ project.generator.templates.each { |k,v| puts k }
110
+ when /compile|update/
111
+ begin
112
+ project.update
113
+ rescue Exception => e
114
+ puts e.message
115
+ ArchitectureJS::Notification.prompt
116
+ end
117
+ when /generate/
118
+ begin
119
+ args = command.split(/\s/)
120
+ parse_command args
121
+ parse_arguments args
122
+ parse_generate_options
123
+ self.send @command
124
+ rescue Exception => e
125
+ puts e.message
126
+ puts "Available templates:"
127
+ project.generator.templates.each { |k,v| puts " - #{k}" }
128
+ ArchitectureJS::Notification.prompt
129
+ end
123
130
  end
124
-
125
- project.update
126
- end
127
-
128
- if removed.length > 0
129
- removed.each do |f|
130
- file = File.basename(f)
131
- puts ArchitectureJS::Notification.event "#{file} deleted"
132
- end
133
- end
134
-
135
131
  end
136
132
 
137
133
  end
@@ -190,15 +186,13 @@ module Architect
190
186
  # each_with_index
191
187
  end
192
188
 
193
- def parse_arguments
194
- @args = Array.try_convert(ARGV)
189
+ def parse_arguments(args = Array.try_convert(ARGV))
190
+ @args = args
195
191
  @args.shift # remove command
196
192
  end
197
193
 
198
- def parse_command
199
- unless ARGV[0].nil? && ARGV[0] =~ /^-/
200
- @command = ARGV[0].to_sym
201
- end
194
+ def parse_command(args = ARGV)
195
+ @command = args[0].to_sym if args[0].respond_to? :to_sym
202
196
  end
203
197
 
204
198
  def help
@@ -31,7 +31,7 @@ module ArchitectureJS
31
31
  @root = File.expand_path(root)
32
32
  @template_directories = ["#{ArchitectureJS::base_directory}/templates", "#{@root}/templates"]
33
33
  @directories = ['lib', 'src']
34
- @src_files = Array.new
34
+ @src_files = []
35
35
  @config = {
36
36
  blueprint: 'default',
37
37
  src_dir: 'src',
@@ -100,7 +100,8 @@ module ArchitectureJS
100
100
  @errors = false
101
101
  end
102
102
 
103
- def get_src_files
103
+ def get_src_files
104
+ @src_files = []
104
105
  [*@config[:src_dir]].each do |directory|
105
106
  add_src_files_to_project File.expand_path(directory, @root)
106
107
  end
@@ -159,6 +160,11 @@ module ArchitectureJS
159
160
  end
160
161
  end
161
162
 
163
+ def watch
164
+ watcher = ArchitectureJS::Watcher.new self
165
+ watcher.watch
166
+ end
167
+
162
168
  end # class Blueprint
163
169
  end # module ArchitectureJS
164
170
 
@@ -53,7 +53,7 @@ module ArchitectureJS
53
53
  def generate_file(filename, template, path = nil)
54
54
  path ||= File.expand_path(Dir.getwd)
55
55
  File.open("#{path}/#{filename}", "w+") { |f| f.write template }
56
- puts ArchitectureJS::Notification.added "#{filename} added" if File.exists?("#{path}/#{filename}")
56
+ puts ArchitectureJS::Notification.added "#{filename} generated" if File.exists?("#{path}/#{filename}")
57
57
  end
58
58
 
59
59
  def render_template(template, filename, arguments, options)
@@ -14,15 +14,16 @@ module ArchitectureJS
14
14
  log: "\e[32m>>>\e[0m ",
15
15
  event: "\e[33m<<<\e[0m ",
16
16
  added: "\e[32m+++\e[0m ",
17
- error: "\e[0;31m!!!\e[0m "
17
+ error: "\e[0;31m!!!\e[0m ",
18
+ prompt: ">>> "
18
19
  }
19
20
 
20
21
  @@indicators.merge!({
21
22
  none: "",
22
- log: ">>>",
23
- event: "<<<",
24
- added: "+++",
25
- error: "!!!"
23
+ log: ">>> ",
24
+ event: "<<< ",
25
+ added: "+++ ",
26
+ error: "!!! ",
26
27
  }) if win_platform
27
28
 
28
29
  def self.notify(type, message)
@@ -49,6 +50,9 @@ module ArchitectureJS
49
50
  def self.error(message)
50
51
  self.notify :error, message
51
52
  end
52
-
53
+
54
+ def self.prompt
55
+ self.notify :prompt, ''
56
+ end
53
57
  end
54
58
  end
@@ -0,0 +1,36 @@
1
+ module ArchitectureJS
2
+ class Watcher
3
+
4
+ def initialize(project)
5
+ @project = project
6
+ @listener = Listen.to(@project.root)
7
+ @listener.ignore(/#{@project.config[:build_dir]}|spec|test/)
8
+ .filter(/\.jst?$/)
9
+ .change do |modified, added, removed|
10
+ update_files(modified, "was modified") if modified.length > 0
11
+ update_files(added, "was added") if added.length > 0
12
+ update_files(removed, "was deleted") if removed.length > 0
13
+ end
14
+ end
15
+
16
+ def watch
17
+ @listener.start(false)
18
+ @listener
19
+ end
20
+
21
+ private
22
+
23
+ def update_files(files, message)
24
+ files.each do |f|
25
+ f = File.basename f
26
+
27
+ puts "\n" << ArchitectureJS::Notification.event("#{f} #{message}")
28
+ end
29
+
30
+ @project.read_config
31
+ @project.update
32
+ print ArchitectureJS::Notification.prompt
33
+ end
34
+
35
+ end
36
+ end
@@ -37,6 +37,6 @@ end
37
37
 
38
38
  require "sprockets/lib/sprockets"
39
39
 
40
- %w(dependencies generator notification blueprint architect).each do |lib|
40
+ %w(dependencies generator notification watcher blueprint architect).each do |lib|
41
41
  require "architecture-js/#{lib}"
42
42
  end
@@ -38,14 +38,14 @@ describe 'architect' do
38
38
  end
39
39
 
40
40
  it 'should generate a template' do
41
- `cd #{TMP_DIR}/src; #{@bin} generate blank test`
41
+ `cd #{TMP_DIR}; #{@bin} generate blank src/test`
42
42
  File.exists?("#{TMP_DIR}/src/test.js").should be_true
43
43
  end
44
44
 
45
45
  it 'should generate a template with options' do
46
46
  FileUtils.mkdir("#{TMP_DIR}/templates")
47
47
  FileUtils.cp("#{FIXTURES}/templates/test_template_two.js", "#{TMP_DIR}/templates/test_template.js")
48
- `cd #{TMP_DIR}/src; #{@bin} generate test_template foo --optional_variable true --is_good -g --bool`
48
+ `cd #{TMP_DIR}; #{@bin} generate test_template src/foo --optional_variable true --is_good -g --bool`
49
49
 
50
50
  File.exists?("#{TMP_DIR}/src/foo.js").should be_true
51
51
  "#{TMP_DIR}/src/foo.js".should be_same_file_as "#{FIXTURES}/test_template_options.js"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: architecture-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-26 00:00:00.000000000 Z
12
+ date: 2012-05-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: listen
@@ -145,6 +145,7 @@ files:
145
145
  - README.md
146
146
  - Rakefile
147
147
  - VERSION
148
+ - architecture-js.gemspec
148
149
  - bin/architect
149
150
  - docs/docco.css
150
151
  - lib/architecture-js.rb
@@ -154,6 +155,7 @@ files:
154
155
  - lib/architecture-js/generator.rb
155
156
  - lib/architecture-js/helpers.rb
156
157
  - lib/architecture-js/notification.rb
158
+ - lib/architecture-js/watcher.rb
157
159
  - lib/sprockets/CHANGELOG
158
160
  - lib/sprockets/LICENSE
159
161
  - lib/sprockets/README.markdown
@@ -240,7 +242,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
242
  version: '0'
241
243
  segments:
242
244
  - 0
243
- hash: -2544092032087362210
245
+ hash: 514518267810295909
244
246
  required_rubygems_version: !ruby/object:Gem::Requirement
245
247
  none: false
246
248
  requirements: