2023-03-27 16:01:20 +02:00
|
|
|
|
|
|
|
# Core
|
|
|
|
require "file_utils"
|
|
|
|
|
|
|
|
# Internal
|
|
|
|
require "./config"
|
|
|
|
|
|
|
|
# Shards
|
|
|
|
require "term-prompt"
|
|
|
|
|
2023-04-23 15:59:29 +02:00
|
|
|
module DocMachine::Scaffold
|
2023-03-27 16:01:20 +02:00
|
|
|
class Run
|
2023-04-23 15:59:29 +02:00
|
|
|
private property config : DocMachine::Scaffold::Config
|
2023-03-27 16:01:20 +02:00
|
|
|
|
|
|
|
def initialize(@config)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Verify parameters
|
|
|
|
def prepare()
|
|
|
|
if ! File.directory? @config.target_directory
|
|
|
|
STDERR.puts "ERROR: target must be a directory"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
puts "Target directory: #{@config.target_directory}"
|
|
|
|
|
|
|
|
if !@config.force
|
|
|
|
prompt = Term::Prompt.new
|
|
|
|
confirm = prompt.no?("Are you sure you want to proceed?")
|
|
|
|
exit 1 if !confirm
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def start()
|
|
|
|
puts "== Scaffolding #{@config.target_directory}"
|
|
|
|
p = Path.new(@config.target_directory)
|
|
|
|
cwd = Dir.current
|
|
|
|
["docs", "slides", "images"].each do |dir|
|
|
|
|
p_sub = p.join(dir)
|
|
|
|
puts "-- creating #{p_sub}"
|
|
|
|
FileUtils.mkdir_p(p_sub)
|
|
|
|
end
|
|
|
|
["docs", "slides"].each do |dir|
|
|
|
|
p_sub = p.join(dir)
|
|
|
|
FileUtils.cd(p_sub)
|
|
|
|
puts "-- creating link to images in #{p_sub}"
|
|
|
|
if File.symlink? "images"
|
|
|
|
FileUtils.rm "images"
|
|
|
|
end
|
|
|
|
FileUtils.ln_sf(Path.new("..","images"), Path.new("images"))
|
|
|
|
FileUtils.cd(cwd)
|
|
|
|
end
|
|
|
|
puts "-- creating README.md"
|
|
|
|
FileUtils.touch("README.md")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Verify parameters
|
|
|
|
def wait()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|