1 | Facade = require('./lib/facade')
|
2 |
|
3 | Facade.fs = require('fs')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | Facade.requireFile = (file) ->
|
17 | if not Ti?
|
18 | ret = require file
|
19 | return if ret.default then ret.default else ret
|
20 |
|
21 |
|
22 | path = file + '.js'
|
23 |
|
24 | if Ti.Platform.name is 'android'
|
25 | return require file
|
26 |
|
27 | fileInfo = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, path)
|
28 |
|
29 | if fileInfo.exists()
|
30 | return require file
|
31 | else
|
32 | throw new Error("#{path}: no such file.")
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | Facade.requireJSON = (path) ->
|
43 | if not Ti?
|
44 | return require path
|
45 |
|
46 | fileInfo = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, path)
|
47 |
|
48 | if fileInfo.exists()
|
49 | return JSON.parse fileInfo.read().getText()
|
50 | else
|
51 | throw new Error("#{path}: no such file.")
|
52 |
|
53 |
|
54 | module.exports = Facade
|