2013-11-08 01:48:23 +08:00
|
|
|
directory 'plugins'
|
|
|
|
|
2017-07-19 04:55:31 +08:00
|
|
|
desc 'install all official plugins (use GIT_WRITE=1 to pull with write access)'
|
2017-07-19 00:09:27 +08:00
|
|
|
task 'plugin:install_all_official' do
|
|
|
|
skip = Set.new([
|
|
|
|
'customer-flair',
|
|
|
|
'discourse-nginx-performance-report',
|
|
|
|
'lazyYT',
|
|
|
|
'poll',
|
2019-01-29 14:19:42 +08:00
|
|
|
'discourse-calendar'
|
2017-07-19 00:09:27 +08:00
|
|
|
])
|
|
|
|
|
|
|
|
map = {
|
|
|
|
'Canned Replies' => 'https://github.com/discourse/discourse-canned-replies',
|
2018-10-13 03:56:23 +08:00
|
|
|
'discourse-perspective' => 'https://github.com/discourse/discourse-perspective-api'
|
2017-07-19 00:09:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#require 'plugin/metadata'
|
|
|
|
Plugin::Metadata::OFFICIAL_PLUGINS.each do |name|
|
|
|
|
next if skip.include? name
|
|
|
|
repo = map[name] || "https://github.com/discourse/#{name}"
|
|
|
|
dir = repo.split('/').last
|
|
|
|
path = File.expand_path('plugins/' + dir)
|
|
|
|
|
|
|
|
if Dir.exist? path
|
|
|
|
STDERR.puts "Skipping #{dir} cause it already exists!"
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
if ENV['GIT_WRITE']
|
|
|
|
STDERR.puts "Allowing write to all repos!"
|
|
|
|
repo.gsub!("https://github.com/", "git@github.com:")
|
|
|
|
repo << ".git"
|
|
|
|
end
|
|
|
|
|
|
|
|
status = system("git clone #{repo} #{path}")
|
|
|
|
unless status
|
|
|
|
abort("Failed to clone #{repo}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-08 01:48:23 +08:00
|
|
|
desc 'install plugin'
|
|
|
|
task 'plugin:install', :repo do |t, args|
|
|
|
|
repo = ENV['REPO'] || ENV['repo'] || args[:repo]
|
|
|
|
name = ENV['NAME'] || ENV['name'] || File.basename(repo, '.git')
|
|
|
|
|
|
|
|
plugin_path = File.expand_path('plugins/' + name)
|
|
|
|
if File.directory?(File.expand_path(plugin_path))
|
2017-07-28 09:20:09 +08:00
|
|
|
abort('Plugin directory, ' + plugin_path + ', already exists.')
|
2013-11-08 01:48:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
clone_status = system('git clone ' + repo + ' ' + plugin_path)
|
|
|
|
unless clone_status
|
|
|
|
FileUtils.rm_rf(plugin_path)
|
|
|
|
abort('Unable to clone plugin')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'update all plugins'
|
|
|
|
task 'plugin:update_all' do |t|
|
|
|
|
# Loop through each directory
|
|
|
|
plugins = Dir.glob(File.expand_path('plugins/*')).select { |f| File.directory? f }
|
|
|
|
# run plugin:update
|
|
|
|
plugins.each { |plugin| Rake::Task['plugin:update'].invoke(plugin) }
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'update a plugin'
|
|
|
|
task 'plugin:update', :plugin do |t, args|
|
|
|
|
plugin = ENV['PLUGIN'] || ENV['plugin'] || args[:plugin]
|
|
|
|
plugin_path = plugin
|
|
|
|
plugin = File.basename(plugin)
|
|
|
|
|
|
|
|
unless File.directory?(plugin_path)
|
|
|
|
if File.directory?('plugins/' + plugin)
|
|
|
|
plugin_path = File.expand_path('plugins/' + plugin)
|
|
|
|
else
|
|
|
|
abort('Plugin ' + plugin + ' not found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
update_status = system('git --git-dir "' + plugin_path + '/.git" --work-tree "' + plugin_path + '" pull')
|
|
|
|
abort('Unable to pull latest version of plugin') unless update_status
|
|
|
|
end
|
2014-02-02 04:22:53 +08:00
|
|
|
|
|
|
|
desc 'run plugin specs'
|
|
|
|
task 'plugin:spec', :plugin do |t, args|
|
2014-03-04 17:00:35 +08:00
|
|
|
args.with_defaults(plugin: "*")
|
2014-02-02 04:22:53 +08:00
|
|
|
ruby = `which ruby`.strip
|
2019-02-01 20:40:29 +08:00
|
|
|
files = Dir.glob("./plugins/#{args[:plugin]}/spec/**/*_spec.rb")
|
2014-02-02 04:22:53 +08:00
|
|
|
if files.length > 0
|
2014-02-05 13:20:28 +08:00
|
|
|
sh "LOAD_PLUGINS=1 #{ruby} -S rspec #{files.join(' ')}"
|
2014-02-02 04:22:53 +08:00
|
|
|
else
|
|
|
|
abort "No specs found."
|
|
|
|
end
|
|
|
|
end
|
2017-07-26 21:07:46 +08:00
|
|
|
|
|
|
|
desc 'run plugin qunit tests'
|
|
|
|
task 'plugin:qunit', [:plugin, :timeout] do |t, args|
|
|
|
|
args.with_defaults(plugin: "*")
|
|
|
|
|
2017-07-27 00:54:56 +08:00
|
|
|
rake = `which rake`.strip
|
|
|
|
|
|
|
|
cmd = 'LOAD_PLUGINS=1 '
|
|
|
|
cmd += 'QUNIT_SKIP_CORE=1 '
|
2017-07-27 01:11:08 +08:00
|
|
|
|
2017-07-26 21:07:46 +08:00
|
|
|
if args[:plugin] == "*"
|
|
|
|
puts "Running qunit tests for all plugins"
|
|
|
|
else
|
|
|
|
puts "Running qunit tests for #{args[:plugin]}"
|
2017-07-27 00:54:56 +08:00
|
|
|
cmd += "QUNIT_SINGLE_PLUGIN='#{args[:plugin]}' "
|
2017-07-26 21:07:46 +08:00
|
|
|
end
|
2017-07-27 01:11:08 +08:00
|
|
|
|
2017-07-27 00:54:56 +08:00
|
|
|
cmd += "#{rake} qunit:test"
|
2017-07-27 01:11:08 +08:00
|
|
|
cmd += "[#{args[:timeout]}]" if args[:timeout]
|
2017-07-27 00:54:56 +08:00
|
|
|
|
|
|
|
sh cmd
|
2017-07-26 21:07:46 +08:00
|
|
|
end
|