forked from sinonjs/sinon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·76 lines (61 loc) · 2.31 KB
/
build
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
#!/usr/bin/env ruby
require "fileutils"
require "pathname"
def add_license(file, version)
contents = File.read(file)
File.open(file, "w") do |f|
f.puts <<PREAMBLE
/**
* Sinon.JS #{version}, #{Time.now.strftime("%Y/%m/%d")}
*
* @author Christian Johansen ([email protected])
* @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
*
* #{File.read("LICENSE").split("\n").join("\n * ")}
*/
PREAMBLE
f.puts(contents)
end
end
# This code is an awful hack that is done here only because
# PhantomJS 1.x incorrectly handles "use strict" statement in
# some cases leading to sinon spy executing in a non-strict
# mode, even though it explicitly says otherwise. Since the
# people still use PhantomJS 1.x, this has to remain here
# to add another wrapper with another "use strict" on top
# of UMD bundle packaged by browserify.
def add_use_strict(file)
contents = File.read(file)
File.open(file, "w") do |f|
f.puts("(function () {")
f.puts(" 'use strict';")
f.puts(contents)
f.puts("}());")
end
file
end
Dir.chdir(File.dirname(__FILE__)) do
version = File.read("package.json").match(/"version":\s+"(.*)"/)[1]
version_string = ARGV[0] == "plain" ? "" : "-#{version}"
output = "pkg/sinon#{version_string}.js"
browserify = "./node_modules/.bin/browserify"
FileUtils.mkdir("pkg") unless File.exists?("pkg")
`#{browserify} -s sinon lib/sinon.js -o #{output}`
add_license(add_use_strict(output), version)
File.open("pkg/sinon-ie#{version_string}.js", "w") do |f|
f.puts(File.read("lib/sinon/util-ie/timers.js"))
f.puts("\n")
f.puts(File.read("lib/sinon/util-ie/xhr.js"))
f.puts(File.read("lib/sinon/util-ie/xdr.js"))
end
add_license("pkg/sinon-ie#{version_string}.js", version)
output_server = "pkg/sinon-server#{version_string}.js"
server_entry_point = "lib/sinon/util/fake_server_with_clock.js"
simulate_empty_sinon_core = "-i './lib/sinon/util/core.js'"
`#{browserify} #{server_entry_point} #{simulate_empty_sinon_core} -s sinon -o #{output_server}`
add_license("pkg/sinon-server#{version_string}.js", version)
FileUtils.cp(output, 'pkg/sinon.js')
FileUtils.cp("pkg/sinon-ie#{version_string}.js", 'pkg/sinon-ie.js')
FileUtils.cp("pkg/sinon-server#{version_string}.js", 'pkg/sinon-server.js')
puts "Built Sinon.JS #{version}"
end