-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathbuildDistFiles.rb
100 lines (80 loc) · 2.61 KB
/
buildDistFiles.rb
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
# File: buildDistFiles.rb
#
# Build distribution files for Evothings libraries.
require "fileutils"
require 'time'
include FileUtils::Verbose
### File helpers
def fileRead(filePath)
File.open(filePath, "r") {
|f|
s = f.read
if (RUBY_VERSION >= "1.9")
return s.force_encoding("UTF-8")
else
return s
end
}
end
def fileReadAndDisableAsyncLoading(filePath)
# Replace evothings.loadScripts and evothings.loadScript
# with dummy function to disable async script loading since
# we have all scripts in one file.
fileRead(filePath)
.gsub("evothings.loadScripts", "evothings.__NOOP_FUN__")
.gsub("evothings.loadScript", "evothings.__NOOP_FUN__")
end
def fileWrite(destFile, content)
File.open(destFile, "w") { |f| f.write(content) }
end
### Build library files
def buildDistFiles
buildEasyBLE
buildEddystone
end
def buildEasyBLE
libsPath = "./libs/evothings/"
distPath = "./libs/evothings/easyble/easyble.dist.js"
# Paths to JS files required by easyble.dist.js.
evothingsbasejs = fileRead(libsPath + "evothings-dist-base.js")
evothingsjs = fileRead(libsPath + "evothings.js")
utiljs = fileReadAndDisableAsyncLoading(libsPath + "util/util.js")
easyblejs = fileReadAndDisableAsyncLoading(libsPath + "easyble/easyble.js")
# File separator.
fileSep = "\n\n// --------------------------------------------------\n\n\n"
# Concatenate files.
distFile =
"// File easyble.dist.js " + Time.now.utc.iso8601 + "\n"+
"// This file was generated by buildDistFiles.rb" + fileSep +
evothingsbasejs + fileSep +
evothingsjs + fileSep +
utiljs + fileSep +
easyblejs + fileSep
# Write out dist JS file.
fileWrite(distPath, distFile)
end
def buildEddystone
libsPath = "./libs/evothings/"
distPath = "./libs/evothings/eddystone/eddystone.dist.js"
# Paths to JS files required by easyble.dist.js.
evothingsbasejs = fileRead(libsPath + "evothings-dist-base.js")
evothingsjs = fileRead(libsPath + "evothings.js")
utiljs = fileReadAndDisableAsyncLoading(libsPath + "util/util.js")
easyblejs = fileReadAndDisableAsyncLoading(libsPath + "easyble/easyble.js")
eddystonejs = fileReadAndDisableAsyncLoading(libsPath + "eddystone/eddystone.js")
# File separator.
fileSep = "\n\n// --------------------------------------------------\n\n\n"
# Concatenate files.
distFile =
"// File eddystone.dist.js " + Time.now.utc.iso8601 + "\n" +
"// This file was generated by buildDistFiles.rb" + fileSep +
evothingsbasejs + fileSep +
evothingsjs + fileSep +
utiljs + fileSep +
easyblejs + fileSep +
eddystonejs + fileSep
# Write out dist JS file.
fileWrite(distPath, distFile)
end
### Call main function
buildDistFiles