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

Backport #2115 to v5.0 #2126

Merged
merged 1 commit into from
Jun 9, 2021
Merged
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
31 changes: 31 additions & 0 deletions lib/alchemy/upgrader/five_point_zero.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# frozen_string_literal: true

require_relative "tasks/harden_gutentag_migrations"
require "rails/generators"
require "thor"
require "alchemy/install/tasks"

module Alchemy
class Upgrader::FivePointZero < Upgrader
include Rails::Generators::Actions
include Thor::Base
include Thor::Actions

source_root File.expand_path("../../generators/alchemy/install/files", __dir__)

class << self
def install_gutentag_migrations
desc "Install Gutentag migrations"
Expand Down Expand Up @@ -36,6 +45,28 @@ def remove_root_page
log "Root page not found.", :skip
end
end

def run_webpacker_installer
# Webpacker does not create a package.json, but we need one
unless File.exist? app_root.join("package.json")
in_root { run "echo '{}' > package.json" }
end
new.rake("webpacker:install", abort_on_failure: true)
end

def add_npm_package
new.run "yarn add @alchemy_cms/admin"
end

def copy_alchemy_entry_point
webpack_config = YAML.load_file(app_root.join("config", "webpacker.yml"))[Rails.env]
new.copy_file "alchemy_admin.js",
app_root.join(webpack_config["source_path"], webpack_config["source_entry_path"], "alchemy/admin.js")
end

def app_root
@_app_root ||= Rails.root
end
end
end
end
20 changes: 20 additions & 0 deletions lib/tasks/alchemy/upgrade.rake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ namespace :alchemy do
"alchemy:upgrade:5.0:install_gutentag_migrations",
"alchemy:upgrade:5.0:remove_layout_roots",
"alchemy:upgrade:5.0:remove_root_page",
"alchemy:upgrade:5.0:run_webpacker_installer",
"alchemy:upgrade:5.0:add_npm_package",
"alchemy:upgrade:5.0:copy_alchemy_entry_point",
]

desc "Install Gutentag migrations"
Expand All @@ -58,6 +61,23 @@ namespace :alchemy do
task remove_root_page: [:environment] do
Alchemy::Upgrader::FivePointZero.remove_root_page
end

desc "Run webpacker installer"
task run_webpacker_installer: [:environment] do
Alchemy::Upgrader::FivePointZero.run_webpacker_installer
end

desc "Add NPM package"
task add_npm_package: [:environment] do
puts "adding npm_package..."
Alchemy::Upgrader::FivePointZero.add_npm_package
end

desc "Copy alchemy entry point"
task copy_alchemy_entry_point: [:environment] do
puts "copying alchemy entry point"
Alchemy::Upgrader::FivePointZero.copy_alchemy_entry_point
end
end
end
end