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};