Skip to content

Conversation

@William-Fernandes252
Copy link
Owner

📌 Objective

Refactor the template method to mke it more clean.

📝 Changes

Use instances of the following class instead of inline objects on the temples to allow it to be smaller and more focused on rendering the components.

export abstract class Case {
	constructor(private raw: Template.Value) {}

	protected getValue(): string {
		return String(this.raw ?? "");
	}

	/**
	 * Convert the value to a formatted string.
	 */
	abstract toString(): string;

	[Symbol.toPrimitive](_: string): string {
		return this.toString();
	}
}

// updated signature
function template(
	strings: TemplateStringsArray,
	...placeholders: Array<Case | string | undefined | null>
): Template.Result

@William-Fernandes252 William-Fernandes252 self-assigned this May 8, 2025
@William-Fernandes252 William-Fernandes252 added the enhancement New feature or request label May 8, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the template system by replacing inline object formatting with instances of abstract Case classes, thereby focusing each template on rendering components. Key changes include:

  • Transitioning the template function to accept Case instances or strings.
  • Updating service, repository, and factory templates to use the new Case classes.
  • Adjusting unit and integration tests to verify the updated API.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/tags.ts Refactored the template function to use Case instances with a Proxy-based API for rendering and composition.
src/utils/formats.ts Introduced the abstract Case class and its concrete implementations for various casing formats.
src/templates/service.ts Updated service template generation to utilize the new formatting classes.
src/templates/repository.ts Updated repository template generation to utilize the new formatting classes.
src/templates/factory.ts Updated factory template generation to utilize the new formatting classes.
tests/unit/utils/tags.test.ts Adjusted unit tests to validate the refactored template functionality and its compose methods.
tests/unit/utils/formats.test.ts Added tests for all Case implementations to ensure correct formatting behavior.
tests/unit/templates.test.ts Updated integration tests for template-based code generation using the new API.
tests/integration/layers.test.ts Minor update to reference the default base path correctly from constants.
Comments suppressed due to low confidence (1)

src/utils/tags.ts:20

  • [nitpick] Consider renaming the 'clean' function to 'resetResult' for improved readability about its purpose.
function clean() {

@codecov
Copy link

codecov bot commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (c87e791) to head (ce1880d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #7   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           11        12    +1     
  Lines          449       483   +34     
  Branches        46        58   +12     
=========================================
+ Hits           449       483   +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@William-Fernandes252 William-Fernandes252 merged commit 2a49297 into main May 8, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants