forked from fealebenpae/node-xcode
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpbxFile.js
141 lines (115 loc) · 3.78 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var $path = require('path'),
util = require('util'),
M_EXTENSION = /[.]m$/, SOURCE_FILE = 'sourcecode.c.objc',
C_EXTENSION = /[.]c$/, C_SOURCE_FILE = 'sourcecode.c',
H_EXTENSION = /[.]h$/, HEADER_FILE = 'sourcecode.c.h',
MM_EXTENSION = /[.]mm$/, MM_SOURCE_FILE = 'sourcecode.cpp.objcpp',
HPP_EXTENSION = /[.](hpp|hxx|h\+\+|hh)$/, CPP_HEADER_FILE = 'sourcecode.cpp.h',
CPP_EXTENSION = /[.](cpp|cxx|c\+\+|cc)$/, CPP_SOURCE_FILE = 'sourcecode.cpp.cpp',
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 fileTypes() {
return {
SOURCE_FILE,
C_SOURCE_FILE,
HEADER_FILE,
MM_SOURCE_FILE,
CPP_HEADER_FILE,
CPP_SOURCE_FILE,
BUNDLE,
XIB_FILE,
FRAMEWORK,
DYLIB,
ARCHIVE,
PNG_IMAGE,
}
}
function detectLastType(path) {
if (M_EXTENSION.test(path))
return SOURCE_FILE;
if (C_EXTENSION.test(path))
return C_SOURCE_FILE;
if (H_EXTENSION.test(path))
return HEADER_FILE;
if (MM_EXTENSION.test(path))
return MM_SOURCE_FILE;
if (CPP_EXTENSION.test(path))
return CPP_SOURCE_FILE;
if (HPP_EXTENSION.test(path))
return CPP_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: pbxFile,
fileTypes: fileTypes
}