Skip to content

Commit 5ec77e0

Browse files
authored
Merge pull request #3 from pyramation/create-gen-app
Create gen app
2 parents 4758990 + 695e1bf commit 5ec77e0

16 files changed

Lines changed: 3462 additions & 1733 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ jobs:
2828

2929
- name: Test inquirerer
3030
run: cd packages/inquirerer && yarn test
31+
32+
- name: Test create-gen-app
33+
run: cd packages/create-gen-app && yarn test

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
<a href="https://www.npmjs.com/package/inquirerer"><img height="20" src="https://img.shields.io/github/package-json/v/pyramation/inquirerer?filename=packages%2Finquirerer%2Fpackage.json"></a>
1515
</p>
1616

17-
This library is designed to facilitate the creation of command-line utilities by providing a robust framework for capturing user input through interactive prompts. It supports a variety of question types, making it highly flexible and suitable for a wide range of applications.
18-
19-
_This is the new and improved version of [pyramation/inquirer](https://github.com/pyramation/inquirerer-v1). Soon this will completely replace it!_
17+
This library is designed to facilitate the creation of command-line utilities by providing a robust framework for capturing user input through interactive prompts. It supports a variety of question types, making it highly flexible and suitable for a wide range of applications.
2018

2119
## Install
2220

packages/create-gen-app/README.md

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

0 commit comments

Comments
 (0)