MCPcopy
hub / github.com/serverless/serverless / writeFileSync

Function writeFileSync

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

Source from the content-addressed store, hash-verified

4import yaml from 'js-yaml'
5
6function writeFileSync(filePath, conts, cycles) {
7 let contents = conts || ''
8
9 fse.mkdirsSync(path.dirname(filePath))
10
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 fse.writeFileSync(filePath, contents)
27}
28
29export default writeFileSync

Callers 4

installMethod · 0.85
renameServiceFunction · 0.85
writeFileSyncMethod · 0.85
test.jsFile · 0.85

Calls 1

writeFileSyncMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…