Class: Lilac::CLI::Scaffold

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/scaffold.rb

Overview

Generates a new Lilac app skeleton under <root>/<name>/:

<name>/
├── .gitignore
├── Gemfile
├── README.md
├── pages/index.html
└── components/counter.lil

Templates live under lib/lilac/cli/templates/. Files are copied 1:1 with {{name}} substituted to the chosen project name. The .gitignore template is shipped as gitignore (no leading dot) so the gem's own working-directory tools don't treat it as a directive for the templates folder; it gets the dot prefix at copy time.

Defined Under Namespace

Classes: Error

Constant Summary collapse

TEMPLATES_DIR =
File.expand_path("templates", __dir__)
NAME_PATTERN =

Project names must look like a valid directory + future gem-ish identifier: ASCII lowercase letters, digits, hyphens, underscores, starting with a letter.

/\A[a-z][a-z0-9_-]*\z/

Instance Method Summary collapse

Constructor Details

#initialize(name, root: Dir.pwd) ⇒ Scaffold

Returns a new instance of Scaffold.



32
33
34
35
36
# File 'lib/lilac/cli/scaffold.rb', line 32

def initialize(name, root: Dir.pwd)
  @name = name
  @root = root
  validate_name!
end

Instance Method Details

#runObject

Returns the list of relative paths written.

Raises:



39
40
41
42
43
44
45
# File 'lib/lilac/cli/scaffold.rb', line 39

def run
  dest = File.expand_path(@name, @root)
  raise Error, "Destination already exists: #{dest}" if File.exist?(dest)

  FileUtils.mkdir_p(dest)
  copy_templates(dest)
end