Skip to content

Kddimitrov/extensions #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
var DEFAULT_SOURCETREE = '"<group>"',
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
DEFAULT_FILEENCODING = 4,
DEFAULT_GROUP = 'Resources',
DEFAULT_FILETYPE = 'unknown',
HEADER_FILE_TYPE_SUFFIX = ".h",
ENTITLEMENTS_FILE_TYPE_SUFFIX = ".entitlements",
SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode.";

var FILETYPE_BY_EXTENSION = {
a: 'archive.ar',
app: 'wrapper.application',
appex: 'wrapper.app-extension',
bundle: 'wrapper.plug-in',
c: 'sourcecode.c.c',
cc: 'sourcecode.cpp.cpp',
cpp: 'sourcecode.cpp.cpp',
cxx: 'sourcecode.cpp.cpp',
'c++': 'sourcecode.cpp.cpp',
dylib: 'compiled.mach-o.dylib',
framework: 'wrapper.framework',
h: 'sourcecode.c.h',
hh: 'sourcecode.cpp.h',
hpp: 'sourcecode.cpp.h',
hxx: 'sourcecode.cpp.h',
'h++': 'sourcecode.cpp.h',
m: 'sourcecode.c.objc',
mm: 'sourcecode.cpp.objcpp',
markdown: 'text',
mdimporter: 'wrapper.cfbundle',
octest: 'wrapper.cfbundle',
pch: 'sourcecode.c.h',
plist: 'text.plist.xml',
entitlements: 'text.plist.entitlements',
png: "image.png",
sh: 'text.script.sh',
swift: 'sourcecode.swift',
tbd: 'sourcecode.text-based-dylib-definition',
xcassets: 'folder.assetcatalog',
xcconfig: 'text.xcconfig',
xcdatamodel: 'wrapper.xcdatamodel',
xcodeproj: 'wrapper.pb-project',
xctest: 'wrapper.cfbundle',
xib: 'file.xib',
strings: 'text.plist.strings'
},
GROUP_BY_FILETYPE = {
'archive.ar': 'Frameworks',
'compiled.mach-o.dylib': 'Frameworks',
'sourcecode.text-based-dylib-definition': 'Frameworks',
'wrapper.framework': 'Frameworks',
'embedded.framework': 'Embed Frameworks',
'sourcecode.c.h': 'Resources',
'sourcecode.c.c': 'Sources',
'sourcecode.c.objc': 'Sources',
'sourcecode.swift': 'Sources',
'sourcecode.cpp.cpp': 'Sources',
'sourcecode.cpp.objcpp': 'Sources'
},
PATH_BY_FILETYPE = {
'compiled.mach-o.dylib': 'usr/lib/',
'sourcecode.text-based-dylib-definition': 'usr/lib/',
'wrapper.framework': 'System/Library/Frameworks/'
},
SOURCETREE_BY_FILETYPE = {
'compiled.mach-o.dylib': 'SDKROOT',
'sourcecode.text-based-dylib-definition': 'SDKROOT',
'wrapper.framework': 'SDKROOT'
},
ENCODING_BY_FILETYPE = {
'sourcecode.c.h': 4,
'sourcecode.c.h': 4,
'sourcecode.cpp.h': 4,
'sourcecode.c.c': 4,
'sourcecode.c.objc': 4,
'sourcecode.cpp.cpp': 4,
'sourcecode.cpp.objcpp': 4,
'sourcecode.swift': 4,
'text': 4,
'text.plist.xml': 4,
'text.script.sh': 4,
'text.xcconfig': 4,
'text.plist.strings': 4
};

function isHeaderFileType(fileType) {
return fileType.endsWith(HEADER_FILE_TYPE_SUFFIX);
}

function isSourceFileType(fileType) {
return fileType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX) && !isHeaderFileType(fileType);
}

function isAssetFileType(fileType) {
return fileType === FILETYPE_BY_EXTENSION.xcassets;
}

function isResource(group) {
return group === "Resources";
}

function isEntitlementFileType(fileType) {
return fileType.endsWith(ENTITLEMENTS_FILE_TYPE_SUFFIX);
}

function isPlistFileType(fileType) {
return fileType === FILETYPE_BY_EXTENSION.plist;
}

