feat: Add support for scaffold
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
6d34bec0e6
commit
b8c887682b
8 changed files with 140 additions and 26 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
/bin
|
/bin
|
||||||
|
/lib
|
||||||
|
|
||||||
|
|
30
shard.lock
Normal file
30
shard.lock
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
version: 2.0
|
||||||
|
shards:
|
||||||
|
completion:
|
||||||
|
git: https://github.com/f/completion.git
|
||||||
|
version: 0.1.0+git.commit.d8799381b2de14430496199260eca64eb329625f
|
||||||
|
|
||||||
|
cor:
|
||||||
|
git: https://github.com/watzon/cor.git
|
||||||
|
version: 0.1.0+git.commit.9c9e51ac6168f3bd4fdc51d679b65de09ef76cac
|
||||||
|
|
||||||
|
ioctl:
|
||||||
|
git: https://github.com/crystal-posix/ioctl.cr.git
|
||||||
|
version: 1.0.0
|
||||||
|
|
||||||
|
term-cursor:
|
||||||
|
git: https://github.com/crystal-term/cursor.git
|
||||||
|
version: 0.1.0+git.commit.8805d5f686d153db92cf2ce3333433f8ed3708d0
|
||||||
|
|
||||||
|
term-prompt:
|
||||||
|
git: https://github.com/crystal-term/prompt.git
|
||||||
|
version: 0.1.0+git.commit.bf2b17f885a6c660aea0dda62b0b9da4343ab295
|
||||||
|
|
||||||
|
term-reader:
|
||||||
|
git: https://github.com/crystal-term/reader.git
|
||||||
|
version: 0.1.0+git.commit.cd022d4d4628e5d9de47e669a770ccb7df412863
|
||||||
|
|
||||||
|
term-screen:
|
||||||
|
git: https://github.com/crystal-term/screen.git
|
||||||
|
version: 0.1.0+git.commit.ea51ee8d1f6c286573c41a7e784d31c80af7b9bb
|
||||||
|
|
13
shard.yml
13
shard.yml
|
@ -12,10 +12,15 @@ targets:
|
||||||
docmachine:
|
docmachine:
|
||||||
main: src/main.cr
|
main: src/main.cr
|
||||||
|
|
||||||
# dependencies:
|
dependencies:
|
||||||
# pg:
|
term-prompt:
|
||||||
# github: will/crystal-pg
|
github: crystal-term/prompt
|
||||||
# version: "~> 0.5"
|
|
||||||
|
# completion:
|
||||||
|
# github: f/completion
|
||||||
|
# pg:
|
||||||
|
# github: will/crystal-pg
|
||||||
|
# version: "~> 0.5"
|
||||||
|
|
||||||
# development_dependencies:
|
# development_dependencies:
|
||||||
# webmock:
|
# webmock:
|
||||||
|
|
|
@ -3,7 +3,7 @@ require "./config"
|
||||||
|
|
||||||
module DocMachine::Builder
|
module DocMachine::Builder
|
||||||
class Cli
|
class Cli
|
||||||
def self.add_options(opts, args, parent_config, command)
|
def self.add_options(opts, args, parent_config, commands)
|
||||||
config = Config.new(parent_config)
|
config = Config.new(parent_config)
|
||||||
|
|
||||||
opts.on("build", "Build content and produce deliverables") do
|
opts.on("build", "Build content and produce deliverables") do
|
||||||
|
@ -28,7 +28,7 @@ module DocMachine::Builder
|
||||||
config.enable_tty = true
|
config.enable_tty = true
|
||||||
end
|
end
|
||||||
|
|
||||||
command << ->() : Nil do
|
commands << ->() : Nil do
|
||||||
app = DocMachine::Builder::Run.new(config)
|
app = DocMachine::Builder::Run.new(config)
|
||||||
app.prepare
|
app.prepare
|
||||||
app.start
|
app.start
|
||||||
|
|
13
src/cli.cr
13
src/cli.cr
|
@ -42,10 +42,17 @@ module DocMachine
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.parse(args)
|
parser.parse(args)
|
||||||
|
puts commands
|
||||||
|
|
||||||
commands.each do |command|
|
if commands.size > 0
|
||||||
puts "running #{command}"
|
commands.each do |command|
|
||||||
command.call()
|
# puts "== Running #{command}"
|
||||||
|
command.call()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts parser.to_s
|
||||||
|
STDOUT.puts ""
|
||||||
|
STDERR.puts "ERROR: no command defined"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,20 +1,29 @@
|
||||||
require "./config"
|
require "./config"
|
||||||
|
require "./run"
|
||||||
|
|
||||||
module DocMachine
|
module DocMachine::Scaffolder
|
||||||
module Scaffolder
|
class Cli
|
||||||
class Cli
|
def self.add_options(opts, args, parent_config, commands)
|
||||||
def self.add_options(opts, args, parent_config, command)
|
config = Config.new(parent_config)
|
||||||
config = Config.new(parent_config)
|
|
||||||
|
|
||||||
opts.on("scaffold", "Scaffold directory") do
|
opts.on("scaffold", "Scaffold target directory") do
|
||||||
opts.banner = "Usage: #{PROGRAM_NAME} scaffold [options]"
|
opts.banner = "Usage: #{PROGRAM_NAME} scaffold [options] TARGET"
|
||||||
|
|
||||||
|
opts.on("-f", "--force", "Don't ask for confirmation") do
|
||||||
|
config.force = true
|
||||||
end
|
end
|
||||||
|
|
||||||
command << ->() : Nil do
|
commands << ->() : Nil do
|
||||||
# app = DocMachine::Scaffolder::Run.new(config)
|
if args.size < 1
|
||||||
# app.prepare
|
STDERR.puts "ERROR: No target given!"
|
||||||
# app.start
|
exit 1
|
||||||
# app.wait
|
end
|
||||||
|
config.target_directory = args[0]
|
||||||
|
|
||||||
|
app = DocMachine::Scaffolder::Run.new(config)
|
||||||
|
app.prepare
|
||||||
|
app.start
|
||||||
|
app.wait
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
|
||||||
|
|
||||||
module DocMachine
|
module DocMachine::Scaffolder
|
||||||
module Scaffolder
|
class Config
|
||||||
class Config
|
property target_directory : String = "."
|
||||||
def initialize(@parent : DocMachine::Config)
|
property force : Bool = false
|
||||||
end
|
|
||||||
|
def initialize(@parent : DocMachine::Config)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
|
||||||
|
# Core
|
||||||
|
require "file_utils"
|
||||||
|
|
||||||
|
# Internal
|
||||||
|
require "./config"
|
||||||
|
|
||||||
|
# Shards
|
||||||
|
require "term-prompt"
|
||||||
|
|
||||||
|
module DocMachine::Scaffolder
|
||||||
|
class Run
|
||||||
|
private property config : DocMachine::Scaffolder::Config
|
||||||
|
|
||||||
|
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
|
Loading…
Reference in a new issue