JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 49
  • Score
    100M100P100Q61686F
  • License MIT

Clone and customize template repositories

Package Exports

  • create-gen-app
  • create-gen-app/esm/index.js
  • create-gen-app/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (create-gen-app) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

create-gen-app

A TypeScript library for cloning and customizing template repositories with variable replacement.

Features

  • Clone GitHub repositories or any git URL
  • Extract template variables from filenames and file contents using __VARIABLE__ syntax
  • Load custom questions from .questions.json or .questions.js files
  • Interactive prompts using inquirerer with CLI argument support
  • Stream-based file processing for efficient variable replacement

Installation

npm install create-gen-app

Usage

Basic Usage

import { createGen } from 'create-gen-app';

await createGen({
  templateUrl: 'https://github.com/user/template-repo',
  outputDir: './my-new-project',
  argv: {
    PROJECT_NAME: 'my-project',
    AUTHOR: 'John Doe'
  }
});

Template Variables

Variables in your template should be wrapped in double underscores:

Filename variables:

__PROJECT_NAME__/
  __MODULE_NAME__.ts

Content variables:

// __MODULE_NAME__.ts
export const projectName = "__PROJECT_NAME__";
export const author = "__AUTHOR__";

Custom Questions

Create a .questions.json file in your template repository:

{
  "questions": [
    {
      "name": "PROJECT_NAME",
      "type": "text",
      "message": "What is your project name?",
      "required": true
    },
    {
      "name": "AUTHOR",
      "type": "text",
      "message": "Who is the author?"
    }
  ]
}

Or use .questions.js for dynamic questions:

/**
 * @typedef {Object} Questions
 * @property {Array} questions - Array of question objects
 */

module.exports = {
  questions: [
    {
      name: 'PROJECT_NAME',
      type: 'text',
      message: 'What is your project name?',
      required: true
    }
  ]
};

API

createGen(options: CreateGenOptions): Promise<string>

Main function to create a project from a template.

Options:

  • templateUrl (string): URL or path to the template repository
  • outputDir (string): Destination directory for the generated project
  • argv (Record<string, any>): Command-line arguments to pre-populate answers
  • noTty (boolean): Whether to disable TTY mode for non-interactive usage

extractVariables(templateDir: string): Promise<ExtractedVariables>

Extract all variables from a template directory.

promptUser(extractedVariables: ExtractedVariables, argv?: Record<string, any>, noTty?: boolean): Promise<Record<string, any>>

Prompt the user for variable values using inquirerer.

replaceVariables(templateDir: string, outputDir: string, extractedVariables: ExtractedVariables, answers: Record<string, any>): Promise<void>

Replace variables in all files and filenames.

Variable Naming Rules

Variables can contain:

  • Letters (a-z, A-Z)
  • Numbers (0-9)
  • Underscores (_)
  • Must start with a letter or underscore

Examples of valid variables:

  • __PROJECT_NAME__
  • __author__
  • __CamelCase__
  • __snake_case__
  • __VERSION_1__

Development

Setup

  1. Clone the repository:
git clone https://github.com/hyperweb-io/dev-utils.git
  1. Install dependencies:
cd dev-utils
pnpm install
pnpm build
  1. Test the package of interest:
cd packages/<packagename>
pnpm test:watch

Credits

Built for developers, with developers.
👉 https://launchql.com | https://hyperweb.io

Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.