cyborg 0.0.9 → 0.1.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: 302f49cf71fff393e1136f674d695ea619973c22
4
- data.tar.gz: 2c17bc91cc6437c4aab49c5b9c1899d157dd9427
3
+ metadata.gz: 23a5939aaf1016d48d5ac825c571505364784030
4
+ data.tar.gz: b9cfd458100f2a917f20de79a72071efbae59a57
5
5
  SHA512:
6
- metadata.gz: f32042ee1e43a00c116a1e8a7448c8004cf075b775f02ad11bd34fa872ae0e2ed33122cbcfabeb9d5fd870b0a9f60c31c6255930925c5cfb5205006fcb7f0316
7
- data.tar.gz: f6b32fcc8a5840a700f012757d6a86e5437d173d01da295bf9b939ac5b263769ca366b572f4121f49b74cbf57d966e90c8e1af2c1578a6ee6cca3d6736e57a52
6
+ metadata.gz: 524dc65ec162fed441ce0b0394673bcc403296ccf95317c11c32ceacbc9b8cf7bb6deca01470ac433acacca49c11e3eff6f640836cb4c0521af2f1cf9b8fb160
7
+ data.tar.gz: c584f04f4038aa2b2796a3c93c7d3262585245308ff6cb7cea155cf4b73c9b2e3127d2cc85aef06423fa0799571332890ca752432b773bef18e42cc41106f4c7
data/bin/cyborg CHANGED
@@ -40,18 +40,24 @@ OptionParser.new do |opts|
40
40
  end
41
41
 
42
42
  if %w(b w s build watch server).include? options[:command]
43
- opts.on("-j", "--js", "Build javascripts") do |val|
43
+ opts.on("-j", "--js", "Build javascripts.") do |val|
44
44
  options[:select_assets] = true
45
45
  options[:js] = true
46
46
  end
47
- opts.on("-c", "--css", "Build css") do |val|
47
+ opts.on("-c", "--css", "Build css.") do |val|
48
48
  options[:select_assets] = true
49
49
  options[:css] = true
50
50
  end
51
- opts.on("-s", "--svg", "Build svg") do |val|
51
+ opts.on("-s", "--svg", "Build svgs.") do |val|
52
52
  options[:select_assets] = true
53
53
  options[:svg] = true
54
54
  end
55
+ opts.on("-m", "--maps", "Enable sourcemaps for javascript and stylesheets.") do |val|
56
+ options[:maps] = true
57
+ end
58
+ opts.on("-p", "--production", "Build assets as with production mode.") do |val|
59
+ options[:production] = true
60
+ end
55
61
  end
56
62
 
57
63
  opts.on("-v", "--version", "Print version") do |version|
@@ -13,7 +13,7 @@ module Cyborg
13
13
  autoload :Application, "cyborg/middleware"
14
14
 
15
15
  def production?
16
- ENV['CI'] || ENV['RAILS_ENV'] == 'production'
16
+ ENV['CI'] || ENV['RAILS_ENV'] == 'production' || Command.production?
17
17
  end
18
18
 
19
19
  def plugin
@@ -7,6 +7,7 @@ module Cyborg
7
7
  extend self
8
8
 
9
9
  def run(options)
10
+ @production = options[:production]
10
11
 
11
12
  case options[:command]
12
13
  when 'new', 'n'
@@ -17,11 +18,34 @@ module Cyborg
17
18
  from_root { dispatch(:watch, options) }
18
19
  when 'server', 's'
19
20
  from_root { dispatch(:server, options) }
21
+ when 'gem:build'
22
+ from_root { gem_build }
23
+ when 'gem:install'
24
+ from_root { gem_build }
20
25
  else
21
26
  puts "Command `#{options[:command]}` not recognized"
22
27
  end
23
28
  end
24
29
 
30
+ def production?
31
+ @production == true
32
+ end
33
+
34
+ def gem_build
35
+ dispatch(:build, production: true)
36
+ system "bundle exec rake build"
37
+ end
38
+
39
+ def gem_install
40
+ dispatch(:build, production: true)
41
+ system "bundle exec rake install"
42
+ end
43
+
44
+ def gem_release
45
+ dispatch(:build, production: true)
46
+ system "bundle exec rake release"
47
+ end
48
+
25
49
  # Handles running threaded commands
26
50
  #
27
51
  def dispatch(command, *args)
@@ -32,7 +56,7 @@ module Cyborg
32
56
 
33
57
  # Build assets
34
58
  def build(options={})
35
- puts 'Building…'
59
+ puts Cyborg.production? ? 'Building for production…' : 'Building…'
36
60
  require File.join(Dir.pwd, Cyborg.rails_path('config/application'))
37
61
  @threads.concat Cyborg.plugin.build(options)
38
62
  end
