未验证 提交 69c963c2 编写于 作者: J Javan Makhmali 提交者: GitHub

Merge pull request #34958 from javan/actiontext/trix-as-peer

Declare Trix as peer dependency of Action Text's npm package
import * as Trix from "trix"
import { AttachmentUpload } from "./attachment_upload"
addEventListener("trix-attachment-add", event => {
......
require "pathname"
require "json"
APPLICATION_PACK_PATH = Pathname.new("app/javascript/packs/application.js")
JS_PACKAGE_PATH = Pathname.new("#{__dir__}/../../package.json")
JS_PACKAGE = JSON.load(JS_PACKAGE_PATH)
JS_DEPENDENCIES = JS_PACKAGE["peerDependencies"].dup.merge \
JS_PACKAGE["name"] => "^#{JS_PACKAGE["version"]}"
say "Copying actiontext.scss to app/assets/stylesheets"
copy_file "#{__dir__}/actiontext.scss", "app/assets/stylesheets/actiontext.scss"
......@@ -8,14 +18,15 @@
copy_file "#{__dir__}/../../app/views/active_storage/blobs/_blob.html.erb",
"app/views/active_storage/blobs/_blob.html.erb"
say "Installing JavaScript dependency"
run "yarn add @rails/actiontext"
APPLICATION_PACK_PATH = "app/javascript/packs/application.js"
say "Installing JavaScript dependencies"
run "yarn add #{JS_DEPENDENCIES.map { |name, version| "#{name}@#{version}" }.join(" ")}"
if File.exist?(APPLICATION_PACK_PATH) && File.read(APPLICATION_PACK_PATH) !~ /import "@rails\/actiontext"/
say "Adding import to default JavaScript pack"
append_to_file APPLICATION_PACK_PATH, <<-EOS
import "@rails/actiontext"
EOS
if APPLICATION_PACK_PATH.exist?
JS_DEPENDENCIES.keys.each do |name|
line = %[require("#{name}")]
unless APPLICATION_PACK_PATH.read.include? line
say "Adding #{name} to #{APPLICATION_PACK_PATH}"
append_to_file APPLICATION_PACK_PATH, "#{line}\n"
end
end
end
......@@ -21,7 +21,9 @@
],
"license": "MIT",
"dependencies": {
"trix": "^1.0.0",
"@rails/activestorage": "^6.0.0-alpha"
},
"peerDependencies": {
"trix": "^1.0.0"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册