xqcoretools 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/xqcoretools +197 -187
- metadata +2 -2
data/bin/xqcoretools
CHANGED
@@ -1,111 +1,116 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'thor'
|
5
|
-
require 'cross_platform_csproj'
|
6
|
-
require 'zip/zip'
|
7
|
-
require 'nokogiri'
|
8
|
-
require 'net/http'
|
9
|
-
require 'execjs'
|
10
|
-
|
11
|
-
class XQCoreTools < Thor
|
12
|
-
desc "processcontent [PLATFORM] [OUTPUT] [PATHS]", "Process content packages"
|
13
|
-
def processcontent(platform, output, paths)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
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
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'thor'
|
5
|
+
require 'cross_platform_csproj'
|
6
|
+
require 'zip/zip'
|
7
|
+
require 'nokogiri'
|
8
|
+
require 'net/http'
|
9
|
+
require 'execjs'
|
10
|
+
|
11
|
+
class XQCoreTools < Thor
|
12
|
+
desc "processcontent [PLATFORM] [OUTPUT] [PATHS]", "Process content packages"
|
13
|
+
def processcontent(platform, output, paths)
|
14
|
+
|
15
|
+
if platform == 'Windows'
|
16
|
+
XQCoreTools::clearFolder(output)
|
17
|
+
basePath = output + '/..'
|
18
|
+
else
|
19
|
+
basePath = XQCoreTools::createTemporaryFolder('xqcoretoolscontent')
|
20
|
+
end
|
21
|
+
|
22
|
+
pathList = paths.split(';')
|
23
|
+
pathList.each do |path|
|
24
|
+
FileUtils.cp_r(path, basePath)
|
25
|
+
end
|
26
|
+
|
27
|
+
compile(platform, basePath)
|
28
|
+
|
29
|
+
case platform
|
30
|
+
when 'Android'
|
31
|
+
archive(output, basePath)
|
32
|
+
when 'iOS', 'IOS'
|
33
|
+
bundle(output, basePath)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "archive [OUTPUT] [PATHS]", "Generates a compressed archive"
|
38
|
+
def archive(output, paths)
|
39
|
+
FileUtils.rm(output, :force=>true)
|
40
|
+
|
41
|
+
pathList = paths.split(';')
|
42
|
+
|
43
|
+
puts "PACKFILE: #{output}"
|
44
|
+
|
45
|
+
Zip::ZipFile.open(output, Zip::ZipFile::CREATE) do |zipfile|
|
46
|
+
pathList.each do |path|
|
47
|
+
XQCoreTools::archiveFilesRecursive(zipfile, path);
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.archiveFilesRecursive(zipfile, path, base = '')
|
53
|
+
Dir.foreach(path) do |item|
|
54
|
+
subPath = "#{path}/#{item}"
|
55
|
+
relPath = base == '' ? item : "#{base}/#{item}"
|
56
|
+
if File.file? subPath
|
57
|
+
puts "PACKING: #{relPath}"
|
58
|
+
zipfile.add(relPath, subPath)
|
59
|
+
else
|
60
|
+
if item != '.' && item != '..'
|
61
|
+
XQCoreTools::archiveFilesRecursive(zipfile, subPath, relPath)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "bundle [OUTPUT] [PATHS]", "Adds files to an existing bundle"
|
68
|
+
def bundle(output, paths)
|
69
|
+
contentDirectory = "#{output}/content"
|
70
|
+
|
71
|
+
FileUtils.rm_r(contentDirectory, :force=>true)
|
72
|
+
|
73
|
+
FileUtils.mkdir(contentDirectory)
|
74
|
+
|
75
|
+
pathList = paths.split(';')
|
76
|
+
packagesList = []
|
77
|
+
|
78
|
+
pathList.each do |path|
|
79
|
+
Dir.foreach(path) do |item|
|
80
|
+
subPath = "#{path}/#{item}"
|
81
|
+
if File.file? subPath
|
82
|
+
if item != '.DS_Store'
|
83
|
+
packagesList.push subPath
|
84
|
+
end
|
85
|
+
else
|
86
|
+
if item != '.' && item != '..'
|
87
|
+
packagesList.push subPath
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
puts "BUNDLE: #{output}"
|
94
|
+
|
95
|
+
packagesList.each do |package|
|
96
|
+
FileUtils.cp_r(package, contentDirectory)
|
97
|
+
|
98
|
+
puts "COPYING: #{package}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
desc "compile [PLATFORM] [PATH]", "Compiles a content package"
|
103
|
+
def compile(platform, path)
|
104
|
+
downloadCache = XQCoreToolsDownloadCache.new('library.xqcore.com', 'xqcoretoolslibrary')
|
105
|
+
|
106
|
+
XQCoreTools::compileDocumentRecursive(platform, path, downloadCache)
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.compileDocumentRecursive(platform, path, downloadCache)
|
110
|
+
Dir.foreach(path) do |item|
|
111
|
+
subPath = "#{path}/#{item}"
|
112
|
+
if File.file? subPath
|
113
|
+
if File.extname(item) == '.html'
|
109
114
|
fileHandle = File.open(subPath)
|
110
115
|
document = Nokogiri::HTML(fileHandle)
|
111
116
|
fileHandle.close
|
@@ -136,25 +141,25 @@ class XQCoreTools < Thor
|
|
136
141
|
break;
|
137
142
|
end
|
138
143
|
end
|
139
|
-
end
|
144
|
+
end
|
140
145
|
|
141
146
|
if isDirty
|
142
147
|
fileHandle = File.open(subPath, 'w')
|
143
148
|
fileHandle.puts(document.to_html(:indent => 4))
|
144
|
-
fileHandle.close
|
145
|
-
end
|
146
|
-
end
|
147
|
-
else
|
148
|
-
if item != '.' && item != '..'
|
149
|
-
XQCoreTools::compileDocumentRecursive(platform, subPath, downloadCache)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def self.compileTemplates(fileName, document, version, downloadCache, insertSibling)
|
156
|
-
script = ''
|
157
|
-
|
149
|
+
fileHandle.close
|
150
|
+
end
|
151
|
+
end
|
152
|
+
else
|
153
|
+
if item != '.' && item != '..'
|
154
|
+
XQCoreTools::compileDocumentRecursive(platform, subPath, downloadCache)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.compileTemplates(fileName, document, version, downloadCache, insertSibling)
|
161
|
+
script = ''
|
162
|
+
|
158
163
|
compilerFile = "compiler.js"
|
159
164
|
compilerPath = downloadCache.cacheFile("#{version}/#{compilerFile}")
|
160
165
|
|
@@ -188,73 +193,78 @@ class XQCoreTools < Thor
|
|
188
193
|
templatesNode = Nokogiri::XML::Node.new('script', document)
|
189
194
|
templatesNode.set_attribute('type', 'text/javascript')
|
190
195
|
templatesNode.content = script
|
191
|
-
insertSibling.add_next_sibling(templatesNode)
|
192
|
-
end
|
193
|
-
|
194
|
-
def self.
|
195
|
-
path
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
def
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
196
|
+
insertSibling.add_next_sibling(templatesNode)
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.clearFolder(path)
|
200
|
+
FileUtils.rm_r(path, :force=>true)
|
201
|
+
|
202
|
+
# Wait because the OS might still have a file system lock on the removed path
|
203
|
+
begin
|
204
|
+
FileUtils.mkdir_p(path)
|
205
|
+
rescue
|
206
|
+
sleep 0.1
|
207
|
+
|
208
|
+
begin
|
209
|
+
FileUtils.mkdir_p(path)
|
210
|
+
rescue
|
211
|
+
sleep 1
|
212
|
+
FileUtils.mkdir_p(path)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def self.createTemporaryFolder(name)
|
218
|
+
path = Dir::tmpdir() + "/#{name}"
|
219
|
+
|
220
|
+
XQCoreTools::clearFolder(path)
|
221
|
+
|
222
|
+
return path
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
class XQCoreToolsDownloadCache
|
227
|
+
def initialize(host, folder)
|
228
|
+
@host = host
|
229
|
+
@cacheFolder = XQCoreTools::createTemporaryFolder(folder)
|
230
|
+
end
|
231
|
+
|
232
|
+
def cacheFile(url)
|
233
|
+
file = @cacheFolder + "/#{url}"
|
234
|
+
dir = File.dirname(file)
|
235
|
+
|
236
|
+
if !Dir.exists? dir
|
237
|
+
FileUtils.mkdir_p dir
|
238
|
+
end
|
239
|
+
|
240
|
+
if !File.exists? file
|
241
|
+
downloadFile(url, file)
|
242
|
+
end
|
243
|
+
|
244
|
+
return file
|
245
|
+
end
|
246
|
+
|
247
|
+
def saveFile(url, file)
|
248
|
+
cachedFile = cacheFile(url)
|
249
|
+
|
250
|
+
dir = File.dirname(file)
|
251
|
+
if !Dir.exists? dir
|
252
|
+
FileUtils.mkdir_p dir
|
253
|
+
end
|
254
|
+
|
255
|
+
FileUtils.cp cachedFile, file
|
256
|
+
end
|
257
|
+
|
258
|
+
def downloadFile(url, file)
|
249
259
|
http = Net::HTTP.start(@host)
|
250
260
|
response = http.get("/#{url}")
|
251
261
|
|
252
262
|
fileHandle = File.open(file, 'w')
|
253
263
|
fileHandle.write(response.body)
|
254
|
-
fileHandle.close
|
255
|
-
|
256
|
-
http.finish
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
264
|
+
fileHandle.close
|
265
|
+
|
266
|
+
http.finish
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
260
270
|
XQCoreTools.start
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xqcoretools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Tools for synchronizing multiple CSharp projects and deploying to several
|
15
15
|
platform
|