MCPcopy
hub / github.com/serverless/serverless / renameYmlService

Function renameYmlService

packages/sf-core/src/utils/fs/index.js:313–330  ·  view source on GitHub ↗
(name, serviceFilePathYml)

Source from the content-addressed store, hash-verified

311 * @param {string} serviceFilePathYml - Path to the YAML service file
312 */
313const renameYmlService = async (name, serviceFilePathYml) => {
314 // Read YAML and get a string
315 let serverlessYml = await readFile(serviceFilePathYml)
316 // Change "service" or "service.name" value while keeping as a string to not lose comments in YAML
317 serverlessYml = serverlessYml
318 .replace(
319 /(^|\s|#)service\s*:.+/,
320 (ignore, prefix) =>
321 `${prefix}# "service" is the name of this project. This will also be added to your AWS resource names.\nservice: ${name}`,
322 )
323 .replace(
324 /(^|\s|#)service\s*:\s*\n(\s+)name:.+/,
325 (match, prefix, indent) =>
326 `${prefix}# "service" is the name of this project. This will also be added to your AWS resource names.\nservice:\n${indent}name: ${name}`,
327 )
328 // Rewrite YAML file
329 await writeFile(serviceFilePathYml, serverlessYml)
330}
331
332/**
333 * Rename service in TypeScript file

Callers 1

renameTemplateInAllFilesFunction · 0.70

Calls 2

readFileFunction · 0.70
writeFileFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…