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
This commit is contained in:
Christian Falch
2025-05-08 12:59:49 -07:00
committed by Facebook GitHub Bot
parent 43bfb5da11
commit 500f458e5d
+29
View File
@@ -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};