frontman-ssg 0.0.3 → 0.0.4

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
  SHA256:
3
- metadata.gz: 34eef05a89e8a6afd90d01f0e07fe8477e348be90b8de3b603b4b7761d93d73a
4
- data.tar.gz: 993051df2124b49cdd7df806c01a7cbe83276f155b08f93d0d4eed00fba342e9
3
+ metadata.gz: d98534ae36366f01f9b304aa66cf452d69688a68e37f33e53a3b0afab9ce328a
4
+ data.tar.gz: aa330a04fd43740fff7dfc1ef6d3e46b640a0a428070456933e24141e58d3b86
5
5
  SHA512:
6
- metadata.gz: 001edb81fb728535077e4dd34dea01ebce3eb184223a6513ce18fcef013c11eaeb601ec5a06503e26b0d0aef2ff24146c2f7bfa59c320f3fc55135dd090f56d4
7
- data.tar.gz: 98bac4af65a1747a4b9c34ffd90e991440a94156f5e2d1b33570a3d519d7aaa8e1ea15135cf0a0f7dcce40ed58333abce0e4f6350f918298719b30431ef9131a
6
+ metadata.gz: 6e23982fea37d56e567c96d9344efb5f98c02fead828861410ead02486fe7d6520eb47d0d509bfd46f57e20e4e0476c1ee69820779074afa51fb1527f985e71e
7
+ data.tar.gz: b1eab4c96e41d2a38951f8893ef29786b20ed2b31689b6c94bfd22a8263f545f9fdd250d3ce8d097fbd694558744c605e92a1d586485376929d2c295520fe335
@@ -4,6 +4,9 @@ AllCops:
4
4
  - '**/Rakefile'
5
5
  - 'vendor/**/*'
6
6
 
7
+ Style/Lambda:
8
+ Enabled: false
9
+
7
10
  Gemspec/RequiredRubyVersion:
8
11
  Exclude:
9
12
  - 'frontman-ssg.gemspec'
@@ -85,4 +88,4 @@ Metrics/ParameterLists:
85
88
 
86
89
  Lint/HandleExceptions:
87
90
  Exclude:
