1 line
1.8 KiB
Plaintext
1 line
1.8 KiB
Plaintext
|
{"version":3,"file":"file-utils.js","sourceRoot":"","sources":["../../src/utils/file-utils.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA0B;AAC1B,gDAAwB;AAExB;;GAEG;AACI,KAAK,UAAU,qBAAqB,CAAC,QAAgB,EAAE,OAAe;IAC3E,IAAI,CAAC,CAAC,MAAM,kBAAE,CAAC,UAAU,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE;QAClD,MAAM,kBAAE,CAAC,MAAM,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;KACzC;IACD,MAAM,kBAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AALD,sDAKC;AAED;;GAEG;AACI,KAAK,UAAU,oBAAoB,CAAC,QAAgB,EAAE,eAAwB;IACnF,IAAI,MAAM,kBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QACjC,OAAO,kBAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;KACvC;IACD,IAAI,eAAe,EAAE;QACnB,OAAO,eAAe,CAAC;KACxB;IACD,MAAM,KAAK,CAAC,kBAAkB,QAAQ,EAAE,CAAC,CAAC;AAC5C,CAAC;AARD,oDAQC;AAEM,KAAK,UAAU,kBAAkB,CAAC,QAAgB;IACvD,IAAI,MAAM,kBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QACjC,MAAM,kBAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;KAC3B;AACH,CAAC;AAJD,gDAIC","sourcesContent":["import fs from 'fs-extra';\nimport path from 'path';\n\n/**\n * Creates file with given content with possible parent directories creation.\n */\nexport async function createDirAndWriteFile(filePath: string, content: string) {\n if (!(await fs.pathExists(path.dirname(filePath)))) {\n await fs.mkdirp(path.dirname(filePath));\n }\n await fs.writeFile(filePath, content);\n}\n\n/**\n * Reads given file as UTF-8 with fallback to given content when file is not found.\n */\nexport async function readFileWithFallback(filePath: string, fallbackContent?: string) {\n if (await fs.pathExists(filePath)) {\n return fs.readFile(filePath, 'utf-8');\n }\n if (fallbackContent) {\n return fallbackContent;\n }\n throw Error(`File not found ${filePath}`);\n}\n\nexport async function removeFileIfExists(filePath: string) {\n if (await fs.pathExists(filePath)) {\n await fs.unlink(filePath);\n }\n}\n"]}
|