-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
97 lines (83 loc) · 2.4 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
require 'erb'
require 'json'
require 'pp'
SRC_DIR = %|./src|
BOOT = %W| class events |
PARSER = %W| tokens parsers cli |
VERSION = File.read("./VERSION").strip;
namespace :test do
def get_files
ENV['TEST'] ? [ "./tests/#{ENV['TEST']}.ms" ] : Dir['./tests/*.ms']
end
desc "run all tests on ruby platform"
task :ruby => :compile do
require "./platforms/gem/lib/mochiscript"
get_files.each do |f|
puts "Testing: " + f
ctx = Mochiscript::Context.new
begin
ctx.eval_ms(File.read(f))
if ENV['VERBOSE']
puts ctx.parse(File.read(f))
end
rescue Exception => e
puts "ERROR:\n" + ctx.parse(File.read(f))
puts "TREE:\n" + ctx.pp(File.read(f))
puts e.to_s
end
end
end
desc "run all tests on node platform"
task :node => :compile do
get_files.each do |f|
puts "Testing: " + f
unless system("./bin/ms-run #{f}")
system("ERROR!!")
system("./bin/ms-parse #{f}")
end
end
end
end
desc "run all platforms' tests"
task :test => [ 'test:ruby', 'test:node' ]
desc "publish both gem and npm"
task :push => :compile do
sh "cd ./platforms/gem; rm *.gem; gem build mochiscript.gemspec; gem push *.gem; "
sh "cd ./platforms/npm; npm publish;"
end
desc "install gem"
task :install_gem => :compile do
sh "cd ./platforms/gem; rm *.gem; gem build mochiscript.gemspec; gem install *.gem; "
end
desc "compile src to target"
task :compile do
@boot = BOOT.collect { |f| parse("#{SRC_DIR}/#{f}.ms") }.join("\n")
@parser = PARSER.collect { |f| parse("#{SRC_DIR}/#{f}.ms") }.join("\n")
traverse_dir('./src/platforms') do |target|
destination = target.sub(/^\.\/src(.*)\.erb$/, '.\1')
puts "Compiling #{target}\n --> #{destination}"
File.open(destination, "w") { |t| t << ERB.new(File.read(target)).result(binding) }
end
system("cp ./platforms/www/mochiscript.js .")
system("cp ./platforms/www/mochiscript-full.js .")
end
desc "copy over bootstrap"
task :bootstrap do
[ './platforms/npm/lib/mochiscript/mochiscript.js' ].each do |f|
sh "cp #{f} ./bootstrap/"
end
end
def parse(file)
`./bootstrap/ms-parse #{file}`
end
def traverse_dir(file_path)
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file!="." and file!=".."
traverse_dir("#{file_path}/#{file}"){ |x| yield x }
end
end
else
yield file_path
end
end