forked from fealebenpae/node-xcode
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpbxFile.js
105 lines (84 loc) · 2.9 KB
/
pbxFile.js
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
101
102
103
104
105
var path = require('path'),
util = require('util'),
M_EXTENSION = /[.]m$/, SOURCE_FILE = 'sourcecode.c.objc',
H_EXTENSION = /[.]h$/, HEADER_FILE = 'sourcecode.c.h',
BUNDLE_EXTENSION = /[.]bundle$/, BUNDLE = '"wrapper.plug-in"',
XIB_EXTENSION = /[.]xib$/, XIB_FILE = 'file.xib',
DYLIB_EXTENSION = /[.]dylib$/, DYLIB = '"compiled.mach-o.dylib"',
FRAMEWORK_EXTENSION = /[.]framework$/, FRAMEWORK = 'wrapper.framework',
ARCHIVE_EXTENSION = /[.]a$/, ARCHIVE = 'archive.ar',
PNG_EXTENSION = /[.]png/, PNG_IMAGE = "image.png",
DEFAULT_SOURCE_TREE = '"<group>"',
DEFAULT_FILE_ENCODING = 4;
function detectLastType(path) {
if (M_EXTENSION.test(path))
return SOURCE_FILE;
if (H_EXTENSION.test(path))
return HEADER_FILE;
if (BUNDLE_EXTENSION.test(path))
return BUNDLE;
if (XIB_EXTENSION.test(path))
return XIB_FILE;
if (FRAMEWORK_EXTENSION.test(path))
return FRAMEWORK;
if (DYLIB_EXTENSION.test(path))
return DYLIB;
if (ARCHIVE_EXTENSION.test(path))
return ARCHIVE;
if (PNG_EXTENSION.test(path))
return PNG_IMAGE;
// dunno
return 'unknown';
}
function fileEncoding(file) {
if (file.lastType != BUNDLE && file.lastType !== PNG_IMAGE && !file.customFramework) {
return DEFAULT_FILE_ENCODING;
}
}
function defaultSourceTree(file) {
if (( file.lastType == DYLIB || file.lastType == FRAMEWORK ) && !file.customFramework) {
return 'SDKROOT';
} else {
return DEFAULT_SOURCE_TREE;
}
}
function correctPath(file, filepath) {
if (file.lastType == FRAMEWORK && !file.customFramework) {
return 'System/Library/Frameworks/' + filepath;
} else if (file.lastType == DYLIB) {
return 'usr/lib/' + filepath;
} else {
return filepath;
}
}
function correctGroup(file) {
if (file.lastType == SOURCE_FILE) {
return 'Sources';
} else if (file.lastType == DYLIB || file.lastType == ARCHIVE || file.lastType == FRAMEWORK) {
return 'Frameworks';
} else {
return 'Resources';
}
}
function pbxFile(filepath, opt) {
var opt = opt || {};
this.lastType = opt.lastType || detectLastType(filepath);
// for custom frameworks
if(opt.customFramework == true) {
this.customFramework = true;
this.dirname = path.dirname(filepath);
}
this.basename = path.basename(filepath);
this.path = correctPath(this, filepath);
this.group = correctGroup(this);
this.sourceTree = opt.sourceTree || defaultSourceTree(this);
this.fileEncoding = opt.fileEncoding || fileEncoding(this);
if (opt.weak && opt.weak === true)
this.settings = { ATTRIBUTES: ['Weak'] };
if (opt.compilerFlags) {
if (!this.settings)
this.settings = {};
this.settings.COMPILER_FLAGS = util.format('"%s"', opt.compilerFlags);
}
}
module.exports = pbxFile;