monoz 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95f85442889a0675ea32c6e1109e20201793b8a9933329103be401551b23438b
4
- data.tar.gz: 81e4f563fc9797196c7bf5531030f5848da689e9e400fea3cdf28263c66dc99d
3
+ metadata.gz: 8690b4b3d6adc785adfa22b77c24f72fb2524aa57f337b9d58723b29d9c95e37
4
+ data.tar.gz: ffce67da4773d0a25c7c0844fcbe35e5ee21b6e8aff7ada1541e5cf7fdaf6feb
5
5
  SHA512:
6
- metadata.gz: '08dad5e93a296263067bcf7e38621772bfd74c88a0258d07f7c3b72674c56c450211aeebc178bd0075c5626356039413c4d129eb38ee2545865d005e1ac43945'
7
- data.tar.gz: 1858caeb0e79ceba16d373b79278a4acc031953963751e5c8815f43ff1691af9e4884002826963989ddd7dfdf9ace6588b3e199778dcbb3ebcec1de90b7b45d3
6
+ metadata.gz: bf09e686e3baddbe8bb618d7372044f0d862a0cbe2b2f787490d98b8d5dce1f40d0c78891c4a910c1d162c3998586d9d96e24671c49a8ea6f23b54d6a4f4fe2d
7
+ data.tar.gz: 21015ca0dbdf5b9ac345043415156003c1ed02e46244b0ca6f20858a8d9b9d99d35060d6f23a4f44ca9076c2ece7f6868466b0a73bbe660336de79284340f95d
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Monoz is a command-line tool that helps you manage your **ruby** monorepo. It provides an easy way to manage multiple related **ruby** projects and their dependencies in a single repository. Monoz helps you keep track of your projects and their interdependencies, making it easier to maintain and scale your codebase.
4
4
 
5
- ## Installation
5
+ ## Getting started
6
6
 
7
7
  You can install Monoz by running the following command:
8
8
 
@@ -10,8 +10,6 @@ You can install Monoz by running the following command:
10
10
  $ gem install monoz
11
11
  ```
12
12
 
13
- ## Getting started
14
-
15
13
  To initialize a Monoz repository in the current directory, simply run:
16
14
 
17
15
  ```console
@@ -29,7 +27,9 @@ This will create a new Monoz repo with the following structure:
29
27
  └── monoz.yml
30
28
  ```
31
29
 
32
- ### Adding projects
30
+ ## Projects
31
+
32
+ ### Add a project
33
33
 
34
34
  Once you've initialized your Monoz repository, you can start adding projects to it.
35
35
 
@@ -57,6 +57,13 @@ To bundle all the projects in the Monoz repository, simply run:
57
57
 
58
58
  ```console
59
59
  $ monoz bundle
60
+
61
+ kiqr_core: bundle ✓
62
+ content_api: bundle ✓
63
+ core_api: bundle ✓
64
+ kiqr_cloud: bundle ✓
65
+
66
+ The command ran successfully in all projects without any errors.
60
67
  ```
61
68
 
62
69
  If you instead want to update the dependencies of your projects, you can use the `monoz bundle update` command. This command will update the `Gemfile.lock` file of each project based on the latest available versions of their dependencies.
@@ -65,33 +72,44 @@ To update the dependencies of all projects in the Monoz repository, simply run:
65
72
 
66
73
  ```console
67
74
  $ monoz bundle update
75
+
76
+ kiqr_core: bundle update ✓
77
+ content_api: bundle update ✓
78
+ core_api: bundle update ✓
79
+ kiqr_cloud: bundle update ✓
80
+
81
+ The command ran successfully in all projects without any errors.
68
82
  ```
69
83
 
70
84
  Note that when you add a new dependency to a project, you'll need to run `monoz bundle` to update its `Gemfile.lock` file before you can use the new dependency. Similarly, if you update the dependencies of a project's `Gemfile`, you'll need to run `monoz bundle` to update its `Gemfile.lock` file with the new versions.
71
85
 
72
86
  #### Run other bundler commands
73
87
 
74
- You can also run other bundler commands on all projects in the repository using the `monoz bundle` command followed by the desired arguments. For example, to run the RSpec tests for all projects, you can use the following command:
88
+ You can also run other bundler commands on all projects in the repository using the `monoz bundle` command followed by the desired arguments. For example, to run Rubocop tests in all projects, you can use the following command:
75
89
 
76
90
  ```console
