Skip to content

Commit 89f658e

Browse files
authored
Merge pull request #5 from NativeScript/kddimitrov/extensions
Kddimitrov/extensions
2 parents a3b6410 + 64ea6c0 commit 89f658e

24 files changed

+514
-206
lines changed

lib/constants.js

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
var DEFAULT_SOURCETREE = '"<group>"',
2+
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
3+
DEFAULT_FILEENCODING = 4,
4+
DEFAULT_GROUP = 'Resources',
5+
DEFAULT_FILETYPE = 'unknown',
6+
HEADER_FILE_TYPE_SUFFIX = ".h",
7+
ENTITLEMENTS_FILE_TYPE_SUFFIX = ".entitlements",
8+
SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode.";
9+
10+
var FILETYPE_BY_EXTENSION = {
11+
a: 'archive.ar',
12+
app: 'wrapper.application',
13+
appex: 'wrapper.app-extension',
14+
bundle: 'wrapper.plug-in',
15+
c: 'sourcecode.c.c',
16+
cc: 'sourcecode.cpp.cpp',
17+
cpp: 'sourcecode.cpp.cpp',
18+
cxx: 'sourcecode.cpp.cpp',
19+
'c++': 'sourcecode.cpp.cpp',
20+
dylib: 'compiled.mach-o.dylib',
21+
framework: 'wrapper.framework',
22+
h: 'sourcecode.c.h',
23+
hh: 'sourcecode.cpp.h',
24+
hpp: 'sourcecode.cpp.h',
25+
hxx: 'sourcecode.cpp.h',
26+
'h++': 'sourcecode.cpp.h',
27+
m: 'sourcecode.c.objc',
28+
mm: 'sourcecode.cpp.objcpp',
29+
markdown: 'text',
30+
mdimporter: 'wrapper.cfbundle',
31+
octest: 'wrapper.cfbundle',
32+
pch: 'sourcecode.c.h',
33+
plist: 'text.plist.xml',
34+
entitlements: 'text.plist.entitlements',
35+
png: "image.png",
36+
sh: 'text.script.sh',
37+
swift: 'sourcecode.swift',
38+
tbd: 'sourcecode.text-based-dylib-definition',
39+
xcassets: 'folder.assetcatalog',
40+
xcconfig: 'text.xcconfig',
41+
xcdatamodel: 'wrapper.xcdatamodel',
42+
xcodeproj: 'wrapper.pb-project',
43+
xctest: 'wrapper.cfbundle',
44+
xib: 'file.xib',
45+
strings: 'text.plist.strings'
46+
},
47+
GROUP_BY_FILETYPE = {
48+
'archive.ar': 'Frameworks',
49+
'compiled.mach-o.dylib': 'Frameworks',
50+
'sourcecode.text-based-dylib-definition': 'Frameworks',
51+
'wrapper.framework': 'Frameworks',
52+
'embedded.framework': 'Embed Frameworks',
53+
'sourcecode.c.h': 'Resources',
54+
'sourcecode.c.c': 'Sources',
55+
'sourcecode.c.objc': 'Sources',
56+
'sourcecode.swift': 'Sources',
57+
'sourcecode.cpp.cpp': 'Sources',
58+
'sourcecode.cpp.objcpp': 'Sources'
59+
},
60+
PATH_BY_FILETYPE = {
61+
'compiled.mach-o.dylib': 'usr/lib/',
62+
'sourcecode.text-based-dylib-definition': 'usr/lib/',
63+
'wrapper.framework': 'System/Library/Frameworks/'
64+
},
65+
SOURCETREE_BY_FILETYPE = {
66+
'compiled.mach-o.dylib': 'SDKROOT',
67+
'sourcecode.text-based-dylib-definition': 'SDKROOT',
68+
'wrapper.framework': 'SDKROOT'
69+
},
70+
ENCODING_BY_FILETYPE = {
71+
'sourcecode.c.h': 4,
72+
'sourcecode.c.h': 4,
73+
'sourcecode.cpp.h': 4,
74+
'sourcecode.c.c': 4,
75+
'sourcecode.c.objc': 4,
76+
'sourcecode.cpp.cpp': 4,
77+
'sourcecode.cpp.objcpp': 4,
78+
'sourcecode.swift': 4,
79+
'text': 4,
80+
'text.plist.xml': 4,
81+
'text.script.sh': 4,
82+
'text.xcconfig': 4,
83+
'text.plist.strings': 4
84+
};
85+
86+
function isHeaderFileType(fileType) {
87+
return fileType.endsWith(HEADER_FILE_TYPE_SUFFIX);
88+
}
89+
90+
function isSourceFileType(fileType) {
91+
return fileType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX) && !isHeaderFileType(fileType);
92+
}
93+
94+
function isAssetFileType(fileType) {
95+
return fileType === FILETYPE_BY_EXTENSION.xcassets;
96+
}
97+
98+
function isResource(group) {
99+
return group === "Resources";
100+
}
101+
102+
function isEntitlementFileType(fileType) {
103+
return fileType.endsWith(ENTITLEMENTS_FILE_TYPE_SUFFIX);
104+
}
105+
106+
function isPlistFileType(fileType) {
107+
return fileType === FILETYPE_BY_EXTENSION.plist;
108+
}
109+
110+
function unquoted(text) {
111+
return text == null ? '' : text.replace (/(^")|("$)/g, '')
112+
}
113+
114+
module.exports = {
115+
DEFAULT_SOURCETREE,
116+
DEFAULT_PRODUCT_SOURCETREE,
117+
DEFAULT_FILEENCODING,
118+
DEFAULT_GROUP,
119+
DEFAULT_FILETYPE,
120+
HEADER_FILE_TYPE_SUFFIX,
121+
ENTITLEMENTS_FILE_TYPE_SUFFIX,
122+
SOURCE_CODE_FILE_TYPE_PREFIX,
123+
FILETYPE_BY_EXTENSION,
124+
GROUP_BY_FILETYPE,
125+
PATH_BY_FILETYPE,
126+
SOURCETREE_BY_FILETYPE,
127+
ENCODING_BY_FILETYPE,
128+
isHeaderFileType,
129+
isSourceFileType,
130+
isAssetFileType,
131+
isResource,
132+
isEntitlementFileType,
133+
isPlistFileType,
134+
unquoted
135+
}