@@ -6,28 +6,31 @@ module Cyborg
6
6
  if command.nil?
7
7
  <<-HERE
8
8
  Commands:
9
- #{command_list.map{|c| commands(c.to_sym) }.join("\n ")}
9
+ #{command_list.map{|c| commands(c) }.join("\n ")}
10
10
 
11
11
  For help with a specific command, run `cyborg help command`
12
12
 
13
13
  Options:
14
14
  HERE
15
- elsif commands(command.to_sym)
16
- "\nUsage:\n cyborg #{commands(command.to_sym)}\n\nOptions:\n"
15
+ elsif commands(command)
16
+ "\nUsage:\n cyborg #{commands(command)}\n\nOptions:\n"
17
17
  end
18
18
  end
19
19
 
20
20
  def command_list
21
- %w(new build watch server help)
21
+ %w(new build watch server help gem:build gem:install gem:release)
22
22
  end
23
23
 
24
24
  def commands(command)
25
25
  case command
26
- when :new, :n; new
27
- when :build, :b; build
28
- when :watch, :w; watch
29
- when :server, :s; server
30
- when :help, :h; help
26
+ when 'new', 'n'; new
27
+ when 'build', 'b'; build
28
+ when 'watch', 'w'; watch
29
+ when 'server', 's'; server
30
+ when 'help', 'h'; help
31
+ when 'gem:build'; gem_build
32
+ when 'gem:install'; gem_install
33
+ when 'gem:release'; gem_release
31
34
  end
32
35
  end
33
36
 
@@ -50,5 +53,17 @@ Options:
50
53
  def help
51
54
  "help [command] # Show help for a specific command"
52
55
  end
56
+
57
+ def gem_build
58
+ "gem:build # Build assets for production and build gem"
59
+ end
60
+
61
+ def gem_install
62
+ "gem:install # Build assets for production, build, and install gem"
63
+ end
64
+
65
+ def gem_release
66
+ "gem:release # Build assets for production, build, and release gem to rubygems.org"
67
+ end
53
68
  end
54
69
  end
@@ -268,10 +268,11 @@ Gem::Specification.new do |spec|
268
268
  spec.description = "Description of your gem (usually longer)."
269
269
  spec.license = "#{spec.license}"
270
270
 
271
- spec.files = Dir["{app,config,lib/public}/**/*", "LICENSE.txt", "README.md"]
271
+ spec.files = Dir["{app,lib}/**/*", "LICENSE.txt", "README.md"]
272
+ spec.files.concat Dir["public/**/*#\{#{@module_name}::VERSION\}*"]
272
273
  spec.require_paths = ["lib"]
273
274
 
274
- spec.add_dependency "rails", "~> #{`rails -v`.strip.split(' ').last}"
275
+ spec.add_dependency "rails", "~> 4.2.6"
275
276
  spec.add_runtime_dependency "megatron"
276
277
 
277
278
  spec.add_development_dependency "bundler", "~> 1.12"
@@ -7,6 +7,7 @@ module Cyborg
7
7
  tags = ''
8
8
 
9
9
  stylesheet_url(args).each do |url|
10
+ url += '.gz' if Cyborg.production?
10
11
  tags += stylesheet_link_tag(url, options)
11
12
  end
12
13
 
@@ -19,6 +20,7 @@ module Cyborg
19
20
 
20
21
  puts "searching for: #{javascript_url(args)}"
21
22
  javascript_url(args).each do |url|
23
+ url += '.gz' if Cyborg.production?
22
24
  tags += javascript_include_tag(url, options)
23
25
  end
24
26
 
@@ -7,6 +7,7 @@ module Cyborg
7
7
  @name = options.delete(:name)
8
8
  @module_name = parent_module.name
9
9
  @gem = Gem.loaded_specs[@name]
10
+ @maps = false
10
11
  config(options)
11
12
  expand_asset_paths
12
13
 
@@ -60,12 +61,19 @@ module Cyborg
60
61
  assets
61
62
  end
62
63
 
64
+ def maps?
65
+ @maps == true
66
+ end
67
+
63
68
  def svgs?
64
69
  @svgs.icons.nil?
65
70
  end
66
71
 
67
72
  def build(options={})
68
- FileUtils.mkdir_p(File.join(destination, asset_root))
73
+ @maps = options[:maps] || Cyborg.production?
74
+ root = File.join(destination, asset_root)
75
+ FileUtils.rm_rf(root) if Cyborg.production?
76
+ FileUtils.mkdir_p(root)
69
77
  threads = []
70
78
  assets(options).each do |asset|
71
79
  threads << Thread.new { asset.build }
@@ -75,6 +83,7 @@ module Cyborg
75
83
  end
76
84
 
77
85
  def watch(options)
86
+ @maps = options[:maps] || Cyborg.production?
78
87
  assets(options).map(&:watch)
