-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbuildEddystonePluginJS.rb
73 lines (59 loc) · 2.03 KB
/
buildEddystonePluginJS.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
# File: buildEddystonePluginJS.rb
#
# Build script for Evothings Eddystone plugin JavaScript file.
#
# Resulting output file is eddystone-plugin.js, which contains code
# for the Eddystone JS API and the required support functions.
#
# Note that this repo contains a pre-built version of eddystone-plugin.js.
# The plugin works out-of-the-box and you only need to rebuild this file
# when updating or developing the plugin, normally done by plugin maintainers.
require "fileutils"
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 fileWrite(destFile, content)
File.open(destFile, "w") { |f| f.write(content) }
end
### Merge library files
def mergeFiles
# Base path for JS files is the evothings-examples repo, which
# should be checked out next to this repo when building.
libsPath = "../evothings-libraries/libs/evothings/"
# Paths to JS files.
utiljs = fileRead(libsPath + "util/util.js")
easyblejs = fileRead(libsPath + "easyble/easyble.js")
eddystonejs = fileRead(libsPath + "eddystone/eddystone.js")
evothingsbasejs = fileRead("js/evothings-base.js")
eddystoneexportsjs = fileRead("js/eddystone-exports.js")
# File separator.
fileSep = "\n\n// --------------------------------------------------\n\n\n"
# Concatenate files.
eddystonepluginjs =
"// This file was generated by buildEddystonePluginJS.rb" + fileSep +
evothingsbasejs + fileSep +
utiljs + fileSep +
easyblejs + fileSep +
eddystonejs + fileSep +
eddystoneexportsjs
# Replace evothings.loadScripts and evothings.loadScript
# with dummy function to disable async script loading since
# we have all scripts in one file now.
eddystonepluginjs = eddystonepluginjs
.gsub("evothings.loadScripts", "evothings.__NOOP_FUN__")
.gsub("evothings.loadScript", "evothings.__NOOP_FUN__")
# Write out plugin JS file.
fileWrite("js/eddystone-plugin.js", eddystonepluginjs)
end
### Call main function
mergeFiles