| 245 | ]; |
| 246 | |
| 247 | const getConfigContents = ({ |
| 248 | filename, |
| 249 | isEsm, |
| 250 | }: { |
| 251 | filename: string; |
| 252 | isEsm: boolean; |
| 253 | }): string | NodeJS.ArrayBufferView => { |
| 254 | if (filename === "package.json") { |
| 255 | const configPath = path.join(__dirname, `../fixtures/${template}-config/.commitlintrc.json`); |
| 256 | const commitlint = JSON.parse(readFileSync(configPath, { encoding: "utf-8" })); |
| 257 | return JSON.stringify({ commitlint }); |
| 258 | } else if (filename === "package.yaml") { |
| 259 | const configPath = path.join(__dirname, `../fixtures/${template}-config/.commitlintrc.yaml`); |
| 260 | const yaml = readFileSync(configPath, { encoding: "utf-8" }); |
| 261 | return `commitlint:\n${yaml.replace(/^/gm, " ")}`; |
| 262 | } else { |
| 263 | const filePath = ["..", "fixtures", `${template}-config`, filename]; |
| 264 | |
| 265 | if (isEsm) { |
| 266 | filePath.splice(3, 0, "esm"); |
| 267 | } |
| 268 | |
| 269 | const configPath = path.join(__dirname, filePath.join("/")); |
| 270 | return readFileSync(configPath); |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | const esmBootstrap = (cwd: string) => { |
| 275 | const packageJsonPath = path.join(cwd, "package.json"); |