-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
139 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module MStrap | ||
abstract class Bootstrapper | ||
include DSL | ||
|
||
def initialize(@config : Configuration) | ||
end | ||
|
||
def self.for(config : Configuration, project : Project) : Array(Bootstrapper) | ||
bootstrappers = Array(Bootstrapper).new | ||
|
||
if project.run_scripts? && Bootstrappers::ScriptBootstrapper.has_scripts?(project) | ||
bootstrappers << Bootstrappers::ScriptBootstrapper.new(config) | ||
else | ||
bootstrappers << Bootstrappers::DefaultBootstrapper.new(config) | ||
|
||
if project.web? | ||
bootstrappers << Bootstrappers::WebBootstrapper.new(config) | ||
end | ||
end | ||
|
||
bootstrappers | ||
end | ||
|
||
abstract def bootstrap(project : Project) : Bool | ||
|
||
protected getter :config | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module MStrap | ||
module Bootstrappers | ||
class DefaultBootstrapper < Bootstrapper | ||
# Conventional bootstrapping from mstrap. This will auto-detect the runtimes | ||
# used by the project and run the standard bootstrapping for each runtime. | ||
# This **does not** run any bootstrapping scripts, and is used mainly for | ||
# calling into conventional bootstrapping within a project's | ||
# `script/bootstrap` or `script/setup` from `mstrap project`. | ||
def bootstrap(project : Project) : Bool | ||
logd "Bootstrapping '#{project.name}' with runtime defaults." | ||
|
||
runtime_impls(project).each do |runtime| | ||
Dir.cd(project.path) do | ||
if runtime.matches? | ||
logd "Detected #{runtime.language_name}. Installing #{runtime.language_name}, project #{runtime.language_name} packages, and other relevant dependencies" | ||
runtime.setup | ||
end | ||
end | ||
end | ||
|
||
true | ||
end | ||
|
||
def runtime_impls(project) | ||
if project.runtimes.empty? | ||
config.runtime_manager.runtimes | ||
else | ||
config.runtime_manager.runtimes.select do |runtime| | ||
project.runtimes.includes?(runtime.language_name) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module MStrap | ||
module Bootstrappers | ||
class ScriptBootstrapper < Bootstrapper | ||
# :nodoc: | ||
BOOTSTRAP_SCRIPT = File.join("script", "bootstrap") | ||
|
||
# :nodoc: | ||
SETUP_SCRIPT = File.join("script", "setup") | ||
|
||
# Executes `script/bootstrap` and `script/setup` (if either exists and are | ||
# configured to run) | ||
def bootstrap(project : Project) : Bool | ||
logd "Found bootstrapping scripts, executing instead of using defaults." | ||
|
||
begin | ||
ENV["__MSTRAP_EXEC_SCRIPTS"] = "true" | ||
|
||
Dir.cd(project.path) do | ||
cmd BOOTSTRAP_SCRIPT if File.exists?(BOOTSTRAP_SCRIPT) | ||
cmd SETUP_SCRIPT if File.exists?(SETUP_SCRIPT) | ||
end | ||
ensure | ||
ENV.delete("__MSTRAP_EXEC_SCRIPTS") | ||
end | ||
|
||
true | ||
end | ||
|
||
# Whether project has any bootstrapping/setup scripts a-la | ||
# [`scripts-to-rule-them-all`](https://github.com/github/scripts-to-rule-them-all) | ||
def self.has_scripts?(project) | ||
[BOOTSTRAP_SCRIPT, SETUP_SCRIPT].any? do |script_path| | ||
File.exists?(File.join(project.path, script_path)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module MStrap | ||
module Bootstrappers | ||
# The `WebBootstrapper` is responsible for bootstrapping web-based projects. | ||
# Currently, this is just setting up an NGINX configuration for the project. | ||
class WebBootstrapper < Bootstrapper | ||
include DSL | ||
|
||
def initialize(@config : Configuration) | ||
super | ||
@mkcert = Mkcert.new | ||
end | ||
|
||
# Executes the bootstrapper | ||
def bootstrap(project : Project) : Bool | ||
logd "'#{project.name}' is a web project. Running web bootstrapper." | ||
|
||
if mkcert.installed? | ||
Dir.cd(Paths::PROJECT_CERTS) do | ||
mkcert.install! | ||
mkcert.install_cert!(project.hostname) | ||
end | ||
else | ||
logw "mkcert not found. Skipping cert setup." | ||
end | ||
|
||
Templates::NginxConf.new(project).write_to_config! | ||
true | ||
end | ||
|
||
private getter :mkcert | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.