archival 0.0.2 → 0.0.7

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
  SHA256:
3
- metadata.gz: 9c657b6a9eef44687dc75a8c85349309433c224fc7a0871890c4c50aa955745f
4
- data.tar.gz: a857f9490e10cf5aa9e49e9df1d5adbb40908dd1731d00a81b41361fb4bbcc4c
3
+ metadata.gz: 7403410bc5164f3be23c22494a716fe7af6d6e805fc38ddb12c920bed918dba7
4
+ data.tar.gz: ebb064928f3295b914609a9751c11cf663ae54af6671b655def56f5d03dab93e
5
5
  SHA512:
6
- metadata.gz: 5bcf4e0b7678dc60aa1769a1afa586cbd3569a36b7d863c5fb83a7fe45e4249f6a176a411e17815c4ce41d0dc95d233f0fdaf7af640dfff81eba4851f54af387
7
- data.tar.gz: 9738d2bc0bfbad7612c9ff5e225e5787691ef736824ff4a546e25bab3855c70af7cffeae2610eb486551dc8fb1f44f885223664a48e41d9bd4f0260eb45615dd
6
+ metadata.gz: 866d33fea5f99757f5a5a01254769ba4a1527341f0f68df03c0daeda38fc642a5177c011d18a902937b72027c2061f92efb0eddea765eae295b520c562188f74
7
+ data.tar.gz: 802638fe184d75b2596bfbb378e02fe8de985bfdda46463dcba009937493faef442c65280307a7d3d25fd3ecbc762584846d305f3e7ceb2cf4bf4949cfe5d057
data/.rubocop.yml CHANGED
@@ -1,14 +1,17 @@
1
+ inherit_mode:
2
+ merge:
3
+ - Exclude
4
+
1
5
  AllCops:
2
6
  NewCops: enable
3
7
  SuggestExtensions: false
4
8
  Exclude:
