pyro 0.9.0 → 1.0.0.rc1

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: 48cc7d2dd7db7c1678d85fe0cecb8992803a30d9
4
- data.tar.gz: 7cffa1ce48fc4f6a68c33272f246288657cfd78e
3
+ metadata.gz: bbd5afb69830d1640ab6d13d5078558c27311a3b
4
+ data.tar.gz: a944401a77fe94e767c5c8636e03cc2188b94bef
5
5
  SHA512:
6
- metadata.gz: 7a853a12955f7060690bb4c5e0b8a3a2b83b60b434bbcf565cd9e0c15bdf1d0668ec15660e4b89d3d622134699090f90c324abaeb5692d308365159ca180c208
7
- data.tar.gz: 8af880a834da535b189964dd222c1e04d33fc7ea64d937d12a3f12701190945de785f733adadb479c88809f3f47c13c0f1b0beaaad7ff71cde488364fbe9f0b5
6
+ metadata.gz: c4bd3c62c7502fa6c39c75beb7ca04df27a530f71b7174f3de2b39942f03dacb1b5ae618b226fe785327f1961c18041dba77086dd14fb25e8e8248591e360c6f
7
+ data.tar.gz: 3efd9c17314c130e00e106091f56fd4afb683af843e9c9def9a19c234e207c6cea116ac5f27c21ca255a69910741ac51f28f72db241cdd28fa6928572cfd93ac
data/README.md CHANGED
@@ -107,7 +107,7 @@ Everything will be built on the first page load, but reloads will only rebuild `
107
107
  When you're ready to deploy, the ```pyro build``` command will compile and minify your app into ```/builds/production/<timestamp>```:
108
108
 
109
109
  ```bash
110
- ~/MyApp $ pyro build
110
+ ~/MyApp $ pyro burn
111
111
  # => MyApp is compiled and minified into ~/MyApp/builds/production/20130816020233/
