Skip to content
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

feat: add "activationRules" parameters to the plugin #11

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const shareExtensionEntitlementsFileName = `${shareExtensionName}.entitle
export const shareExtensionStoryBoardFileName = 'MainInterface.storyboard';
export const shareExtensionViewControllerFileName = 'ShareViewController.swift';

export type Parameters = { activationRules?: { [key: string]: number | boolean | string} }

export const getAppGroups = (identifier: string) => [`group.${identifier}`];

export const getShareExtensionBundledIdentifier = (appIdentifier: string) =>
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
withPlugins,
} from "@expo/config-plugins";

import { Parameters } from "./constants";
import { withAppEntitlements } from "./withAppEntitlements";
import { withShareExtensionConfig } from "./withShareExtensionConfig";
import { withShareExtensionXcodeTarget } from "./withShareExtensionXcodeTarget";
Expand All @@ -13,12 +14,12 @@ let pkg: { name: string; version?: string } = {
version: "UNVERSIONED",
};

const withShareMenu: ConfigPlugin = createRunOncePlugin(
(config) => {
const withShareMenu: ConfigPlugin<Parameters> = createRunOncePlugin(
(config, params) => {
return withPlugins(config, [
withAppEntitlements,
withShareExtensionConfig,
withShareExtensionXcodeTarget,
() => withShareExtensionXcodeTarget(config, params),
]);
},
pkg.name,
Expand Down
6 changes: 3 additions & 3 deletions src/withShareExtensionXcodeTarget.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ConfigPlugin, withXcodeProject } from '@expo/config-plugins';

import { getShareExtensionBundledIdentifier, shareExtensionName } from './constants';
import { Parameters, getShareExtensionBundledIdentifier, shareExtensionName } from './constants';
import {
getShareExtensionEntitlementsFilePath,
getShareExtensionInfoFilePath,
Expand All @@ -9,7 +9,7 @@ import {
writeShareExtensionFiles,
} from './writeShareExtensionFiles';

export const withShareExtensionXcodeTarget: ConfigPlugin = (config) => {
export const withShareExtensionXcodeTarget: ConfigPlugin<Parameters> = (config, parameters) => {
return withXcodeProject(config, async (config) => {
const extensionName = shareExtensionName;
const platformProjectRoot = config.modRequest.platformProjectRoot;
Expand All @@ -24,7 +24,7 @@ export const withShareExtensionXcodeTarget: ConfigPlugin = (config) => {
const viewControllerFilePath = getShareExtensionViewControllerPath(platformProjectRoot);
const storyboardFilePath = getShareExtensionStoryboardFilePath(platformProjectRoot);

await writeShareExtensionFiles(platformProjectRoot, scheme, appIdentifier);
await writeShareExtensionFiles(platformProjectRoot, scheme, appIdentifier, parameters);

const pbxProject = config.modResults;

Expand Down
16 changes: 9 additions & 7 deletions src/writeShareExtensionFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import {
shareExtensionInfoFileName,
shareExtensionStoryBoardFileName,
shareExtensionViewControllerFileName,
Parameters,
} from "./constants";

export async function writeShareExtensionFiles(
platformProjectRoot: string,
scheme: string,
appIdentifier: string
appIdentifier: string,
parameters: Parameters
) {
const infoPlistFilePath = getShareExtensionInfoFilePath(platformProjectRoot);
const infoPlistContent = getShareExtensionInfoContent();
const infoPlistContent = getShareExtensionInfoContent(parameters.activationRules);
await fs.promises.mkdir(path.dirname(infoPlistFilePath), { recursive: true });
await fs.promises.writeFile(infoPlistFilePath, infoPlistContent);

Expand All @@ -34,7 +36,7 @@ export async function writeShareExtensionFiles(

const viewControllerFilePath =
getShareExtensionViewControllerPath(platformProjectRoot);
const viewControllerContent = getShareExtensionViewControllerContent(scheme);
const viewControllerContent = getShareExtensionViewControllerContent(scheme, appIdentifier);
await fs.promises.writeFile(viewControllerFilePath, viewControllerContent);
}

Expand Down Expand Up @@ -68,7 +70,7 @@ export function getShareExtensionInfoFilePath(platformProjectRoot: string) {
);
}

export function getShareExtensionInfoContent() {
export function getShareExtensionInfoContent(activationRules: Parameters["activationRules"]) {
return plist.build({
CFBundleName: "$(PRODUCT_NAME)",
CFBundleDisplayName: "Share Extension",
Expand All @@ -79,7 +81,7 @@ export function getShareExtensionInfoContent() {
CFBundlePackageType: "$(PRODUCT_BUNDLE_PACKAGE_TYPE)",
NSExtension: {
NSExtensionAttributes: {
NSExtensionActivationRule: {
NSExtensionActivationRule: activationRules || {
NSExtensionActivationSupportsWebURLWithMaxCount: 1,
NSExtensionActivationSupportsWebPageWithMaxCount: 1,
},
Expand Down Expand Up @@ -140,8 +142,8 @@ export function getShareExtensionViewControllerPath(
);
}

export function getShareExtensionViewControllerContent(scheme: string) {
console.debug("************ scheme", scheme);
export function getShareExtensionViewControllerContent(scheme: string, appIdentifier: string) {
console.debug("************ scheme", scheme, "appIdentifier", appIdentifier);

return `import MobileCoreServices
import Social
Expand Down