lib/pbxFile.js

+17-123
Original file line numberDiff line numberDiff line change
@@ -16,116 +16,24 @@
1616
*/
1717

1818
var path = require('path'),
19-
util = require('util');
20-
21-
var DEFAULT_SOURCETREE = '"<group>"',
22-
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
23-
DEFAULT_FILEENCODING = 4,
24-
DEFAULT_GROUP = 'Resources',
25-
DEFAULT_FILETYPE = 'unknown',
26-
HEADER_FILE_TYPE_SUFFIX = ".h",
27-
SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode.";
28-
29-
var FILETYPE_BY_EXTENSION = {
30-
a: 'archive.ar',
31-
app: 'wrapper.application',
32-
appex: 'wrapper.app-extension',
33-
bundle: 'wrapper.plug-in',
34-
c: 'sourcecode.c.c',
35-
cc: 'sourcecode.cpp.cpp',
36-
cpp: 'sourcecode.cpp.cpp',
37-
cxx: 'sourcecode.cpp.cpp',
38-
'c++': 'sourcecode.cpp.cpp',
39-
dylib: 'compiled.mach-o.dylib',
40-
framework: 'wrapper.framework',
41-
h: 'sourcecode.c.h',
42-
hh: 'sourcecode.cpp.h',
43-
hpp: 'sourcecode.cpp.h',
44-
hxx: 'sourcecode.cpp.h',
45-
'h++': 'sourcecode.cpp.h',
46-
m: 'sourcecode.c.objc',
47-
mm: 'sourcecode.cpp.objcpp',
48-
markdown: 'text',
49-
mdimporter: 'wrapper.cfbundle',
50-
octest: 'wrapper.cfbundle',
51-
pch: 'sourcecode.c.h',
52-
plist: 'text.plist.xml',
53-
png: "image.png",
54-
sh: 'text.script.sh',
55-
swift: 'sourcecode.swift',
56-
tbd: 'sourcecode.text-based-dylib-definition',
57-
xcassets: 'folder.assetcatalog',
58-
xcconfig: 'text.xcconfig',
59-
xcdatamodel: 'wrapper.xcdatamodel',
60-
xcodeproj: 'wrapper.pb-project',
61-
xctest: 'wrapper.cfbundle',
62-
xib: 'file.xib',
63-
strings: 'text.plist.strings'
64-
},
65-
GROUP_BY_FILETYPE = {
66-
'archive.ar': 'Frameworks',
67-
'compiled.mach-o.dylib': 'Frameworks',
68-
'sourcecode.text-based-dylib-definition': 'Frameworks',
69-
'wrapper.framework': 'Frameworks',
70-
'embedded.framework': 'Embed Frameworks',
71-
'sourcecode.c.h': 'Resources',
72-
'sourcecode.c.c': 'Sources',
73-
'sourcecode.c.objc': 'Sources',
74-
'sourcecode.swift': 'Sources',
75-
'sourcecode.cpp.cpp': 'Sources',
76-
'sourcecode.cpp.objcpp': 'Sources'
77-
},
78-
PATH_BY_FILETYPE = {
79-
'compiled.mach-o.dylib': 'usr/lib/',
80-
'sourcecode.text-based-dylib-definition': 'usr/lib/',
81-
'wrapper.framework': 'System/Library/Frameworks/'
82-
},
83-
SOURCETREE_BY_FILETYPE = {
84-
'compiled.mach-o.dylib': 'SDKROOT',
85-
'sourcecode.text-based-dylib-definition': 'SDKROOT',
86-
'wrapper.framework': 'SDKROOT'
87-
},
88-
ENCODING_BY_FILETYPE = {
89-
'sourcecode.c.h': 4,
90-
'sourcecode.c.h': 4,
91-
'sourcecode.cpp.h': 4,
92-
'sourcecode.c.c': 4,
93-
'sourcecode.c.objc': 4,
94-
'sourcecode.cpp.cpp': 4,
95-
'sourcecode.cpp.objcpp': 4,
96-
'sourcecode.swift': 4,
97-
'text': 4,
98-
'text.plist.xml': 4,
99-
'text.script.sh': 4,
100-
'text.xcconfig': 4,
101-
'text.plist.strings': 4
102-
};
103-
104-
function isSourceOrHeaderFileType(fileType) {
105-
return fileType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX);
106-
}
107-
108-
function isHeaderFileType(fileType) {
109-
return fileType.endsWith(HEADER_FILE_TYPE_SUFFIX);
110-
}
111-
112-
function unquoted(text){
113-
return text == null ? '' : text.replace (/(^")|("$)/g, '')
114-
}
19+
util = require('util'),
20+
constants = require('./constants'),
21+
unquoted = constants.unquoted,
22+
FILETYPE_BY_EXTENSION = constants.FILETYPE_BY_EXTENSION;
11523

