bookbindery 2.1.5 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bookbinder.rb +0 -4
- data/lib/bookbinder/cf_command_runner.rb +11 -5
- data/lib/bookbinder/cli.rb +8 -12
- data/lib/bookbinder/colorizer.rb +1 -2
- data/lib/bookbinder/command_runner.rb +0 -2
- data/lib/bookbinder/commands/bind.rb +96 -99
- data/lib/bookbinder/commands/bind/directory_preparer.rb +60 -0
- data/lib/bookbinder/commands/build_and_push_tarball.rb +5 -4
- data/lib/bookbinder/commands/push_from_local.rb +56 -2
- data/lib/bookbinder/commands/push_to_prod.rb +6 -2
- data/lib/bookbinder/commands/tag.rb +15 -3
- data/lib/bookbinder/config/aws_credentials.rb +21 -0
- data/lib/bookbinder/config/cf_credentials.rb +87 -0
- data/lib/bookbinder/configuration.rb +4 -140
- data/lib/bookbinder/configuration_fetcher.rb +28 -4
- data/lib/bookbinder/configuration_validator.rb +11 -164
- data/lib/bookbinder/distributor.rb +16 -12
- data/lib/bookbinder/{dita_to_html_converter.rb → dita_command_creator.rb} +5 -17
- data/lib/bookbinder/dita_preprocessor.rb +14 -12
- data/lib/bookbinder/git_accessor.rb +21 -2
- data/lib/bookbinder/git_hub_repository.rb +0 -43
- data/lib/bookbinder/ingest/cloner_factory.rb +5 -4
- data/lib/bookbinder/ingest/destination_directory.rb +15 -0
- data/lib/bookbinder/ingest/git_hub_repository_cloner.rb +22 -13
- data/lib/bookbinder/ingest/local_filesystem_cloner.rb +38 -14
- data/lib/bookbinder/ingest/working_copy.rb +31 -0
- data/lib/bookbinder/local_dita_section_gatherer.rb +4 -3
- data/lib/bookbinder/local_file_system_accessor.rb +1 -4
- data/lib/bookbinder/middleman_runner.rb +22 -26
- data/lib/bookbinder/remote_yaml_credential_provider.rb +10 -10
- data/lib/bookbinder/repositories/command_repository.rb +18 -12
- data/lib/bookbinder/repositories/section_repository.rb +8 -8
- data/lib/bookbinder/server_director.rb +16 -33
- data/lib/bookbinder/sheller.rb +33 -7
- data/lib/bookbinder/spider.rb +3 -0
- data/lib/bookbinder/streams/switchable_stdout_and_red_stderr.rb +38 -0
- data/lib/bookbinder/terminal.rb +11 -1
- data/lib/bookbinder/validation_checkers/archive_menu_checker.rb +31 -0
- data/lib/bookbinder/validation_checkers/config_version_checker.rb +91 -0
- data/lib/bookbinder/validation_checkers/dita_section_checker.rb +20 -0
- data/lib/bookbinder/validation_checkers/duplicate_section_name_checker.rb +25 -0
- data/lib/bookbinder/validation_checkers/repository_name_presence_checker.rb +33 -0
- data/lib/bookbinder/validation_checkers/required_keys_checker.rb +43 -0
- data/lib/bookbinder/values/dita_section.rb +5 -1
- data/lib/bookbinder/values/output_locations.rb +25 -2
- data/lib/bookbinder/values/user_message.rb +2 -2
- data/master_middleman/bookbinder_helpers.rb +5 -15
- data/template_app/Gemfile.lock +1 -1
- metadata +60 -80
- data/lib/bookbinder/commands/generate_pdf.rb +0 -141
- data/lib/bookbinder/pdf_generator.rb +0 -73
- data/lib/bookbinder/publisher.rb +0 -58
- data/lib/bookbinder/user_message_presenter.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ee95fb7c8fa4d8f94f82fb98582fd65cb95b00
|
4
|
+
data.tar.gz: 402dbbe4d95e314482d09803c85d2560f424bde5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 657c1ab7338a891a60f59b3f3a01d683f65cac80a528907ee9918d55ef45202615684a57069c72525a65bbf6a310bb4183fecaabde6c2bfa73743ef9daeaa2b1
|
7
|
+
data.tar.gz: 725747cd9531772d3df4fe41af349bc165bc13fbc8db64c886debfc7f0866d720c730a72ee977ff3759d0f046e3f20dd18267ebe19fe5d47aed302b0f84532ef
|
data/lib/bookbinder.rb
CHANGED
@@ -8,7 +8,6 @@ require 'middleman-core/profiling'
|
|
8
8
|
require 'anemone'
|
9
9
|
require 'css_parser'
|
10
10
|
require 'vienna'
|
11
|
-
require 'popen4'
|
12
11
|
require 'puma'
|
13
12
|
|
14
13
|
require_relative 'bookbinder/deprecated_logger'
|
@@ -28,9 +27,7 @@ require_relative 'bookbinder/server_director'
|
|
28
27
|
require_relative 'bookbinder/spider'
|
29
28
|
|
30
29
|
require_relative 'bookbinder/archive'
|
31
|
-
require_relative 'bookbinder/pdf_generator'
|
32
30
|
require_relative 'bookbinder/middleman_runner'
|
33
|
-
require_relative 'bookbinder/publisher'
|
34
31
|
require_relative 'bookbinder/cf_command_runner'
|
35
32
|
require_relative 'bookbinder/pusher'
|
36
33
|
require_relative 'bookbinder/artifact_namer'
|
@@ -44,7 +41,6 @@ require_relative 'bookbinder/commands/push_to_prod'
|
|
44
41
|
require_relative 'bookbinder/commands/run_publish_ci'
|
45
42
|
require_relative 'bookbinder/commands/update_local_doc_repos'
|
46
43
|
require_relative 'bookbinder/commands/tag'
|
47
|
-
require_relative 'bookbinder/commands/generate_pdf'
|
48
44
|
|
49
45
|
require_relative 'bookbinder/cli'
|
50
46
|
|
@@ -3,8 +3,9 @@ require_relative 'values/blue_green_app'
|
|
3
3
|
|
4
4
|
module Bookbinder
|
5
5
|
class CfCommandRunner
|
6
|
-
def initialize(logger, cf_credentials, trace_file)
|
6
|
+
def initialize(logger, sheller, cf_credentials, trace_file)
|
7
7
|
@logger = logger
|
8
|
+
@sheller = sheller
|
8
9
|
@creds = cf_credentials
|
9
10
|
@trace_file = trace_file
|
10
11
|
end
|
@@ -35,14 +36,19 @@ module Bookbinder
|
|
35
36
|
# Theoretically we shouldn't need this (and corresponding "stop" below), but we've seen CF pull files from both
|
36
37
|
# green and blue when a DNS redirect points to HOST.cfapps.io
|
37
38
|
# Also, shutting down the unused app saves $$
|
38
|
-
|
39
|
+
sheller.run_command("#{cf_binary_path} start #{deploy_target_app}",
|
40
|
+
out: $stdout,
|
41
|
+
err: $stderr)
|
39
42
|
end
|
40
43
|
|
41
44
|
def push(deploy_target_app)
|
42
45
|
# Currently --no-routes is used to blow away all existing routes from a newly deployed app.
|
43
46
|
# The routes will then be recreated from the creds repo.
|
44
|
-
|
45
|
-
|
47
|
+
status = sheller.run_command(environment_variables,
|
48
|
+
"#{cf_binary_path} push #{deploy_target_app} --no-route -m 256M -i 3",
|
49
|
+
out: $stdout,
|
50
|
+
err: $stderr)
|
51
|
+
raise "Could not deploy app to #{deploy_target_app}" unless status.success?
|
46
52
|
end
|
47
53
|
|
48
54
|
def unmap_routes(app)
|
@@ -78,7 +84,7 @@ module Bookbinder
|
|
78
84
|
|
79
85
|
private
|
80
86
|
|
81
|
-
attr_reader :creds
|
87
|
+
attr_reader :creds, :sheller
|
82
88
|
|
83
89
|
def stop(app)
|
84
90
|
success = Kernel.system("#{cf_binary_path} stop #{app}")
|
data/lib/bookbinder/cli.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative '
|
2
|
-
require_relative 'command_runner'
|
1
|
+
require_relative 'repositories/command_repository'
|
3
2
|
require_relative 'command_validator'
|
3
|
+
require_relative 'command_runner'
|
4
|
+
require_relative 'config/cf_credentials'
|
4
5
|
require_relative 'configuration'
|
5
|
-
require_relative '
|
6
|
+
require_relative 'colorizer'
|
6
7
|
require_relative 'terminal'
|
7
|
-
require_relative 'user_message_presenter'
|
8
8
|
|
9
9
|
module Bookbinder
|
10
10
|
class Cli
|
@@ -23,17 +23,13 @@ module Bookbinder
|
|
23
23
|
command_name = command_name ? command_name : '--help'
|
24
24
|
|
25
25
|
colorizer = Colorizer.new
|
26
|
-
|
27
|
-
terminal = Terminal.new
|
26
|
+
terminal = Terminal.new(colorizer)
|
28
27
|
|
29
28
|
user_message = command_validator.validate(command_name)
|
29
|
+
terminal.update(user_message)
|
30
|
+
|
30
31
|
if user_message.error?
|
31
|
-
error_message = user_message_presenter.get_error(user_message)
|
32
|
-
terminal.update(error_message)
|
33
32
|
return 1
|
34
|
-
elsif user_message.warn?
|
35
|
-
warning_message = user_message_presenter.get_warning(user_message)
|
36
|
-
terminal.update(warning_message)
|
37
33
|
end
|
38
34
|
|
39
35
|
begin
|
@@ -42,7 +38,7 @@ module Bookbinder
|
|
42
38
|
rescue Config::RemoteBindConfiguration::VersionUnsupportedError => e
|
43
39
|
logger.error "config.yml at version '#{e.message}' has an unsupported API."
|
44
40
|
1
|
45
|
-
rescue
|
41
|
+
rescue Config::CfCredentials::CredentialKeyError => e
|
46
42
|
logger.error "#{e.message}, in credentials.yml"
|
47
43
|
1
|
48
44
|
rescue KeyError => e
|
data/lib/bookbinder/colorizer.rb
CHANGED
@@ -2,7 +2,6 @@ require 'ansi/code'
|
|
2
2
|
require 'ostruct'
|
3
3
|
|
4
4
|
module Bookbinder
|
5
|
-
|
6
5
|
class Colorizer
|
7
6
|
Colors = OpenStruct.new(red: Proc.new { |msg| ANSI.red {msg} },
|
8
7
|
yellow: Proc.new { |msg| ANSI.yellow {msg} })
|
@@ -11,4 +10,4 @@ module Bookbinder
|
|
11
10
|
color.call string.to_s
|
12
11
|
end
|
13
12
|
end
|
14
|
-
end
|
13
|
+
end
|
@@ -1,19 +1,22 @@
|
|
1
|
-
|
1
|
+
require 'middleman-syntax'
|
2
|
+
|
2
3
|
require_relative '../archive_menu_configuration'
|
3
|
-
require_relative '../
|
4
|
-
require_relative '../
|
4
|
+
require_relative '../book'
|
5
|
+
require_relative '../dita_section_gatherer_factory'
|
5
6
|
require_relative '../errors/cli_error'
|
7
|
+
require_relative '../streams/switchable_stdout_and_red_stderr'
|
8
|
+
require_relative '../values/dita_section'
|
9
|
+
require_relative '../values/output_locations'
|
6
10
|
require_relative '../values/section'
|
7
|
-
require_relative '../publisher'
|
8
|
-
require_relative '../book'
|
9
11
|
require_relative 'naming'
|
10
12
|
|
11
13
|
module Bookbinder
|
12
14
|
module Commands
|
13
15
|
class Bind
|
14
|
-
include Bookbinder::DirectoryHelperMethods
|
15
16
|
include Commands::Naming
|
16
17
|
|
18
|
+
DitaToHtmlLibraryFailure = Class.new(RuntimeError)
|
19
|
+
|
17
20
|
def initialize(logger,
|
18
21
|
config_fetcher,
|
19
22
|
config_factory,
|
@@ -26,7 +29,11 @@ module Bookbinder
|
|
26
29
|
context_dir,
|
27
30
|
dita_preprocessor,
|
28
31
|
cloner_factory,
|
29
|
-
dita_section_gatherer_factory
|
32
|
+
dita_section_gatherer_factory,
|
33
|
+
section_repository,
|
34
|
+
command_creator,
|
35
|
+
sheller,
|
36
|
+
directory_preparer)
|
30
37
|
@logger = logger
|
31
38
|
@config_fetcher = config_fetcher
|
32
39
|
@config_factory = config_factory
|
@@ -40,6 +47,10 @@ module Bookbinder
|
|
40
47
|
@dita_preprocessor = dita_preprocessor
|
41
48
|
@cloner_factory = cloner_factory
|
42
49
|
@dita_section_gatherer_factory = dita_section_gatherer_factory
|
50
|
+
@section_repository = section_repository
|
51
|
+
@command_creator = command_creator
|
52
|
+
@sheller = sheller
|
53
|
+
@directory_preparer = directory_preparer
|
43
54
|
end
|
44
55
|
|
45
56
|
def usage
|
@@ -56,18 +67,11 @@ module Bookbinder
|
|
56
67
|
end
|
57
68
|
|
58
69
|
def run(cli_arguments)
|
59
|
-
raise CliError::InvalidArguments unless arguments_are_valid?(cli_arguments)
|
60
|
-
|
61
|
-
@section_repository = Repositories::SectionRepository.new(logger)
|
62
|
-
@gem_root = File.expand_path('../../../../', __FILE__)
|
63
|
-
publisher = Publisher.new(logger, sitemap_writer, static_site_generator, file_system_accessor)
|
64
|
-
|
65
70
|
bind_source, *options = cli_arguments
|
71
|
+
validate(bind_source, options)
|
66
72
|
|
67
73
|
bind_config = config_factory.produce(bind_source)
|
68
|
-
|
69
|
-
@versions = bind_config.fetch(:versions, [])
|
70
|
-
@book_repo = bind_config[:book_repo]
|
74
|
+
output_streams = Streams::SwitchableStdoutAndRedStderr.new(options)
|
71
75
|
|
72
76
|
output_locations = OutputLocations.new(
|
73
77
|
context_dir: context_dir,
|
@@ -76,15 +80,30 @@ module Bookbinder
|
|
76
80
|
local_repo_dir: generate_local_repo_dir(context_dir, bind_source)
|
77
81
|
)
|
78
82
|
|
79
|
-
prepare_directories(
|
83
|
+
directory_preparer.prepare_directories(
|
84
|
+
File.expand_path('../../../../', __FILE__),
|
85
|
+
bind_config.fetch(:versions, []),
|
86
|
+
output_locations,
|
87
|
+
bind_config[:book_repo]
|
88
|
+
)
|
80
89
|
|
81
90
|
dita_gatherer = dita_section_gatherer_factory.produce(bind_source, output_locations)
|
82
91
|
gathered_dita_sections = dita_gatherer.gather(config.dita_sections)
|
83
92
|
|
84
|
-
gathered_dita_sections
|
85
|
-
|
86
|
-
|
87
|
-
|
93
|
+
dita_preprocessor.preprocess(gathered_dita_sections,
|
94
|
+
output_locations.subnavs_for_layout_dir,
|
95
|
+
output_locations.dita_subnav_template_path) do |dita_section|
|
96
|
+
command = command_creator.convert_to_html_command(
|
97
|
+
dita_section,
|
98
|
+
write_to: dita_section.html_from_dita_section_dir
|
99
|
+
)
|
100
|
+
status = sheller.run_command(command, output_streams.to_h)
|
101
|
+
unless status.success?
|
102
|
+
raise DitaToHtmlLibraryFailure.new 'The DITA-to-HTML conversion failed. ' +
|
103
|
+
'Please check that you have specified the path to your DITA-OT library in the ENV, ' +
|
104
|
+
'that your DITA-specific keys/values in config.yml are set, ' +
|
105
|
+
'and that your DITA toolkit is correctly configured.'
|
106
|
+
end
|
88
107
|
end
|
89
108
|
|
90
109
|
cloner = cloner_factory.produce(
|
@@ -99,11 +118,12 @@ module Bookbinder
|
|
99
118
|
|
100
119
|
subnavs = (sections + gathered_dita_sections).map(&:subnav).reduce(&:merge)
|
101
120
|
|
102
|
-
success =
|
121
|
+
success = publish(
|
103
122
|
subnavs,
|
104
|
-
{verbose:
|
123
|
+
{verbose: options.include?('--verbose')},
|
105
124
|
output_locations,
|
106
|
-
archive_menu_config.generate(bind_config, sections)
|
125
|
+
archive_menu_config.generate(bind_config, sections),
|
126
|
+
cloner
|
107
127
|
)
|
108
128
|
|
109
129
|
success ? 0 : 1
|
@@ -123,107 +143,84 @@ module Bookbinder
|
|
123
143
|
:context_dir,
|
124
144
|
:dita_preprocessor,
|
125
145
|
:cloner_factory,
|
126
|
-
:dita_section_gatherer_factory
|
146
|
+
:dita_section_gatherer_factory,
|
147
|
+
:section_repository,
|
148
|
+
:command_creator,
|
149
|
+
:sheller,
|
150
|
+
:directory_preparer
|
151
|
+
|
152
|
+
def publish(subnavs, cli_options, output_locations, publish_config, cloner)
|
153
|
+
FileUtils.cp 'redirects.rb', output_locations.final_app_dir if File.exists?('redirects.rb')
|
154
|
+
|
155
|
+
host_for_sitemap = publish_config.fetch(:host_for_sitemap)
|
156
|
+
|
157
|
+
static_site_generator.run(output_locations,
|
158
|
+
publish_config,
|
159
|
+
cloner,
|
160
|
+
cli_options[:verbose],
|
161
|
+
subnavs)
|
162
|
+
file_system_accessor.copy output_locations.build_dir, output_locations.public_dir
|
163
|
+
|
164
|
+
|
165
|
+
result = generate_sitemap(host_for_sitemap)
|
166
|
+
|
167
|
+
logger.log "Bookbinder bound your book into #{output_locations.final_app_dir.to_s.green}"
|
168
|
+
|
169
|
+
!result.has_broken_links?
|
170
|
+
end
|
171
|
+
|
172
|
+
def generate_sitemap(host_for_sitemap)
|
173
|
+
raise "Your public host must be a single String." unless host_for_sitemap.is_a?(String)
|
174
|
+
sitemap_writer.write(host_for_sitemap)
|
175
|
+
end
|
127
176
|
|
128
177
|
def generate_local_repo_dir(context_dir, bind_source)
|
129
178
|
File.expand_path('..', context_dir) if bind_source == 'local'
|
130
179
|
end
|
131
180
|
|
132
181
|
def gather_sections(workspace, cloner, ref_override)
|
133
|
-
config.sections.map do |
|
182
|
+
config.sections.map do |section_config|
|
134
183
|
target_ref = ref_override ||
|
135
|
-
|
184
|
+
section_config.fetch('repository', {})['ref'] ||
|
136
185
|
'master'
|
137
|
-
repo_name =
|
138
|
-
directory =
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
186
|
+
repo_name = section_config.fetch('repository').fetch('name')
|
187
|
+
directory = section_config['directory']
|
188
|
+
working_copy = cloner.call(source_repo_name: repo_name,
|
189
|
+
source_ref: target_ref,
|
190
|
+
destination_parent_dir: workspace,
|
191
|
+
destination_dir_name: directory)
|
143
192
|
@section_repository.get_instance(
|
144
|
-
|
145
|
-
|
193
|
+
section_config,
|
194
|
+
working_copy: working_copy,
|
146
195
|
destination_dir: workspace
|
147
196
|
) { |*args| Section.new(*args) }
|
148
197
|
end
|
149
198
|
end
|
150
199
|
|
151
|
-
def prepare_directories(locations)
|
152
|
-
forget_sections(locations.output_dir)
|
153
|
-
file_system_accessor.remove_directory(File.join(locations.final_app_dir, '.'))
|
154
|
-
file_system_accessor.remove_directory(locations.dita_home_dir)
|
155
|
-
|
156
|
-
copy_directory_from_gem('template_app', locations.final_app_dir)
|
157
|
-
copy_directory_from_gem('master_middleman', locations.site_generator_home)
|
158
|
-
file_system_accessor.copy(File.join(locations.layout_repo_dir, '.'), locations.site_generator_home)
|
159
|
-
|
160
|
-
copy_version_master_middleman(locations.source_for_site_generator)
|
161
|
-
end
|
162
|
-
|
163
|
-
# Copy the index file from each version into the version's directory. Because version
|
164
|
-
# subdirectories are sections, this is the only way they get content from their master
|
165
|
-
# middleman directory.
|
166
|
-
def copy_version_master_middleman(dest_dir)
|
167
|
-
@versions.each do |version|
|
168
|
-
Dir.mktmpdir(version) do |tmpdir|
|
169
|
-
book = Book.from_remote(logger: logger,
|
170
|
-
full_name: @book_repo,
|
171
|
-
destination_dir: tmpdir,
|
172
|
-
ref: version,
|
173
|
-
git_accessor: version_control_system)
|
174
|
-
index_source_dir = File.join(tmpdir, book.directory, 'master_middleman', source_dir_name)
|
175
|
-
index_dest_dir = File.join(dest_dir, version)
|
176
|
-
file_system_accessor.make_directory(index_dest_dir)
|
177
|
-
|
178
|
-
Dir.glob(File.join(index_source_dir, 'index.*')) do |f|
|
179
|
-
file_system_accessor.copy(File.expand_path(f), index_dest_dir)
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def forget_sections(middleman_scratch)
|
186
|
-
file_system_accessor.remove_directory File.join middleman_scratch, '.'
|
187
|
-
end
|
188
|
-
|
189
|
-
def copy_directory_from_gem(dir, output_dir)
|
190
|
-
file_system_accessor.copy File.join(@gem_root, "#{dir}/."), output_dir
|
191
|
-
end
|
192
|
-
|
193
200
|
def config
|
194
201
|
config_fetcher.fetch_config
|
195
202
|
end
|
196
203
|
|
197
204
|
def layout_repo_path(local_repo_dir)
|
198
|
-
if config.has_option?('layout_repo')
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
section,
|
206
|
-
version_control_system)
|
207
|
-
repository.copy_from_remote(destination_dir, 'master')
|
208
|
-
if repository
|
209
|
-
File.join(destination_dir, repository.directory)
|
210
|
-
else
|
211
|
-
raise 'failed to fetch repository'
|
212
|
-
end
|
213
|
-
end
|
205
|
+
if local_repo_dir && config.has_option?('layout_repo')
|
206
|
+
File.join(local_repo_dir, config.layout_repo.split('/').last)
|
207
|
+
elsif config.has_option?('layout_repo')
|
208
|
+
cloner = cloner_factory.produce('github', nil)
|
209
|
+
working_copy = cloner.call(source_repo_name: config.layout_repo,
|
210
|
+
destination_parent_dir: Dir.mktmpdir)
|
211
|
+
working_copy.path
|
214
212
|
else
|
215
213
|
File.absolute_path('master_middleman')
|
216
214
|
end
|
217
215
|
end
|
218
216
|
|
219
|
-
def
|
220
|
-
bind_source,
|
221
|
-
valid_options = %w(--verbose --ignore-section-refs).to_set
|
222
|
-
%w(local github).include?(bind_source) && options.to_set.subset?(valid_options)
|
217
|
+
def validate(bind_source, options)
|
218
|
+
raise CliError::InvalidArguments unless arguments_are_valid?(bind_source, options)
|
223
219
|
end
|
224
220
|
|
225
|
-
def
|
226
|
-
|
221
|
+
def arguments_are_valid?(bind_source, options)
|
222
|
+
valid_options = %w(--verbose --ignore-section-refs).to_set
|
223
|
+
%w(local github).include?(bind_source) && options.to_set.subset?(valid_options)
|
227
224
|
end
|
228
225
|
end
|
229
226
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../../directory_helpers'
|
2
|
+
|
3
|
+
module Bookbinder
|
4
|
+
module Commands
|
5
|
+
module BindComponents
|
6
|
+
class DirectoryPreparer
|
7
|
+
include Bookbinder::DirectoryHelperMethods
|
8
|
+
|
9
|
+
def initialize(logger, file_system_accessor, version_control_system)
|
10
|
+
@logger = logger
|
11
|
+
@file_system_accessor = file_system_accessor
|
12
|
+
@version_control_system = version_control_system
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepare_directories(gem_root, versions, locations, book_repo)
|
16
|
+
forget_sections(locations.output_dir)
|
17
|
+
file_system_accessor.remove_directory(File.join(locations.final_app_dir, '.'))
|
18
|
+
file_system_accessor.remove_directory(locations.dita_home_dir)
|
19
|
+
|
20
|
+
copy_directory_from_gem(gem_root, 'template_app', locations.final_app_dir)
|
21
|
+
copy_directory_from_gem(gem_root, 'master_middleman', locations.site_generator_home)
|
22
|
+
file_system_accessor.copy(File.join(locations.layout_repo_dir, '.'), locations.site_generator_home)
|
23
|
+
|
24
|
+
versions.each do |version|
|
25
|
+
copy_index_file_from_version_to_master_middleman(version, locations.source_for_site_generator, book_repo)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :logger, :file_system_accessor, :version_control_system
|
32
|
+
|
33
|
+
def copy_index_file_from_version_to_master_middleman(version, dest_dir, book_repo)
|
34
|
+
Dir.mktmpdir(version) do |tmpdir|
|
35
|
+
book = Book.from_remote(logger: logger,
|
36
|
+
full_name: book_repo,
|
37
|
+
destination_dir: tmpdir,
|
38
|
+
ref: version,
|
39
|
+
git_accessor: version_control_system)
|
40
|
+
index_source_dir = File.join(tmpdir, book.directory, 'master_middleman', source_dir_name)
|
41
|
+
index_dest_dir = File.join(dest_dir, version)
|
42
|
+
file_system_accessor.make_directory(index_dest_dir)
|
43
|
+
|
44
|
+
Dir.glob(File.join(index_source_dir, 'index.*')) do |f|
|
45
|
+
file_system_accessor.copy(File.expand_path(f), index_dest_dir)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def forget_sections(middleman_scratch)
|
51
|
+
file_system_accessor.remove_directory File.join middleman_scratch, '.'
|
52
|
+
end
|
53
|
+
|
54
|
+
def copy_directory_from_gem(gem_root, dir, output_dir)
|
55
|
+
file_system_accessor.copy File.join(gem_root, "#{dir}/."), output_dir
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|