capistrano-faster-assets-and-packs 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f952d6737627d0543cfb7cba55778ed62fd21736d14ec5fc50a9ba62dda1b027
4
+ data.tar.gz: d506e108b114bd3fdcb63ff91fb8ccefe839fcea12facac4632d2694b9e19c9b
5
+ SHA512:
6
+ metadata.gz: ff47915e19698df4a031d434a1b069399e10d9bf8007f36e00ad0cdd948e5e884d7ef26dd54a5772d4a02336814b1a5fe718ec56e25f35ab7ae717d6ac4984af
7
+ data.tar.gz: 8c746b093d0de5f53d6c7c052f7ade40fcff3dc92cabe91ca3d5cd9b1cedb1ed350b6f6325d07326a25fca09da534629acb9dd37f425c73e6db1f907869336b0
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /vendor/ruby
19
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in *.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Andrew Thal, Ruben Stranders
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Capistrano::FasterAssets
2
+
3
+ This gem speeds up asset compilation by skipping the assets:precompile task if none of the assets were changed since last release.
4
+
5
+ **Feature**: Skipping the webpack:compile task if none of the `app/javascript/*` or `yarn.lock` changed since last release.
6
+
7
+ This Gem is fork form **capistrano-faster-assets** and one of amazing PR of this gem.
8
+ Original Gem was amazing, but unfortunately it was stop maintenance from 5 years ago. So I fork it and push this gem to rubygem.
9
+
10
+ Original Version: https://github.com/capistrano-plugins/capistrano-faster-assets
11
+ Original PR: https://github.com/AutoUncle/capistrano-faster-assets
12
+
13
+ Works *only* with Capistrano 3+.
14
+
15
+ ### Installation
16
+
17
+ Add this to `Gemfile`:
18
+
19
+ group :development do
20
+ gem 'capistrano', '~> 3.1'
21
+ gem 'capistrano-rails', '~> 1.1'
22
+ gem 'capistrano-faster-assets-and-packs', '~> 1.0'
23
+ end
24
+
25
+ And then:
26
+
27
+ $ bundle install
28
+
29
+ ### Setup and usage
30
+
31
+ #### assets compilation
32
+ Add this line to `Capfile`, after `require 'capistrano/rails/assets'`
33
+
34
+ require 'capistrano/faster_assets'
35
+
36
+ Configure your asset depedencies in deploy.rb if you need to check additional paths (e.g. if you have some assets in YOUR_APP/engines/YOUR_ENGINE/app/assets). Default paths are:
37
+
38
+ set :assets_dependencies, %w(app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb)
39
+
40
+ ### webpack compilation
41
+ Configure your webpack depedencies in deploy.rb if you need to check additional paths. Default paths are:
42
+ set :webpack_dependencies, %w(app/javascript app/yarn.lock)
43
+
44
+ Configure your webpack source_entry_packs in deploy.rb, if your `source_entry_packs` configuration in config/webpack.yml is not `packs`.
45
+ Default is:
46
+
47
+ set :webpack_entry_path, 'packs'
48
+
49
+ ### Reference
50
+
51
+ Original Gem: https://github.com/capistrano-plugins/capistrano-faster-assets
52
+ The PR Version: https://github.com/AutoUncle/capistrano-faster-assets
53
+
54
+
55
+
56
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'capistrano/faster_assets/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'capistrano-faster-assets-and-packs'
7
+ gem.version = Capistrano::FasterAssets::VERSION
8
+ gem.authors = ['Andrew Thal', 'Ruben Stranders', 'Arthur Li']
9
+ gem.email = ['athal7@me.com', 'r.stranders@gmail.com', 'z22919456@gmail.com']
10
+ gem.description = <<-EOF.gsub(/^\s+/, '')
11
+ Speeds up asset compilation by skipping the assets:precompile task if none of the assets were changed since last release.
12
+ And also skiping the webpack:compile task if nonoe of the app/javascript or yarn.lock changed since last release.
13
+
14
+ This Gem is fork form *capistrano-faster-assets* and one of amazing PR in this gem
15
+
16
+ Original Version: https://github.com/capistrano-plugins/capistrano-faster-assets
17
+ Original PR: https://github.com/AutoUncle/capistrano-faster-assets
18
+
19
+
20
+
21
+ Works *only* with Capistrano 3+.
22
+
23
+ Based on https://coderwall.com/p/aridag
24
+ EOF
25
+ gem.summary = 'Speeds up asset compilation if none of the assets were changed since last release.'
26
+ gem.homepage = 'https://github.com/z22919456/capistrano-faster-assets-and-packs'
27
+
28
+ gem.files = `git ls-files`.split($/)
29
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
30
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
31
+ gem.require_paths = ['lib']
32
+
33
+ gem.add_dependency 'capistrano', '>= 3.1'
34
+ gem.add_development_dependency 'rake'
35
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module FasterAssets
3
+ VERSION = '1.2.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../tasks/faster_assets.rake", __FILE__)
@@ -0,0 +1,133 @@
1
+ # Original source: https://coderwall.com/p/aridag
2
+ # Original Gem: https://github.com/capistrano-plugins/capistrano-faster-assets
3
+ # Original PR: https://github.com/AutoUncle/capistrano-faster-assets
4
+
5
+ # set the locations that we will look for changed assets to determine whether to precompile
6
+ set :assets_dependencies, %w[app/assets lib/assets vendor/assets Gemfile.lock config/routes.rb]
7
+ set :webpack_dependencies, %w[app/javascript yarn.lock package-lock.json]
8
+ set :force_precompile, false
9
+ set :webpack_entry_path, 'packs'
10
+
11
+ # clear the previous precompile task
12
+ Rake::Task['deploy:assets:precompile'].clear_actions
13
+ class PrecompileRequired < StandardError; end
14
+ class WebpackCompileRequired < StandardError; end
15
+
16
+ namespace :deploy do
17
+ namespace :assets do
18
+ desc 'Precompile assets'
19
+ task :precompile do
20
+ on roles(fetch(:assets_roles)) do
21
+ within release_path do
22
+ with rails_env: fetch(:rails_env) do
23
+ raise PrecompileRequired, 'A forced precompile was triggered' if fetch(:force_precompile)
24
+
25
+ # find the most recent release
26
+ latest_release = capture(:ls, '-xr', releases_path).split[1]
27
+
28
+ # precompile if this is the first deploy
29
+ raise PrecompileRequired, 'Fresh deployment detected (no previous releases present)' unless latest_release
30
+
31
+ latest_release_path = releases_path.join(latest_release)
32
+
33
+ # precompile if the previous deploy failed to finish precompiling
34
+ begin
35
+ execute(:ls, latest_release_path.join('assets_manifest_backup'))
36
+ rescue StandardError
37
+ raise PrecompileRequired,
38
+ 'The previous deployment does not have any assets_manifest_backup this indicates precompile was not successful'
39
+ end
40
+
41
+ ### Check Assets
42
+
43
+ fetch(:assets_dependencies).each do |dep|
44
+ release = release_path.join(dep)
45
+ latest = latest_release_path.join(dep)
46
+
47
+ # skip if both directories/files do not exist
48
+ next if [release, latest].map { |d| test "[ -e #{d} ]" }.uniq == [false]
49
+
50
+ # execute raises if there is a diff
51
+ begin
52
+ execute(:diff, '-Nqr', release, latest)
53
+ rescue StandardError
54
+ raise PrecompileRequired, "Found a difference between the current and the new version of: #{dep}"
55
+ end
56
+ end
57
+
58
+ # copy over all of the assets from the last release
59
+ release_asset_path = release_path.join('public', fetch(:assets_prefix))
60
+ # skip if assets directory is symlink
61
+ begin
62
+ execute(:test, '-L', release_asset_path.to_s)
63
+ rescue StandardError
64
+ execute(:cp, '-r', latest_release_path.join('public', fetch(:assets_prefix)), release_asset_path.parent)
65
+ end
66
+
67
+ # check that the manifest has been created correctly, if not
68
+ # trigger a precompile
69
+ begin
70
+ # Support sprockets 2
71
+ execute(:ls, release_asset_path.join('manifest*'))
72
+ rescue StandardError
73
+ begin
74
+ # Support sprockets 3
75
+ execute(:ls, release_asset_path.join('.sprockets-manifest*'))
76
+ rescue StandardError
77
+ raise PrecompileRequired, 'No sprockets-manifest found'
78
+ end
79
+ end
80
+
81
+ ### Check Webpack
82
+ fetch(:webpack_dependencies).each do |dep|
83
+ release = release_path.join(dep)
84
+ latest = latest_release_path.join(dep)
85
+
86
+ # skip if both directories/files do not exist
87
+ next if [release, latest].map { |d| test "[ -e #{d} ]" }.uniq == [false]
88
+
89
+ # execute raises if there is a diff
90
+ begin
91
+ execute(:diff, '-Nqr', release, latest)
92
+ rescue StandardError
93
+ raise WebpackCompileRequired, "Found a difference between the current and the new version of: #{dep}"
94
+ end
95
+ end
96
+
97
+ # copy over all of the packs from the last release
98
+ release_webpack_path = release_path.join('public', fetch(:webpack_entry_path))
99
+ # skip if packs directory is symlink
100
+ begin
101
+ execute(:test, '-L', release_webpack_path.to_s)
102
+ rescue StandardError
103
+ begin
104
+ # check that the packs of the last release has been created, or trigger a webpack compile
105
+ execute(:cp, '-r', latest_release_path.join('public', fetch(:webpack_entry_path)),
106
+ release_webpack_path.parent)
107
+ rescue StandardError
108
+ raise WebpackCompileRequired, 'No latest packs found'
109
+ end
110
+ end
111
+
112
+ # check that the webpack manifest has been created correctly, if not
113
+ # trigger a webpack compile
114
+ begin
115
+ execute(:ls, release_webpack_path.join('manifest*'))
116
+ rescue StandardError
117
+ raise WebpackCompileRequired, 'No webpack manifest found'
118
+ end
119
+
120
+ info('Skipping webpack precompile, no asset diff found')
121
+ rescue PrecompileRequired => e
122
+ warn(e.message)
123
+ execute(:rake, 'assets:precompile')
124
+ rescue WebpackCompileRequired => e
125
+ warn(e.message)
126
+ execute(:rake, 'yarn:install')
127
+ execute(:rake, 'webpacker:compile')
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
File without changes
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-faster-assets-and-packs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Thal
8
+ - Ruben Stranders
9
+ - Arthur Li
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2022-06-28 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: capistrano
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '3.1'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ description: |
44
+ Speeds up asset compilation by skipping the assets:precompile task if none of the assets were changed since last release.
45
+ And also skiping the webpack:compile task if nonoe of the app/javascript or yarn.lock changed since last release.
46
+ This Gem is fork form *capistrano-faster-assets* and one of amazing PR in this gem
47
+ Original Version: https://github.com/capistrano-plugins/capistrano-faster-assets
48
+ Original PR: https://github.com/AutoUncle/capistrano-faster-assets
49
+ Works *only* with Capistrano 3+.
50
+ Based on https://coderwall.com/p/aridag
51
+ email:
52
+ - athal7@me.com
53
+ - r.stranders@gmail.com
54
+ - z22919456@gmail.com
55
+ executables: []
56
+ extensions: []
57
+ extra_rdoc_files: []
58
+ files:
59
+ - ".gitignore"
60
+ - Gemfile
61
+ - LICENSE.md
62
+ - README.md
63
+ - Rakefile
64
+ - capistrano-faster-assets.gemspec
65
+ - lib/capistrano-faster-assets.rb
66
+ - lib/capistrano/faster_assets.rb
67
+ - lib/capistrano/faster_assets/version.rb
68
+ - lib/capistrano/tasks/faster_assets.rake
69
+ homepage: https://github.com/z22919456/capistrano-faster-assets-and-packs
70
+ licenses: []
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.1.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Speeds up asset compilation if none of the assets were changed since last
91
+ release.
92
+ test_files: []