Skip to content

Commit 2195720

Browse files
committed
merged
2 parents 1c3e8b0 + c4d9774 commit 2195720

36 files changed

+4002
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
- schema-typescript
6060
- strfy-js
6161
- yanse
62+
- inquirerer
63+
- create-gen-app
6264

6365
steps:
6466
- name: Checkout code
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5+
6+
# 0.1.0 (2025-11-16)
7+
8+
**Note:** Version bump only for package create-gen-app

packages/create-gen-app/README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# create-gen-app
2+
3+
<p align="center" width="100%">
4+
<img height="90" src="https://user-images.githubusercontent.com/545047/190171475-b416f99e-2831-4786-9ba3-a7ff4d95b0d3.svg" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
9+
<a href="https://github.com/hyperweb-io/dev-utils/actions/workflows/ci.yml">
10+
<img height="20" src="https://github.com/hyperweb-io/dev-utils/actions/workflows/ci.yml/badge.svg" />
11+
</a>
12+
<a href="https://github.com/hyperweb-io/dev-utils/blob/main/LICENSE">
13+
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
14+
</a>
15+
<a href="https://www.npmjs.com/package/create-gen-app"><img height="20" src="https://img.shields.io/npm/dt/create-gen-app"></a>
16+
<a href="https://www.npmjs.com/package/create-gen-app"><img height="20" src="https://img.shields.io/github/package-json/v/hyperweb-io/dev-utils?filename=packages%2Fcreate-gen-app%2Fpackage.json"></a>
17+
</p>
18+
19+
A TypeScript library for cloning and customizing template repositories with variable replacement.
20+
21+
## Features
22+
23+
- Clone GitHub repositories or any git URL
24+
- Extract template variables from filenames and file contents using `__VARIABLE__` syntax
25+
- Load custom questions from `.questions.json` or `.questions.js` files
26+
- Interactive prompts using inquirerer with CLI argument support
27+
- Stream-based file processing for efficient variable replacement
28+
29+
## Installation
30+
31+
```bash
32+
npm install create-gen-app
33+
```
34+
35+
## Usage
36+
37+
### Basic Usage
38+
39+
```typescript
40+
import { createGen } from 'create-gen-app';
41+
42+
await createGen({
43+
templateUrl: 'https://github.com/user/template-repo',
44+
outputDir: './my-new-project',
45+
argv: {
46+
PROJECT_NAME: 'my-project',
47+
AUTHOR: 'John Doe'
48+
}
49+
});
50+
```
51+
52+
### Template Variables
53+
54+
Variables in your template should be wrapped in double underscores:
55+
56+
**Filename variables:**
57+
```
58+
__PROJECT_NAME__/
59+
__MODULE_NAME__.ts
60+
```
61+
62+
**Content variables:**
63+
```typescript
64+
// __MODULE_NAME__.ts
65+
export const projectName = "__PROJECT_NAME__";
66+
export const author = "__AUTHOR__";
67+
```
68+
69+
### Custom Questions
70+
71+
Create a `.questions.json` file in your template repository:
72+
73+
```json
74+
{
75+
"questions": [
76+
{
77+
"name": "PROJECT_NAME",
78+
"type": "text",
79+
"message": "What is your project name?",
80+
"required": true
81+
},
82+
{
83+
"name": "AUTHOR",
84+
"type": "text",
85+
"message": "Who is the author?"
86+
}
87+
]
88+
}
89+
```
90+
91+
Or use `.questions.js` for dynamic questions:
92+
93+
```javascript
94+
/**
95+
* @typedef {Object} Questions
96+
* @property {Array} questions - Array of question objects
97+
*/
98+
99+
module.exports = {
100+
questions: [
101+
{
102+
name: 'PROJECT_NAME',
103+
type: 'text',
104+
message: 'What is your project name?',
105+
required: true
106+
}
107+
]
108+
};
109+
```
110+
111+
## API
112+
113+
### `createGen(options: CreateGenOptions): Promise<string>`
114+
115+
Main function to create a project from a template.
116+
117+
**Options:**
118+
- `templateUrl` (string): URL or path to the template repository
119+
- `outputDir` (string): Destination directory for the generated project
120+
- `argv` (Record<string, any>): Command-line arguments to pre-populate answers
121+
- `noTty` (boolean): Whether to disable TTY mode for non-interactive usage
122+
123+
### `extractVariables(templateDir: string): Promise<ExtractedVariables>`
124+
125+
Extract all variables from a template directory.
126+
127+
### `promptUser(extractedVariables: ExtractedVariables, argv?: Record<string, any>, noTty?: boolean): Promise<Record<string, any>>`
128+
129+
Prompt the user for variable values using inquirerer.
130+
131+
### `replaceVariables(templateDir: string, outputDir: string, extractedVariables: ExtractedVariables, answers: Record<string, any>): Promise<void>`
132+
133+
Replace variables in all files and filenames.
134+
135+
## Variable Naming Rules
136+
137+
Variables can contain:
138+
- Letters (a-z, A-Z)
139+
- Numbers (0-9)
140+
- Underscores (_)
141+
- Must start with a letter or underscore
142+
143+
Examples of valid variables:
144+
- `__PROJECT_NAME__`
145+
- `__author__`
146+
- `__CamelCase__`
147+
- `__snake_case__`
148+
- `__VERSION_1__`
149+
150+
## License
151+
152+
MIT

0 commit comments

Comments
 (0)