-
-
Notifications
You must be signed in to change notification settings - Fork 197
Kddimitrov/ios app extensions #4453
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
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b6e652c
initial extensions spike
KristianDD 488fea2
add bundle indentifier
KristianDD 23fcd2a
feat: add extensions from plugins
KristianDD 9bdefab
feat: codesign extension targets
KristianDD 7a43b7a
chore: fix tests
KristianDD 1fd1eb3
refactor: extract add extension method
KristianDD 9ae3d14
refactor: extract add extension method
KristianDD c6b7501
refactor: extract addExtensionToProject method
KristianDD 860893f
chore: linting
KristianDD 6caa6f6
refactor: extract extensions service
KristianDD 51ed81b
chore: fix comments
KristianDD 4512b0a
fix: project parsed once and overrides previous target
KristianDD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import * as path from "path"; | ||
|
||
export class IOSExtensionsService implements IIOSExtensionsService { | ||
constructor(private $fs: IFileSystem, | ||
private $pbxprojDomXcode: IPbxprojDomXcode) { | ||
} | ||
|
||
public async addExtensionsFromPath(extensionsFolderPath: string, projectData: IProjectData, platformData: IPlatformData, projectPath: string, project: IXcode.project): Promise<void> { | ||
const targetUuids: string[] = []; | ||
if (!this.$fs.exists(extensionsFolderPath)) { | ||
return; | ||
} | ||
|
||
this.$fs.readDirectory(extensionsFolderPath) | ||
.filter(fileName => { | ||
const filePath = path.join(extensionsFolderPath, fileName); | ||
const stats = this.$fs.getFsStats(filePath); | ||
|
||
return stats.isDirectory() && !fileName.startsWith("."); | ||
}) | ||
.forEach(extensionFolder => { | ||
const targetUuid = this.addExtensionToProject(extensionsFolderPath, extensionFolder, project, projectData, platformData); | ||
targetUuids.push(targetUuid); | ||
}); | ||
|
||
this.$fs.writeFile(projectPath, project.writeSync({omitEmptyValues: true})); | ||
this.prepareExtensionSigning(targetUuids, projectData, projectPath); | ||
} | ||
|
||
private addExtensionToProject(extensionsFolderPath: string, extensionFolder: string, project: IXcode.project, projectData: IProjectData, platformData: IPlatformData): string { | ||
const extensionPath = path.join(extensionsFolderPath, extensionFolder); | ||
const extensionRelativePath = path.relative(platformData.projectRoot, extensionPath); | ||
const files = this.$fs.readDirectory(extensionPath) | ||
.filter(filePath => !filePath.startsWith(".")) | ||
.map(filePath => path.join(extensionPath, filePath)); | ||
const group: INativeSourceCodeGroup = { name: extensionFolder, path: extensionPath, files}; | ||
const target = project.addTarget(extensionFolder, 'app_extension', extensionRelativePath); | ||
project.addBuildPhase([], 'PBXSourcesBuildPhase', 'Sources', target.uuid); | ||
project.addBuildPhase([], 'PBXResourcesBuildPhase', 'Resources', target.uuid); | ||
project.addBuildPhase([], 'PBXFrameworksBuildPhase', 'Frameworks', target.uuid); | ||
|
||
const extJsonPath = path.join(extensionsFolderPath, extensionFolder, "extension.json"); | ||
if (this.$fs.exists(extJsonPath)) { | ||
const extensionJson = this.$fs.readJson(extJsonPath); | ||
_.forEach(extensionJson.frameworks, framework => { | ||
project.addFramework( | ||
framework, | ||
{ target: target.uuid } | ||
); | ||
}); | ||
if (extensionJson.assetcatalogCompilerAppiconName) { | ||
project.addToBuildSettings("ASSETCATALOG_COMPILER_APPICON_NAME", extensionJson.assetcatalogCompilerAppiconName, target.uuid); | ||
} | ||
} | ||
|
||
project.addPbxGroup(group.files, group.name, group.path, null, { isMain: true, target: target.uuid, filesRelativeToProject: true }); | ||
project.addBuildProperty("PRODUCT_BUNDLE_IDENTIFIER", `${projectData.projectIdentifiers.ios}.${extensionFolder}`, "Debug", extensionFolder); | ||
project.addBuildProperty("PRODUCT_BUNDLE_IDENTIFIER", `${projectData.projectIdentifiers.ios}.${extensionFolder}`, "Release", extensionFolder); | ||
project.addToHeaderSearchPaths(group.path, target.pbxNativeTarget.productName); | ||
|
||
return target.uuid; | ||
} | ||
|
||
private prepareExtensionSigning(targetUuids: string[], projectData:IProjectData, projectPath: string) { | ||
const xcode = this.$pbxprojDomXcode.Xcode.open(projectPath); | ||
const signing = xcode.getSigning(projectData.projectName); | ||
if (signing !== undefined) { | ||
_.forEach(targetUuids, targetUuid => { | ||
if (signing.style === "Automatic") { | ||
xcode.setAutomaticSigningStyleByTargetKey(targetUuid, signing.team); | ||
} else { | ||
for (const config in signing.configurations) { | ||
const signingConfiguration = signing.configurations[config]; | ||
xcode.setManualSigningStyleByTargetKey(targetUuid, signingConfiguration); | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
xcode.save(); | ||
} | ||
|
||
public removeExtensions(project: IXcode.project, projectPath: string): void { | ||
project.removeTargetsByProductType("com.apple.product-type.app-extension"); | ||
this.$fs.writeFile(projectPath, project.writeSync({omitEmptyValues: true})); | ||
} | ||
} | ||
|
||
$injector.register("iOSExtensionsService", IOSExtensionsService); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
projectPath -> pbxProjectPath + extract into object