UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

1 lines 3 kB
{"version":3,"sources":["../../src/lib/utilities/write-file.ts"],"names":["writeFile","log","filepath","content","skipFormat","writeFileBase","config","resolveConfig","formatted","format","error","LogLevelLabel","ERROR","message"],"mappings":";;;;;;;AA+BA,eAAsBA,SAAAA,CACpBC,GAAAA,EACAC,QAAAA,EACAC,OAAAA,EACAC,aAAa,KAAA,EAAK;AAElB,EAAA,IAAI;AACF,IAAA,IAAIA,UAAAA,EAAY;AACd,MAAA,MAAMC,qBAAAA,CAAcH,UAAUC,OAAAA,CAAAA;IAChC,CAAA,MAAO;AACL,MAAA,MAAMG,MAAAA,GAAS,MAAMC,sBAAAA,CAAcL,QAAAA,CAAAA;AACnC,MAAA,MAAMM,SAAAA,GAAY,MAAMC,eAAAA,CAAON,OAAAA,EAAS;AACtC,QAAA,GAAIG,UAAU,EAAC;AACfJ,QAAAA;OACF,CAAA;AAEA,MAAA,MAAMG,qBAAAA,CAAcH,QAAAA,EAAUM,SAAAA,IAAa,EAAA,CAAA;AAC7C,IAAA;AACF,EAAA,CAAA,CAAA,OAASE,KAAAA,EAAO;AACdT,IAAAA,GAAAA,CACEU,mBAAAA,CAAcC,KAAAA,EACd,CAAA,qBAAA,EAAwBV,QAAAA,CAAAA;AAAuBQ,EAAAA,KAAAA,EAAiBG,OAAAA,GAAWH,KAAAA,CAAgBG,OAAAA,GAAU,EAAA,CAAA,CAAI,CAAA;AAE7G,EAAA;AACF;AAxBsBb,wBAAAA,CAAAA,SAAAA,EAAAA,WAAAA,CAAAA","file":"chunk-END3JFY3.cjs","sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Storm Stack\n\n This code was released as part of the Storm Stack project. Storm Stack\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/storm-stack.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/storm-stack\n Documentation: https://docs.stormsoftware.com/projects/storm-stack\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { writeFile as writeFileBase } from \"@stryke/fs/write-file\";\nimport { format, resolveConfig } from \"prettier\";\nimport type { LogFn } from \"../../types/config\";\n\n/**\n * Writes and formats a file to the file system\n *\n * @param log - The logging function to use for logging errors\n * @param filepath - The file path to write the file\n * @param content - The content to write to the file\n * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier\n */\nexport async function writeFile(\n log: LogFn,\n filepath: string,\n content: string,\n skipFormat = false\n) {\n try {\n if (skipFormat) {\n await writeFileBase(filepath, content);\n } else {\n const config = await resolveConfig(filepath);\n const formatted = await format(content, {\n ...(config ?? {}),\n filepath\n });\n\n await writeFileBase(filepath, formatted || \"\");\n }\n } catch (error) {\n log(\n LogLevelLabel.ERROR,\n `Failed to write file ${filepath} to disk \\n${(error as Error)?.message ? (error as Error).message : \"\"}`\n );\n }\n}\n"]}