function unquoted(text) {
return text == null ? '' : text.replace (/(^")|("$)/g, '')
}

module.exports = {
DEFAULT_SOURCETREE,
DEFAULT_PRODUCT_SOURCETREE,
DEFAULT_FILEENCODING,
DEFAULT_GROUP,
DEFAULT_FILETYPE,
HEADER_FILE_TYPE_SUFFIX,
ENTITLEMENTS_FILE_TYPE_SUFFIX,
SOURCE_CODE_FILE_TYPE_PREFIX,
FILETYPE_BY_EXTENSION,
GROUP_BY_FILETYPE,
PATH_BY_FILETYPE,
SOURCETREE_BY_FILETYPE,
ENCODING_BY_FILETYPE,
isHeaderFileType,
isSourceFileType,
isAssetFileType,
isResource,
isEntitlementFileType,
isPlistFileType,
unquoted
}
140 changes: 17 additions & 123 deletions lib/pbxFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,116 +16,24 @@
*/

var path = require('path'),
util = require('util');

var DEFAULT_SOURCETREE = '"<group>"',
DEFAULT_PRODUCT_SOURCETREE = 'BUILT_PRODUCTS_DIR',
DEFAULT_FILEENCODING = 4,
DEFAULT_GROUP = 'Resources',
DEFAULT_FILETYPE = 'unknown',
HEADER_FILE_TYPE_SUFFIX = ".h",
SOURCE_CODE_FILE_TYPE_PREFIX = "sourcecode.";

var FILETYPE_BY_EXTENSION = {
a: 'archive.ar',
app: 'wrapper.application',
appex: 'wrapper.app-extension',
bundle: 'wrapper.plug-in',
c: 'sourcecode.c.c',
cc: 'sourcecode.cpp.cpp',
cpp: 'sourcecode.cpp.cpp',
cxx: 'sourcecode.cpp.cpp',
'c++': 'sourcecode.cpp.cpp',
dylib: 'compiled.mach-o.dylib',
framework: 'wrapper.framework',
h: 'sourcecode.c.h',
hh: 'sourcecode.cpp.h',
hpp: 'sourcecode.cpp.h',
hxx: 'sourcecode.cpp.h',
'h++': 'sourcecode.cpp.h',
m: 'sourcecode.c.objc',
mm: 'sourcecode.cpp.objcpp',
markdown: 'text',
mdimporter: 'wrapper.cfbundle',
octest: 'wrapper.cfbundle',
pch: 'sourcecode.c.h',
plist: 'text.plist.xml',
png: "image.png",
sh: 'text.script.sh',
swift: 'sourcecode.swift',
tbd: 'sourcecode.text-based-dylib-definition',
xcassets: 'folder.assetcatalog',
xcconfig: 'text.xcconfig',
xcdatamodel: 'wrapper.xcdatamodel',
xcodeproj: 'wrapper.pb-project',
xctest: 'wrapper.cfbundle',
xib: 'file.xib',
strings: 'text.plist.strings'
},
GROUP_BY_FILETYPE = {
'archive.ar': 'Frameworks',
'compiled.mach-o.dylib': 'Frameworks',
'sourcecode.text-based-dylib-definition': 'Frameworks',
'wrapper.framework': 'Frameworks',
'embedded.framework': 'Embed Frameworks',
'sourcecode.c.h': 'Resources',
'sourcecode.c.c': 'Sources',
'sourcecode.c.objc': 'Sources',
'sourcecode.swift': 'Sources',
'sourcecode.cpp.cpp': 'Sources',
'sourcecode.cpp.objcpp': 'Sources'
},
PATH_BY_FILETYPE = {
'compiled.mach-o.dylib': 'usr/lib/',
'sourcecode.text-based-dylib-definition': 'usr/lib/',
'wrapper.framework': 'System/Library/Frameworks/'
},
SOURCETREE_BY_FILETYPE = {
'compiled.mach-o.dylib': 'SDKROOT',
'sourcecode.text-based-dylib-definition': 'SDKROOT',
'wrapper.framework': 'SDKROOT'
},
ENCODING_BY_FILETYPE = {
'sourcecode.c.h': 4,
'sourcecode.c.h': 4,
'sourcecode.cpp.h': 4,
'sourcecode.c.c': 4,
'sourcecode.c.objc': 4,
'sourcecode.cpp.cpp': 4,
'sourcecode.cpp.objcpp': 4,
'sourcecode.swift': 4,
'text': 4,
'text.plist.xml': 4,
'text.script.sh': 4,
'text.xcconfig': 4,
'text.plist.strings': 4
};