11624
function detectType(filePath) {
11725
var extension = path.extname(filePath).substring(1),
11826
filetype = FILETYPE_BY_EXTENSION[unquoted(extension)];
11927

12028
if (!filetype) {
121-
return DEFAULT_FILETYPE;
29+
return constants.DEFAULT_FILETYPE;
12230
}
12331

12432
return filetype;
12533
}
12634

12735
function defaultExtension(fileRef) {
128-
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
36+
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != constants.DEFAULT_FILETYPE ?
12937
fileRef.lastKnownFileType : fileRef.explicitFileType;
13038

13139
for(var extension in FILETYPE_BY_EXTENSION) {
@@ -138,7 +46,7 @@ function defaultExtension(fileRef) {
13846

13947
function defaultEncoding(fileRef) {
14048
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
141-
encoding = ENCODING_BY_FILETYPE[unquoted(filetype)];
49+
encoding = constants.ENCODING_BY_FILETYPE[unquoted(filetype)];
14250

14351
if (encoding) {
14452
return encoding;
@@ -148,18 +56,18 @@ function defaultEncoding(fileRef) {
14856
function detectGroup(fileRef, opt) {
14957
var extension = path.extname(fileRef.basename).substring(1),
15058
filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
151-
groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
59+
groupName = constants.GROUP_BY_FILETYPE[unquoted(filetype)];
15260

15361
if (extension === 'xcdatamodeld') {
15462
return 'Sources';
15563
}
15664

15765
if (opt.customFramework && opt.embed) {
158-
return GROUP_BY_FILETYPE['embedded.framework'];
66+
return constants.GROUP_BY_FILETYPE['embedded.framework'];
15967
}
16068

16169
if (!groupName) {
162-
return DEFAULT_GROUP;
70+
return constants.DEFAULT_GROUP;
16371
}
16472

16573
return groupName;
@@ -168,26 +76,26 @@ function detectGroup(fileRef, opt) {
16876
function detectSourcetree(fileRef) {
16977

17078
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
171-
sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
79+
sourcetree = constants.SOURCETREE_BY_FILETYPE[unquoted(filetype)];
17280

17381
if (fileRef.explicitFileType) {
174-
return DEFAULT_PRODUCT_SOURCETREE;
82+
return constants.DEFAULT_PRODUCT_SOURCETREE;
17583
}
17684

17785
if (fileRef.customFramework) {
178-
return DEFAULT_SOURCETREE;
86+
return constants.DEFAULT_SOURCETREE;
17987
}
18088

18189
if (!sourcetree) {
182-
return DEFAULT_SOURCETREE;
90+
return constants.DEFAULT_SOURCETREE;
18391
}
18492

18593
return sourcetree;
18694
}
18795

18896
function defaultPath(fileRef, filePath) {
18997
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
190-
defaultPath = PATH_BY_FILETYPE[unquoted(filetype)];
98+
defaultPath = constants.PATH_BY_FILETYPE[unquoted(filetype)];
19199

192100
if (fileRef.customFramework) {
193101
return filePath;
@@ -200,18 +108,8 @@ function defaultPath(fileRef, filePath) {
200108
return filePath;
201109
}
202110

203-
function defaultGroup(fileRef) {
204-
var groupName = GROUP_BY_FILETYPE[fileRef.lastKnownFileType];
205-
206-
if (!groupName) {
207-
return DEFAULT_GROUP;
208-
}
209-
210-
return defaultGroup;
211-
}
212-
213111
function pbxFile(filepath, opt) {
214-
var opt = opt || {};
112+
opt = opt || {};
215113

216114
this.basename = opt.basename || path.basename(filepath);
217115
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
@@ -257,8 +155,4 @@ function pbxFile(filepath, opt) {
257155
}
258156
}
259157

260-
module.exports = {
261-
pbxFile: pbxFile,
262-
isSourceOrHeaderFileType,
263-
isHeaderFileType
264-
}
158+
module.exports = pbxFile;

0 commit comments

Comments
 (0)