88
- - 'lib/frontman/commands/serve.rb'
91
+ - 'lib/frontman/commands/serve.rb'
@@ -5,19 +5,30 @@ We document all notable changes to the project in the file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [semantic versioning](http://semver.org/).
6
6
 
7
7
  # Release Notes
8
- ## [Unreleased](https://github.com/algolia/frontman/compare/0.0.3...master)
8
+ ## [Unreleased](https://github.com/algolia/frontman/compare/0.0.4...master)
9
+
10
+ ## [0.0.4](https://github.com/algolia/frontman/tree/0.0.3) - 2020-08-28
11
+
12
+ ### Added
13
+ * Retry strategy to allow for multiple running Frontman processes ([`#24`](https://github.com/algolia/frontman/pull/24)) by [@westonganger](https://github.com/westonganger)
14
+ * Added `--force` flag to the `frontman init` command ([`#29`](https://github.com/algolia/frontman/pull/29)) by [@MikeRogers0](https://github.com/MikeRogers0)
15
+ * Improved data directory registration ([`#30`](https://github.com/algolia/frontman/pull/30)) by [@westonganger](https://github.com/westonganger)
16
+ * `import_config` method to easily load multiple configuration files ([`#34`](https://github.com/algolia/frontman/pull/34)) by [@westonganger](https://github.com/westonganger)
17
+
18
+ ### Fixed
19
+ * Added `https://rubygems.org` as a source for our dependencies ([`#32`](https://github.com/algolia/frontman/pull/32)) by [@MikeRogers0](https://github.com/MikeRogers0)
9
20
 
10
21
  ## [0.0.3](https://github.com/algolia/frontman/tree/0.0.3) - 2020-08-28
11
22
 
12
- #### Added
23
+ ### Added
13
24
  * Documentation on the release process.
14
25
  * Load possible `.env` files before application bootstrapping.
15
26
  * Asset fingerprinting through configuration.
16
27
 
17
- #### Security
28
+ ### Security
18
29
  * Update dependencies in the Webpack project template.
19
30
 
20
- #### Fixed
31
+ ### Fixed
21
32
  * Prevent `DataStoreFile` from being converted to `OpenStruct`.
22
33
  * Misc. updates to the projects documentation.
23
34
 
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'frontman/errors'
3
4
  require 'frontman/app'
4
5
  require 'frontman/context'
5
6
  require 'frontman/config'
6
7
  require 'frontman/custom_struct'
7
8
  require 'frontman/data_store'
8
9
  require 'frontman/data_store_file'
10
+ require 'frontman/errors'
9
11
  require 'frontman/sitemap_tree'
10
12
  require 'frontman/resource'
11
13
 
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'frontman/sitemap_tree'
5
5
  require 'frontman/data_store'
6
+ require 'frontman/errors'
6
7
  require 'singleton'
7
8
  require 'sorbet-runtime'
8
9
 
@@ -94,11 +95,15 @@ module Frontman
94
95
  @assets_manifest[key] = '/' + value.sub(%r{^/}, '')
95
96
  end
96
97
 
97
- sig { params(dirs: Array).void }
98
+ sig { params(dirs: T.any(Array, Hash)).void }
98
99
  def register_data_dirs(dirs)
99
- dirs.each do |dir|
100
- define_singleton_method dir.to_sym do
101
- @data_dirs[dir] ||= DataStore.new(File.join(Dir.pwd, dir))
100
+ if dirs.is_a?(Array)
101
+ dirs = dirs.map { |dir| [dir.split('/').last, dir] }.to_h
102
+ end
103
+
104
+ dirs.each do |name, dir|
105
+ define_singleton_method name do
106
+ @data_dirs[name] ||= DataStore.new(File.join(Dir.pwd, dir))
102
107
  end
103
108
  end
104
109
  end
@@ -127,6 +132,15 @@ module Frontman
127
132
  )
128
133
  end
129
134
 
135
+ sig { params(file_path: String).void }
136
+ def import_config(file_path)
137
+ if !file_path.end_with?('.rb') && !File.exist?(file_path)
138
+ return import_config("#{file_path}.rb")
139
+ end
140
+
141
+ run File.read(file_path)
142
+ end
143
+
130
144
  def method_missing(method_id, *_)
131
145
  from_view_data = get_from_view_data(method_id)
132
146
  return from_view_data unless from_view_data.nil?
@@ -164,12 +178,5 @@ module Frontman
164
178
  local_data = @view_data.last[:locals]
165
179
  local_data[key] unless local_data.nil?
166
180
  end
167
-
168
- class ExistingResourceError < StandardError
169
- def self.create(url, resource)
170
- new("Unable to redirect for #{url},
171
- the resource #{resource.file_path} already exists on this URL")
172
- end
173
- end
174
181
  end
175
182
  end
@@ -52,7 +52,7 @@ module Frontman
52
52
  builder.build_directory = build_directory
53
53
  builder.current_build_files = current_build_files
54
54
 
55
- builder.on('created, updated, deleted, unchanged', lambda { |build_file|
55
+ builder.on('created, updated, deleted, unchanged', ->(build_file) {
56
56
  mapping.add_from_build_file(build_file)
57
57
  })
58
58
 
@@ -6,6 +6,7 @@ require 'thor'
6
6
  module Frontman
7
7
  class CLI < Thor
8
8
  option :template
9
+ option :force, type: :boolean
9
10
  desc 'init', 'Bootstrap a new Frontman project'
10
11
  def init(path)
11
12
  template = options[:template] || 'default'
@@ -38,6 +39,7 @@ module Frontman
38
39
  end
39
40
 
40
41
  def allowed_to_modify_dir?(dir)
42
+ return true if options[:force]
41
43
  return true if !Dir.exist?(dir) || Dir.empty?(dir)
42
44
 
43
45
  say 'This folder already contains files. '
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: false
2
2
 
3
+ require 'socket'
3
4
  require 'thor'
4
5
  require 'sinatra/base'
5
6
  require 'better_errors'
@@ -8,6 +9,7 @@ require 'frontman/app'
8
9
  require 'frontman/bootstrapper'
9
10
  require 'frontman/builder/asset_pipeline'
10
11
  require 'frontman/config'
12
+ require 'frontman/errors'
11
13
  require 'frontman/resource'
12
14
 
13
15
  module Frontman
@@ -70,11 +72,11 @@ module Frontman
70
72
 
71
73
  listener.start
72
74
 
73
- FrontManServer.set :public_folder, Frontman::Config.get(
75
+ FrontmanServer.set :public_folder, Frontman::Config.get(
74
76
  :public_dir, fallback: 'public'
75
77
  )
76
- FrontManServer.run! do
77
- host = "http://localhost:#{FrontManServer.settings.port}"
78
+ FrontmanServer.run! do
79
+ host = "http://localhost:#{FrontmanServer.settings.port}"
78
80
  print "== View your site at \"#{host}/\"\n"
79
81
  processes += assets_pipeline.run_in_background!(:after)
80
82
  at_exit { processes.each { |pid| Process.kill(0, pid) } }
@@ -83,8 +85,34 @@ module Frontman
83
85
  end
84
86
  end
85
87
 
86
- class FrontManServer < Sinatra::Base
87
- set :port, 4568
88
+ class FrontmanServer < Sinatra::Base
89
+ port = Frontman::Config.get(:port, fallback: 4568)
90
+ num_retries = Frontman::Config.get(:port_retries, fallback: 3)
91
+
92
+ retry_strategy = Frontman::Config.get(:port_retry_strategy, fallback: ->(p) {
93
+ port_in_use = false
94
+
95
+ (1 + num_retries).times do
96
+ begin
97
+ port_in_use = Socket.tcp('localhost', p, connect_timeout: 3) { true }
98
+ rescue StandardError
99
+ port_in_use = false
100
+ end
101
+
102
+ break unless port_in_use
103
+
104
+ p += 1
105
+ end
106
+
107
+ raise Frontman::ServerPortError if port_in_use
108
+
109
+ p
110
+ })
111
+
112
+ port = retry_strategy.call(port)
113
+
114
+ set :port, port
115
+
88
116
  set :server_settings,
89
117
  # Avoid having webrick displaying logs for every requests to the serve
90
118
  AccessLog: [],
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Frontman
4
+ class Error < StandardError; end
5
+
6
+ class DuplicateResourceError < StandardError
7
+ def self.create(resource, url, existing_resource)
8
+ new("Unable to add #{resource.file_path} as #{url}.
9
+ Resource #{existing_resource.file_path} already exists on this URL.")
10
+ end
11
+ end
12
+
13
+ class ExistingRedirectError < StandardError
14
+ def self.create(resource, url)
15
+ new("Unable to add #{resource.file_path} as #{url}.
16
+ A redirect already exists for this URL.")
17
+ end
18
+ end
19
+
20
+ class ExistingResourceError < StandardError
21
+ def self.create(url, resource)
22
+ new("Unable to redirect for #{url},
23
+ the resource #{resource.file_path} already exists on this URL")
24
+ end
25
+ end
26
+
27
+ class ServerPortError < StandardError
28
+ def initialize
29
+ super('Server failed to attach to port. Please shutdown some processes
30
+ or increase the :port_retries configuration variable.')
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,8 @@
1
1
  # typed: false
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'frontman/errors'
5
+
4
6
  module Frontman
5
7
  class SitemapTree
6
8
  attr_reader :path, :children, :url_part
@@ -194,18 +196,4 @@ module Frontman
194
196
  "SitemapTree: #{@resource ? @resource.destination_path : @url_part}"
195
197
  end
196
198
  end
197
-
198
- class DuplicateResourceError < StandardError
199
- def self.create(resource, url, existing_resource)
200
- new("Unable to add #{resource.file_path} as #{url}.
201
- Resource #{existing_resource.file_path} already exists on this URL.")
202
- end
203
- end
204
-
205
- class ExistingRedirectError < StandardError
206
- def self.create(resource, url)
207
- new("Unable to add #{resource.file_path} as #{url}.
208
- A redirect already exists for this URL.")
209
- end
210
- end
211
199
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Frontman
4
4
  # Current Version
5
- VERSION = '0.0.3'
5
+ VERSION = '0.0.4'
6
6
  end
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ source 'https://rubygems.org'
4
+
3
5
  gem 'frontman-ssg'
@@ -1,3 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ source 'https://rubygems.org'
4
+
3
5
  gem 'frontman-ssg'
@@ -45,4 +45,26 @@ describe Frontman::App do
45
45
  it 'should return itself when calling app' do
46
46
  expect(subject.app).to eq subject
47
47
  end
48
+
49
+ it 'should register variables named after keys if hash passed' do
50
+ subject.register_data_dirs(my_data: 'spec/frontman/mocks')
51
+ subject.my_data
52
+ subject.my_data.info
53
+ subject.my_data.nested.data
54
+ subject.my_data.nested.more_data
55
+ expect { subject.mocks }.to raise_error NoMethodError
56
+ end
57
+
58
+ it 'should register variables named after data directory names if array passed' do
59
+ subject.register_data_dirs(['spec/frontman/mocks'])
60
+ subject.mocks
61
+ subject.mocks.info
62
+ subject.mocks.nested.data
63
+ subject.mocks.nested.more_data
64
+ expect { subject.data }.to raise_error NoMethodError
65
+ end
66
+
67
+ it 'should work with import_config' do
68
+ expect(subject.import_config('spec/frontman/mocks/import_config'))
69
+ end
48
70
  end
@@ -20,7 +20,7 @@ describe Frontman::Bootstrapper do
20
20
  it 'should find all resources in a given folder' do
21
21
  resources = Frontman::Bootstrapper.resources_from_dir('spec/frontman/mocks')
22
22
 
23
- expect(resources.size).to eq 14 # Number of non-YAML files in this folder
23
+ expect(resources.size).to eq 15 # Number of non-YAML files in this folder
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ import_config 'spec/frontman/mocks/config'
4
+ import_config 'spec/frontman/mocks/config.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontman-ssg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Devin Beeuwkes
@@ -376,6 +376,7 @@ files:
376
376
  - lib/frontman/custom_struct.rb
377
377
  - lib/frontman/data_store.rb
378
378
  - lib/frontman/data_store_file.rb
379
+ - lib/frontman/errors.rb
379
380
  - lib/frontman/helpers/app_helper.rb
380
381
  - lib/frontman/helpers/link_helper.rb
381
382
  - lib/frontman/helpers/render_helper.rb
@@ -462,6 +463,7 @@ files:
462
463
  - spec/frontman/mocks/html_file.html
463
464
  - spec/frontman/mocks/html_file.html.md.erb
464
465
  - spec/frontman/mocks/html_file.md.html
466
+ - spec/frontman/mocks/import_config.rb
465
467
  - spec/frontman/mocks/info.yml
466
468
  - spec/frontman/mocks/layouts/raw_without_body.haml
467
469
  - spec/frontman/mocks/nested/data.yml