79
88
  end
80
89
 
@@ -47,8 +47,6 @@ module Cyborg
47
47
  # Determine if an NPM module is installed by checking paths with `npm ls`
48
48
  # Returns path to binary if installed
49
49
  def find_node_module(cmd)
50
-
51
- system "$(npm bin)/#{cmd}"
52
50
  response = Open3.capture3("npm ls #{cmd}")
53
51
 
54
52
  # Look in local `./node_modules` path.
@@ -110,6 +108,22 @@ module Cyborg
110
108
  list
111
109
  end
112
110
 
111
+ def compress(file)
112
+ return unless Cyborg.production?
113
+ mtime = File.mtime(file)
114
+ gz_file = "#{file}.gz"
115
+ return if File.exist?(gz_file) && File.mtime(gz_file) >= mtime
116
+
117
+ File.open(gz_file, "wb") do |dest|
118
+ gz = Zlib::GzipWriter.new(dest, Zlib::BEST_COMPRESSION)
119
+ gz.mtime = mtime.to_i
120
+ IO.copy_stream(open(file), gz)
121
+ gz.close
122
+ end
123
+
124
+ File.utime(mtime, mtime, gz_file)
125
+ end
126
+
113
127
  end
114
128
  end
115
129
  end
@@ -13,7 +13,10 @@ module Cyborg
13
13
  if Open3.capture3("npm ls browserify-incremental")[1].empty?
14
14
  find_files.each do |file|
15
15
  dest = destination(file).sub(/\.js$/,'')
16
- system "browserifyinc --cachefile #{Cyborg.rails_path("tmp/cache/assets/.browserify-cache.json")} #{file} -t babelify --standalone #{plugin.module_name} -o #{dest}.js -d -p [ minifyify --map #{url(file).sub(/\.js$/,'')}.map.json --output #{dest}.map.json ]"
16
+ cmd = "browserifyinc --cachefile #{Cyborg.rails_path("tmp/cache/assets/.browserify-cache.json")} #{file} -t babelify --standalone #{plugin.module_name} -o #{dest}.js -d"
17
+ cmd += " -p [ minifyify --map #{url(file).sub(/\.js$/,'')}.map.json --output #{dest}.map.json ]" if plugin.maps? || Cyborg.production?
18
+ system cmd
19
+ compress(destination(file))
17
20
  puts build_msg(file)
18
21
  end
19
22
  else
@@ -28,16 +28,12 @@ module Cyborg
28
28
 
29
29
  def build_css(file)
30
30
  system "cp #{file} #{destination(file)}"
31
+ compress(destination(file))
31
32
  end
32
33
 
33
34
  def build_sass(file)
34
- style = 'nested'
35
- sourcemap = 'auto'
36
-
37
- if Cyborg.production?
38
- style = "compressed"
39
- sourcemap = 'false'
40
- end
35
+ style = Cyborg.production? ? "compressed" : 'nested'
36
+ sourcemap = plugin.maps? ? 'auto' : 'false'
41
37
 
42
38
  dest = destination(file)
43
39
 
@@ -45,6 +41,7 @@ module Cyborg
45
41
 
46
42
  dest = destination(file)
47
43
  npm_command "postcss --use autoprefixer #{dest} -o #{dest}"
44
+ compress(dest)
48
45
  end
49
46
 
50
47
 
@@ -1,3 +1,3 @@
1
1
  module Cyborg
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyborg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-19 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -155,7 +155,6 @@ files:
155
155
  - lib/cyborg.rb
156
156
  - lib/cyborg/assets.rb
157
157
  - lib/cyborg/command.rb
158
- - lib/cyborg/command/compress.rb
159
158
  - lib/cyborg/command/help.rb
160
159
  - lib/cyborg/command/npm.rb
161
160
  - lib/cyborg/command/scaffold.rb
@@ -1,24 +0,0 @@
1
- module Cyborg
2
- module GZIP
3
- ZIP_TYPES = /\.(?:css|html|js|otf|svg|txt|xml)$/
4
-
5
- def compress(glob)
6
- Dir["#{Cyborg.config[:paths][:output]}/#{glob}"].each do |f|
7
- next unless f =~ ZIP_TYPES
8
-
9
- mtime = File.mtime(f)
10
- gz_file = "#{f}.gz"
11
- next if File.exist?(gz_file) && File.mtime(gz_file) >= mtime
12
-
13
- File.open(gz_file, "wb") do |dest|
14
- gz = Zlib::GzipWriter.new(dest, Zlib::BEST_COMPRESSION)
15
- gz.mtime = mtime.to_i
16
- IO.copy_stream(open(f), gz)
17
- gz.close
18
- end
19
-
20
- File.utime(mtime, mtime, gz_file)
21
- end
22
- end
23
- end
24
- end