112
112
  ```
113
113
 
data/bin/pyro CHANGED
@@ -10,27 +10,48 @@ class PyroCLI < Thor
10
10
  FileUtils.cp_r("#{File.dirname(__FILE__)}/../templates/app", name)
11
11
  end
12
12
 
13
- desc 'build DIR', 'Builds an app for production'
14
- def build(dir = '.')
15
- Pyro.build('production', false, dir)
13
+ desc 'burn DIR', 'Builds an app for production'
14
+ def burn(dir = '.')
15
+ Pyro.burn('production', false, dir)
16
16
  end
17
17
 
18
- desc 'serve DIR', 'Starts a Pyro app on localhost,
19
- --fast skips asset reloading'
18
+ desc 'serve', 'Starts a Pyro app on localhost,
19
+ --fast skips asset reloading,
20
+ --test includes tests'
21
+
20
22
  option :fast
21
- def serve(dir = '.')
23
+ option :test
24
+ def serve
22
25
  require 'pyro/server'
23
26
 
24
- PyroServer.set :src_folder, dir
25
- PyroServer.set :public_folder,
26
- "#{PyroServer.settings.src_folder}/tmp"
27
-
28
27
  if options[:fast]
29
28
  PyroServer.set :fast, true
30
29
  else
31
30
  PyroServer.set :fast, false
32
31
  end
33
32
 
33
+ PyroServer.set(:target, 'test') if options[:test]
34
+
35
+ PyroServer.run!
36
+ end
37
+
38
+ desc 'stage BUILD', 'Stages a Pyro build on localhost'
39
+ def stage(build_num = false)
40
+ if build_num
41
+ build_dir = "./pkg/#{build_num}"
42
+ else
43
+ Pyro.burn('production', false) if Dir.glob('./pkg/**').count == 0
44
+ build_dir = Dir.glob('./pkg/**').last
45
+ end
46
+
47
+ unless Dir.exists? build_dir
48
+ puts "That build doesn't exist. Try running 'pyro burn' to create a build."
49
+ exit
50
+ end
51
+
52
+ require 'pyro/server'
53
+ PyroServer.set :public_folder, build_dir
54
+ PyroServer.set :staging, true
34
55
  PyroServer.run!
35
56
  end
36
57
 
data/lib/pyro.rb CHANGED
@@ -4,17 +4,17 @@ require 'pyro/assets'
4
4
  module Pyro
5
5
  include Pyro::Assets
6
6
 
7
- def self.build(target = 'production', fast = false, working_dir = '.')
7
+ def self.burn(target = 'production', fast = false, working_dir = '.')
8
8
  @target = target
9
9
  @timestamp = Time.now.strftime "%Y%m%d%H%M%S"
10
10
  @working_dir = working_dir
11
11
  @links = []
12
12
 
13
13
  unless File.exists? "#{@working_dir}/index.erb"
14
- raise 'Can\'t find an index.erb file to build.'
14
+ raise 'Can\'t find an index.erb file to burn.'
15
15
  end
16
16
 
17
- if @target == 'development'
17
+ if @target == 'development' || @target == 'test'
18
18
  @build_dir = "#{@working_dir}/tmp"
19
19
  else
20
20
  @build_dir = "#{@working_dir}/pkg/#{@timestamp}"
@@ -31,7 +31,7 @@ module Pyro
31
31
  File.open("#{@build_dir}/index.html", 'w+') do |f|
32
32
  f.write( ERB.new(File.read "#{@working_dir}/index.erb").result(binding) )
33
33
  end
34
-
34
+
35
35
  compress(@build_dir) if @target == 'production'
36
36
  end
37
37
  end
data/lib/pyro/asset.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'barber'
2
+ require 'coffee-script'
3
+ require 'fileutils'
4
+ require 'sass'
5
+
6
+ module Pyro
7
+ class Asset
8
+ attr_accessor :file, :build_dir, :working_dir, :helper_args
9
+
10
+ def initialize(args)
11
+ args.each { |k, v| instance_variable_set("@#{k}", v) }
12
+ end
13
+
14
+ def mtime
15
+ File.mtime file
16
+ end
17
+
18
+ def basename
19
+ File.basename file
20
+ end
21
+
22
+ def dirname
23
+ File.dirname file
24
+ end
25
+
26
+ def extname
27
+ File.extname file
28
+ end
29
+
30
+ def name
31
+ basename.sub(extname, '')
32
+ end
33
+
34
+ def timestamp
35
+ mtime.strftime "%Y%m%d%H%M%S"
36
+ end
37
+
38
+ def relative_dir
39
+ dirname.sub("#{working_dir}/", '')
40
+ end
41
+
42
+ def relative_file
43
+ if helper_args[:target]
44
+ helper_args[:target]
45
+ else
46
+ "#{relative_dir}/#{name}#{compiled_ext}"
47
+ end
48
+ end
49
+
50
+ def compiled_ext
51
+ case extname
52
+ when '.coffee', '.hbs', '.handlebars'
53
+ '.js'
54
+ when '.scss'
55
+ '.css'
56
+ else
57
+ extname
58
+ end
59
+ end
60
+
61
+ def contents
62
+ contents = File.read file
63
+ case extname
64
+ when '.coffee'
65
+ contents = CoffeeScript.compile(contents, bare: true)
66
+ when '.scss'
67
+ contents = Sass::Engine.new(contents, { syntax: :scss }).render
68
+ when '.hbs', '.handlebars'
69
+ contents = Barber::Ember::FilePrecompiler.call(contents)
70
+ contents = "Ember.TEMPLATES['#{template_name}'] = #{contents}"
71
+ end
72
+ contents
73
+ end
74
+
75
+ def template_name
76
+ if helper_args[:name]
77
+ helper_args[:name]
78
+ elsif helper_args[:src]
79
+ name
80
+ elsif helper_args[:dir]
81
+ file.sub("#{working_dir}/#{helper_args[:dir]}/", '').sub(extname, '')
82
+ else
83
+ 'name-not-found'
84
+ end
85
+ end
86
+
87
+ def generate_file
88
+ FileUtils.mkdir_p "#{build_dir}/#{relative_dir}"
89
+ File.open("#{build_dir}/#{relative_file}", 'a+') { |f| f.write contents }
90
+ end
91
+
92
+ def generate_link
93
+ case compiled_ext
94
+ when '.js'
95
+ "<script type='text/javascript' src='#{relative_file}?#{timestamp}'></script>\n"
96
+ when '.css'
97
+ "<link type='text/css' rel='stylesheet' href='#{relative_file}?#{timestamp}' />\n"
98
+ end
99
+ end
100
+ end
101
+ end
data/lib/pyro/assets.rb CHANGED
@@ -1,8 +1,7 @@
1
- require 'barber'
2
- require 'coffee-script'
3
1
  require 'fileutils'
4
2
  require 'jsmin'
5
3
  require 'sass'
4
+ require 'pyro/asset'
6
5
 
7
6
  module Pyro
8
7
  module Assets
@@ -12,131 +11,52 @@ module Pyro
12
11
 
13
12
  module ClassMethods
14
13
 
15
- def script(*args)
16
- tags = ''
17
- find_files(args.first, 'js, coffee').each do |file|
18
- tags << compile(args.first, file, 'js')
19
- end
20
- tags
21
- end
14
+ define_method(:script) { |*args| build(args.first, 'js, coffee') }
15
+ define_method(:stylesheet) { |*args| build(args.first, 'css, scss') }
16
+ define_method(:template) { |*args| build(args.first, 'hbs, handlebars') }
22
17
 
23
- def stylesheet(*args)
24
- tags = ''
25
- find_files(args.first, 'css, scss').each do |file|
26
- tags << compile(args.first, file, 'css')
27
- end
28
- tags
18
+ def test(*args)
19
+ build(args.first, 'js, coffee, css, scss') if @target == 'test'
29
20
  end
30
21
 
31
- def template(*args)
32
- tags = ''
33
- find_files(args.first, 'hbs, handlebars').each do |file|
34
- tags << compile(args.first, file, 'js')
22
+ private
23
+
24
+ def build(args, src_ext)
25
+ tags = ''
26
+ find_assets(args, src_ext).each do |asset|
27
+ asset.generate_file
28
+ link = asset.generate_link
29
+ unless @links.include? link
30
+ @links << link
31
+ tags << link
32
+ end
35
33
  end
36
34
  tags
37
35
  end
38
36
 
39
- private
40
-
41
- def find_files(args, extensions)
37
+ def find_assets(args, exts)
42
38
  if @target == 'production'
43
39
  args[:src] = args[:prod_src] if args[:prod_src]
44
40
  args[:dir] = args[:prod_dir] if args[:prod_dir]
45
41
  end
46
-
47
- files = []
48
- if args[:src]
49
- files << "#{@working_dir}/#{args[:src]}"
50
- elsif args[:dir]
51
- Dir.glob("#{@working_dir}/#{args[:dir]}/**/*.{#{extensions}}").each do |f|
52
- files << f
53
- end
54
- end
55
- files
56
- end
57
-
58
- def parse_path(args, path)
59
- p = {}
60
- p[:contents] = File.read(path)
61
- p[:file_name] = path.split('/').last
62
- p[:extension] = path.split('.').last
63
- p[:name] = p[:file_name].sub(".#{p[:extension]}", '')
64
- p[:path] = path.sub(p[:file_name], '')
65
- p[:build_path] = p[:path].sub('./', "#{@build_dir}/")
66
-
67
- if args[:target]
68
- target_name = args[:target].split('/').last
69
- target_ext = target_name.split('.').last
70
- args[:target] = args[:target].sub(".#{target_ext}", '')
71
- p[:target_path] = "#{@build_dir}/#{args[:target]}"
72
- else
73
- p[:target_path] = "#{p[:build_path]}#{p[:name]}"
74
- end
75
-
76
- p[:target_link] = p[:target_path].sub(@build_dir, '')
77
- p
78
- end
79
42
 
80
- def parse_name(args, file)
81
- if args[:name]
82
- name = args[:name]
83
- elsif args[:src]
84
- name = f.split('/').last.split('.').first
43
+ assets = []
44
+ if args[:src]
45
+ assets << Asset.new(file: "#{@working_dir}/#{args[:src]}",
46
+ build_dir: @build_dir,
47
+ working_dir: @working_dir,
48
+ helper_args: args)
85
49
  elsif args[:dir]
86
- name = file.sub("#{@working_dir}/#{args[:dir]}/", '').split('.').first
87
- else
88
- name = 'name-not-found'
89
- end
90
- name
91
- end
92
-
93
- def generate_file(path_attrs, extension, template_name)
94
- FileUtils.mkdir_p(path_attrs[:build_path])
95
- File.open("#{path_attrs[:target_path]}.#{extension}", 'a+') do |f|
96
- if template_name == ''
97
- f.write(path_attrs[:contents])
98
- else
99
- f.write("Ember.TEMPLATES['#{template_name}'] = #{path_attrs[:contents]}")
50
+ Dir.glob("#{@working_dir}/#{args[:dir]}/**/*.{#{exts}}").each do |file|
51
+ assets << Asset.new(file: file,
52
+ build_dir: @build_dir,
53
+ working_dir: @working_dir,
54
+ helper_args: args)
100
55
  end
101
56
  end
57
+ assets
102
58
  end
103
59
 
104
- def generate_link(path, extension)
105
- case extension
106
- when 'js'
107
- link = "<script src='#{path}.#{extension}?#{@timestamp}' type='text/javascript'></script>"
108
- when 'css'
109
- link = "<link rel='stylesheet' href='#{path}.#{extension}?#{@timestamp}' type='text/css' />"
110
- end
111
-
112
- if @links.include? link
113
- ''
114
- else
115
- @links << link
116
- link
117
- end
118
- end
119
-
120
- def compile(args, file, extension)
121
- path_attrs = parse_path(args, file)
122
- template_name = ''
123
-
124
- case path_attrs[:extension]
125
- when 'coffee'
126
- path_attrs[:contents] = CoffeeScript.compile(path_attrs[:contents], bare: true)
127
- when 'hbs', 'handlebars'
128
- path_attrs[:contents] = Barber::Ember::FilePrecompiler.call(path_attrs[:contents])
129
- template_name = parse_name(args, file)
130
- when 'scss'
131
- path_attrs[:contents] = Sass::Engine.new( path_attrs[:contents],
132
- { style: :expanded,
133
- syntax: :scss } ).render
134
- end
135
-
136
- generate_file(path_attrs, extension, template_name)
137
- generate_link(path_attrs[:target_link], extension)
138
- end
139
-
140
60
  def compress(dir)
141
61
  Dir.glob("#{dir}/**/*.js").each do |file|
142
62
  contents = File.read(file)
@@ -144,14 +64,13 @@ module Pyro
144
64
  f.write(JSMin.minify(contents).strip)
145
65
  end
146
66
  end
147
-
67
+
148
68
  Dir.glob("#{dir}/**/*.css").each do |file|
149
69
  contents = File.read(file)
150
70
  File.open(file, 'w+') do |f|
151
71
  f.write(Sass::Engine.new( contents, { style: :compressed,
152
72
  syntax: :scss } ).render)
153
73
  end
154
-
155
74
  end
156
75
  end
157
76
 
data/lib/pyro/server.rb CHANGED
@@ -5,13 +5,18 @@ require 'erb'
5
5
  class PyroServer < Sinatra::Base
6
6
  include Pyro
7
7
 
8
- set :port, 5678
8
+ set :fast_build, false
9
+ set :port, 7976
9
10
  set :public_folder, './tmp'
10
- set :fast_build, false
11
+ set :staging, false
12
+ set :target, 'development'
11
13
 
12
14
  get '/?' do
13
- Pyro.build('development', settings.fast_build, settings.src_folder)
14
- settings.fast_build = settings.fast
15
- File.read("#{settings.src_folder}/tmp/index.html")
15
+ unless settings.staging
16
+ Pyro.burn(settings.target, settings.fast_build)
17
+ settings.fast_build = settings.fast
18
+ end
19
+
20
+ File.read "#{settings.public_folder}/index.html"
16
21
  end
17
22
  end
data/pyro.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "pyro"
7
- gem.version = "0.9.0"
7
+ gem.version = "1.0.0.rc1"
8
8
  gem.authors = "Jarrod Taylor"
9
9
  gem.email = "jarrodtaylor@icloud.com"
10
10
  gem.homepage = "https://github.com/jarrodtaylor/pyro"
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency 'barber', '~> 0.4.2'
21
21
  gem.add_dependency 'execjs', '~> 1.4.0'
22
22
  gem.add_dependency 'coffee-script', '~> 2.2.0'
23
- gem.add_dependency 'ember-source', '~> 1.0.0.rc8'
23
+ gem.add_dependency 'ember-source', '~> 1.0.0'
24
24
  gem.add_dependency 'handlebars-source', '~> 1.0.12'
25
25
  gem.add_dependency 'jsmin', '~> 1.0.1'
26
26
  gem.add_dependency 'sass', '~> 3.2.10'
@@ -1,23 +1,28 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <meta charset="utf-8">
5
- <title>Ember Starter Kit</title>
4
+ <meta charset="utf-8">
5
+ <title>Ember Starter Kit</title>
6
6
  <%= stylesheet src: 'resources/stylesheets/normalize.css' %>
7
7
  <%= stylesheet src: 'resources/stylesheets/style.scss' %>
8
+
9
+ <%= test src: 'vendor/qunit/qunit.css' %>
8
10
  </head>
9
11
  <body>
10
12
  <%= script src: 'vendor/jquery/jquery-1.9.1.js',
11
13
  target: 'vendor/concatenated.js' %>
12
14
  <%= script src: 'vendor/handlebars/handlebars-1.0.0.js',
13
15
  target: 'vendor/concatenated.js' %>
14
- <%= script src: 'vendor/ember/ember-1.0.0-rc.8.js',
16
+ <%= script src: 'vendor/ember/ember.js',
15
17
  prod_src: 'vendor/ember/ember.prod.js',
16
18
  target: 'vendor/concatenated.js' %>
17
- <%= script src: 'vendor/ember/ember-data-0.13.js',
19
+ <%= script src: 'vendor/ember/ember-data.js',
20
+ prod_src: 'vendor/ember/ember-data.prod.js',
18
21
  target: 'vendor/concatenated.js' %>
19
-
22
+
20
23
  <%= script src: 'lib/app.coffee' %>
21
24
  <%= template dir: 'lib/templates' %>
25
+
26
+ <%= test src: 'test/example.coffee' %>
22
27
  </body>
23
28
  </html>