MCPcopy
hub / github.com/serverless/serverless / writeFile

Function writeFile

packages/serverless/lib/utils/fs/write-file.js:7–28  ·  view source on GitHub ↗
(filePath, conts, cycles)

Source from the content-addressed store, hash-verified

5import yaml from 'js-yaml'
6
7async function writeFile(filePath, conts, cycles) {
8 let contents = conts || ''
9
10 return fse.mkdirs(path.dirname(filePath)).then(() => {
11 if (filePath.indexOf('.json') !== -1 && typeof contents !== 'string') {
12 if (cycles) {
13 contents = jc.stringify(contents, null, 2)
14 } else {
15 contents = JSON.stringify(contents, null, 2)
16 }
17 }
18
19 const yamlFileExists = filePath.indexOf('.yaml') !== -1
20 const ymlFileExists = filePath.indexOf('.yml') !== -1
21
22 if ((yamlFileExists || ymlFileExists) && typeof contents !== 'string') {
23 contents = yaml.dump(contents)
24 }
25
26 return fsp.writeFile(filePath, contents)
27 })
28}
29
30export default writeFile

Callers 3

_buildMethod · 0.50
_preparePackageJsonMethod · 0.50
hash-file.test.jsFile · 0.50

Calls 1

writeFileMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…