From 500f458e5dd7ba9b9ee973c2ff4e7319fa544ebe Mon Sep 17 00:00:00 2001 From: Christian Falch Date: Thu, 8 May 2025 12:59:49 -0700 Subject: [PATCH] Add utils script to create folders to prebuild React Native core (#51194) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51194 This change adds an utils script to set up folders when needed. ## Changelog: [INTERNAL] - Add utils script Test Plan: This is tested in the next diff of the stack. Reviewed By: cortinico Differential Revision: D74393298 Pulled By: cipolleschi fbshipit-source-id: db3db61ec938d2ebe5c0bf5ae0a42aa20c673bb0 --- .../scripts/ios-prebuild/utils.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 packages/react-native/scripts/ios-prebuild/utils.js diff --git a/packages/react-native/scripts/ios-prebuild/utils.js b/packages/react-native/scripts/ios-prebuild/utils.js new file mode 100644 index 00000000000..b55b11201d6 --- /dev/null +++ b/packages/react-native/scripts/ios-prebuild/utils.js @@ -0,0 +1,29 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + * @oncall react_native + */ + +const fs = require('fs'); + +/** + * Creates a folder if it does not exist + * @param {string} folderPath - The path to the folder + * @returns {string} The path to the created or existing folder + */ +function createFolderIfNotExists(folderPath /*:string*/) /*: string*/ { + if (!fs.existsSync(folderPath)) { + fs.mkdirSync(folderPath, {recursive: true}); + if (!fs.existsSync(folderPath)) { + throw new Error(`Failed to create folder: ${folderPath}`); + } + } + return folderPath; +} + +module.exports = {createFolderIfNotExists};