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.
Files changed (2) hide show
  1. data/bin/xqcoretools +197 -187
  2. 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
- basePath = XQCoreTools::createTemporaryFolder('xqcoretoolscontent')
16
-
17
- pathList = paths.split(';')
18
- pathList.each do |path|
19
- FileUtils.cp_r(path, basePath)
20
- end
21
-
22
- compile(platform, basePath)
23
-
24
- case platform
25
- when 'Android'
26
- # archive(output, basePath)
27
- when 'iOS', 'IOS'
28
- # bundle(output, basePath)
29
- end
30
- end
31
-
32
- desc "archive [OUTPUT] [PATHS]", "Generates a compressed archive"
33
- def archive(output, paths)
34
- FileUtils.rm(output, :force=>true)
35
-
36
- pathList = paths.split(';')
37
-
38
- puts "PACKFILE: #{output}"
39
-
40
- Zip::ZipFile.open(output, Zip::ZipFile::CREATE) do |zipfile|
41
- pathList.each do |path|
42
- XQCoreTools::archiveFilesRecursive(zipfile, path);
43
- end
44
- end
45
- end
46
-
47
- def self.archiveFilesRecursive(zipfile, path, base = '')
48
- Dir.foreach(path) do |item|
49
- subPath = "#{path}/#{item}"
50
- relPath = base == '' ? item : "#{base}/#{item}"
51
- if File.file? subPath
52
- puts "PACKING: #{relPath}"
53
- zipfile.add(relPath, subPath)
54
- else
55
- if item != '.' && item != '..'
56
- XQCoreTools::archiveFilesRecursive(zipfile, subPath, relPath)
57
- end
58
- end
59
- end
60
- end
61
-
62
- desc "bundle [OUTPUT] [PATHS]", "Adds files to an existing bundle"
63
- def bundle(output, paths)
64
- contentDirectory = "#{output}/content"
65
-
66
- FileUtils.rm_r(contentDirectory, :force=>true)
67
-
68
- FileUtils.mkdir(contentDirectory)
69
-
70
- pathList = paths.split(';')
71
- packagesList = []
72
-
73
- pathList.each do |path|
74
- Dir.foreach(path) do |item|
75
- subPath = "#{path}/#{item}"
76
- if File.file? subPath
77
- if item != '.DS_Store'
78
- packagesList.push subPath
79
- end
80
- else
81
- if item != '.' && item != '..'
82
- packagesList.push subPath
83
- end
84
- end
85
- end
86
- end
87
-
88
- puts "BUNDLE: #{output}"
89
-
90
- packagesList.each do |package|
91
- FileUtils.cp_r(package, contentDirectory)
92
-
93
- puts "COPYING: #{package}"
94
- end
95
- end
96
-
97
- desc "compile [PLATFORM] [PATH]", "Compiles a content package"
98
- def compile(platform, path)
99
- downloadCache = XQCoreToolsDownloadCache.new('library.xqcore.com', 'xqcoretoolslibrary')
100
-
101
- XQCoreTools::compileDocumentRecursive(platform, path, downloadCache)
102
- end
103
-
104
- def self.compileDocumentRecursive(platform, path, downloadCache)
105
- Dir.foreach(path) do |item|
106
- subPath = "#{path}/#{item}"
107
- if File.file? subPath
108
- if File.extname(item) == '.html'
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.createTemporaryFolder(name)
195
- path = Dir::tmpdir() + "/#{name}"
196
- FileUtils.rm_r(path, :force=>true)
197
-
198
- # Wait because the OS might still have a file system lock on the removed path
199
- begin
200
- FileUtils.mkdir_p(path)
201
- rescue
202
- sleep 0.1
203
-
204
- begin
205
- FileUtils.mkdir_p(path)
206
- rescue
207
- sleep 1
208
- FileUtils.mkdir_p(path)
209
- end
210
- end
211
-
212
- return path
213
- end
214
- end
215
-
216
- class XQCoreToolsDownloadCache
217
- def initialize(host, folder)
218
- @host = host
219
- @cacheFolder = XQCoreTools::createTemporaryFolder(folder)
220
- end
221
-
222
- def cacheFile(url)
223
- file = @cacheFolder + "/#{url}"
224
- dir = File.dirname(file)
225
-
226
- if !Dir.exists? dir
227
- FileUtils.mkdir_p dir
228
- end
229
-
230
- if !File.exists? file
231
- downloadFile(url, file)
232
- end
233
-
234
- return file
235
- end
236
-
237
- def saveFile(url, file)
238
- cachedFile = cacheFile(url)
239
-
240
- dir = File.dirname(file)
241
- if !Dir.exists? dir
242
- FileUtils.mkdir_p dir
243
- end
244
-
245
- FileUtils.cp cachedFile, file
246
- end
247
-
248
- def downloadFile(url, file)
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.5
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-05 00:00:00.000000000 Z
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