@figma/code-connect
Version:
A tool for connecting your design system components in code with your design system in Figma
20 lines • 909 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFileIfExists = getFileIfExists;
const fs_1 = require("fs");
const child_process_1 = require("child_process");
// Check if a file matching a search pattern exists, and return the first match if so
function getFileIfExists(cwd, search) {
// "find" command is not available on Windows. Use a fs instead.
if (process.platform === 'win32') {
const pattern = search.replace(/\./g, '\\.').replace(/\*/g, '.*');
const regex = new RegExp(`^${pattern}$`);
const files = (0, fs_1.readdirSync)(cwd);
const match = files.find((file) => regex.test(file));
return match ? `./${match}` : '';
}
else {
return (0, child_process_1.execSync)(`find . -maxdepth 1 -name ${search}`, { cwd }).toString().trim().split('\n')[0];
}
}
//# sourceMappingURL=get_file_if_exists.js.map