Skip to content

Commit 957692c

Browse files
committed
[pbxFile] file wrapper object
1 parent b104dfc commit 957692c

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

lib/pbxFile.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var M_EXTENSION = /[.]m$/, SOURCE_FILE = 'sourcecode.c.objc',
2+
H_EXTENSION = /[.]h$/, HEADER_FILE = 'sourcecode.c.h',
3+
BUNDLE_EXTENSION = /[.]bundle$/, BUNDLE = '"wrapper.plug-in"',
4+
XIB_EXTENSION = /[.]xib$/, XIB_FILE = 'file.xib',
5+
DEFAULT_SOURCE_TREE = '"<group>"'
6+
7+
function detectLastType(path) {
8+
if (M_EXTENSION.test(path))
9+
return SOURCE_FILE;
10+
11+
if (H_EXTENSION.test(path))
12+
return HEADER_FILE;
13+
14+
if (BUNDLE_EXTENSION.test(path))
15+
return BUNDLE;
16+
17+
if (XIB_EXTENSION.test(path))
18+
return XIB_FILE;
19+
20+
// dunno
21+
return 'unknown';
22+
}
23+
24+
function pbxFile(path, opt) {
25+
var opt = opt || {};
26+
27+
this.lastType = opt.lastType || detectLastType(path);
28+
29+
if (this.lastType == SOURCE_FILE) {
30+
this.group = 'Sources';
31+
} else {
32+
this.group = 'Resources';
33+
}
34+
35+
this.sourceTree = opt.sourceTree || DEFAULT_SOURCE_TREE;
36+
}
37+
38+
module.exports = pbxFile;

test/pbxFile.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
var pbxFile = require('../lib/pbxFile');
2+
3+
exports['lastType'] = {
4+
'should detect that a .m path means sourcecode.c.objc': function (test) {
5+
var sourceFile = new pbxFile('Plugins/ChildBrowser.m');
6+
7+
test.equal('sourcecode.c.objc', sourceFile.lastType);
8+
test.done();
9+
},
10+
11+
'should detect that a .h path means sourceFile.c.h': function (test) {
12+
var sourceFile = new pbxFile('Plugins/ChildBrowser.h');
13+
14+
test.equal('sourcecode.c.h', sourceFile.lastType);
15+
test.done();
16+
},
17+
18+
'should detect that a .bundle path means "wrapper.plug-in"': function (test) {
19+
var sourceFile = new pbxFile('Plugins/ChildBrowser.bundle');
20+
21+
test.equal('"wrapper.plug-in"', sourceFile.lastType);
22+
test.done();
23+
},
24+
25+
'should detect that a .xib path means file.xib': function (test) {
26+
var sourceFile = new pbxFile('Plugins/ChildBrowser.xib');
27+
28+
test.equal('file.xib', sourceFile.lastType);
29+
test.done();
30+
},
31+
32+
'should allow lastType to be overridden': function (test) {
33+
var sourceFile = new pbxFile('Plugins/ChildBrowser.m',
34+
{ lastType: 'somestupidtype' });
35+
36+
test.equal('somestupidtype', sourceFile.lastType);
37+
test.done();
38+
},
39+
40+
'should set lastType to unknown if undetectable': function (test) {
41+
var sourceFile = new pbxFile('Plugins/ChildBrowser.guh');
42+
43+
test.equal('unknown', sourceFile.lastType);
44+
test.done();
45+
}
46+
}
47+
48+
exports['group'] = {
49+
'should be Sources for source files': function (test) {
50+
var sourceFile = new pbxFile('Plugins/ChildBrowser.m');
51+
52+
test.equal('Sources', sourceFile.group);
53+
test.done();
54+
},
55+
'should be Resources for all other files': function (test) {
56+
var headerFile = new pbxFile('Plugins/ChildBrowser.h'),
57+
xibFile = new pbxFile('Plugins/ChildBrowser.xib');
58+
59+
test.equal('Resources', headerFile.group);
60+
test.equal('Resources', xibFile.group);
61+
test.done();
62+
}
63+
}

0 commit comments

Comments
 (0)