-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure watch via .amber.yml (#996)
* restart server process if it stops; display compilation time; improved wording of messages * amber watch: can now (optionally) read config from .amber.yml (see template for details); rewrote ProcessRunner to handle any generic task that can be specified by a set of build and run commands and a set of globs to include and exclude; removed unused build_args and run_args args * resolved ameba warnings
- Loading branch information
Showing
6 changed files
with
263 additions
and
104 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 |
---|---|---|
@@ -1,28 +1,81 @@ | ||
module Amber::CLI | ||
def self.config | ||
if File.exists? AMBER_YML | ||
Config.from_yaml File.read(AMBER_YML) | ||
begin | ||
Config.from_yaml File.read(AMBER_YML) | ||
rescue ex : YAML::ParseException | ||
logger.error "Couldn't parse #{AMBER_YML} file", "Watcher", :red | ||
exit 1 | ||
end | ||
else | ||
Config.new | ||
end | ||
end | ||
|
||
class Config | ||
SHARD_YML = "shard.yml" | ||
DEFAULT_NAME = "[process_name]" | ||
|
||
# see defaults below | ||
alias WatchOptions = Hash(String, Hash(String, Array(String))) | ||
|
||
property database : String = "pg" | ||
property language : String = "slang" | ||
property model : String = "granite" | ||
property recipe : (String | Nil) = nil | ||
property recipe_source : (String | Nil) = nil | ||
property watch : WatchOptions | ||
|
||
def initialize | ||
@watch = default_watch_options | ||
end | ||
|
||
YAML.mapping( | ||
database: {type: String, default: "pg"}, | ||
language: {type: String, default: "slang"}, | ||
model: {type: String, default: "granite"}, | ||
recipe: String | Nil, | ||
recipe_source: String | Nil | ||
recipe_source: String | Nil, | ||
watch: {type: WatchOptions, default: default_watch_options} | ||
) | ||
|
||
def default_watch_options | ||
appname = self.class.get_name | ||
|
||
WatchOptions{ | ||
"run" => Hash{ | ||
"build_commands" => [ | ||
"mkdir -p bin", | ||
"crystal build ./src/#{appname}.cr -o bin/#{appname}", | ||
], | ||
"run_commands" => [ | ||
"bin/#{appname}", | ||
], | ||
"include" => [ | ||
"./config/**/*.cr", | ||
"./src/**/*.cr", | ||
"./src/views/**/*.slang", | ||
], | ||
}, | ||
"npm" => Hash{ | ||
"build_commands" => [ | ||
"npm install --loglevel=error", | ||
], | ||
"run_commands" => [ | ||
"npm run watch", | ||
], | ||
}, | ||
} | ||
end | ||
|
||
def self.get_name | ||
if File.exists?(SHARD_YML) && | ||
(yaml = YAML.parse(File.read SHARD_YML)) && | ||
(name = yaml["name"]?) | ||
name.as_s | ||
else | ||
DEFAULT_NAME | ||
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
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
Oops, something went wrong.