| 273 | ]; |
| 274 | |
| 275 | const getConfigContents = ({ |
| 276 | filename, |
| 277 | isEsm, |
| 278 | }: { |
| 279 | filename: string; |
| 280 | isEsm: boolean; |
| 281 | }): string | NodeJS.ArrayBufferView => { |
| 282 | if (filename === "package.json") { |
| 283 | const configPath = path.join(__dirname, `../fixtures/${template}-config/.commitlintrc.json`); |
| 284 | const commitlint = JSON.parse(readFileSync(configPath, { encoding: "utf-8" })); |
| 285 | return JSON.stringify({ commitlint }); |
| 286 | } else if (filename === "package.yaml") { |
| 287 | const configPath = path.join(__dirname, `../fixtures/${template}-config/.commitlintrc.yaml`); |
| 288 | const yaml = readFileSync(configPath, { encoding: "utf-8" }); |
| 289 | return `commitlint:\n${yaml.replace(/^/gm, " ")}`; |
| 290 | } else { |
| 291 | const filePath = ["..", "fixtures", `${template}-config`, filename]; |
| 292 | |
| 293 | if (isEsm) { |
| 294 | filePath.splice(3, 0, "esm"); |
| 295 | } |
| 296 | |
| 297 | const configPath = path.join(__dirname, filePath.join("/")); |
| 298 | return readFileSync(configPath); |
| 299 | } |
| 300 | }; |
| 301 | |
| 302 | const esmBootstrap = (cwd: string) => { |
| 303 | const packageJsonPath = path.join(cwd, "package.json"); |