function isSourceOrHeaderFileType(fileType) {
return fileType.startsWith(SOURCE_CODE_FILE_TYPE_PREFIX);
}

function isHeaderFileType(fileType) {
return fileType.endsWith(HEADER_FILE_TYPE_SUFFIX);
}

function unquoted(text){
return text == null ? '' : text.replace (/(^")|("$)/g, '')
}
util = require('util'),
constants = require('./constants'),
unquoted = constants.unquoted,
FILETYPE_BY_EXTENSION = constants.FILETYPE_BY_EXTENSION;

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

if (!filetype) {
return DEFAULT_FILETYPE;
return constants.DEFAULT_FILETYPE;
}

return filetype;
}

function defaultExtension(fileRef) {
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != DEFAULT_FILETYPE ?
var filetype = fileRef.lastKnownFileType && fileRef.lastKnownFileType != constants.DEFAULT_FILETYPE ?
fileRef.lastKnownFileType : fileRef.explicitFileType;

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

function defaultEncoding(fileRef) {
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
encoding = ENCODING_BY_FILETYPE[unquoted(filetype)];
encoding = constants.ENCODING_BY_FILETYPE[unquoted(filetype)];

if (encoding) {
return encoding;
Expand All @@ -148,18 +56,18 @@ function defaultEncoding(fileRef) {
function detectGroup(fileRef, opt) {
var extension = path.extname(fileRef.basename).substring(1),
filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
groupName = GROUP_BY_FILETYPE[unquoted(filetype)];
groupName = constants.GROUP_BY_FILETYPE[unquoted(filetype)];

if (extension === 'xcdatamodeld') {
return 'Sources';
}

if (opt.customFramework && opt.embed) {
return GROUP_BY_FILETYPE['embedded.framework'];
return constants.GROUP_BY_FILETYPE['embedded.framework'];
}

if (!groupName) {
return DEFAULT_GROUP;
return constants.DEFAULT_GROUP;
}

return groupName;
Expand All @@ -168,26 +76,26 @@ function detectGroup(fileRef, opt) {
function detectSourcetree(fileRef) {

var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
sourcetree = SOURCETREE_BY_FILETYPE[unquoted(filetype)];
sourcetree = constants.SOURCETREE_BY_FILETYPE[unquoted(filetype)];

if (fileRef.explicitFileType) {
return DEFAULT_PRODUCT_SOURCETREE;
return constants.DEFAULT_PRODUCT_SOURCETREE;
}

if (fileRef.customFramework) {
return DEFAULT_SOURCETREE;
return constants.DEFAULT_SOURCETREE;
}

if (!sourcetree) {
return DEFAULT_SOURCETREE;
return constants.DEFAULT_SOURCETREE;
}

return sourcetree;
}

function defaultPath(fileRef, filePath) {
var filetype = fileRef.lastKnownFileType || fileRef.explicitFileType,
defaultPath = PATH_BY_FILETYPE[unquoted(filetype)];
defaultPath = constants.PATH_BY_FILETYPE[unquoted(filetype)];

if (fileRef.customFramework) {
return filePath;
Expand All @@ -200,18 +108,8 @@ function defaultPath(fileRef, filePath) {
return filePath;
}

function defaultGroup(fileRef) {
var groupName = GROUP_BY_FILETYPE[fileRef.lastKnownFileType];

if (!groupName) {
return DEFAULT_GROUP;
}

return defaultGroup;
}

function pbxFile(filepath, opt) {
var opt = opt || {};
opt = opt || {};

this.basename = opt.basename || path.basename(filepath);
this.lastKnownFileType = opt.lastKnownFileType || detectType(filepath);
Expand Down Expand Up @@ -257,8 +155,4 @@ function pbxFile(filepath, opt) {
}
}

module.exports = {
pbxFile: pbxFile,
isSourceOrHeaderFileType,
isHeaderFileType
}
module.exports = pbxFile;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line.

Loading