5
- - bin/bundle
9
+ - bin/*
6
10
 
7
11
  Layout/LineLength:
8
12
  Max: 80
9
13
  Exclude:
10
14
  - archival.gemspec
11
- - bin/*
12
15
  - spec/spec_helper.rb
13
16
 
14
17
  Layout/TrailingWhitespace:
@@ -29,6 +32,18 @@ Metrics/BlockLength:
29
32
  Metrics/ClassLength:
30
33
  Max: 150
31
34
 
35
+ Metrics/CyclomaticComplexity:
36
+ Max: 10
37
+ Exclude:
38
+ # This file does a lot of defaulting. It's easy to read.
39
+ - lib/archival/config.rb
40
+
41
+ Metrics/PerceivedComplexity:
42
+ Max: 10
43
+ Exclude:
44
+ # This file does a lot of defaulting. It's easy to read.
45
+ - lib/archival/config.rb
46
+
32
47
  Lint/ImplicitStringConcatenation:
33
48
  Exclude:
34
49
  - spec/tags/layout_spec.rb
data/Rakefile CHANGED
@@ -10,3 +10,4 @@ RuboCop::RakeTask.new
10
10
 
11
11
  task default: :spec
12
12
  task lint: :rubocop
13
+ task 'lint:fix': 'rubocop:auto_correct'
data/archival.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'archival'
5
- s.version = '0.0.2'
5
+ s.version = '0.0.7'
6
6
  s.summary = 'An incredibly simple CMS for durable websites'
7
7
  s.description = 'https://jesseditson.com/the-simplest-cms-part-1'
8
8
  s.authors = ['Jesse Ditson']
@@ -24,5 +24,6 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.add_dependency 'liquid', '~> 5.1.0'
26
26
  s.add_dependency 'listen', '~> 3.7.0'
27
+ s.add_dependency 'redcarpet', '~> 3.5.1'
27
28
  s.add_dependency 'tomlrb', '~> 2.0.1'
28
29
  end
data/bin/archival CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('archival', 'archival')
29
+ load Gem.bin_path("archival", "archival")
data/bin/bundle CHANGED
@@ -8,46 +8,46 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'rubygems'
11
+ require "rubygems"
12
12
 
13
13
  m = Module.new do
14
14
  module_function
15
15
 
16
16
  def invoked_as_script?
17
- File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
18
  end
19
19
 
20
20
  def env_var_version
21
- ENV['BUNDLER_VERSION']
21
+ ENV["BUNDLER_VERSION"]
22
22
  end
23
23
 
24
24
  def cli_arg_version
25
25
  return unless invoked_as_script? # don't want to hijack other binstubs
26
- return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
27
-
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
28
27
  bundler_version = nil
29
28
  update_index = nil
30
29
  ARGV.each_with_index do |a, i|
31
- bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
32
33
  next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
33
-
34
- bundler_version = Regexp.last_match(1)
34
+ bundler_version = $1
35
35
  update_index = i
36
36
  end
37
37
  bundler_version
38
38
  end
39
39
 
40
40
  def gemfile
41
- gemfile = ENV['BUNDLE_GEMFILE']
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
42
  return gemfile if gemfile && !gemfile.empty?
43
43
 
44
- File.expand_path('../Gemfile', __dir__)
44
+ File.expand_path("../../Gemfile", __FILE__)
45
45
  end
46
46
 
47
47
  def lockfile
48
48
  lockfile =
49
49
  case File.basename(gemfile)
50
- when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
51
  else "#{gemfile}.lock"
52
52
  end
53
53
  File.expand_path(lockfile)
@@ -55,17 +55,15 @@ m = Module.new do
55
55
 
56
56
  def lockfile_version
57
57
  return unless File.file?(lockfile)
58
-
59
58
  lockfile_contents = File.read(lockfile)
60
59
  return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
61
-
62
60
  Regexp.last_match(1)
63
61
  end
64
62
 
65
63
  def bundler_requirement
66
64
  @bundler_requirement ||=
67
65
  env_var_version || cli_arg_version ||
68
- bundler_requirement_for(lockfile_version)
66
+ bundler_requirement_for(lockfile_version)
69
67
  end
70
68
 
71
69
  def bundler_requirement_for(version)
@@ -75,32 +73,28 @@ m = Module.new do
75
73
 
76
74
  requirement = bundler_gem_version.approximate_recommendation
77
75
 
78
- return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.7.0')
76
+ return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
79
77
 
80
- requirement += '.a' if bundler_gem_version.prerelease?
78
+ requirement += ".a" if bundler_gem_version.prerelease?
81
79
 
82
80
  requirement
83
81
  end
84
82
 
85
83
  def load_bundler!
86
- ENV['BUNDLE_GEMFILE'] ||= gemfile
84
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
87
85
 
88
86
  activate_bundler
89
87
  end
90
88
 
91
89
  def activate_bundler
92
90
  gem_error = activation_error_handling do
93
- gem 'bundler', bundler_requirement
91
+ gem "bundler", bundler_requirement
94
92
  end
95
93
  return if gem_error.nil?
96
-
97
94
  require_error = activation_error_handling do
98
- require 'bundler/version'
99
- end
100
- if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
101
- return
95
+ require "bundler/version"
102
96
  end
103
-
97
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
104
98
  warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
105
99
  exit 42
106
100
  end
@@ -115,4 +109,6 @@ end
115
109
 
116
110
  m.load_bundler!
117
111
 
118
- load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?
112
+ if m.invoked_as_script?
113
+ load Gem.bin_path("bundler", "bundle")
114
+ end
data/bin/htmldiff CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('diff-lcs', 'htmldiff')
29
+ load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('diff-lcs', 'ldiff')
29
+ load Gem.bin_path("diff-lcs", "ldiff")
data/bin/listen CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('listen', 'listen')
29
+ load Gem.bin_path("listen", "listen")
data/bin/rake CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('rake', 'rake')
29
+ load Gem.bin_path("rake", "rake")
data/bin/redcarpet ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'redcarpet' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("redcarpet", "redcarpet")
data/bin/rspec CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('rspec-core', 'rspec')
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('rubocop', 'rubocop')
29
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/ruby-parse CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('parser', 'ruby-parse')
29
+ load Gem.bin_path("parser", "ruby-parse")
data/bin/ruby-rewrite CHANGED
@@ -8,16 +8,14 @@
8
8
  # this file is here to facilitate running it.
9
9
  #
10
10
 
11
- require 'pathname'
12
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
- Pathname.new(__FILE__).realpath)
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
14
 
15
- bundle_binstub = File.expand_path('bundle',
16
- __dir__)
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
17
16
 
18
17
  if File.file?(bundle_binstub)
19
- if File.read(bundle_binstub,
20
- 300) =~ /This file was generated by Bundler/
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
21
19
  load(bundle_binstub)
22
20
  else
23
21
  abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
@@ -25,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this
25
23
  end
26
24
  end
27
25
 
28
- require 'rubygems'
29
- require 'bundler/setup'
26
+ require "rubygems"
27
+ require "bundler/setup"
30
28
 
31
- load Gem.bin_path('parser', 'ruby-rewrite')
29
+ load Gem.bin_path("parser", "ruby-rewrite")
data/exe/archival CHANGED
@@ -19,17 +19,13 @@ build_dir = Dir.pwd
19
19
 
20
20
  case command
21
21
  when 'build'
22
- builder = Archival::Builder.new('root' => build_dir)
23
- builder.write_all
24
- when 'run'
25
- Archival.listen(build_dir)
26
- begin
27
- sleep
28
- rescue Interrupt
29
- # Don't print a stack when a user interrupts, as this is the right way to
30
- # stop the development server.
31
- puts ''
22
+ Archival::Logger.benchmark('built') do
23
+ config = Archival::Config.new('root' => build_dir)
24
+ builder = Archival::Builder.new(config)
25
+ builder.write_all
32
26
  end
27
+ when 'run'
28
+ Archival.listen('root' => build_dir)
33
29
  else
34
30
  # print help
35
31
  puts 'archival [command]'
@@ -0,0 +1,91 @@
1
+ /**
2
+ * When running archival in development mode (archival run), this file is
3
+ * injected into all pages, and is responsible for reloading the page when the
4
+ * source has changed.
5
+ */
6
+
7
+ (function () {
8
+ const remotePort = $PORT;
9
+ const CONNECTING_COLOR = "#bd270d";
10
+ const CONNECTED_COLOR = "#19bd0d";
11
+ const CHECK_INTERVAL = 500;
12
+ const DISCONNECTED_INTERVAL = 1000;
13
+ const connectionDot = document.createElement("div");
14
+ connectionDot.style = `position: absolute; z-index: 9999; bottom: 10px; right: 10px; background-color: ${CONNECTING_COLOR}; width: 15px; height: 15px; border-radius: 50%; opacity: 0.8;`;
15
+ connectionDot.setAttribute("title", "Archival Dev Server: Connecting");
16
+ connectionDot.addEventListener(
17
+ "mouseenter",
18
+ () => (connectionDot.style.opacity = 0.2)
19
+ );
20
+ connectionDot.addEventListener(
21
+ "mouseleave",
22
+ () => (connectionDot.style.opacity = 0.8)
23
+ );
24
+
25
+ let lastContact = -1;
26
+ let isConnecting = false;
27
+ let connection;
28
+
29
+ function connectionLoop() {
30
+ connection.send(`page:${window.location.pathname}`);
31
+ if (Date.now() - lastContact > DISCONNECTED_INTERVAL) {
32
+ setConnected(false);
33
+ connectSocket();
34
+ }
35
+ setTimeout(connectionLoop, CHECK_INTERVAL);
36
+ }
37
+
38
+ function setConnected(connected) {
39
+ connectionDot.style.backgroundColor = connected
40
+ ? CONNECTED_COLOR
41
+ : CONNECTING_COLOR;
42
+ connectionDot.setAttribute(
43
+ "title",
44
+ `Archival Dev Server: ${connected ? "Connected" : "Disconnected"}`
45
+ );
46
+ }
47
+
48
+ window.onload = () => {
49
+ connectSocket(true);
50
+ };
51
+
52
+ function connectSocket(init) {
53
+ if (isConnecting) {
54
+ return;
55
+ }
56
+ isConnecting = true;
57
+ console.log(
58
+ `${init ? "connecting" : "reconnecting"} to archival dev server...`
59
+ );
60
+ document.body.appendChild(connectionDot);
61
+ connection = new WebSocket(`ws://localhost:${remotePort}`);
62
+ connection.onerror = () => {
63
+ isConnecting = false;
64
+ };
65
+
66
+ connection.onopen = () => {
67
+ isConnecting = false;
68
+ connection.send("connected");
69
+ if (init) {
70
+ connectionLoop();
71
+ }
72
+ };
73
+ connection.onmessage = (event) => {
74
+ lastContact = Date.now();
75
+ switch (event.data) {
76
+ case "ready":
77
+ console.log("connected to archival dev server.");
78
+ break;
79
+ case "ok":
80
+ setConnected(true);
81
+ break;
82
+ case "refresh":
83
+ window.location.reload();
84
+ break;
85
+ default:
86
+ console.log(`receieved unexpected message ${event.data}`);
87
+ break;
88
+ }
89
+ };
90
+ }
91
+ })();