torba 0.5.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +6 -2
- data/.yardopts +2 -0
- data/CHANGELOG.md +59 -0
- data/README.md +16 -78
- data/lib/torba.rb +15 -1
- data/lib/torba/cli.rb +45 -0
- data/lib/torba/css_url_to_erb_asset_path.rb +5 -1
- data/lib/torba/manifest.rb +11 -1
- data/lib/torba/package.rb +12 -8
- data/lib/torba/rake_task.rb +10 -3
- data/lib/torba/remote_sources/common.rb +1 -1
- data/lib/torba/remote_sources/targz.rb +1 -1
- data/lib/torba/ui.rb +13 -0
- data/lib/torba/verify.rb +4 -11
- data/test/acceptance-cli/open_test.rb +101 -0
- data/test/acceptance-cli/pack_test.rb +49 -0
- data/test/acceptance-cli/show_test.rb +61 -0
- data/test/acceptance-cli/verify_test.rb +25 -0
- data/test/css_url_to_erb_asset_path_test.rb +5 -0
- data/test/fixtures/home_path/01/trumbowyg/icons-2x.png +0 -0
- data/test/fixtures/home_path/01/trumbowyg/icons.png +0 -0
- data/test/fixtures/home_path/01/trumbowyg/trumbowyg.css.erb +471 -0
- data/test/fixtures/home_path/01/trumbowyg/trumbowyg.js +1124 -0
- data/test/fixtures/home_path/02/lo_dash/lodash.js +2793 -0
- data/test/fixtures/home_path/03/bourbon/_border-image.scss +59 -0
- data/test/fixtures/home_path/03/bourbon/_font-source-declaration.scss +43 -0
- data/test/fixtures/home_path/03/bourbon/_retina-image.scss +25 -0
- data/test/fixtures/torbafiles/01_gh_release.rb +8 -0
- data/test/fixtures/torbafiles/01_image_asset_not_specified.rb +7 -0
- data/test/fixtures/torbafiles/01_targz.rb +7 -0
- data/test/fixtures/torbafiles/01_zip.rb +7 -0
- data/test/fixtures/torbafiles/02_npm.rb +1 -0
- data/test/fixtures/torbafiles/03_not_existed_assets.rb +5 -0
- data/test/fixtures/torbafiles/04_similar_names.rb +2 -0
- data/test/manifest_test.rb +27 -0
- data/test/package_test.rb +10 -0
- data/test/rake_task_test.rb +13 -0
- data/test/test_helper.rb +55 -8
- data/test/torba_test.rb +13 -0
- data/torba.gemspec +5 -4
- metadata +73 -18
- data/lib/torba/rails.rb +0 -13
- data/test/acceptance_test.rb +0 -87
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69ed394ec8286280a4b97265fb95dd36abb8bc5a57439ae1941963105186a433
|
4
|
+
data.tar.gz: f46c8d171e7b3c5e2771cf58358db711b3fe3b1c05b1a55b5bff79da76485bab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e44c0cf8d1026f64f4dc75b8c5e6bda0f684c5ea8a5359f3238a057b5427562f819f5762a563f85989d450b3a1593a2d730797f25202276685667b6ccebb7a4
|
7
|
+
data.tar.gz: cfa4245b61895fad5fd22449e56933cfa001adeb140412ac298807aeb3fc4f12335737f748959c50c18140f68b494148745ae072821e8057d7062898607bf2ee
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,64 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
## Version 1.1.0
|
4
|
+
|
5
|
+
### Enhancements
|
6
|
+
|
7
|
+
* Thor dependency has been relaxed to support Rails 6.x.
|
8
|
+
|
9
|
+
## Version 1.0.1
|
10
|
+
|
11
|
+
### Bug fixes
|
12
|
+
|
13
|
+
* Fix unpacking tar.gz when running on unpriveleged containers
|
14
|
+
|
15
|
+
## Version 1.0.0
|
16
|
+
|
17
|
+
### Breaking changes
|
18
|
+
|
19
|
+
* Rails support has been removed. Use [torba-rails][torba-rails] instead.
|
20
|
+
* `torba/verify` no longer checks, whether it is executed within Rake task
|
21
|
+
or not. This was a workaround for Rails support, which is no longer a goal
|
22
|
+
of this gem.
|
23
|
+
* `torba/verify` no longer checks `TORBA_DONT_VERIFY` env variable. Same as
|
24
|
+
above.
|
25
|
+
|
26
|
+
### Upgrading notes
|
27
|
+
|
28
|
+
If you are a non-Rails user, this should be a non-breaking update. In rare cases,
|
29
|
+
when you depend on old behaviour of `torba/verify`, please, add the conditionals
|
30
|
+
to your application code.
|
31
|
+
|
32
|
+
Rails users should:
|
33
|
+
|
34
|
+
1. Replace `gem "torba"` with `gem "torba-rails"` in the Gemfile.
|
35
|
+
2. Remove `require "torba/verify"` from `boot.rb`.
|
36
|
+
3. Remove `require "torba/rails"` from `application.rb`.
|
37
|
+
4. Unset obsolete `TORBA_DONT_VERIFY` env variable if present.
|
38
|
+
|
39
|
+
### Enhancements
|
40
|
+
|
41
|
+
* Rake task accepts a block to be executed before packing process
|
42
|
+
|
43
|
+
[torba-rails]: https://github.com/torba-rb/torba-rails
|
44
|
+
|
45
|
+
## Version 0.7.0
|
46
|
+
|
47
|
+
### Enhancements
|
48
|
+
|
49
|
+
* `torba show` command
|
50
|
+
* `torba open` command
|
51
|
+
|
52
|
+
## Version 0.6.0
|
53
|
+
|
54
|
+
### Enhancements
|
55
|
+
|
56
|
+
* Torba.cache_path= setter
|
57
|
+
|
58
|
+
### Bug fixes
|
59
|
+
|
60
|
+
* Handle stylesheets that mention nonexisting assets (e.g. with SCSS variables)
|
61
|
+
|
3
62
|
## Version 0.5.1
|
4
63
|
|
5
64
|
### Bug fixes
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Production ready.
|
|
17
17
|
|
18
18
|
## Documentation
|
19
19
|
|
20
|
-
[Released version](http://rubydoc.info/gems/torba/
|
20
|
+
[Released version](http://rubydoc.info/gems/torba/1.1.0)
|
21
21
|
|
22
22
|
## Why
|
23
23
|
|
@@ -53,29 +53,20 @@ Problems with the Bower:
|
|
53
53
|
|
54
54
|
## Installation
|
55
55
|
|
56
|
-
|
56
|
+
### Rails
|
57
57
|
|
58
|
-
|
59
|
-
gem 'torba'
|
60
|
-
```
|
58
|
+
Use [torba-rails][torba-rails-github].
|
61
59
|
|
62
|
-
###
|
60
|
+
### Sinatra
|
63
61
|
|
64
|
-
|
62
|
+
See this [example project][sinatra-example].
|
65
63
|
|
66
|
-
|
67
|
-
require 'bundler/setup' # Set up gems listed in the Gemfile.
|
68
|
-
+require 'torba/verify'
|
69
|
-
```
|
64
|
+
### Other Ruby application
|
70
65
|
|
71
|
-
|
66
|
+
Add this line to your application's Gemfile and run bundle:
|
72
67
|
|
73
|
-
```
|
74
|
-
|
75
|
-
# you've limited to :test, :development, or :production.
|
76
|
-
Bundler.require(*Rails.groups)
|
77
|
-
+
|
78
|
-
+require 'torba/rails'
|
68
|
+
```ruby
|
69
|
+
gem 'torba'
|
79
70
|
```
|
80
71
|
|
81
72
|
## Usage
|
@@ -87,14 +78,8 @@ in config/application.rb
|
|
87
78
|
3. Add "require" [Sprockets directives][sprockets-directives] to your "application.js"
|
88
79
|
and/or "@import" [Sass directives][sass-import] to "application.css".
|
89
80
|
|
90
|
-
4. Non JS/CSS assets are automatically added to precompile list, nothing to do here.
|
91
|
-
|
92
81
|
If any changes made to the Torbafile, run `bundle exec torba pack` again.
|
93
82
|
|
94
|
-
### Examples
|
95
|
-
|
96
|
-
See fully configured [Rails application][rails-example].
|
97
|
-
|
98
83
|
### Torbafile
|
99
84
|
|
100
85
|
Torbafile is an assets specification. It is a plain text file that contains one or more
|
@@ -179,6 +164,10 @@ You can omit the name, it will be equal to the package name:
|
|
179
164
|
npm package: "coffee-script", version: "1.9.2"
|
180
165
|
```
|
181
166
|
|
167
|
+
### Examples
|
168
|
+
|
169
|
+
See [Torbafiles][torbafile-examples] used for testing.
|
170
|
+
|
182
171
|
### "Packing the torba" process
|
183
172
|
|
184
173
|
When you run `torba pack` the following happens:
|
@@ -248,58 +237,6 @@ gh_release "lightslider", source: "sachinchoolur/lightslider", tag: "1.1.2", imp
|
|
248
237
|
|
249
238
|
In addition to this "path/" is treated as a shortcut for "path/**/*" glob pattern.
|
250
239
|
|
251
|
-
Be careful to **import only that you really need**. Everything that is non JS or CSS asset is
|
252
|
-
going to be precompiled by Sprockets and accessible publicly. See [Rails ticket][rails-ticket-vendoring]
|
253
|
-
that explains this problem (and why Rails >= 4 precompiles only application.js/css in vendor by
|
254
|
-
default), except that Torba does have a way to specify exact list of files to import.
|
255
|
-
|
256
|
-
## Deployment
|
257
|
-
|
258
|
-
In Rails apps, Torba automatically hooks into the existing `assets:precompile`
|
259
|
-
Rake task to ensure that `torba pack` is executed. This means that Rails
|
260
|
-
deployments will "just work", although there are some optimizations you can make
|
261
|
-
as explained below.
|
262
|
-
|
263
|
-
### Heroku
|
264
|
-
|
265
|
-
You will need to specify some config vars to ensure Torba's files are placed in
|
266
|
-
locations suitable for the Heroku platform.
|
267
|
-
|
268
|
-
`TORBA_HOME_PATH` should be within your app so that Torba's assets are included
|
269
|
-
in the slug.
|
270
|
-
|
271
|
-
`TORBA_CACHE_PATH` should make use of the `tmp/cache/assets` directory. This is
|
272
|
-
where the Ruby buildpack expects cached files to be stored related to the
|
273
|
-
`assets:precompile` step. This way Torba doesn't have to download packages fresh
|
274
|
-
every time.
|
275
|
-
|
276
|
-
```bash
|
277
|
-
heroku config:set TORBA_HOME_PATH=vendor/torba TORBA_CACHE_PATH=tmp/cache/assets/torba
|
278
|
-
```
|
279
|
-
|
280
|
-
Now your Heroku app is good to go.
|
281
|
-
|
282
|
-
### Capistrano
|
283
|
-
|
284
|
-
Specify the `TORBA_HOME_PATH` env variable pointing to a persistent directory
|
285
|
-
writable by your deploy user and shared across releases. Capistrano's `shared`
|
286
|
-
directory is good for this.
|
287
|
-
|
288
|
-
For Capistrano 3, you can set this up in `config/deploy.rb`:
|
289
|
-
```
|
290
|
-
set :default_env, { torba_home_path: shared_path.join('vendor/torba') }
|
291
|
-
```
|
292
|
-
|
293
|
-
### Troubleshooting
|
294
|
-
|
295
|
-
If you are getting an error like `Your Torba is not packed yet` when trying to
|
296
|
-
run `rake assets:precompile` (or `bin/rails assets:precompile` in Rails 5),
|
297
|
-
set the `TORBA_DONT_VERIFY` environment variable, like this:
|
298
|
-
|
299
|
-
```bash
|
300
|
-
TORBA_DONT_VERIFY=1 bin/rake assets:precompile
|
301
|
-
```
|
302
|
-
|
303
240
|
[bower]: http://bower.io/
|
304
241
|
[sprockets]: https://github.com/rails/sprockets/
|
305
242
|
[sprockets-load-path]: https://github.com/rails/sprockets#the-load-path
|
@@ -310,6 +247,7 @@ TORBA_DONT_VERIFY=1 bin/rake assets:precompile
|
|
310
247
|
[rails-assets]: https://rails-assets.org/
|
311
248
|
[bower-rails]: https://github.com/rharriso/bower-rails
|
312
249
|
[semver]: http://semver.org/
|
313
|
-
[rails-ticket-vendoring]: https://github.com/rails/rails/pull/7968
|
314
250
|
[npm]: https://npmjs.com
|
315
|
-
[rails-
|
251
|
+
[torba-rails-github]: https://github.com/torba-rb/torba-rails
|
252
|
+
[sinatra-example]: https://github.com/xfalcox/sinatra-assets-seed
|
253
|
+
[torbafile-examples]: https://github.com/torba-rb/torba/tree/master/test/fixtures/torbafiles
|
data/lib/torba.rb
CHANGED
@@ -30,6 +30,14 @@ module Torba
|
|
30
30
|
@cache_path ||= ENV["TORBA_CACHE_PATH"] || File.join(home_path, "cache")
|
31
31
|
end
|
32
32
|
|
33
|
+
# Override cache path with a new value
|
34
|
+
# @param val [String] new cache path
|
35
|
+
# @return [void]
|
36
|
+
# @since 0.6.0
|
37
|
+
def self.cache_path=(val)
|
38
|
+
@cache_path = val
|
39
|
+
end
|
40
|
+
|
33
41
|
# @return [Ui]
|
34
42
|
def self.ui
|
35
43
|
@ui ||= Ui.new
|
@@ -70,6 +78,12 @@ module Torba
|
|
70
78
|
Digest::SHA1.hexdigest(string)[0..7]
|
71
79
|
end
|
72
80
|
|
81
|
+
# @see Manifest#find_packages_by_name
|
82
|
+
# @since 0.7.0
|
83
|
+
def self.find_packages_by_name(name)
|
84
|
+
manifest.find_packages_by_name(name)
|
85
|
+
end
|
86
|
+
|
73
87
|
# @yield a block, converts common exceptions into useful messages
|
74
88
|
def self.pretty_errors
|
75
89
|
yield
|
@@ -90,7 +104,7 @@ module Torba
|
|
90
104
|
ui.suggest "Make sure that the path has trailing '/' if its a directory."
|
91
105
|
exit(false)
|
92
106
|
rescue Errors::AssetNotFound => e
|
93
|
-
ui.error "
|
107
|
+
ui.error "Unknown asset to process with path '#{e.message}'."
|
94
108
|
ui.suggest "Make sure that you've imported all image/font assets mentioned in a stylesheet(-s)."
|
95
109
|
exit(false)
|
96
110
|
end
|
data/lib/torba/cli.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "thor"
|
2
|
+
require "shellwords"
|
2
3
|
require "torba"
|
3
4
|
|
4
5
|
module Torba
|
@@ -15,5 +16,49 @@ module Torba
|
|
15
16
|
Torba.pretty_errors { Torba.verify }
|
16
17
|
Torba.ui.confirm "Torba is prepared!"
|
17
18
|
end
|
19
|
+
|
20
|
+
desc "show PACKAGE", "show the source location of a particular package"
|
21
|
+
def show(name)
|
22
|
+
Torba.pretty_errors do
|
23
|
+
Torba.pack
|
24
|
+
Torba.ui.info(find_package(name).load_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "open PACKAGE", "open a particular package in editor"
|
29
|
+
def open(name)
|
30
|
+
editor = [ENV["TORBA_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find { |e| !e.nil? && !e.empty? }
|
31
|
+
unless editor
|
32
|
+
Torba.ui.error("To open a package, set $EDITOR or $TORBA_EDITOR")
|
33
|
+
exit(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
Torba.pretty_errors do
|
37
|
+
Torba.pack
|
38
|
+
|
39
|
+
command = Shellwords.split(editor) << find_package(name).load_path
|
40
|
+
system(*command) || Torba.ui.error("Could not run '#{command.join(" ")}'")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def find_package(name)
|
47
|
+
packages = Torba.find_packages_by_name(name)
|
48
|
+
case packages.size
|
49
|
+
when 0
|
50
|
+
Torba.ui.error "Could not find package '#{name}'."
|
51
|
+
exit(false)
|
52
|
+
when 1
|
53
|
+
packages.first
|
54
|
+
else
|
55
|
+
index = Torba.ui.choose_one(packages.map(&:name))
|
56
|
+
if index
|
57
|
+
packages[index]
|
58
|
+
else
|
59
|
+
exit(false)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
18
63
|
end
|
19
64
|
end
|
@@ -52,7 +52,11 @@ module Torba
|
|
52
52
|
content.gsub(URL_RE) do
|
53
53
|
absolute_image_file_path = File.expand_path($2, File.dirname(file_path))
|
54
54
|
sprockets_file_path = yield absolute_image_file_path
|
55
|
-
|
55
|
+
if sprockets_file_path
|
56
|
+
"#{$1}<%= asset_path('#{sprockets_file_path}') %>#{$3}"
|
57
|
+
else
|
58
|
+
$&
|
59
|
+
end
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
data/lib/torba/manifest.rb
CHANGED
@@ -15,6 +15,7 @@ module Torba
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
18
19
|
# Represents Torbafile.
|
19
20
|
class Manifest
|
20
21
|
# all packages defined in Torbafile
|
@@ -28,7 +29,7 @@ module Torba
|
|
28
29
|
#
|
29
30
|
# @overload self.build
|
30
31
|
# Reads Torbafile from current directory
|
31
|
-
def self.build(file_path =
|
32
|
+
def self.build(file_path = ENV["TORBA_FILE"])
|
32
33
|
file_path ||= File.join(Dir.pwd, "Torbafile")
|
33
34
|
|
34
35
|
manifest = new
|
@@ -120,5 +121,14 @@ module Torba
|
|
120
121
|
raise Errors::MissingPackages.new(missing)
|
121
122
|
end
|
122
123
|
end
|
124
|
+
|
125
|
+
# @return [Array<Package>] where each package name at least partially matches given name.
|
126
|
+
# @since 0.7.0
|
127
|
+
def find_packages_by_name(name)
|
128
|
+
re = Regexp.new(name, Regexp::IGNORECASE)
|
129
|
+
packages.find_all do |package|
|
130
|
+
package.name =~ re
|
131
|
+
end
|
132
|
+
end
|
123
133
|
end
|
124
134
|
end
|
data/lib/torba/package.rb
CHANGED
@@ -155,18 +155,22 @@ module Torba
|
|
155
155
|
end
|
156
156
|
|
157
157
|
def process_stylesheets
|
158
|
-
import_list.css_assets.each do |
|
159
|
-
content = File.read(
|
160
|
-
|
161
|
-
new_content = CssUrlToErbAssetPath.call(content,
|
162
|
-
|
163
|
-
|
158
|
+
import_list.css_assets.each do |css_asset|
|
159
|
+
content = File.read(css_asset.absolute_path)
|
160
|
+
|
161
|
+
new_content = CssUrlToErbAssetPath.call(content, css_asset.absolute_path) do |asset_file_path|
|
162
|
+
if File.exist?(asset_file_path)
|
163
|
+
asset = import_list.find_by_absolute_path(asset_file_path)
|
164
|
+
asset.logical_path
|
165
|
+
else
|
166
|
+
nil
|
167
|
+
end
|
164
168
|
end
|
165
169
|
|
166
170
|
if content == new_content
|
167
|
-
new_absolute_path = File.join(load_path,
|
171
|
+
new_absolute_path = File.join(load_path, css_asset.logical_path)
|
168
172
|
else
|
169
|
-
new_absolute_path = File.join(load_path,
|
173
|
+
new_absolute_path = File.join(load_path, css_asset.logical_path + ".erb")
|
170
174
|
end
|
171
175
|
|
172
176
|
ensure_directory(new_absolute_path)
|
data/lib/torba/rake_task.rb
CHANGED
@@ -18,6 +18,12 @@ module Torba
|
|
18
18
|
# require "torba/rake_task"
|
19
19
|
# Torba::RakeTask.new("torba:pack", :before => "assets:precompile")
|
20
20
|
#
|
21
|
+
# You can also provide a block, which will be executed before packing process:
|
22
|
+
#
|
23
|
+
# Torba::RakeTask.new do
|
24
|
+
# # some preconfiguration to be run when the "torba:pack" task is executed
|
25
|
+
# end
|
26
|
+
#
|
21
27
|
# Note that when you require "torba/rails" in a Rails app, this Rake task is
|
22
28
|
# installed for you automatically. You only need to install the task yourself
|
23
29
|
# if you are using something different, like Sinatra.
|
@@ -25,17 +31,18 @@ module Torba
|
|
25
31
|
class RakeTask < Rake::TaskLib
|
26
32
|
attr_reader :torba_pack_task_name
|
27
33
|
|
28
|
-
def initialize(name="torba:pack", options={})
|
34
|
+
def initialize(name="torba:pack", options={}, &before_pack)
|
29
35
|
@torba_pack_task_name = name
|
30
|
-
define_task
|
36
|
+
define_task(before_pack)
|
31
37
|
install_as_prerequisite(options[:before]) if options[:before]
|
32
38
|
end
|
33
39
|
|
34
40
|
private
|
35
41
|
|
36
|
-
def define_task
|
42
|
+
def define_task(before_pack_proc)
|
37
43
|
desc "Download and prepare all packages defined in Torbafile"
|
38
44
|
task torba_pack_task_name do
|
45
|
+
before_pack_proc.call if before_pack_proc
|
39
46
|
Torba.pretty_errors { Torba.pack }
|
40
47
|
end
|
41
48
|
end
|