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.jsonor.questions.jsfiles - Interactive prompts using inquirerer with CLI argument support
- Stream-based file processing for efficient variable replacement
Installation
npm install create-gen-appUsage
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__.tsContent 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 repositoryoutputDir(string): Destination directory for the generated projectargv(Record<string, any>): Command-line arguments to pre-populate answersnoTty(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
- Clone the repository:
git clone https://github.com/hyperweb-io/dev-utils.git- Install dependencies:
cd dev-utils
pnpm install
pnpm build- Test the package of interest:
cd packages/<packagename>
pnpm test:watchCredits
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.