Modifying Project Structure and Components
This guide assumes you have basic knowledge of TypeScript and the structure of your SoapJS project. The example configuration provided will be our reference point.
Understanding Your Configuration
First, familiarize yourself with the structure of your plugin.config.json
. This file defines how your components like entities, repositories, and services are scaffolded.
Components Configuration
Each component, such as mapper
, entity
, use_case
, etc., has specific configurations:
name_pattern
: Defines how the file's name is generated.path_pattern
: Specifies the file's location within your project structure.element_type
: Determines the type of component (e.g., class, interface, unit_tests).defaults
: Contains default settings for various aspects like methods, properties, and imports.
Using Dynamic Template Expressions (DTE)
Dynamic Template Expressions allow for flexible and dynamic generation based on specific project conditions. For example:
This expression fetches the type of a dependency marked as an entity.
Modifying File Structure
To change where files are generated:
Update the
path_pattern
in the corresponding component configuration. Use placeholders like{{kebab name}}
to maintain dynamic file naming based on component names.
Adding or Modifying Components
Adding Imports
Locate the
imports
array in the component'sdefaults
you want to modify.Add a new
ImportJson
entry:
Adding Methods
In the
methods
array of a component'sdefaults
, add a newMethodJson
object:
Adding Properties
Under the
props
array, add newPropJson
objects:
Using DTE for Custom Logic
Dynamic Template Expressions (DTE) allow for customizable and dynamic generation of your component configurations based on specific project conditions and logic:
Dependencies: Use
{{USE DEPENDENCY(...)}}
expressions to dynamically fetch types, names, or other attributes from your project's dependencies. This is useful for ensuring your component configurations are aligned with the actual project dependencies.Conditional Logic: Apply
{{IF condition}}
expressions within your configurations to conditionally include or exclude certain parts of the template. This can be based on various factors like the presence of certain dependencies, specific project settings, or other conditions.Addons: Utilize
{{USE ADDONS(...)}}
for a more flexible configuration approach, pulling in elements based on instructions enclosed within the parentheses. This is particularly useful for accessing customized settings or predefined values that are not part of the standard dependency objects. The{{USE ADDONS(...)}}
expression works similarly to{{USE DEPENDENCY(...)}}
but targets theaddons
object within a component configuration, likeUseCase
.Flags: Apply
{{FLAG <name_of_the_flag>}}
to mark specific sections of the configuration, such as methods or properties, with custom flags. For example,"meta": "{{FLAG isConfigurator}}"
can designate a method as a configurator, allowing for special parameter assignments or identification in method lists, beyond mere name checking. This method introduces greater flexibility by enabling feature-based rather than name-based logic in your configurations.
This DTE is a work in progress (WIP) and is designed to reduce hardcoding and increase configurability. However, effective use of it requires an understanding of how the CLI code operates and how these addons/dependencies or meta are structured.
Tips for Modifying Configuration
Always backup your configuration before making significant changes.
Test your configuration changes with a small, isolated part of your project first.
Remember, changes in configuration will affect how new components are scaffolded but won’t retroactively modify existing ones.
Conclusion
Modifying the file structure and components in a SoapJS project allows for greater flexibility and adaptation to project-specific needs. By understanding and utilizing the plugin.config.json
, you can tailor your development process to better suit your application’s architecture and coding standards.
Last updated