()
| 393 | } |
| 394 | |
| 395 | async write(): Promise<void> { |
| 396 | debug("Generator.write...") |
| 397 | const sourcePath = this.sourcePath() |
| 398 | const paths = await readdirRecursive(sourcePath, (name) => { |
| 399 | const additionalFilesToIgnore = this.filesToIgnore() |
| 400 | return ![...alwaysIgnoreFiles, ...additionalFilesToIgnore].includes(name) |
| 401 | }) |
| 402 | const prettierOptions = await this.prettier?.resolveConfig(sourcePath) |
| 403 | for (let filePath of paths) { |
| 404 | try { |
| 405 | let templateValues = await this.getTemplateValues() |
| 406 | const pathSuffix = path.join(this.getTargetDirectory(), filePath) |
| 407 | const sourcePath = this.sourcePath(filePath) |
| 408 | const destinationPath = this.destinationPath(pathSuffix) |
| 409 | let templatedPathSuffix = this.replaceTemplateValues(pathSuffix, templateValues) |
| 410 | const templatedDestinationPath = this.destinationPath(templatedPathSuffix) |
| 411 | const destinationExists = fs.existsSync(templatedDestinationPath) |
| 412 | |
| 413 | templateValues = await this.preFileWrite(templatedPathSuffix) |
| 414 | |
| 415 | if (!this.useTs && tsExtension.test(this.destinationPath(pathSuffix))) { |
| 416 | templatedPathSuffix = templatedPathSuffix.replace(tsExtension, ".js") |
| 417 | } |
| 418 | |
| 419 | if (destinationExists) { |
| 420 | const newContent = this.process( |
| 421 | this.fs.read(templatedDestinationPath, {raw: true}) as any, |
| 422 | pathSuffix, |
| 423 | templateValues, |
| 424 | prettierOptions ?? undefined, |
| 425 | ) |
| 426 | this.fs.write(templatedDestinationPath, newContent) |
| 427 | } else { |
| 428 | this.fs.copy(escapePath(sourcePath), escapePath(destinationPath), { |
| 429 | process: (input) => |
| 430 | this.process(input, pathSuffix, templateValues, prettierOptions ?? undefined), |
| 431 | }) |
| 432 | |
| 433 | if (templatedPathSuffix !== pathSuffix) { |
| 434 | this.fs.move(destinationPath, templatedDestinationPath) |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | await this.postFileWrite(templatedPathSuffix, templateValues) |
| 439 | } catch (error) { |
| 440 | log.error(`Error generating ${filePath}`) |
| 441 | throw error |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | async preCommit(): Promise<void> { |
| 447 | // expose precommit hook, no default implementation |
nothing calls this directly
no test coverage detected