-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run multiple assets processes (#131)
Update the `assets compile` and `assets watch` commands to fork a child process per slice and run a separate assets command per each. Provide appropriate `--path` and `--dest` flags for each of these commands, allowing each slice's assets to be compiled separately and generated into distinct directories (`public/assets/` for the app, and `public/assets/[slice_name]/` for slices). Support per-slice assets config by running a slice's own `config/assets.js`, if present, otherwise falling back to the app's `config/assets.js`. Use the new `node_command` setting to invoke node when running the `config/assets.js` command.
- Loading branch information
Showing
12 changed files
with
562 additions
and
37 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
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 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 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,94 @@ | ||
# frozen_string_literal: true | ||
|
||
require "hanami/devtools/integration/files" | ||
require "hanami/devtools/integration/with_tmp_directory" | ||
require "json" | ||
require "tmpdir" | ||
require "zeitwerk" | ||
|
||
module RSpec | ||
module Support | ||
module WithTmpDirectory | ||
private | ||
|
||
def make_tmp_directory | ||
Pathname(Dir.mktmpdir).tap do |dir| | ||
(@made_tmp_dirs ||= []) << dir | ||
end | ||
end | ||
end | ||
|
||
module App | ||
end | ||
end | ||
end | ||
|
||
RSpec.shared_context "App integration" do | ||
let(:app_modules) { %i[Test TestApp Admin Main] } | ||
end | ||
|
||
def autoloaders_teardown! | ||
ObjectSpace.each_object(Zeitwerk::Loader) do |loader| | ||
loader.unregister if loader.dirs.any? { |dir| | ||
dir.include?("/spec/") || dir.include?(Dir.tmpdir) || | ||
dir.include?("/slices/") || dir.include?("/app") | ||
} | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include RSpec::Support::Files, :app_integration | ||
config.include RSpec::Support::WithTmpDirectory, :app_integration | ||
config.include RSpec::Support::App, :app_integration | ||
config.include_context "App integration", :app, :app_integration | ||
|
||
prepare_example = proc do | ||
# Conditionally assign in case these have been assigned earlier for specific example groups | ||
@load_paths ||= $LOAD_PATH.dup | ||
@loaded_features ||= $LOADED_FEATURES.dup | ||
end | ||
|
||
tidy_example = proc do | ||
autoloaders_teardown! | ||
|
||
Hanami.instance_variable_set(:@_bundled, {}) | ||
Hanami.remove_instance_variable(:@_app) if Hanami.instance_variable_defined?(:@_app) | ||
|
||
$LOAD_PATH.replace(@load_paths) | ||
|
||
# Remove example-specific LOADED_FEATURES added when running each example | ||
new_features_to_keep = ($LOADED_FEATURES - @loaded_features).tap { |feats| | ||
feats.delete_if do |path| | ||
path =~ %r{hanami/(setup|prepare|boot|application/container/providers)} || | ||
path.include?(SPEC_ROOT.to_s) || | ||
path.include?(Dir.tmpdir) | ||
end | ||
} | ||
$LOADED_FEATURES.replace(@loaded_features + new_features_to_keep) | ||
|
||
app_modules.each do |app_module_name| | ||
next unless Object.const_defined?(app_module_name) | ||
|
||
Object.const_get(app_module_name).tap do |mod| | ||
mod.constants.each do |name| | ||
mod.send(:remove_const, name) | ||
end | ||
end | ||
|
||
Object.send(:remove_const, app_module_name) | ||
end | ||
end | ||
|
||
config.before(:each, :app) { instance_eval(&prepare_example) } | ||
config.before(:each, :app_integration) { instance_eval(&prepare_example) } | ||
config.after(:each, :app) { instance_eval(&tidy_example) } | ||
config.after(:each, :app_integration) { instance_eval(&tidy_example) } | ||
|
||
config.after :all do | ||
if instance_variable_defined?(:@made_tmp_dirs) | ||
Array(@made_tmp_dirs).each do |dir| | ||
FileUtils.remove_entry dir | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.