Skip to content

Commit 81bcf8a

Browse files
committed
cleanup
1 parent 4b6bd4e commit 81bcf8a

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

src/cli.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ import { execa } from 'execa';
55
import inquirer from 'inquirer';
66
import fs from 'fs-extra';
77
import path from 'path';
8-
import templates from './templates.js';
8+
import { defaultTemplates }from './templates.js';
99
import { mergeTemplates } from './template-loader.js';
1010

11+
/** Project data provided by the user */
1112
type ProjectData = {
12-
name: string,
13+
/** Project name */
14+
name: string,
15+
/** Project version */
1316
version: string,
17+
/** Project description */
1418
description: string,
19+
/** Project author */
1520
author: string
1621
}
1722

23+
/** Command to create a new project */
1824
program
1925
.version('1.0.0')
2026
.command('create')
@@ -23,7 +29,7 @@ program
2329
.argument('[template-name]', 'The name of the template to use')
2430
.option('-t, --template-file <path>', 'Path to a JSON file with custom templates (same format as built-in)')
2531
.action(async (projectDirectory, templateName, options) => {
26-
const templatesToUse = mergeTemplates(templates, options?.templateFile);
32+
const templatesToUse = mergeTemplates(defaultTemplates, options?.templateFile);
2733

2834
// If template name is not provided, show available templates and let user select
2935
if (!templateName) {
@@ -161,13 +167,14 @@ program
161167
}
162168
});
163169

170+
/** Command to list all available templates */
164171
program
165172
.command('list')
166173
.description('List all available templates')
167174
.option('--verbose', 'List all available templates with verbose information')
168175
.option('-t, --template-file <path>', 'Include templates from a JSON file (same format as built-in)')
169176
.action((options) => {
170-
const templatesToUse = mergeTemplates(templates, options?.templateFile);
177+
const templatesToUse = mergeTemplates(defaultTemplates, options?.templateFile);
171178
console.log('\n📋 Available templates:\n');
172179
templatesToUse.forEach(template => {
173180
console.log(` ${template.name.padEnd(20)} - ${template.description}`)
@@ -181,6 +188,7 @@ program
181188
console.log('');
182189
});
183190

191+
/** Command to run PatternFly codemods on a directory */
184192
program
185193
.command('update')
186194
.description('Run PatternFly codemods on a directory to transform code to the latest PatternFly patterns')

src/template-loader.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs-extra';
22
import path from 'path';
33
import type { Template } from './templates.js';
44

5+
/** Functoin used to load custom templates from a JSON file */
56
export function loadCustomTemplates(filePath: string): Template[] {
67
const resolved = path.resolve(filePath);
78
if (!fs.existsSync(resolved)) {
@@ -64,6 +65,7 @@ export function loadCustomTemplates(filePath: string): Template[] {
6465
return result;
6566
}
6667

68+
/** Function used to merge built-in templates with custom templates */
6769
export function mergeTemplates(builtIn: Template[], customFilePath?: string): Template[] {
6870
if (!customFilePath) {
6971
return builtIn;

src/templates.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
export type Template = {
2+
/** Template name */
23
name: string;
4+
/** Template description */
35
description: string;
6+
/** Template repository URL */
47
repo: string;
8+
/** Template checkout options */
59
options?: string[];
10+
/** Template package manager */
611
packageManager?: string;
712
};
813

9-
const templates: Template[] = [
14+
export const defaultTemplates: Template[] = [
1015
{
1116
name: "starter",
1217
description: "A starter template for Patternfly react typescript project",
@@ -34,4 +39,4 @@ const templates: Template[] = [
3439
}
3540
]
3641

37-
export default templates;
42+
export default defaultTemplates;

0 commit comments

Comments
 (0)