#!/usr/bin/env ruby # frozen_string_literal: true STDOUT.sync = true $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "bridgetown-core" require "mercenary" Bridgetown::PluginManager.require_from_bundler Bridgetown::Deprecator.process(ARGV) Mercenary.program(:bridgetown) do |p| p.version Bridgetown::VERSION p.description "Bridgetown is a Webpack-aware, Ruby-powered static site generator for the modern Jamstack era" p.syntax "bridgetown [options]" # TODO: it seems wonky to include build options in this top-level # exe. Should probably remove most things here and relocated to # individual comments. …in fact there are duplicate option listings # if you do bridgetown build --help — ouch! p.option "source", "-s", "--source [DIR]", "Source directory (defaults to src)" p.option "destination", "-d", "--destination [DIR]", "Destination directory (defaults to output)" p.option "plugins_dir", "-p", "--plugins PLUGINS_DIR1[,PLUGINS_DIR2[,...]]", Array, "Plugins directory (defaults to plugins)" p.option "layouts_dir", "--layouts DIR", String, "Layouts directory (defaults to src/_layouts)" p.option "profile", "--profile", "Generate a Liquid rendering profile" # TODO: this is not the way to bring in extra command gems! # Bridgetown::External.require_if_present(Bridgetown::External.blessed_gems) do |g, ver_constraint| # cmd = g.split("-").last # p.command(cmd.to_sym) do |c| # c.syntax cmd # c.action do # Bridgetown.logger.abort_with "You must install the '#{g}' gem" \ # " version #{ver_constraint} to use the 'bridgetown #{cmd}' command." # end # end # end Bridgetown::Command.subclasses.each { |c| c.init_with_program(p) } p.action do |args, _| if args.empty? Bridgetown.logger.error "A subcommand is required." puts p abort else subcommand = args.first unless p.has_command? subcommand Bridgetown.logger.abort_with "fatal: 'bridgetown #{args.first}' could not" \ " be found. You may need to install the bridgetown-#{args.first} gem" \ " or a related gem to be able to use this subcommand." end end end end