This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Rakefile
55 lines (46 loc) · 1.74 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'bundler/gem_tasks'
require 'json'
README_VERSION_REGEXP = /bundled by this gem is \[([^\]]*)\]/
VERSION_FILE_REGEXP = /MEDIUM_EDITOR_VERSION\s.*/
namespace :bower do
desc "updates JS version references in README and VERSION files"
task :bump do
bump_readme_file
bump_version_file
end
desc "updates javascripts from bower package manager"
task :update do
puts `bower install medium-editor --save`
end
desc "vendors javascripts and stylesheets for rails assets pipeline"
task :vendor do
cp_asset "bower_components/medium-editor/dist/js/medium-editor.js"
cp_asset "bower_components/medium-editor/dist/css/medium-editor.css"
cp_themes
end
end
def version_from_bower
data = JSON.load File.read "bower_components/medium-editor/.bower.json"
data["version"]
end
def cp_themes
puts "vendoring themes"
FileUtils.cp_r "bower_components/medium-editor/dist/css/themes", "vendor/assets/stylesheets/medium-editor"
end
def cp_asset filename
base_filename = File.basename(filename)
asset_folder = base_filename.include?(".js") ? "javascripts" : "stylesheets/medium-editor"
puts "vendoring " + base_filename
FileUtils.cp filename, File.join("vendor/assets/#{asset_folder}", base_filename)
end
def bump_readme_file
latest_version = "bundled by this gem is [#{version_from_bower}]"
lines = File.read('README.md')
File.open('README.md', 'w'){ |f| f.puts lines.gsub(README_VERSION_REGEXP, latest_version) }
end
def bump_version_file
version_filename = File.join("lib", "medium-editor-rails", "version.rb")
latest_version = "MEDIUM_EDITOR_VERSION = '#{version_from_bower}'"
lines = File.read(version_filename)
File.open(version_filename, 'w') { |f| f.puts lines.gsub(VERSION_FILE_REGEXP, latest_version) }
end