Skip to content
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8abe79c
Added new exception page
faustinoaq Jun 16, 2018
994e730
Simplify Helpers.run
faustinoaq Jun 16, 2018
7925382
Add new amber watch config
faustinoaq Jun 16, 2018
d148ce9
Add new watch config
faustinoaq Jun 16, 2018
b65e3fb
Add JavaScript to support reload on html pages using default layout.
faustinoaq Jun 16, 2018
7f49bd7
Add missing exception
faustinoaq Jun 16, 2018
19dc8d6
Fix typo
faustinoaq Jun 17, 2018
10e9f60
Replace mtime by modification_time
faustinoaq Jun 17, 2018
4995c92
Merge branch 'fa/new-amber-watch-config' of github.com:amberframework…
faustinoaq Jun 17, 2018
65f81aa
Remove trailing whitespaces
faustinoaq Jun 19, 2018
36f7b3a
Client field is optional
faustinoaq Jun 19, 2018
11a014f
Use more descriptive var name
faustinoaq Jun 19, 2018
dbd3163
Merge branch 'master' into fa/new-amber-watch-config
faustinoaq Jun 20, 2018
20d9892
Merge branch 'master' into fa/new-exception-page
faustinoaq Jun 20, 2018
dd65e57
Error pipe cleanup
faustinoaq Jun 20, 2018
55312e9
Merge branch 'fa/new-exception-page' of github.com:amberframework/amb…
faustinoaq Jun 20, 2018
08a3e17
Add missing context argument
faustinoaq Jun 20, 2018
a31f347
Fixes valid_route? method
faustinoaq Jun 20, 2018
ba2abe4
Fixes error specs
faustinoaq Jun 20, 2018
ee8940a
Merge branch 'fa/new-exception-page' into fa/new-amber-watch-config
faustinoaq Jun 20, 2018
c405408
Remove dead sentry require
faustinoaq Jun 20, 2018
235add8
Fix error server
faustinoaq Jun 20, 2018
a4a094b
Merge branch 'master' into fa/new-amber-watch-config
faustinoaq Jun 20, 2018
b6e21a8
Merge branch 'master' into fa/new-amber-watch-config
faustinoaq Jun 20, 2018
25443c3
Add reload pipe again (still need to generate websocket reload server)
faustinoaq Jun 21, 2018
080f96c
Fix layout template
faustinoaq Jun 21, 2018
0521e1d
Add config generator
faustinoaq Jun 21, 2018
a3167ed
Add handle_terminaded_process
faustinoaq Jun 21, 2018
b88fdc2
Use Titlecase
faustinoaq Jun 21, 2018
ff5f794
Use tryReload()
faustinoaq Jun 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/amber/cli/commands/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Amber::CLI
when "create"
Micrate.logger.info create_database
when "seed"
Helpers.run("crystal db/seeds.cr", wait: true, shell: true)
Helpers.run("crystal db/seeds.cr", shell: true).wait

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helpers is a module and the .wait call makes it look like is an instance of an object and the method .run is deceiving since its just creating an instance of Process. I like that this method has some helpful arguments defaults and in that case I recommend to use class CLIProcess < Process and overwrite the run method with defaults and call super on it.

require "process"

class CLIProcess
 CLI_IO = Process::Redirect::Inherit 

 def self.instance(command, shell = true, input = CLI_IO, output = CLI_IO, error = CLI_IO)
    Process.new(command, shell: shell, input: input, output: output, error: error)
  end
end
CLIProcess.instance("crystal db/seeds.cr", shell: true).wait

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cleaner, Nice idea! 👍

Micrate.logger.info "Seeded database"
when "migrate"
begin
Expand Down
1 change: 0 additions & 1 deletion src/amber/cli/commands/pipelines.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "cli"
require "shell-table"
require "../helpers/sentry"

module Amber::CLI
class MainCommand < ::Cli::Supercommand
Expand Down
1 change: 0 additions & 1 deletion src/amber/cli/commands/routes.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "cli"
require "shell-table"
require "../helpers/sentry"

module Amber::CLI
class MainCommand < ::Cli::Supercommand
Expand Down
17 changes: 8 additions & 9 deletions src/amber/cli/commands/watch.cr
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
require "cli"
require "../helpers/sentry"
require "../helpers/process_runner"

module Amber::CLI
class MainCommand < ::Cli::Supercommand
command "w", aliased: "watch"

class Watch < Sentry::SentryCommand
command_name "watch"

class Watch < ::Cli::Command
class Options
bool "--no-color", desc: "# Disable colored output", default: false
help
end

class Help
header "Starts amber development server and rebuilds on file changes"
caption "# Starts amber development server and rebuilds on file changes"
header <<-HEADER
Starts amber development server and rebuilds on file changes.
See `.amber.yml` for more settings.
HEADER
end

def run
CLI.toggle_colors(options.no_color?)
options.watch << "./config/**/*.cr"
options.watch << "./src/views/**/*.slang"
super
process_runner = Helpers::ProcessRunner.new
process_runner.run
end
end
end
Expand Down
23 changes: 16 additions & 7 deletions src/amber/cli/config.cr
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
require "yaml"

module Amber::CLI
def self.config
if File.exists? AMBER_YML
Config.from_yaml File.read(AMBER_YML)
else
Config.new
end
rescue ex : YAML::ParseException
logger.error "Couldn't parse #{AMBER_YML} file", "Watcher", :red
exit 1
end

class Config
property database : String = "pg"
property language : String = "slang"
property model : String = "granite"
property recipe : (String | Nil) = nil
property recipe_source : (String | Nil) = nil
alias Watch = Hash(String, Hash(String, Array(String)))

getter database : String = "pg"
getter language : String = "slang"
getter model : String = "granite"
getter recipe : String?
getter recipe_source : String?
getter watch : Watch?

def initialize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this initializer since is not doing anything

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove the initialize then I can't use Config.new because it complains about no matching parameters 😅

Let me add a comment about this 👍

end
Expand All @@ -21,8 +29,9 @@ module Amber::CLI
database: {type: String, default: "pg"},
language: {type: String, default: "slang"},
model: {type: String, default: "granite"},
recipe: String | Nil,
recipe_source: String | Nil
recipe: String?,
recipe_source: String?,
watch: Watch?
)
end
end
19 changes: 19 additions & 0 deletions src/amber/cli/helpers/file_watcher.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Amber
class FileWatcher
@file_timestamps = {} of String => String

private def get_timestamp(file : String)
File.info(file).modification_time.to_s("%Y%m%d%H%M%S")
end

def scan_files(files)
Dir.glob(files) do |file|
timestamp = get_timestamp(file)
if @file_timestamps[file]? != timestamp
@file_timestamps[file] = timestamp
yield file
end
end
end
end
end
8 changes: 2 additions & 6 deletions src/amber/cli/helpers/helpers.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ module Amber::CLI::Helpers
File.write("./config/application.cr", application.gsub("require \"amber\"", replacement))
end

def self.run(command, wait = true, shell = true)
if wait
Process.run(command, shell: shell, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
else
Process.new(command, shell: shell, output: Process::Redirect::Inherit, error: Process::Redirect::Inherit)
end
def self.run(command, shell = true, input = Process::Redirect::Inherit, output = Process::Redirect::Inherit, error = Process::Redirect::Inherit)
Process.new(command, shell: shell, input: input, output: output, error: error)
end
end
Loading