77
- $ monoz bundle exec rspec
91
+ $ monoz bundle exec rubocop
92
+
93
+ kiqr_core: bundle exec rubocop ✓
94
+ content_api: bundle exec rubocop ✗
95
+ Configuration file not found: /some/path/.rubocop.yml
78
96
 
79
- [kiqr_core] bundle exec rspec
80
- [core_api] bundle exec rspec
81
- [content_api] bundle exec rspec
82
- [kiqr_cloud] bundle exec rspec
97
+ core_api: bundle exec rubocop ✓
98
+ kiqr_cloud: bundle exec rubocop ✓
99
+
100
+ Error: The command bundle exec rubocop failed to run in one or more project directories
83
101
  ```
84
102
 
85
- This will execute the `bundle exec rspec` command in each project directory, ensuring that all the necessary dependencies are installed and loaded for each project. Similarly, you can run other bundler commands such as `bundle install`, `bundle update`, and so on, by appending the desired arguments to the `monoz bundle` command.
103
+ This will execute the `bundle exec rubocop` command in each project directory, ensuring that all the necessary dependencies are installed and loaded for each project. Similarly, you can run other bundler commands such as `bundle install`, `bundle update`, and so on, by appending the desired arguments to the `monoz bundle` command.
86
104
 
87
- ### Inspect projects
105
+ ### List projects
88
106
 
89
- You can inspect the projects in your Monoz repository using the `monoz inspect` command. This command will display a table that shows the projects in the repository, their type (app or gem), the gem name (if it's a gem), the test framework(s) used, and the projects that depend on them.
107
+ You can inspect the projects in your Monoz repository using the `monoz projects` command. This command will display a table that shows the projects in the repository, their type (app or gem), the gem name (if it's a gem), the test framework(s) used, and the projects that depend on them.
90
108
 
91
- Here's an example output of the `monoz inspect` command:
109
+ Here's an example output of the `monoz projects` command:
92
110
 
93
111
  ```console
94
- $ monoz inspect
112
+ $ monoz projects
95
113
 
96
114
  o---------------o--------o-------------o---------------------o-------------------------------------o
97
115
  | Project | Type | Gem Name | Test Framework(s) | Dependants |
@@ -103,6 +121,97 @@ o---------------o--------o-------------o---------------------o------------------
103
121
  o---------------o--------o-------------o---------------------o-------------------------------------o
