This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
105 lines (79 loc) · 2.2 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
105
# encoding: utf-8
require 'rubygems'
require 'bundler'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "js-routes"
gem.summary = "Expose Rails's routes to JavaScript"
gem.description = ""
gem.email = "[email protected]"
gem.homepage = "http://github.com/sirlantis/js-routes"
gem.authors = ["Marcel Jackwerth"]
gem.license = "MIT"
end
# Jeweler::RubygemsDotOrgTasks.new
task :release => ['gemspec:release', 'git:release']
task :default => :ci
desc "Runs all relevant tasks to check healthiness of this gem"
task :ci do
results = ["spec:js", "lint:js"].collect do |task_name|
task = Rake::Task[task_name]
error = nil
begin
task.execute
rescue => e
error = e
end
[task_name, error]
end
fails = results.select { |result| result[1] }
unless fails.empty?
fails.each do |fail|
puts "[#{fail[0]}] #{fail[1].message}"
end
end
exit(fails.count)
end
namespace :spec do
desc "Runs the specs for JavaScript files"
task :js do
puts `node specs.js $@`
exit_code = $?
raise "Exited with #{exit_code}." unless exit_code == 0
end
end
namespace :lint do
desc "Runs JSLint for JavaScript files"
task :js do
`which jslint`
unless $? == 0
puts "JSLint command-line tool required."
puts "Install via 'npm install jslint' (v0.1.1+) for correct error reporting."
return 0
end
require "active_support/core_ext/object"
template_file = File.join(File.dirname(__FILE__), 'lib', 'templates', 'router.js')
template = IO.read(template_file)
global = "Router"
converted_routes = {}
script = "" << template << global << " = " << "new RouterClass(" << converted_routes.to_json << ");"
# require 'jsmin'
# script = JSMin.minify(script)
require 'tempfile'
tmp = Tempfile.new('js-routes.js')
File.open(tmp.path, 'w') do |f|
f.puts script
end
puts `jslint #{tmp.path}`
exit_code = $?
raise "Exited with #{exit_code}." unless exit_code == 0
end
end