Skip to content

Commit f00b453

Browse files
author
Murat
committed
fix(xcode): make addTarget name non optional
1 parent e08a5b4 commit f00b453

File tree

7 files changed

+46
-24
lines changed

7 files changed

+46
-24
lines changed

src/__tests__/unit/tasks/xcodeTask.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe('xcodeTask', () => {
6666
it('should add notification service to project', async () => {
6767
const pbxFilePath = getPbxProjectPath();
6868
mockFs.writeFileSync(pbxFilePath, mockPbxProjTemplate);
69+
mockPrompter.text.mockReset().mockImplementation(() => 'test');
6970

7071
const proj = xcode.project(pbxFilePath);
7172
proj.parseSync();
@@ -80,6 +81,7 @@ describe('xcodeTask', () => {
8081
},
8182
],
8283
};
84+
8385
await xcodeTask({
8486
configPath: 'path/to/config',
8587
task: task,
@@ -112,6 +114,7 @@ describe('xcodeTask', () => {
112114
type: 'xcode',
113115
actions: [
114116
{
117+
name: 'noti',
115118
addTarget: 'test',
116119
type: 'notification-service',
117120
},
@@ -134,6 +137,7 @@ describe('xcodeTask', () => {
134137
type: 'xcode',
135138
actions: [
136139
{
140+
name: 'noti',
137141
addTarget: 'test2',
138142
type: 'notification-service',
139143
},
@@ -167,6 +171,7 @@ describe('xcodeTask', () => {
167171
type: 'xcode',
168172
actions: [
169173
{
174+
name: 'noti',
170175
addTarget: 'test',
171176
type: 'notification-content',
172177
},
@@ -206,6 +211,7 @@ describe('xcodeTask', () => {
206211
type: 'xcode',
207212
actions: [
208213
{
214+
name: 'noti',
209215
addTarget: 'test',
210216
type: 'notification-content',
211217
},
@@ -231,6 +237,7 @@ describe('xcodeTask', () => {
231237
type: 'xcode',
232238
actions: [
233239
{
240+
name: 'noti',
234241
addTarget: 'test',
235242
type: 'notification-content',
236243
},

src/schema/integrate.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@
16301630
},
16311631
"required": [
16321632
"addTarget",
1633+
"name",
16331634
"type"
16341635
],
16351636
"type": "object"

src/schema/upgrade.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@
16301630
},
16311631
"required": [
16321632
"addTarget",
1633+
"name",
16331634
"type"
16341635
],
16351636
"type": "object"

src/tasks/xcode/xcodeTask.addTarget.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import path from 'path';
33
import color from 'picocolors';
44
import { XcodeProjectType } from 'xcode';
55
import { Constants } from '../../constants';
6-
import { logMessage, logMessageGray, text } from '../../prompter';
6+
import { logMessage, logMessageGray } from '../../prompter';
77
import { notificationContentFiles } from '../../scaffold/notification-content';
88
import { notificationServiceFiles } from '../../scaffold/notification-service';
99
import { XcodeAddTarget } from '../../types/mod.types';
1010
import { getProjectPath } from '../../utils/getProjectPath';
11+
import { runPrompt } from '../../utils/runPrompt';
1112
import { getText, variables } from '../../variables';
1213
import {
1314
normalizeBundleId,
@@ -18,17 +19,24 @@ import {
1819

1920
export async function applyAddTarget(
2021
content: XcodeProjectType,
21-
action: XcodeAddTarget
22+
action: XcodeAddTarget,
23+
packageName: string
2224
): Promise<XcodeProjectType> {
2325
const { type } = action;
2426
action.addTarget = getText(action.addTarget);
2527

26-
let targetName = await text(action.message || 'Enter new target name:', {
27-
defaultValue: action.addTarget,
28-
placeholder: action.addTarget,
29-
});
28+
await runPrompt(
29+
{
30+
name: action.name + '.target',
31+
text: action.message || 'Enter new target name:',
32+
type: 'text',
33+
defaultValue: action.addTarget,
34+
placeholder: action.addTarget,
35+
},
36+
packageName
37+
);
38+
let targetName = variables.get<string>(action.name + '.target');
3039
if (!targetName) targetName = action.addTarget;
31-
if (action.name) variables.set(action.name + '.target', targetName);
3240

3341
const mainGroup = content.getFirstProject().firstProject.mainGroup;
3442

src/tasks/xcode/xcodeTask.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ async function applyXcodeModification(
6868
packageName: string
6969
) {
7070
if ('addFile' in action) return applyAddFile(content, action, packageName);
71-
if ('addTarget' in action) return applyAddTarget(content, action);
71+
if ('addTarget' in action)
72+
return applyAddTarget(content, action, packageName);
7273
if ('addCapability' in action) return applyAddCapability(content, action);
7374
if ('setDeploymentVersion' in action)
7475
return applySetDeploymentVersion(content, action);

src/types/mod.types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ export type XcodeAddFile = ActionBase & {
219219
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
220220
target?: 'root' | 'main' | string;
221221
};
222-
export type XcodeAddTarget = ActionBase & {
222+
export type XcodeAddTarget = Omit<ActionBase, 'name'> & {
223+
name: string;
223224
addTarget: string;
224225
type: XcodeAddTargetType;
225226
message?: string;

website/docs/for-developers/guides/task-types/ios-tasks/xcode.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,24 @@ Specifies the target group within the iOS project where the resource should be a
5050
| type | "notification-service" or "notification-content" | Specifies target type to be added. "notification-service" adds Notification Service Extension and "notification-content" adds Notification Content Extension. |
5151
| message | string | Specifies the message when requesting the target name from the user. |
5252

53-
> **Note**: Specify `name` field for this action to expose the `name.target` variable which will hold the name of the target which was entered by the user.
54-
>
55-
> For example:
56-
> ```yaml
57-
> # add a notification service extension
58-
> # with the default name `MyNotificationService`.
59-
> # User can change this when running this action!
60-
> - addTarget: MyNotificationService
61-
> name: notificationsv # Give it a name
62-
> type: notification-service
63-
>
64-
> # set extension version to same as main target
65-
> - setDeploymentVersion: $[IOS_DEPLOYMENT_VERSION]
66-
> target: $[notificationsv.target] # use the name here
67-
> ```
53+
:::info
54+
`name` must be specified for this action or you will get a validation error.
55+
This action will expose the `name.target` variable which will hold the name of the target which was entered by the user.
56+
57+
For example:
58+
```yaml
59+
# add a notification service extension
60+
# with the default name `MyNotificationService`.
61+
# User can change this when running this action!
62+
- addTarget: MyNotificationService
63+
name: notificationsv # Give it a name
64+
type: notification-service
65+
66+
# set extension version to same as main target
67+
- setDeploymentVersion: $[IOS_DEPLOYMENT_VERSION]
68+
target: $[notificationsv.target] # use the name here
69+
```
70+
:::
6871
6972
### Add new capability to a target
7073

0 commit comments

Comments
 (0)