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:

"return_type": "{{USE DEPENDENCY(WHERE type.isEntity IS true).type}}"

This expression fetches the type of a dependency marked as an entity.

Modifying File Structure

To change where files are generated:

  1. 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

  1. Locate the imports array in the component's defaults you want to modify.

  2. Add a new ImportJson entry:

    {
      "list": ["NewImport"],
      "path": "path/to/import"
    }

Adding Methods

  1. In the methods array of a component's defaults, add a new MethodJson object:

    {
      "name": "newMethod",
      "params": [{"name": "param", "type": "string"}],
      "return_type": "void"
    }

Adding Properties

  1. Under the props array, add new PropJson objects:

    {
      "name": "newProperty",
      "type": "number",
      "access": "public"
    }

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 the addons object within a component configuration, like UseCase.

  • 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