Skip to content

Commit

Permalink
Backport AlchemyCMS#2115 to v5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwinger committed Jun 9, 2021
1 parent f8708e2 commit d2879a1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
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

0 comments on commit d2879a1

Please sign in to comment.