Sha256: 11bfff2d06019e035597a7bc3b04742feda29594932b715e302c0ba461d5c7bc

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require "dry/cli"

module Staticky
  module CLI
    module Commands
      extend Dry::CLI::Registry

      class Version < Dry::CLI::Command
        desc "Print version"

        def call(*) = puts VERSION
      end

      class Build < Dry::CLI::Command
        desc "Build site"

        def call(*) = Staticky.builder.call
      end

      class Generate < Dry::CLI::Command
        desc "Create new site"

        argument :path,
                 required: true,
                 desc: "Relative path where the site will be generated"

        option :url,
               default: "https://example.com",
               desc: "Site URL",
               aliases: ["-u"]
        option :title,
               default: "Example",
               desc: "Site title",
               aliases: ["-t"]
        option :description,
               default: "Example site",
               desc: "Site description",
               aliases: ["-d"]
        option :twitter,
               default: "",
               desc: "Twitter handle",
               aliases: ["-t"]

        def call(path:, **)
          path = Pathname.new(path).expand_path

          Staticky.generator.call(path, **)

          commands = [
            "bundle install",
            "bundle binstubs bundler rake rspec-core vite_ruby",
            "yarn install",
            "bin/rspec"
          ].join(" && ")

          system(commands, chdir: path) || abort("install failed")
        end
      end

      register "version", Version
      register "build", Build
      register "new", Generate
    end

    def self.new(...)
      Dry::CLI.new(Commands)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
staticky-0.1.1 lib/staticky/cli.rb
staticky-0.1.0 lib/staticky/cli.rb