Skip to content

Commit 999a081

Browse files
author
Murat
committed
feat: add swift file support to xcode files
1 parent 985a3ee commit 999a081

File tree

10 files changed

+610
-297
lines changed

10 files changed

+610
-297
lines changed

src/__tests__/mocks/mockAll.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function writeMockAppDelegate(
4545
): string {
4646
const appDelegatePath = path.resolve(
4747
__dirname,
48-
`../${name}/ios/test/${Constants.APP_DELEGATE_FILE_NAME}`
48+
`../${name}/ios/test/${Constants.APP_DELEGATE_MM_FILE_NAME}`
4949
);
5050
mockFs.writeFileSync(appDelegatePath, appDelegateContent);
5151
return appDelegatePath;
@@ -56,7 +56,7 @@ function writeMockNotificationService(
5656
): string {
5757
const notificationServicePath = path.resolve(
5858
__dirname,
59-
`../${name}/ios/test/${Constants.NOTIFICATION_SERVICE_FILE_NAME}`
59+
`../${name}/ios/test/${Constants.NOTIFICATION_SERVICE_M_FILE_NAME}`
6060
);
6161
mockFs.writeFileSync(notificationServicePath, notificationServiceContent);
6262
return notificationServicePath;
@@ -67,7 +67,7 @@ function writeMockNotificationContent(
6767
): string {
6868
const notificationContentPath = path.resolve(
6969
__dirname,
70-
`../${name}/ios/test/${Constants.NOTIFICATION_VIEW_CONTROLLER_FILE_NAME}`
70+
`../${name}/ios/test/${Constants.NOTIFICATION_VIEW_CONTROLLER_M_FILE_NAME}`
7171
);
7272
mockFs.writeFileSync(notificationContentPath, notificationContentContent);
7373
return notificationContentPath;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export const mockAppDelegateSwiftTemplate = `import UIKit
2+
import React
3+
import React_RCTAppDelegate
4+
import ReactAppDependencyProvider
5+
6+
@main
7+
class AppDelegate: RCTAppDelegate {
8+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
9+
self.moduleName = "ReactNativeCliTemplates"
10+
self.dependencyProvider = RCTAppDependencyProvider()
11+
12+
// You can add your custom initial props in the dictionary below.
13+
// They will be passed down to the ViewController used by React Native.
14+
self.initialProps = [:]
15+
16+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
17+
}
18+
19+
override func sourceURL(for bridge: RCTBridge) -> URL? {
20+
self.bundleURL()
21+
}
22+
23+
override func bundleURL() -> URL? {
24+
#if DEBUG
25+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
26+
#else
27+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
28+
#endif
29+
}
30+
}
31+
`;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const mock = jest.spyOn(require('../../../utils/stringSplice'), 'stringSplice');
66
import { appDelegateTask, runTask } from '../../../tasks/appDelegateTask';
77
import { AppDelegateTaskType } from '../../../types/mod.types';
88
import { writeMockAppDelegate } from '../../mocks/mockAll';
9+
import { mockAppDelegateSwiftTemplate } from '../../mocks/mockAppDelegateSwiftTemplate';
910
import { mockAppDelegateTemplate } from '../../mocks/mockAppDelegateTemplate';
1011

1112
describe('appDelegateTask', () => {
@@ -37,6 +38,31 @@ describe('appDelegateTask', () => {
3738
expect.stringContaining('found existing ')
3839
);
3940
});
41+
it('should prepend text into didLaunchWithOptions in swift lang', async () => {
42+
let content = mockAppDelegateSwiftTemplate;
43+
const task: AppDelegateTaskType = {
44+
task: 'app_delegate',
45+
lang: 'swift',
46+
actions: [
47+
{
48+
prepend: 'import Firebase',
49+
},
50+
{
51+
block: 'didFinishLaunchingWithOptions',
52+
prepend: 'FirebaseApp.configure()',
53+
},
54+
],
55+
};
56+
content = await appDelegateTask({
57+
configPath: 'path/to/config',
58+
task: task,
59+
content,
60+
packageName: 'test-package',
61+
});
62+
console.log('content', content);
63+
// @ts-ignore
64+
expect(content).toContain(task.actions[1].prepend);
65+
});
4066
it('should prepend text into didLaunchWithOptions', async () => {
4167
let content = mockAppDelegateTemplate;
4268
const task: AppDelegateTaskType = {

src/constants.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ export const Constants = {
55
UPGRADE_CONFIG_FILE_NAME: 'upgrade.yml',
66
GIT_FOLDER_NAME: '.git',
77
PACKAGE_JSON_FILE_NAME: 'package.json',
8-
APP_DELEGATE_FILE_NAME: 'AppDelegate.mm',
9-
NOTIFICATION_SERVICE_FILE_NAME: 'NotificationService.m',
10-
NOTIFICATION_VIEW_CONTROLLER_FILE_NAME: 'NotificationViewController.m',
8+
APP_DELEGATE_MM_FILE_NAME: 'AppDelegate.mm',
9+
APP_DELEGATE_SWIFT_FILE_NAME: 'AppDelegate.swift',
10+
NOTIFICATION_SERVICE_M_FILE_NAME: 'NotificationService.m',
11+
NOTIFICATION_SERVICE_SWIFT_FILE_NAME: 'NotificationService.swift',
12+
NOTIFICATION_VIEW_CONTROLLER_M_FILE_NAME: 'NotificationViewController.m',
13+
NOTIFICATION_VIEW_CONTROLLER_SWIFT_FILE_NAME:
14+
'NotificationViewController.swift',
1115
PLIST_FILE_NAME: 'Info.plist',
1216
BABEL_CONFIG_FILE_NAME: 'babel.config.js',
1317
ANDROID_MAIN_FILE_PATH: 'android/app/src/main',

src/schema/integrate.schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
"label": {
109109
"type": "string"
110110
},
111+
"lang": {
112+
"$ref": "#/definitions/IosCodeType"
113+
},
111114
"name": {
112115
"type": "string"
113116
},
@@ -565,6 +568,13 @@
565568
],
566569
"type": "object"
567570
},
571+
"IosCodeType": {
572+
"enum": [
573+
"objc",
574+
"swift"
575+
],
576+
"type": "string"
577+
},
568578
"JsonTaskType": {
569579
"additionalProperties": false,
570580
"properties": {
@@ -753,6 +763,9 @@
753763
"label": {
754764
"type": "string"
755765
},
766+
"lang": {
767+
"$ref": "#/definitions/IosCodeType"
768+
},
756769
"name": {
757770
"type": "string"
758771
},
@@ -792,6 +805,9 @@
792805
"label": {
793806
"type": "string"
794807
},
808+
"lang": {
809+
"$ref": "#/definitions/IosCodeType"
810+
},
795811
"name": {
796812
"type": "string"
797813
},

src/schema/upgrade.schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
"label": {
109109
"type": "string"
110110
},
111+
"lang": {
112+
"$ref": "#/definitions/IosCodeType"
113+
},
111114
"name": {
112115
"type": "string"
113116
},
@@ -565,6 +568,13 @@
565568
],
566569
"type": "object"
567570
},
571+
"IosCodeType": {
572+
"enum": [
573+
"objc",
574+
"swift"
575+
],
576+
"type": "string"
577+
},
568578
"JsonTaskType": {
569579
"additionalProperties": false,
570580
"properties": {
@@ -753,6 +763,9 @@
753763
"label": {
754764
"type": "string"
755765
},
766+
"lang": {
767+
"$ref": "#/definitions/IosCodeType"
768+
},
756769
"name": {
757770
"type": "string"
758771
},
@@ -792,6 +805,9 @@
792805
"label": {
793806
"type": "string"
794807
},
808+
"lang": {
809+
"$ref": "#/definitions/IosCodeType"
810+
},
795811
"name": {
796812
"type": "string"
797813
},

0 commit comments

Comments
 (0)