|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, salesforce.com, inc. |
| 3 | + * All rights reserved. |
| 4 | + * SPDX-License-Identifier: BSD-3-Clause |
| 5 | + * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
| 6 | + */ |
| 7 | + |
| 8 | +import path from "path"; |
| 9 | +import fs from "fs-extra"; |
| 10 | +import { PRODUCTION_API_PATH } from "./lib/config"; |
| 11 | + |
| 12 | +/** |
| 13 | + * Recursively removes all files ending in '-internal.yaml' from a directory and its subdirectories |
| 14 | + * @param directoryPath - The path to the directory to process |
| 15 | + */ |
| 16 | +export function removeInternalOas(directoryPath: string): void { |
| 17 | + if (!fs.existsSync(directoryPath)) { |
| 18 | + console.warn(`Directory does not exist: ${directoryPath}`); |
| 19 | + return; |
| 20 | + } |
| 21 | + |
| 22 | + const items = fs.readdirSync(directoryPath); |
| 23 | + |
| 24 | + items.forEach((item) => { |
| 25 | + const fullPath = path.join(directoryPath, item); |
| 26 | + const stat = fs.statSync(fullPath); |
| 27 | + |
| 28 | + if (stat.isDirectory()) { |
| 29 | + // Recursively process subdirectories |
| 30 | + removeInternalOas(fullPath); |
| 31 | + } else if (stat.isFile() && item.endsWith("-internal.yaml")) { |
| 32 | + // Remove internal files |
| 33 | + fs.removeSync(fullPath); |
| 34 | + console.log(`Removed internal file: ${fullPath}`); |
| 35 | + } |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +// Run the function if this file is executed directly |
| 40 | +if (require.main === module) { |
| 41 | + console.log(`Removing internal OAS files from: ${PRODUCTION_API_PATH}`); |
| 42 | + removeInternalOas(PRODUCTION_API_PATH); |
| 43 | + console.log("Internal OAS files removal completed."); |
| 44 | +} |
0 commit comments