crawlscope 0.7.0 → 0.7.1
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +19 -10
- data/lib/crawlscope/version.rb +1 -1
- data/lib/crawlscope.rb +1 -0
- data/lib/generators/crawlscope/install_generator.rb +37 -0
- data/lib/generators/crawlscope/templates/initializer.rb.tt +27 -0
- data/test/crawlscope/install_generator_test.rb +58 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 34b82022958c0d4bbc782e95ee899e555932d764050bb20f940c6ffaeb754cc1
|
|
4
|
+
data.tar.gz: 2587fd40b220f51d9752196323953abd2af194c95e480e52aa432259ec9f263b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 589b924f5f5a627e988156a77ca280c7f8a8ae4a8602bb0ff9fb4d59b449b18c546eab14fbbeb22ad02aee1d2ccfb79a9e5e2e5af870d06c15e057a30c404187
|
|
7
|
+
data.tar.gz: 327e346ca6a0702ae37b37cdf413443b578042f06a43306b87d14d8fc0d165480c952da6ba36ef483d1cec76125bbc1226d6e8ae3acf3c836dc737e3970330e1
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.7.1] - 2026-07-21
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- add lazy install generator
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
8
17
|
## [0.7.0] - 2026-07-21
|
|
9
18
|
|
|
10
19
|
|
data/README.md
CHANGED
|
@@ -146,20 +146,18 @@ puts result.issues.to_a.map(&:message)
|
|
|
146
146
|
|
|
147
147
|
## Rails Usage
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
only when a Crawlscope task is requested. In the application's `Rakefile`,
|
|
151
|
-
before `require_relative "config/application"`:
|
|
149
|
+
Run the install generator after adding the gem:
|
|
152
150
|
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
require "crawlscope/tasks" if list_tasks || ARGV.any? { |argument| argument.start_with?("crawlscope:") }
|
|
151
|
+
```bash
|
|
152
|
+
bin/rails generate crawlscope:install
|
|
156
153
|
```
|
|
157
154
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
The generator creates `config/initializers/crawlscope.rb` with an idempotent
|
|
156
|
+
`CrawlscopeConfiguration.apply` loader and adds conditional `crawlscope/tasks`
|
|
157
|
+
loading to the application's `Rakefile`. This preserves `bin/rails --tasks` and
|
|
158
|
+
the `crawlscope:*` tasks without loading Crawlscope during normal Rails boot.
|
|
161
159
|
|
|
162
|
-
|
|
160
|
+
Customize the `Crawlscope.configure` block inside the generated initializer:
|
|
163
161
|
|
|
164
162
|
```ruby
|
|
165
163
|
Crawlscope.configure do |config|
|
|
@@ -170,6 +168,17 @@ Crawlscope.configure do |config|
|
|
|
170
168
|
end
|
|
171
169
|
```
|
|
172
170
|
|
|
171
|
+
Runtime callers must apply the generated configuration before using
|
|
172
|
+
Crawlscope:
|
|
173
|
+
|
|
174
|
+
```ruby
|
|
175
|
+
CrawlscopeConfiguration.apply
|
|
176
|
+
Crawlscope.configuration.audit
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Rake tasks apply it automatically because `crawlscope/tasks` loads the gem
|
|
180
|
+
before Rails evaluates the initializer.
|
|
181
|
+
|
|
173
182
|
Then run:
|
|
174
183
|
|
|
175
184
|
```bash
|
data/lib/crawlscope/version.rb
CHANGED
data/lib/crawlscope.rb
CHANGED
|
@@ -27,6 +27,7 @@ module Crawlscope
|
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
Crawlscope.instance_variable_set(:@loader, Zeitwerk::Loader.for_gem)
|
|
30
|
+
Crawlscope.loader.ignore("#{__dir__}/generators")
|
|
30
31
|
Crawlscope.loader.ignore("#{__dir__}/tasks")
|
|
31
32
|
Crawlscope.loader.ignore("#{__dir__}/crawlscope/railtie.rb")
|
|
32
33
|
Crawlscope.loader.ignore("#{__dir__}/crawlscope/tasks.rb")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators"
|
|
4
|
+
|
|
5
|
+
module Crawlscope
|
|
6
|
+
module Generators
|
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
|
9
|
+
|
|
10
|
+
desc "Create a lazy-safe Crawlscope initializer and task loader"
|
|
11
|
+
|
|
12
|
+
def create_initializer
|
|
13
|
+
template "initializer.rb.tt", "config/initializers/crawlscope.rb"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def configure_rakefile
|
|
17
|
+
rakefile = File.join(destination_root, "Rakefile")
|
|
18
|
+
return unless File.exist?(rakefile)
|
|
19
|
+
return if File.read(rakefile).include?('require "crawlscope/tasks"')
|
|
20
|
+
|
|
21
|
+
inject_into_file "Rakefile", rakefile_setup, before: /^require_relative ["']config\/application["']/
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def rakefile_setup
|
|
27
|
+
<<~RUBY
|
|
28
|
+
crawlscope_tasks_requested = Rake.application.options.show_tasks ||
|
|
29
|
+
ARGV.any? { |argument| ["-T", "--tasks"].include?(argument) }
|
|
30
|
+
require "crawlscope/tasks" if crawlscope_tasks_requested ||
|
|
31
|
+
ARGV.any? { |argument| argument.start_with?("crawlscope:") }
|
|
32
|
+
|
|
33
|
+
RUBY
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module CrawlscopeConfiguration
|
|
4
|
+
MUTEX = Mutex.new
|
|
5
|
+
|
|
6
|
+
def self.apply
|
|
7
|
+
return if @applied
|
|
8
|
+
|
|
9
|
+
MUTEX.synchronize do
|
|
10
|
+
return if @applied
|
|
11
|
+
|
|
12
|
+
require "crawlscope"
|
|
13
|
+
|
|
14
|
+
Crawlscope.configure do |config|
|
|
15
|
+
config.base_url = -> { ENV.fetch("CRAWLSCOPE_BASE_URL", "http://localhost:3000") }
|
|
16
|
+
config.sitemap_path = lambda {
|
|
17
|
+
ENV.fetch("SITEMAP", Rails.public_path.join("sitemap.xml").to_s)
|
|
18
|
+
}
|
|
19
|
+
config.site_name = ENV.fetch("CRAWLSCOPE_SITE_NAME", "Application")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@applied = true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
CrawlscopeConfiguration.apply if defined?(Crawlscope)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
require "generators/crawlscope/install_generator"
|
|
5
|
+
require "open3"
|
|
6
|
+
require "rbconfig"
|
|
7
|
+
|
|
8
|
+
class CrawlscopeInstallGeneratorTest < Minitest::Test
|
|
9
|
+
def test_generates_lazy_initializer_and_task_loader
|
|
10
|
+
Dir.mktmpdir do |destination|
|
|
11
|
+
File.write(File.join(destination, "Rakefile"), <<~RUBY)
|
|
12
|
+
require_relative "config/application"
|
|
13
|
+
Rails.application.load_tasks
|
|
14
|
+
RUBY
|
|
15
|
+
|
|
16
|
+
Crawlscope::Generators::InstallGenerator.start([], destination_root: destination)
|
|
17
|
+
|
|
18
|
+
initializer = File.join(destination, "config/initializers/crawlscope.rb")
|
|
19
|
+
rakefile = File.read(File.join(destination, "Rakefile"))
|
|
20
|
+
|
|
21
|
+
assert File.exist?(initializer)
|
|
22
|
+
assert_includes File.read(initializer), "module CrawlscopeConfiguration"
|
|
23
|
+
assert_includes File.read(initializer), "CrawlscopeConfiguration.apply if defined?(Crawlscope)"
|
|
24
|
+
assert_includes rakefile, 'require "crawlscope/tasks"'
|
|
25
|
+
assert_operator rakefile.index('require "crawlscope/tasks"'), :<, rakefile.index('require_relative "config/application"')
|
|
26
|
+
|
|
27
|
+
_stdout, stderr, status = Open3.capture3(RbConfig.ruby, initializer)
|
|
28
|
+
assert status.success?, stderr
|
|
29
|
+
|
|
30
|
+
script = <<~RUBY
|
|
31
|
+
require "pathname"
|
|
32
|
+
|
|
33
|
+
module Rails
|
|
34
|
+
def self.public_path
|
|
35
|
+
Pathname.new("public")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
require "crawlscope"
|
|
40
|
+
load ARGV.fetch(0)
|
|
41
|
+
|
|
42
|
+
configuration = Crawlscope.configuration
|
|
43
|
+
CrawlscopeConfiguration.apply
|
|
44
|
+
abort "configuration replaced" unless Crawlscope.configuration.equal?(configuration)
|
|
45
|
+
abort "base URL missing" unless configuration.base_url == "http://localhost:3000"
|
|
46
|
+
abort "sitemap missing" unless configuration.sitemap_path == "public/sitemap.xml"
|
|
47
|
+
RUBY
|
|
48
|
+
_stdout, stderr, status = Open3.capture3(
|
|
49
|
+
RbConfig.ruby,
|
|
50
|
+
"-I#{File.expand_path("../../lib", __dir__)}",
|
|
51
|
+
"-e",
|
|
52
|
+
script,
|
|
53
|
+
initializer
|
|
54
|
+
)
|
|
55
|
+
assert status.success?, stderr
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: crawlscope
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paulo Fidalgo
|
|
@@ -259,6 +259,8 @@ files:
|
|
|
259
259
|
- lib/crawlscope/tasks.rb
|
|
260
260
|
- lib/crawlscope/url.rb
|
|
261
261
|
- lib/crawlscope/version.rb
|
|
262
|
+
- lib/generators/crawlscope/install_generator.rb
|
|
263
|
+
- lib/generators/crawlscope/templates/initializer.rb.tt
|
|
262
264
|
- lib/tasks/crawlscope_tasks.rake
|
|
263
265
|
- test/crawlscope/browser_test.rb
|
|
264
266
|
- test/crawlscope/cli_test.rb
|
|
@@ -269,6 +271,7 @@ files:
|
|
|
269
271
|
- test/crawlscope/fetch_executor_test.rb
|
|
270
272
|
- test/crawlscope/http_test.rb
|
|
271
273
|
- test/crawlscope/indexability_rule_test.rb
|
|
274
|
+
- test/crawlscope/install_generator_test.rb
|
|
272
275
|
- test/crawlscope/links_rule_test.rb
|
|
273
276
|
- test/crawlscope/loader_test.rb
|
|
274
277
|
- test/crawlscope/metadata_rule_test.rb
|