Patchy: Dev & CI Commands For Component Packs

by Admin 46 views
Implement Setup Commands for Development and CI

This document outlines the implementation of new patchy commands (patchy dev and patchy ci) designed to streamline the development and continuous integration (CI) workflows for component packs. These commands aim to simplify the process of creating development and CI environments directly from within a component pack.

Overview & Context

Currently, patchy commands are primarily executed within the context of a project, such as:

  • patchy generate ...: Copies a component from the pack to the project.
  • patchy commit ...: Stores component changes from a project back into the pack.

To enhance the development lifecycle, we introduce commands that operate directly within a component pack:

  • Generate a development project: Creates a project for developing the component pack.
  • Generate a CI project: Creates a project suitable for running continuous integration tests.

Future Considerations: A standalone patchy command for scaffolding new component packs may be added in the future.

While a dedicated "dev project template" isn't strictly necessary, its use is strongly encouraged to facilitate contributions and enable thorough CI testing. It's like having a mini-sandbox to play with your components without messing up a real application.

Desired Workflows

These workflows rely on the existence of templates within the component pack. Let's dive into the specifics of how these commands should function. Think of these templates as pre-configured starting points, making your life a whole lot easier!

Preconditions:

  • A component pack gem contains one or more templates:
    • templates/<template_name>/: Contains a "project template," such as a minimal Rails application (created with rails new --skip-git to avoid initial Git setup).

Important Note:

  • If a component pack lacks a template, the following commands will simply fail. We're assuming you've got these templates ready to go!

Creating a Dev Project: patchy dev

This command is your go-to for quickly setting up a development environment. It takes a template and spins up a project ready for hacking.

  • Command: patchy dev <template_name> -p <path>
    • <template_name>: Specifies the template to use.

    • -p <path>: Defines the destination path for the new project. Defaults to ../<pack_name>_dev, placing the project in a directory next to the pack. This is super handy for keeping things organized!

    • Error Handling: If <path> isn't a valid patchy project (determined by the presence of a configuration file), the command will fail, indicating a user error. We're making sure you don't accidentally overwrite something important!

    • Clean Slate: The command deletes everything in <path>. Be careful! This ensures a clean environment based on the template.

    • Template Copying: The specified template is copied into <path>. This is where the magic happens – your project is born!

    • Setup Execution: Runs bin/setup within the new project. This is crucial for initializing the environment and installing dependencies.

    • Component Installation: Installs all components using patchy generate */*. This populates the project with the necessary components from the pack. The patchy generate */* command effectively tells Patchy to generate all components within all namespaces of your component pack. This is a broad stroke, intended to bring in everything defined in your pack into the development project. It is important to ensure that the template is correctly configured to handle this mass import of components. Patchy won't automatically configure the template or resolve any conflicts that arise during the component generation process.

    • Configuration Responsibility: The template is expected to be pre-configured to handle component installation correctly. patchy itself won't manage template configuration.

Running CI: patchy ci

This command is designed to create an environment suitable for running automated tests. This helps to automate testing and ensure code quality.

  • Command: patchy ci <template_name> -p <path> -t <test_command> -c <component_glob>
    • <template_name>: The template to use for the CI environment.
    • -p <path>: The destination path for the CI project. Defaults to ../<pack_name>_ci.
    • -t <test_command>: The command to execute for running tests (e.g., rake test).
    • -c <component_glob>: A glob pattern specifying which components to install (e.g., */* for all, or component_a/* for a specific component). Defaults to */*.
    • Error Handling: Similar to patchy dev, the command fails if <path> isn't a valid patchy project.
    • Clean Slate: Deletes everything in <path> to ensure a fresh environment.
    • Template Copying: Copies the specified template into <path>.
    • Setup Execution: Runs bin/setup within the new project.
    • Component Installation: Installs the selected components using patchy generate <component_glob>. This allows for targeted testing of specific components.
    • Test Execution: Runs the specified test command (<test_command>). This triggers the automated tests.

Isolation Testing with Component Globs:

The <component_glob> option allows developers to run "isolation tests" for their component pack. This is useful for identifying dependency issues. For example:

  • If component A depends on component B, but you only install component A, the tests should fail, highlighting the missing dependency.

Recommendation:

  • Isolation tests are recommended for manual testing or during releases to catch potential dependency problems.

Benefits of These Commands

  • Simplified Development: Quickly create development environments with a single command.
  • Automated Testing: Streamline CI workflows for component packs.
  • Dependency Management: Easily identify and manage dependencies between components.
  • Consistency: Ensure consistent environments for development and testing.
  • Contribution Friendly: Makes it easier for others to contribute to your component packs.

In Summary

The patchy dev and patchy ci commands provide a powerful and efficient way to manage the development and testing of component packs. By leveraging templates and providing flexible configuration options, these commands empower developers to create robust and reliable component libraries.

Remember, guys, this is all about making our lives easier and our code better! So let's embrace these new tools and build some awesome component packs!