|
1 | 1 | # :nodoc: |
2 | | -# Legacy CLI import - no longer needed |
3 | 2 | require "yaml" |
4 | 3 | require "./process_runner" |
5 | 4 |
|
| 5 | +# Sentry module provides file watching and process management for Amber CLI |
| 6 | +# This is used by the watch command to automatically rebuild and restart |
| 7 | +# the application when source files change. |
6 | 8 | module Sentry |
7 | | - class SentryCommand |
8 | | - property name : String = "sentry" |
9 | | - |
10 | | - class Options |
11 | | - def self.defaults |
12 | | - name = Amber::CLI::Config.get_name |
13 | | - { |
14 | | - name: name, |
15 | | - process_name: "./bin/#{name}", |
16 | | - build: join_commands(Amber::CLI.config.watch["run"]["build_commands"]), |
17 | | - run: join_commands(Amber::CLI.config.watch["run"]["run_commands"]), |
18 | | - watch: Amber::CLI.config.watch["run"]["include"], |
19 | | - } |
20 | | - end |
21 | | - |
22 | | - string %w(-n --name), desc: "Sets the name of the app process", |
23 | | - default: Options.defaults[:name] |
24 | | - |
25 | | - string %w(-b --build), desc: "Overrides the default build command", |
26 | | - default: Options.defaults[:build] |
27 | | - |
28 | | - string %w(-r --run), desc: "Overrides the default run command", |
29 | | - default: Options.defaults[:run] |
30 | | - |
31 | | - array %w(-w --watch), |
32 | | - desc: "Overrides default files and appends to list of watched files", |
33 | | - default: Options.defaults[:watch] |
34 | | - |
35 | | - bool %w(-i --info), |
36 | | - desc: "Shows the values for build/run commands, and watched files", |
37 | | - default: false |
38 | | - |
39 | | - help |
40 | | - |
41 | | - def self.join_commands(command_array : Array(String)) : String |
42 | | - case command_array.size |
43 | | - when 0 then "echo" |
44 | | - when 1 then command_array.first |
45 | | - else |
46 | | - command_array.map { |c| "(#{c})" }.join(" && ") |
47 | | - end |
48 | | - end |
49 | | - end |
50 | | - |
51 | | - def run |
52 | | - if options.info? |
53 | | - puts <<-INFO |
54 | | - name: #{options.name?} |
55 | | - build: #{options.build?} |
56 | | - run: #{options.run?} |
57 | | - files: #{options.watch} |
58 | | - INFO |
59 | | - exit! code: 0 |
60 | | - end |
61 | | - |
62 | | - build_commands = Hash(String, String).new |
63 | | - run_commands = Hash(String, String).new |
64 | | - includes = Hash(String, Array(String)).new |
65 | | - excludes = Hash(String, Array(String)).new |
66 | | - Amber::CLI.config.watch.each do |task, opts| |
67 | | - build_commands[task] = Options.join_commands(opts["build_commands"]) if opts.has_key?("build_commands") |
68 | | - run_commands[task] = Options.join_commands(opts["run_commands"]) if opts.has_key?("run_commands") |
69 | | - includes[task] = opts["include"] if opts.has_key?("include") |
70 | | - excludes[task] = opts["exclude"] if opts.has_key?("exclude") |
71 | | - |
72 | | - if task == "run" # can override via command line args |
73 | | - build_commands[task] = options.build |
74 | | - run_commands[task] = options.run |
75 | | - includes[task] = options.watch |
76 | | - end |
77 | | - end |
78 | | - process_runner = Sentry::ProcessRunner.new( |
79 | | - process_name: options.name, |
80 | | - build_commands: build_commands, |
81 | | - run_commands: run_commands, |
82 | | - includes: includes, |
83 | | - excludes: excludes |
84 | | - ) |
85 | | - |
86 | | - process_runner.run |
87 | | - end |
88 | | - end |
| 9 | + # ProcessRunner handles the actual file watching and process management |
| 10 | + # It's used by the watch command to monitor files and restart processes |
| 11 | + # when changes are detected. |
89 | 12 | end |
0 commit comments