Contributing to create-awesome-node-app

Learn how to contribute templates and extensions to the project

Contribution Overview

The create-awesome-node-app project welcomes contributions from the community. You can contribute by:

  • Adding new templates
  • Adding new extensions
  • Improving existing templates or extensions
  • Fixing bugs or adding features to the CLI

This guide focuses on contributing templates and extensions, which are the most common types of contributions.

Contribution Workflow

Contributing New Templates

Templates are the foundation of create-awesome-node-app. They provide the initial structure and configuration for new projects. This guide will walk you through the process of creating and contributing a new template.

1Template Structure

A template is essentially a complete project structure that serves as a starting point. Here's the recommended structure for a template:

templates/
└── your-template-name/
    ├── public/           # Static assets
    ├── src/              # Source code
    │   ├── components/   # React components (for frontend templates)
    │   ├── lib/          # Utility functions and libraries
    │   └── styles/       # CSS and styling
    ├── .gitignore        # Git ignore file
    ├── package.json      # Package dependencies and scripts
    ├── README.md         # Template documentation
    └── tsconfig.json     # TypeScript configuration (if applicable)

2Adding Your Template to templates.json

Each template must be registered in the templates.json file. This file helps the CLI understand how to use and present your template.

{
  "templates": [
    // ... existing templates
    {
      "name": "Your Template Name",
      "slug": "your-template-name",
      "description": "A concise description of your template",
      "url": "https://github.com/Create-Node-App/cna-templates/tree/main/templates/your-template-name",
      "type": "template-type",
      "category": "category-slug",
      "labels": ["Label1", "Label2", "Label3"]
    }
  ]
}

Here's what each property means:

  • name: The display name of your template
  • slug: A unique identifier for your template (URL-friendly)
  • description: A brief description of what your template offers
  • url: The URL to your template in the repository
  • type: The type of template (e.g., "react", "nestjs-backend", "nextjs")
  • category: The category slug from the categories section
  • labels: Keywords that describe your template

3Creating a Template

Follow these steps to create a new template:

  1. Start with a working project: Begin with a fully functional project that you want to turn into a template.
  2. Clean up the project: Remove any unnecessary files, personal configurations, or environment-specific settings.
  3. Add template documentation: Create a comprehensive README.md that explains the template's purpose, features, and usage.
  4. Add custom options (optional): If your template supports customization, add a customOptions property to your template entry in templates.json.
  5. Test your template: Ensure that your template can be used to create a new project that works correctly.
// Example of customOptions in templates.json
"customOptions": [
  {
    "name": "srcDir",
    "type": "text",
    "message": "Subdirectory to put all source content (e.g., `src`). Leave blank to use the root directory.",
    "initial": "src"
  },
  {
    "name": "projectImportPath",
    "type": "text",
    "message": "Import alias to use for the project, e.g., `@/`",
    "initial": "@/"
  }
]

4Submitting Your Template

Once your template is ready, you can submit it for inclusion in the create-awesome-node-app project:

  1. Fork the repository: Create a fork of the cna-templates repository on GitHub.
  2. Add your template: Place your template in the templates/ directory.
  3. Update templates.json: Add your template to the templates.json file as described above.
  4. Create a pull request: Submit a pull request with a clear description of your template.

Contributing Extensions

Extensions enhance templates with additional functionality. They are modular and can be applied to compatible templates.

1Extension Structure

An extension typically consists of files that will be added to or modified in a template. Here's a recommended structure:

extensions/
└── your-extension-name/
    ├── files/           # Files to be added to the template
    │   ├── src/         # Source files to be added
    │   └── ...          # Other files
    ├── dependencies.json # Dependencies to be added to package.json
    ├── scripts.json     # Scripts to be added to package.json
    └── README.md        # Extension documentation

2Adding Your Extension to templates.json

Each extension must be registered in the templates.json file:

{
  "extensions": [
    // ... existing extensions
    {
      "name": "Your Extension Name",
      "slug": "your-extension-name",
      "description": "A concise description of your extension",
      "url": "https://github.com/Create-Node-App/cna-templates/tree/main/extensions/your-extension-name",
      "type": ["template-type1", "template-type2"],
      "category": "Extension Category",
      "labels": ["Label1", "Label2", "Label3"]
    }
  ]
}

Here's what each property means:

  • name: The display name of your extension
  • slug: A unique identifier for your extension (URL-friendly)
  • description: A brief description of what your extension offers
  • url: The URL to your extension in the repository
  • type: The type(s) of templates this extension is compatible with (string or array of strings)
  • category: The category of the extension (e.g., "UI", "State Management", "Tooling")
  • labels: Keywords that describe your extension

3Creating an Extension

Follow these steps to create a new extension:

  1. Identify the need: Determine what functionality you want to add to existing templates.
  2. Create the extension files: Prepare the files that will be added to or modified in the template.
  3. Define dependencies: Create a dependencies.json file listing any npm packages your extension requires.
  4. Add scripts: If your extension needs to add scripts to package.json, create a scripts.json file.
  5. Document your extension: Create a README.md that explains how to use your extension and what it provides.
// Example dependencies.json
{
  "dependencies": {
    "axios": "^1.3.4",
    "react-query": "^3.39.3"
  },
  "devDependencies": {
    "@types/axios": "^0.14.0"
  }
}

// Example scripts.json
{
  "scripts": {
    "api:generate": "openapi-generator-cli generate -i api-spec.yaml -g typescript-axios -o src/api"
  }
}

4Ensuring Compatibility

Extensions must be compatible with the templates they're designed for. Here's how to ensure compatibility:

  • Specify compatible template types: In your extension's entry in templates.json, list all compatible template types in the type property.
  • Test with all compatible templates: Verify that your extension works correctly with all the template types you've specified.
  • Handle template variations: If templates have different structures (e.g., with or without a src directory), make your extension adaptable.
// Example of specifying multiple compatible template types
"type": ["react", "nextjs", "webextension-react"]

5Submitting Your Extension

The process for submitting an extension is similar to submitting a template:

  1. Fork the repository: Create a fork of the cna-templates repository on GitHub.
  2. Add your extension: Place your extension in the extensions/ directory.
  3. Update templates.json: Add your extension to the templates.json file as described above.
  4. Create a pull request: Submit a pull request with a clear description of your extension.

Best Practices for Template and Extension Design

Project Structure

  • Follow a clear and logical directory structure
  • Group related files together
  • Use consistent naming conventions
  • Include appropriate configuration files

Code Quality

  • Include linting and formatting configurations
  • Set up TypeScript for type safety
  • Add comprehensive comments where necessary
  • Follow best practices for the technologies used

Documentation

  • Provide a detailed README.md
  • Include usage examples
  • Document available scripts and commands
  • Explain any non-standard configurations

Compatibility

  • Ensure compatibility with supported extensions
  • Use the latest stable versions of dependencies
  • Test with different Node.js versions
  • Consider cross-platform compatibility