Skip to content

Commit 232f74f

Browse files
committed
Added new git ssh additon.
1 parent caacef1 commit 232f74f

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

src/cli.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,26 @@ program
2525
.version('1.0.0')
2626
.command('create')
2727
.description('Create a new project from a git template')
28-
.argument('<project-directory>', 'The directory to create the project in')
28+
.argument('[project-directory]', 'The directory to create the project in')
2929
.argument('[template-name]', 'The name of the template to use')
3030
.option('-t, --template-file <path>', 'Path to a JSON file with custom templates (same format as built-in)')
31+
.option('--ssh', 'Use SSH URL for cloning the template repository')
3132
.action(async (projectDirectory, templateName, options) => {
3233
const templatesToUse = mergeTemplates(defaultTemplates, options?.templateFile);
3334

35+
// If project directory is not provided, prompt for it
36+
if (!projectDirectory) {
37+
const projectDirAnswer = await inquirer.prompt([
38+
{
39+
type: 'input',
40+
name: 'projectDirectory',
41+
message: 'Please provide the directory where you want to create the project?',
42+
default: 'my-app',
43+
},
44+
]);
45+
projectDirectory = projectDirAnswer.projectDirectory;
46+
}
47+
3448
// If template name is not provided, show available templates and let user select
3549
if (!templateName) {
3650
console.log('\n📋 Available templates:\n');
@@ -66,8 +80,22 @@ program
6680
console.log('');
6781
process.exit(1);
6882
}
69-
70-
const templateRepoUrl = template.repo;
83+
84+
// If --ssh was not passed, prompt whether to use SSH
85+
let useSSH = options?.ssh;
86+
if (useSSH === undefined && template.repoSSH) {
87+
const sshAnswer = await inquirer.prompt([
88+
{
89+
type: 'confirm',
90+
name: 'useSSH',
91+
message: 'Use SSH URL for cloning?',
92+
default: false,
93+
},
94+
]);
95+
useSSH = sshAnswer.useSSH;
96+
}
97+
98+
const templateRepoUrl = useSSH && template.repoSSH ? template.repoSSH : template.repo;
7199

72100
// Define the full path for the new project
73101
const projectPath = path.resolve(projectDirectory);
@@ -93,25 +121,25 @@ program
93121
{
94122
type: 'input',
95123
name: 'name',
96-
message: 'Project name?',
124+
message: 'What is the project name?',
97125
default: path.basename(projectPath),
98126
},
99127
{
100128
type: 'input',
101129
name: 'version',
102-
message: 'Version?',
130+
message: 'What version number would you like to use?',
103131
default: '1.0.0',
104132
},
105133
{
106134
type: 'input',
107135
name: 'description',
108-
message: 'Description?',
136+
message: 'What is the project description?',
109137
default: '',
110138
},
111139
{
112140
type: 'input',
113141
name: 'author',
114-
message: 'Author?',
142+
message: 'Who is the author of the project?',
115143
default: '',
116144
},
117145
];

src/template-loader.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +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 */
5+
/** Function used to load custom templates from a JSON file */
66
export function loadCustomTemplates(filePath: string): Template[] {
77
const resolved = path.resolve(filePath);
88
if (!fs.existsSync(resolved)) {
@@ -44,8 +44,13 @@ export function loadCustomTemplates(filePath: string): Template[] {
4444
console.error(`❌ Template at index ${i}: "repo" must be a non-empty string.\n`);
4545
process.exit(1);
4646
}
47+
const repoSSH = obj['repoSSH'];
4748
const options = obj['options'];
4849
const packageManager = obj['packageManager'];
50+
if (typeof repoSSH !== 'undefined' && (typeof repoSSH !== 'string' || !repoSSH.trim())) {
51+
console.error(`❌ Template at index ${i}: "repoSSH" must be a non-empty string.\n`);
52+
process.exit(1);
53+
}
4954
if (options !== undefined && (!Array.isArray(options) || options.some((o) => typeof o !== 'string'))) {
5055
console.error(`❌ Template at index ${i}: "options" must be an array of strings.\n`);
5156
process.exit(1);
@@ -58,6 +63,7 @@ export function loadCustomTemplates(filePath: string): Template[] {
5863
name: name.trim(),
5964
description: String(description),
6065
repo: repo.trim(),
66+
...(typeof repoSSH === 'string' && repoSSH.trim() && { repoSSH: repoSSH.trim() }),
6167
...(Array.isArray(options) && options.length > 0 && { options: options as string[] }),
6268
...(typeof packageManager === 'string' && packageManager.length > 0 && { packageManager }),
6369
});

src/templates.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export type Template = {
55
description: string;
66
/** Template repository URL */
77
repo: string;
8+
/** Template repository SSH URL (optional, falls back to repo if not provided) */
9+
repoSSH?: string;
810
/** Template checkout options */
911
options?: string[];
1012
/** Template package manager */
@@ -16,25 +18,29 @@ export const defaultTemplates: Template[] = [
1618
name: "starter",
1719
description: "A starter template for Patternfly react typescript project",
1820
repo: "https://github.com/patternfly/patternfly-react-seed.git",
21+
repoSSH: "git@github.com:patternfly/patternfly-react-seed.git",
1922
packageManager: "yarn"
2023
},
2124
{
2225
name: "compass-starter",
2326
description: "A starter template for Patternfly compass theme typescript project",
2427
repo: "https://github.com/patternfly/patternfly-react-seed.git",
28+
repoSSH: "git@github.com:patternfly/patternfly-react-seed.git",
2529
options: ["--single-branch", "--branch", "compass_theme"],
2630
packageManager: "yarn"
2731
},
2832
{
2933
name: "nextjs-starter",
3034
description: "A starter template for Patternfly nextjs project",
31-
repo: "git@github.com:patternfly/patternfly-nextjs-seed.git",
35+
repo: "https://github.com/patternfly/patternfly-nextjs-seed.git",
36+
repoSSH: "git@github.com:patternfly/patternfly-nextjs-seed.git",
3237
packageManager: "yarn"
3338
},
3439
{
3540
name: "rhoai_enabled_starter",
3641
description: "A starter template for Red Hat Open AI enabled project",
3742
repo: "https://gitlab.cee.redhat.com/uxd/prototypes/rhoai",
43+
repoSSH: "git@gitlab.cee.redhat.com:uxd/prototypes/rhoai.git",
3844
options: ["--single-branch", "--branch", "3.2"]
3945
}
4046
]

0 commit comments

Comments
 (0)