(name, serviceFilePathYml)
| 311 | * @param {string} serviceFilePathYml - Path to the YAML service file |
| 312 | */ |
| 313 | const 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 |
no test coverage detected
searching dependent graphs…