104
122
  ```
105
123
 
124
+ ## Runing commands
125
+
126
+ ### Running commands in projects
127
+
128
+ You can run any command in all projects of your Monoz repository using the `monoz run` command. Simply provide the command you want to run as an argument, and Monoz will execute it in each project directory.
129
+
130
+ For example, to create an empty file named test.txt in the tmp/ directory of all projects, you can use the following command:
131
+
132
+ ```console
133
+ $ monoz run touch tmp/test.txt
134
+
135
+ kiqr_core: touch tmp/test.txt ✓
136
+ content_api: touch tmp/test.txt ✓
137
+ core_api: touch tmp/test.txt ✓
138
+ kiqr_cloud: touch tmp/test.txt ✓
139
+
140
+ The command ran successfully in all projects without any errors.
141
+ ```
142
+
143
+ This will execute the `touch tmp/test.txt` command in each project directory, creating the test.txt file in the tmp/ directory. If a command fails to run in a project directory, Monoz will display an error message with the output of the command.
144
+
145
+ Note that if you need to run a command in a specific project, you can simply navigate to the project directory and run the command as you would in a regular Ruby project. The monoz run command is primarily useful for running commands across one ore many projects in a Monoz repository at once.
146
+
147
+ ### Run in foreground / interactive mode
148
+
149
+ You can run commands in interactive mode using the flag `--tty`, or `-t`:
150
+
151
+ ```console
152
+ $ monoz run bin/dev --filter=example_com --tty
153
+
154
+ example_com: bin/dev
155
+ 23:41:04 web.1 | started with pid 96841
156
+ 23:41:04 css.1 | started with pid 96842
157
+ 23:41:05 web.1 | => Booting Puma
158
+ 23:41:05 web.1 | => Rails 7.0.4.3 application starting in development
159
+ 23:41:05 web.1 | => Run `bin/rails server --help` for more startup options
160
+ 23:41:06 web.1 | Puma starting in single mode...
161
+ 23:41:06 web.1 | * Puma version: 5.6.5 (ruby 3.2.0-p0) ("Birdie's Version")
162
+ 23:41:06 web.1 | * Min threads: 5
163
+ 23:41:06 web.1 | * Max threads: 5
164
+ 23:41:06 web.1 | * Environment: development
165
+ 23:41:06 web.1 | * PID: 96841
166
+ 23:41:06 web.1 | * Listening on http://127.0.0.1:3000
167
+ 23:41:06 web.1 | * Listening on http://[::1]:3000
168
+ 23:41:06 web.1 | Use Ctrl-C to stop
169
+ 23:41:06 css.1 |
170
+ 23:41:06 css.1 | Rebuilding...
171
+ 23:41:06 css.1 |
172
+ 23:41:06 css.1 | Done in 354ms.
173
+ ```
174
+
175
+ ### Filtering projects
176
+
177
+ The `--filter` option in Monoz allows you to select certain projects based on specific criteria. This is useful if you only want to run a command on a specific subset of projects, rather than all of them. To use the `--filter` option, you simply specify a filter expression after the option. The filter expression is a comma-separated list of keywords that match the project names or tags in your Monoz configuration.
178
+
179
+ For example, suppose you have a Monoz configuration with several projects, some of which are tagged as **apps** and some of which are tagged as **gems**. You can use the `--filter` option to select only the **apps** projects by running the following command:
180
+
181
+ ```console
182
+ $ monoz bundle --filter=apps
183
+
184
+ content_api: bundle ✓
185
+ core_api: bundle ✓
186
+ kiqr_cloud: bundle ✓
187
+
188
+ The command ran successfully in all project directories without any errors.
189
+ ```
190
+
191
+ Similarly, if you only want to list only gem projects, you can use the following command:
192
+
193
+ ```console
194
+ $ monoz projects --filter=gems
195
+
196
+ o-------------o--------o-------------o----------------------o-------------------------------------o
197
+ | Project | Type | Gem name | Found Framework(s) | Dependants |
198
+ o-------------o--------o-------------o----------------------o-------------------------------------o
199
+ | kiqr_core | gem | kiqr_core | rspec | content_api, core_api, kiqr_cloud |
200
+ o-------------o--------o-------------o----------------------o-------------------------------------o
201
+ ```
202
+
203
+ You can also use multiple keywords in the filter expression to select projects that match any of the keywords. For example, to run the `mrsk deploy` command on all **apps** and **apis** projects, you can use the following command:
204
+
205
+ ```console
206
+ $ monoz run mrsk deploy --filter="apps,apis"
207
+ ```
208
+
209
+ Finally, you can also specify individual project names in the filter expression. For example, to run the `rubocop` command on only the **gem1** and **gem2** projects, you can use the following command:
210
+
211
+ ```console
212
+ $ monoz run rubocop --filter="gem1,gem2"
213
+ ```
214
+
106
215
  ## Contributing
107
216
  We welcome contributions from everyone! If you're interested in contributing to Monoz, please check out our contributing guidelines for more information.
108
217
 
data/bin/monoz CHANGED
@@ -4,8 +4,12 @@
4
4
  require "monoz"
5
5
 
6
6
  begin
7
- Monoz::Cli::Main.start(ARGV)
7
+ Monoz::Application.start(ARGV)
8
8
  rescue Monoz::Errors::ConfigurationNotFound
9
- puts "This is not a valid Monoz directory."
9
+ puts "Error: This is not a valid Monoz directory."
10
10
  puts "Run monoz init to initialize Monoz in the current directory."
11
+ exit(1)
12
+ rescue Monoz::Errors::StandardError => e
13
+ puts "Error: #{e.message}"
14
+ exit(1)
11
15
  end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "yaml"
5
+ require "fileutils"
6
+
7
+ module Monoz
8
+ class Application < Thor
9
+ class_option :tty, type: :boolean, aliases: ["--verbose", "-t"], default: false
10
+ class_option :filter
11
+
12
+ def initialize(*args)
13
+ super
14
+ Monoz.app = self
15
+ end
16
+
17
+ desc "init [PATH]", "Initialize a monozrepo at the specified PATH"
18
+ def init(path = ".")
19
+ Monoz::Services::InitService.new(self).call(path)
20
+ end
21
+
22
+ desc "bundle [COMMAND]", "Run bundle commands in all projects"
23
+ def bundle(*command)
24
+ return help("bundle") if command.nil? || command.first == "help"
25
+
26
+ projects = Monoz.projects.order(:dependants)
27
+ Monoz::Services::RunService.new(self).call(projects, "bundle", *command)
28
+
29
+ say "The command ran successfully in all project directories without any errors.", [:green]
30
+ end
31
+
32
+ desc "projects", "Shows a list of projects in this repository"
33
+ def projects
34
+ Monoz.projects.order(:name).to_table
35
+ end
36
+
37
+ map "run" => "run_action"
38
+ desc "run [COMMAND]", "Run commands in all projects"
39
+ def run_action(*command)
40
+ return help("run") if command.empty? || command.first == "help"
41
+
42
+ projects = Monoz.projects.order(:dependants)
43
+ Monoz::Services::RunService.new(self).call(projects, *command)
44
+
45
+ say "The command ran successfully in all project directories without any errors.", [:green]
46
+ end
47
+
48
+ desc "version", "Get the current version of Monoz"
49
+ def version
50
+ say "Monoz version: #{Monoz::VERSION}"
51
+ end
52
+ end
53
+ end
data/lib/monoz/project.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Monoz
4
4
  class Project
5
- attr_reader :name, :root_path, :gemspec, :type, :dependencies, :gem_name, :dependants
5
+ attr_reader :name, :root_path, :gemspec, :type, :dependencies, :gem_name, :dependants, :frameworks
6
6
 
7
7
  def initialize(root_path)
8
8
  @root_path = root_path
@@ -21,33 +21,27 @@ module Monoz
21
21
  @root_path != nil && gemfile_path != nil
22
22
  end
23
23
 
24
- def run(*command)
25
- FileUtils.chdir(root_path) do
26
- system(*command)
27
- end
28
- end
29
-
30
24
  def text_color
31
25
  is_gem? ? :green : :blue
32
26
  end
33
27
 
34
- def test_frameworks
35
- frameworks = []
28
+ private
29
+ def find_frameworks
30
+ frameworks = []
36
31
 
37
- rspec_files = Dir.glob(File.join(@root_path, "**/*_spec.rb"))
38
- if !rspec_files.empty?
39
- frameworks << "rspec"
40
- end
32
+ rspec_files = Dir.glob(File.join(@root_path, "**/*_spec.rb"))
33
+ if !rspec_files.empty?
34
+ frameworks << "rspec"
35
+ end
41
36
 
42
- minitest_files = Dir.glob(File.join(@root_path, "test/**/*_test.rb"))
43
- if !minitest_files.empty?
44
- frameworks << "minitest"
45
- end
37
+ minitest_files = Dir.glob(File.join(@root_path, "test/**/*_test.rb"))
38
+ if !minitest_files.empty?
39
+ frameworks << "minitest"
40
+ end
46
41
 
47
- frameworks
48
- end
42
+ frameworks
43
+ end
49
44
 
50
- private
51
45
  def parse_project_files
52
46
  @gemspec = parse_gemspec
53
47
  end
@@ -61,8 +55,7 @@ module Monoz
61
55
 
62
56
  spec = Gem::Specification.load(gemspec_file)
63
57
  {
64
- name: spec.name,
65
- version: spec.version.to_s
58
+ name: spec.name
66
59
  }
67
60
  end
68
61
 
@@ -70,7 +63,7 @@ module Monoz
70
63
  @name = File.basename(root_path)
71
64
  @gem_name = @gemspec.dig(:name) if is_gem?
72
65
  @type = is_gem? ? "gem" : "app"
73
- @test_frameworks =
66
+ @frameworks = find_frameworks
74
67
  @dependants = []
75
68
  end
76
69
 
@@ -51,27 +51,42 @@ module Monoz
51
51
  end
52
52
  end
53
53
 
54
- def filter(key)
55
- if key.to_sym == :apps
56
- @items = @items.select { |i| i.type == "app" }
57
- self
58
- elsif key.to_sym == :gems
59
- @items = @items.select { |i| i.type == "gem" }
60
- self
61
- else
62
- raise "Invalid filter key: #{key}"
54
+ def filter(filters = [])
55
+ if filters.is_a?(String)
56
+ filters = filters.split(",").map(&:strip)
57
+ end
58
+ if filters.empty?
59
+ @items = []
60
+ return self
61
+ end
62
+ filtered_items = []
63
+ filters.each do |filter|
64
+ if filter == "gems"
65
+ filtered_items += @items.select { |i| i.type == "gem" }
66
+ elsif filter == "apps"
67
+ filtered_items += @items.select { |i| i.type == "app" }
68
+ else
69
+ project = find(filter)
70
+ if project
71
+ filtered_items << project
72
+ else
73
+ raise Monoz::Errors::StandardError.new("Invalid key: #{filter}")
74
+ end
75
+ end
63
76
  end
77
+ @items = filtered_items.uniq
78
+ self
64
79
  end
65
80
 
66
81
  def to_table
67
82
  rows = []
68
83
  @items.each do |project|
69
- rows << [project.name, project.type, project.gem_name, project.test_frameworks.join(", "), project.dependants.join(", ")]
84
+ rows << [project.name, project.type, project.gem_name, project.frameworks.join(", "), project.dependants.join(", ")]
70
85
  end
71
86
  table = Terminal::Table.new(
72
- headings: ["Project", "Type", "Gem Name", "Test Framework(s)", "Dependants"],
73
- rows:,
74
- style: { padding_left: 2, padding_right: 2, border_i: "o" },
87
+ headings: ["Project", "Type", "Gem name", "Found Framework(s)", "Dependants"],
88
+ rows: rows,
89
+ style: { padding_left: 2, padding_right: 2, border_i: "o" }
75
90
  )
76
91
  puts table
77
92
  end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "fileutils"
5
+ require "open3"
6
+
7
+ module Monoz
8
+ class Spinner
9
+ include Thor::Shell
10
+
11
+ def initialize(message, prefix: nil)
12
+ @spinner = nil
13
+ @message = message
14
+ @prefix = prefix
15
+ end
16
+
17
+ def start
18
+ @spinner = main
19
+ self
20
+ end
21
+
22
+ def success!
23
+ @spinner.kill
24
+ say_formatted(" \u2713 ", [:bold, :green])
25
+ say() # line break
26
+ end
27
+
28
+ def error!
29
+ @spinner.kill
30
+ say_formatted(" \u2717 ", [:bold, :red])
31
+ say() # line break
32
+ end
33
+
34
+ private
35
+ def reset
36
+ say("\r", nil, false)
37
+ end
38
+
39
+ def say_formatted(suffix, suffix_formatting = nil)
40
+ if @prefix != nil
41
+ say "\r[#{@prefix}] ", [:blue, :bold], nil
42
+ say @message, nil, false
43
+ say suffix, suffix_formatting, false
44
+ else
45
+ say "\r#{@message}", nil, false
46
+ say suffix, suffix_formatting, false
47
+ end
48
+ end
49
+
50
+ def main
51
+ spinner_count = 0
52
+
53
+ Thread.new do
54
+ loop do
55
+ dots = case spinner_count % 3
56
+ when 0 then "."
57
+ when 1 then ".."
58
+ when 2 then "..."
59
+ end
60
+
61
+ say_formatted(dots)
62
+ spinner_count += 1
63
+ sleep(0.5)
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ module Services
70
+ class RunService < Monoz::Services::BaseService
71
+ attr_reader :errors, :warnings
72
+
73
+ def initialize(thor_instance)
74
+ @projects = nil
75
+ @errors = []
76
+ @warnings = []
77
+ super(thor_instance)
78
+ end
79
+
80
+ def success?
81
+ !errors? && !warnings?
82
+ end
83
+
84
+ def errors?
85
+ @errors.any?
86
+ end
87
+
88
+ def warnings?
89
+ @warnings.any?
90
+ end
91
+
92
+ def call(projects, *command)
93
+ raise ArgumentError.new("Missing command") if command.empty?
94
+
95
+ if projects.is_a?(Monoz::ProjectCollection)
96
+ @projects = projects.all
97
+ elsif projects.is_a?(Monoz::Project)
98
+ @projects = [projects]
99
+ else
100
+ raise "Invalid projects"
101
+ end
102
+
103
+ @projects.each do |project|
104
+ # say "#{project.name}: ", [:bold, :blue]
105
+ # Monoz.tty? ? say(command.join(" ")) : say("#{command.join(" ")} ")
106
+
107
+ if Monoz.tty?
108
+ say "[#{project.name}] ", [:blue, :bold], nil
109
+ say command.join(" ")
110
+ else
111
+ spinner = Monoz::Spinner.new(command.join(" "), prefix: project.name).start
112
+ end
113
+
114
+ response = run_commands_in_project(project, *command)
115
+
116
+ if response.success?
117
+ spinner.success! unless Monoz.tty?
118
+ else
119
+ spinner.error! unless Monoz.tty?
120
+ say response.output
121
+ say "" # line break
122
+ @errors << {
123
+ project: project.name,
124
+ command: command.join(" "),
125
+ exit_code: response.exit_code,
126
+ output: response.output
127
+ }
128
+ end
129
+ end
130
+
131
+ say ""
132
+
133
+ if errors?
134
+ say "Error: The command ", :red
135
+ say "#{command.join(" ")} ", [:red, :bold]
136
+ say "failed to run in one or more project directories", [:red]
137
+ exit(1)
138
+ end
139
+ end
140
+
141
+ private
142
+ def run_commands_in_project(project, *command)
143
+ raise ArgumentError.new("Invalid command") if command.empty?
144
+
145
+ output = ""
146
+ exit_status = nil
147
+
148
+ FileUtils.chdir(project.root_path) do
149
+ if Monoz.tty?
150
+ Open3.popen2e(*command.map { |arg| Shellwords.escape(arg) }) do |stdin, stdout_err, wait_thr|
151
+ while line = stdout_err.gets
152
+ output += line
153
+ print line
154
+ end
155
+
156
+ exit_status = wait_thr.value.exitstatus
157
+ end
158
+
159
+ say ""
160
+ else
161
+ output, status = Open3.capture2e(*command.map { |arg| Shellwords.escape(arg) })
162
+ exit_status = status.exitstatus
163
+ end
164
+ end
165
+
166
+ return Monoz::Responses::CaptureRunResponse.new(output, exit_status)
167
+ end
168
+ end
169
+ end
170
+ end
data/lib/monoz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Monoz
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/monoz.rb CHANGED
@@ -3,36 +3,71 @@
3
3
  require_relative "monoz/version"
4
4
 
5
5
  require "pathname"
6
+ require "shellwords"
6
7
 
7
8
  module Monoz
8
9
  module Errors
10
+ class StandardError < StandardError; end
9
11
  class ConfigurationNotFound < StandardError; end
10
12
  end
11
13
 
12
- module Cli
13
- autoload "Inspect", "monoz/cli/inspect"
14
- autoload "Main", "monoz/cli/main"
15
- autoload "Run", "monoz/cli/run"
14
+ module Responses
15
+ class CaptureRunResponse
16
+ attr_reader :output, :exit_code
17
+
18
+ def initialize(output, exit_code)
19
+ @output = output
20
+ @exit_code = exit_code
21
+ end
22
+
23
+ def success?
24
+ exit_code == 0
25
+ end
26
+
27
+ def error?
28
+ exit_code == 1
29
+ end
30
+ end
16
31
  end
17
32
 
18
33
  module Services
19
34
  autoload "BaseService", "monoz/services/base_service"
20
- autoload "BundleService", "monoz/services/bundle_service"
21
35
  autoload "InitService", "monoz/services/init_service"
22
- autoload "RunActionService", "monoz/services/run_action_service"
36
+ autoload "RunService", "monoz/services/run_service"
23
37
  end
24
38
 
39
+ autoload "Application", "monoz/application"
25
40
  autoload "Configuration", "monoz/configuration"
26
41
  autoload "Project", "monoz/project"
27
42
  autoload "ProjectCollection", "monoz/project_collection"
28
43
 
29
44
  class << self
45
+ def app
46
+ @app
47
+ end
48
+
49
+ def app=(value)
50
+ @app = value
51
+ end
52
+
30
53
  def config
31
54
  @config ||= Monoz::Configuration.new(pwd)
32
55
  end
33
56
 
57
+ def options
58
+ @app&.options
59
+ end
60
+
61
+ def tty?
62
+ Monoz.options.dig("tty") == true
63
+ end
64
+
34
65
  def projects
35
- Monoz::ProjectCollection.new(config.root_path)
66
+ filter = Monoz.options&.dig("filter")
67
+ projects = Monoz::ProjectCollection.new(config.root_path)
68
+ projects = projects.filter(filter) unless filter.nil?
69
+
70
+ projects
36
71
  end
37
72
 
38
73
  def pwd
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monoz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kjellberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-04 00:00:00.000000000 Z
11
+ date: 2023-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -64,15 +64,13 @@ files:
64
64
  - README.md
65
65
  - bin/monoz
66
66
  - lib/monoz.rb
67
- - lib/monoz/cli/inspect.rb
68
- - lib/monoz/cli/main.rb
67
+ - lib/monoz/application.rb
69
68
  - lib/monoz/configuration.rb
70
69
  - lib/monoz/project.rb
71
70
  - lib/monoz/project_collection.rb
72
71
  - lib/monoz/services/base_service.rb
73
- - lib/monoz/services/bundle_service.rb
74
72
  - lib/monoz/services/init_service.rb
75
- - lib/monoz/services/run_action_service.rb
73
+ - lib/monoz/services/run_service.rb
76
74
  - lib/monoz/version.rb
77
75
  homepage: https://github.com/kjellberg/monoz
78
76
  licenses:
@@ -89,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
87
  requirements:
90
88
  - - ">="
91
89
  - !ruby/object:Gem::Version
92
- version: 2.6.0
90
+ version: 2.7.0
93
91
  required_rubygems_version: !ruby/object:Gem::Requirement
94
92
  requirements:
95
93
  - - ">="
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor"
4
- require "yaml"
5
-
6
- module Monoz
7
- module Cli
8
- class Inspect < Thor
9
- default_task :all
10
-
11
- desc "all", "Returns a list of all projects in this monozrepo"
12
- def all
13
- Monoz.projects.order(:name).to_table
14
- end
15
-
16
- desc "apps", "Returns a list of apps in this monozrepo"
17
- def apps
18
- Monoz.projects.order(:name).filter(:apps).to_table
19
- end
20
-
21
- desc "gems", "Returns a list of gems in this monozrepo"
22
- def gems
23
- Monoz.projects.filter(:gems).order(:name).to_table
24
- end
25
- end
26
- end
27
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor"
4
- require "yaml"
5
- require "fileutils"
6
-
7
- module Monoz
8
- module Cli
9
- class Main < Thor
10
- desc "init [PATH]", "Initialize a monozrepo at the specified PATH"
11
- def init(path = ".")
12
- Monoz::Services::InitService.new(self).call(path)
13
- end
14
-
15
- desc "bundle [COMMAND]", "Run bundle commands in all projects"
16
- def bundle(*command)
17
- Monoz::Services::BundleService.new(self).call(*command)
18
- end
19
-
20
- desc "inspect", "Inspect this monozrepo"
21
- subcommand "inspect", Monoz::Cli::Inspect
22
-
23
- map "run" => "run_action"
24
- desc "run [action]", "Run commands in all projects"
25
- def run_action(keys = nil)
26
- return help("run") if keys.nil? || keys == "help"
27
-
28
- Monoz::Services::RunActionService.new(self).call(keys)
29
- end
30
-
31
- desc "version", "Get the current version of Monoz"
32
- def version
33
- say "Monoz version: #{Monoz::VERSION}"
34
- end
35
- end
36
- end
37
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
- require "fileutils"
5
- require "active_support"
6
-
7
- module Monoz
8
- module Services
9
- class BundleService < Monoz::Services::BaseService
10
- def call(*command)
11
- Monoz.projects.order(:dependants).each do |project|
12
- say "[#{project.name}] ", [:blue, :bold], false
13
- say("bundle #{command.join(" ")}".strip, :green)
14
- project.run "bundle", *command
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
- require "fileutils"
5
-
6
- module Monoz
7
- module Services
8
- class RunActionService < Monoz::Services::BaseService
9
- def call(keys = nil)
10
- action = Monoz.config.dig("actions", *keys)
11
-
12
- if action.nil?
13
- say "Invalid action: ", :red, false
14
- say keys, [:red, :bold]
15
- exit 0
16
- end
17
-
18
- pp action
19
- # Monoz.projects.order(:dependants).each do |project|
20
- # project.run "ls"
21
- # end
22
- end
23
- end
24
- end
25
- end