develop #3

Merged
glenux merged 35 commits from develop into master 2024-06-02 07:08:41 +00:00
6 changed files with 44 additions and 31 deletions
Showing only changes of commit 6d34bec0e6 - Show all commits

View file

@ -3,7 +3,7 @@ require "./config"
module DocMachine::Builder
class Cli
def self.add_options(opts, parent_config)
def self.add_options(opts, args, parent_config, command)
config = Config.new(parent_config)
opts.on("build", "Build content and produce deliverables") do
@ -27,7 +27,15 @@ module DocMachine::Builder
opts.on("-t", "--tty", "Enable TTY mode (needed for shell)") do
config.enable_tty = true
end
end
command << ->() : Nil do
app = DocMachine::Builder::Run.new(config)
app.prepare
app.start
app.wait
end
end
end
end
end

View file

@ -6,10 +6,7 @@ module DocMachine
class Run
def initialize(@config : DocMachine::Builder::Config)
@basedir = config[:data_dir]? ? config[:data_dir] : Dir.current
@basehash = Digest::SHA256.hexdigest(@basedir)[0..6]
@action = config[:action]? ? config[:action] : "watch"
# @verbosity = config[:verbose]? ? config[:verbose] : 0
@basehash = Digest::SHA256.hexdigest(@config.data_dir)[0..6]
@docker_name = "docmachine-#{@basehash}"
@docker_image = "glenux/docmachine:latest"
@docker_opts = [] of String
@ -21,9 +18,9 @@ module DocMachine
# create directories
# setup permissions
def prepare()
puts "basedir = #{@basedir}"
puts "basedir = #{@config.data_dir}"
puts "docker_image = #{@docker_image}"
puts "action = #{@action}"
puts "action = #{@config.action}"
docker_cid = %x{docker ps -f "name=#{@docker_name}" -q}.strip
@ -45,21 +42,21 @@ module DocMachine
docker_opts << "run"
docker_opts << "-i"
# add tty support
docker_opts << "-t" if @enable_tty
docker_opts << "-t" if @config.enable_tty
# add container name
docker_opts.concat ["--name", @docker_name]
docker_opts << "--rm"
docker_opts << "--shm-size=1gb"
docker_opts.concat ["-e", "EXT_UID=#{uid}"]
docker_opts.concat ["-e", "EXT_GID=#{gid}"]
docker_opts.concat ["-v", "#{@basedir}/docs:/app/docs"]
docker_opts.concat ["-v", "#{@basedir}/slides:/app/slides"]
docker_opts.concat ["-v", "#{@basedir}/images:/app/images"]
docker_opts.concat ["-v", "#{@basedir}/_build:/app/_build"]
docker_opts.concat ["-v", "#{@config.data_dir}/docs:/app/docs"]
docker_opts.concat ["-v", "#{@config.data_dir}/slides:/app/slides"]
docker_opts.concat ["-v", "#{@config.data_dir}/images:/app/images"]
docker_opts.concat ["-v", "#{@config.data_dir}/_build:/app/_build"]
## Detect Marp SCSS
if File.exists?("#{@basedir}/.marp/theme.scss")
docker_opt_marp_theme = ["-v", "#{@basedir}/.marp:/app/.marp"]
if File.exists?("#{@config.data_dir}/.marp/theme.scss")
docker_opt_marp_theme = ["-v", "#{@config.data_dir}/.marp:/app/.marp"]
docker_opts.concat docker_opt_marp_theme
puts "Theme: detected Marp files. Adding option to command line (#{docker_opt_marp_theme})"
else
@ -67,14 +64,14 @@ module DocMachine
end
## Detect Mkdocs configuration - old format (full)
if File.exists?("#{@basedir}/mkdocs.yml")
if File.exists?("#{@config.data_dir}/mkdocs.yml")
puts "Mkdocs: detected mkdocs.yml file. Please rename to mkdocs-patch.yml"
exit 1
end
## Detect Mkdocs configuration - new format (patch)
if File.exists?("#{@basedir}/mkdocs-patch.yml")
docker_opt_mkdocs_config = ["-v", "#{@basedir}/mkdocs-patch.yml:/app/mkdocs-patch.yml"]
if File.exists?("#{@config.data_dir}/mkdocs-patch.yml")
docker_opt_mkdocs_config = ["-v", "#{@config.data_dir}/mkdocs-patch.yml:/app/mkdocs-patch.yml"]
docker_opts.concat docker_opt_mkdocs_config
puts "Mkdocs: detected mkdocs-patch.yml file. Adding option to command line (#{docker_opt_mkdocs_config})"
else
@ -82,7 +79,7 @@ module DocMachine
end
## Detect slides
if Dir.exists?("#{@basedir}/slides")
if Dir.exists?("#{@config.data_dir}/slides")
docker_opt_marp_port = ["-p", "5200:5200"]
docker_opts.concat docker_opt_marp_port
puts "Slides: detected slides directory. Adding option to command line (#{docker_opt_marp_port})"
@ -91,7 +88,7 @@ module DocMachine
end
## Detect docs
if Dir.exists?("#{@basedir}/docs")
if Dir.exists?("#{@config.data_dir}/docs")
docker_opt_marp_port = ["-p", "5100:5100"]
docker_opts.concat docker_opt_marp_port
puts "Slides: detected docs directory. Adding option to command line (#{docker_opt_marp_port})"
@ -100,7 +97,7 @@ module DocMachine
end
docker_opts << @docker_image
docker_opts << @action
docker_opts << @config.action
puts docker_opts.inspect.colorize(:yellow)
@process = Process.new("docker", docker_opts, output: STDOUT, error: STDERR)

View file

@ -13,8 +13,9 @@ module DocMachine
def initialize
end
def start(argv)
def start(args)
config = Config.new
commands = [] of Proc(Nil)
parser = OptionParser.new do |opts|
opts.banner = [
@ -35,17 +36,17 @@ module DocMachine
opts.separator ""
opts.separator "Commands:"
DocMachine::Builder::Cli.add_options(opts, config)
DocMachine::Scaffolder::Cli.add_options(opts, config)
DocMachine::Planner::Cli.add_options(opts, config)
DocMachine::Builder::Cli.add_options(opts, args, config, commands)
DocMachine::Scaffolder::Cli.add_options(opts, args, config, commands)
DocMachine::Planner::Cli.add_options(opts, args, config, commands)
end
parser.parse(ARGV)
parser.parse(args)
builder = DocMachine::Builder::Run.new(config)
builder.prepare
builder.start
builder.wait
commands.each do |command|
puts "running #{command}"
command.call()
end
end
end
end

View file

@ -4,7 +4,7 @@ require "./config"
module DocMachine
module Planner
class Cli
def self.add_options(opts, parent_config)
def self.add_options(opts, args, parent_config, command)
config = Config.new(parent_config)
opts.on("content", "Generate content and structure") do

View file

@ -3,12 +3,19 @@ require "./config"
module DocMachine
module Scaffolder
class Cli
def self.add_options(opts, parent_config)
def self.add_options(opts, args, parent_config, command)
config = Config.new(parent_config)
opts.on("scaffold", "Scaffold directory") do
opts.banner = "Usage: #{PROGRAM_NAME} scaffold [options]"
end
command << ->() : Nil do
# app = DocMachine::Scaffolder::Run.new(config)
# app.prepare
# app.start
# app.wait
end
end
end
end

0
src/scaffolder/run.cr Normal file
View file