Skip to content
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
16 changes: 16 additions & 0 deletions packages/create-react-native-library/src/add-dummy-swift-file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
gem 'xcodeproj'
require 'xcodeproj'

project_path = ARGV[0]
target_name = ARGV[1]
project = Xcodeproj::Project.open(project_path)

project.targets.each do |target|
if target.name == target_name
swift_file = File.join(project.path, '..', 'File.swift')
group = project.groups.select {|i| i.name == target_name }.first
file = group&.new_file(swift_file)
target.add_file_references([file])
end
end
project.save
1 change: 1 addition & 0 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ async function create(argv: yargs.Arguments<any>) {
projectName: options.project.name,
arch,
reactNativeVersion,
swift: options.project.swift,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const PACKAGES_TO_REMOVE = [
'typescript',
];

const ADD_DUMMY_SWIFT_FILE = path.resolve(
__dirname,
'../../src/add-dummy-swift-file.rb'
);

const PACKAGES_TO_ADD_DEV = {
'babel-plugin-module-resolver': '^5.0.0',
};
Expand All @@ -54,13 +59,15 @@ export default async function generateExampleApp({
projectName,
arch,
reactNativeVersion = 'latest',
swift = false,
}: {
type: 'expo' | 'native';
dest: string;
slug: string;
projectName: string;
arch: 'new' | 'mixed' | 'legacy';
reactNativeVersion?: string;
swift?: boolean;
}) {
const directory = path.join(dest, 'example');
const args =
Expand All @@ -85,6 +92,18 @@ export default async function generateExampleApp({
env: { ...process.env, npm_config_yes: 'true' },
});

if (swift && process.platform === 'darwin') {
await spawn(
'ruby',
[
ADD_DUMMY_SWIFT_FILE,
path.join(directory, 'ios', `${projectName}Example.xcodeproj`),
`${projectName}Example`,
],
{}
);
}

// Remove unnecessary files and folders
for (const file of FILES_TO_DELETE) {
await fs.remove(path.join(directory, file));
Expand Down