Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homepage webpacker task #35

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ And then execute:
bundle
bundle exec rake decidim_homepage_interactive_map:install:migrations
bundle exec rake db:migrate
bundle exec rake decidim_homepage_interactive_map:initialize
bundle exec rake decidim_homepage_interactive_map:webpacker:install
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion decidim-homepage_interactive_map.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.summary = "A decidim homepage_interactive_map module"
s.description = "Displays an interactive map on homepage."

s.files = Dir["{app,config,lib,vendor}/**/*", "LICENSE-AGPLv3.txt", "Rakefile", "README.md"]
s.files = Dir["{app,config,lib,vendor}/**/*", "LICENSE-AGPLv3.txt", "Rakefile", "README.md", "package.json"]

s.add_dependency "decidim-admin", Decidim::HomepageInteractiveMap::COMPAT_DECIDIM_VERSION
s.add_dependency "decidim-core", Decidim::HomepageInteractiveMap::COMPAT_DECIDIM_VERSION
Expand Down
10 changes: 0 additions & 10 deletions lib/tasks/map.rake

This file was deleted.

61 changes: 61 additions & 0 deletions lib/tasks/webpacker_tasks.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

require "decidim/gem_manager"

# Copied from : https://github.com/Platoniq/decidim-module-decidim_awesome/blob/main/lib/tasks/decidim_awesome_webpacker_tasks.rake

namespace :decidim_homepage_interactive_map do
namespace :webpacker do
desc "Installs module's webpacker files in Rails instance application"
task install: :environment do
raise "Decidim gem is not installed" if decidim_path.nil?

install_npm
end

desc "Adds JS dependencies in package.json"
task upgrade: :environment do
raise "Decidim gem is not installed" if decidim_path.nil?

install_npm
end

def install_npm
npm_dependencies.each do |type, packages|
puts "install NPM packages. You can also do this manually with this command:"
puts "npm i --save-#{type} #{packages.join(" ")}"
system! "npm i --save-#{type} #{packages.join(" ")}"
end
end

def npm_dependencies
@npm_dependencies ||= begin
package_json = JSON.parse(File.read(module_path.join("package.json")))

{
prod: package_json["dependencies"].map { |package, version| "#{package}@#{version}" },
}.freeze
end
end

def module_path
@module_path ||= Pathname.new(module_gemspec.full_gem_path) if Gem.loaded_specs.has_key?(gem_name)
end

def module_gemspec
@module_gemspec ||= Gem.loaded_specs[gem_name]
end

def rails_app_path
@rails_app_path ||= Rails.root
end

def system!(command)
system("cd #{rails_app_path} && #{command}") || abort("\n== Command #{command} failed ==")
end

def gem_name
"decidim-homepage_interactive_map"
end
end
end