File: Rakefile

package info (click to toggle)
camping 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,312 kB
  • sloc: ruby: 5,032; javascript: 2,362; makefile: 29
file content (195 lines) | stat: -rw-r--r-- 4,592 bytes parent folder | download
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
$:.unshift 'extras'

begin
  require 'rake/dsl_definition'
  require 'rake/alt_system'
rescue LoadError
else
  begin
    if defined?(Rake::DeprecatedObjectDSL)
      Rake::DeprecatedObjectDSL.class_eval do
        private_instance_methods(false).each do |meth|
          remove_method meth
        end
      end
    end
  rescue Exception
  end
end

require "bundler/gem_tasks"
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'tempfile'
require 'open3'

# require File.expand_path('../constants', __FILE__)

CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log', '.*.pt']

task :default => :check

# New Docs

## context for the docs sections: we're going to move to using Rdoc and yard.
## With some extras. The Docs folder will probably go away.

## New docs directly serve a website like a boss.
desc "Serves the docs locally"
task :serve do
  sh "ruby -run -e httpd docs -p 8000"
end

## RDoc
begin
  gem 'rdoc', '~>3.9.0'
rescue LoadError
  task :docs do
    puts "** Camping needs RDoc 3.9 in order to use the Flipbook template."
  end
else
  require 'rdoc/task'
  RDoc::Task.new(:docs) do |rdoc|
    # We have a recent version of RDoc, so let's use flipbook.
    require 'rdoc/generator/singledarkfish'
    rdoc.options += ['-f', 'singledarkfish', *RDOC_OPTS]
    rdoc.template = "flipbook"

    rdoc.rdoc_dir = 'doc'
    rdoc.title = "Camping, a Microframework"
    rdoc.rdoc_files.add ['README', 'lib/camping-unabridged.rb', 'lib/camping/**/*.rb', 'book/*']
  end
end


task :rubygems_docs do
  require 'rubygems/doc_manager'

  def spec.installation_path; '.' end
  def spec.full_gem_path;     '.' end
  manager = Gem::DocManager.new(spec)
  manager.generate_rdoc
end

desc "Packages Camping."
task :package => :clean

## Tests
namespace :test do

  Rake::TestTask.new(:camping) do |t|
    t.libs << "test"
    t.test_files = FileList['test/app_*.rb']
  end

  Rake::TestTask.new(:gear) do |t|
    t.libs << "test"
    t.test_files = FileList['test/gear/gear_*.rb']
  end

  ## Reloader Tests
  Rake::TestTask.new(:reloader) do |t|
    t.libs << "test"
    t.test_files = FileList['test/reload_*.rb']
  end

  ## Config Reloader Tests
  Rake::TestTask.new(:configreloader) do |t|
    t.libs << "test"
    t.test_files = FileList['test/config_*.rb']
  end

  desc "Run Camping::Server tests"
  Rake::TestTask.new("server") do |t|
    t.libs << 'test/server'
    t.test_files = FileList["test/server/**/spec_*.rb"]
    t.warning = false
    t.verbose = false
  end

end

## Diff
desc "Compare camping and camping-unabridged"
task :diff do
  require 'parser/current'
  require 'unparser'
  require 'pp'
  u = Tempfile.new('unabridged')
  m = Tempfile.new('mural')

  usexp = Parser::CurrentRuby.parse(File.read("lib/camping-unabridged.rb"))
  msexp = Parser::CurrentRuby.parse(File.read("lib/camping.rb"))

  u << Unparser.unparse(usexp)
  m << Unparser.unparse(msexp)

  u.flush
  m.flush

  sh "diff -u #{u.path} #{m.path} | less"

  u.delete
  m.delete
end

error = false

## Check
task :check => ["test:camping", "test:gear", "test:reloader", "test:configreloader", "test:server", "check:valid", "check:equal", "check:size", "check:lines", "check:exit"]
namespace :check do

  desc "Check source code validity"
  task :valid do
    sh "ruby -c lib/camping.rb"
  end

  desc "Check equality between mural and unabridged"
  task :equal do
    require 'ruby_parser'
    u = RubyParser.new.parse(File.read("lib/camping-unabridged.rb"))
    m = RubyParser.new.parse(File.read("lib/camping.rb"))

    u.reject! do |sexp|
      sexp.is_a?(Sexp) and sexp[1] == s(:gvar, :$LOADED_FEATURES)
    end

    unless u == m
      STDERR.puts "camping.rb and camping-unabridged.rb are not synchronized."
      error = true
    else
      puts "✅ synchronized....."
    end
  end

  SIZE_LIMIT = 6144
  desc "Compare camping sizes to unabridged"
  task :size do
    FileList["lib/camping*.rb"].each do |path|
      s = File.size(path)
      puts "%21s : % 6d % 4d%%" % [File.basename(path), s, (100 * s / SIZE_LIMIT)]
    end
    if File.size("lib/camping.rb") > SIZE_LIMIT
      STDERR.puts "lib/camping.rb: file is too big (> #{SIZE_LIMIT})"
      error = true
    end
  end

  desc "Verify that line length doesn't exceed 80 (120) chars for camping.rb"
  task :lines do
    i = 1
    File.open("lib/camping.rb").each_line do |line|
      if line.size > 121 # 1 added for \n
        error = true
        STDERR.puts "lib/camping.rb:#{i}: line too long (#{line[-10..-1].inspect})"
      end
      i += 1
    end
  end

  task :exit do
    exit 1 if error
  end

end