This repository has been archived by the owner on Nov 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Rakefile
105 lines (83 loc) · 2.54 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require 'rubygems'
require 'bundler/setup'
require 'yaml'
require 'json'
require 'sequel'
require './server/config_manager'
require './server/model/user'
require './server/model/form'
require './server/model/connection_manager'
require './server/lib/extensions'
ConfigManager.load
namespace :deploy do
desc 'Compile and bundle assets for the application'
task :build do
require 'yui/compressor'
root = File.dirname __FILE__
assets = YAML.load_file("#{root}/server/assets.yml")
out = File.open "#{root}/public/javascripts/build.js", 'w'
# javascript
puts 'bundling JS...'
compressor = YUI::JavaScriptCompressor.new :munge => true
assets['javascripts'].each do |filename|
out.puts "/* #{filename}.js */"
out.puts compressor.compress( File.open "#{root}/public/javascripts/#{filename}.js", 'r' )
puts "...#{filename}.js [ok]"
end
# asset build timestamp
puts 'writing build time...'
File.open( "#{root}/.build_time", 'w' ) { |f| f.write Time.new.to_i }
# fin
puts 'done!'
end
end
namespace :db do
task :migrate do
Sequel.extension :migration, :core_extensions
db = ConnectionManager.rackless_connection
Sequel::Migrator.apply(db, 'server/model/migrations')
db.disconnect
puts "migrated successfully."
end
end
namespace :admin do
desc "Grant a user admin privileges"
task :add, :username do |t, args|
db = ConnectionManager.rackless_connection
username = args[:username]
abort "Missing required parameter: username" unless username
user = User.find(username)
abort "Could not find user: #{username}" if user.nil?
user.admin = true
user.save
puts "granted #{username} admin privileges"
end
desc "Revoke a user's admin privileges"
task :remove, :username do |t, args|
db = ConnectionManager.rackless_connection
username = args[:username]
abort "Missing required parameter: username" unless username
user = User.find(username)
user.admin = false
user.save
puts "revoked admin privileges from #{username}"
end
desc "List all users with admin priviliges"
task :list do
db = ConnectionManager.rackless_connection
admins = db[:users].query do |q|
q.add "admin", :equals, true
end
puts "users with admin privileges:"
admins.each { |admin| puts "#{admin["display_name"]} (#{admin["email"]})" }
end
end
desc "Run all tests"
task :test do
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "test"
t.pattern = "test/**/*_test.rb"
t.verbose = false
end
end