Skip to content

Commit 42728ba

Browse files
committed
Update README and tests to standardize variable naming convention
- Changed variable naming in README and test files from uppercase to lowercase format (e.g., ____PROJECT_NAME____ to ____projectName____). - Updated extraction patterns in the extract module and types to reflect the new naming convention. - Ensured consistency across documentation and code for better clarity and usability.
1 parent aa61fc8 commit 42728ba

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

packages/create-gen-app/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ A TypeScript-first CLI/library for cloning template repositories, asking the use
2121
## Features
2222

2323
- Clone any Git repo (or GitHub `org/repo` shorthand) and optionally select a branch + subdirectory
24-
- Extract template variables from filenames and file contents using the safer `____VARIABLE____` convention
24+
- Extract template variables from filenames and file contents using the safer `____variable____` convention
2525
- Merge auto-discovered variables with `.questions.{json,js}` (questions win, including `ignore` patterns)
2626
- Interactive prompts powered by `inquirerer`, with CLI flag overrides (`--VAR value`) and non-TTY mode for CI
2727
- Built-in CLI (`create-gen-app` / `cga`) that discovers templates, prompts once, and writes output safely
@@ -84,14 +84,14 @@ await createGen({
8484
Variables should be wrapped in four underscores on each side:
8585

8686
```
87-
____PROJECT_NAME____/
88-
src/____MODULE_NAME____.ts
87+
____projectName____/
88+
src/____moduleName____.ts
8989
```
9090

9191
```typescript
92-
// ____MODULE_NAME____.ts
93-
export const projectName = "____PROJECT_NAME____";
94-
export const author = "____USERFULLNAME____";
92+
// ____moduleName____.ts
93+
export const projectName = "____projectName____";
94+
export const author = "____fullName____";
9595
```
9696

9797
### Custom Questions & Ignore Rules
@@ -103,13 +103,13 @@ Create a `.questions.json`:
103103
"ignore": ["__tests__", "docs/drafts"],
104104
"questions": [
105105
{
106-
"name": "____USERFULLNAME____",
106+
"name": "____fullName____",
107107
"type": "text",
108108
"message": "Enter author full name",
109109
"required": true
110110
},
111111
{
112-
"name": "____LICENSE____",
112+
"name": "____license____",
113113
"type": "list",
114114
"message": "Choose a license",
115115
"options": ["MIT", "Apache-2.0", "ISC", "GPL-3.0"]
@@ -118,7 +118,7 @@ Create a `.questions.json`:
118118
}
119119
```
120120

121-
Or `.questions.js` for dynamic logic. Question names can use `____VAR____` or plain `VAR`; they'll be normalized automatically.
121+
Or `.questions.js` for dynamic logic. Question names can use `____var____` or plain `VAR`; they'll be normalized automatically.
122122

123123
### License Templates
124124

@@ -136,4 +136,4 @@ No code changes are needed; the CLI discovers templates at runtime and will warn
136136
- `promptUser(extracted, argv, noTty)` – run interactive questions with CLI overrides and alias deduping
137137
- `replaceVariables(templateDir, outputDir, extracted, answers)` – copy files, rename paths, render licenses
138138

139-
See `dev/README.md` for the local development helper script (`pnpm dev`).
139+
See `dev/README.md` for the local development helper script (`pnpm dev`).

packages/create-gen-app/__tests__/create-gen.test.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ describe("create-gen-app", () => {
4545
describe("extractVariables", () => {
4646
it("should extract variables from filenames", async () => {
4747
fs.writeFileSync(
48-
path.join(testTempDir, "____PROJECT_NAME____.txt"),
48+
path.join(testTempDir, "____projectName____.txt"),
4949
"content"
5050
);
51-
fs.writeFileSync(path.join(testTempDir, "____AUTHOR____.md"), "content");
51+
fs.writeFileSync(path.join(testTempDir, "____author____.md"), "content");
5252

5353
const result = await extractVariables(testTempDir);
5454

@@ -62,7 +62,7 @@ describe("create-gen-app", () => {
6262
it("should extract variables from file contents", async () => {
6363
fs.writeFileSync(
6464
path.join(testTempDir, "test.txt"),
65-
"Hello ____USER_NAME____, welcome to ____PROJECT_NAME____!"
65+
"Hello ____userName____, welcome to ____projectName____!"
6666
);
6767

6868
const result = await extractVariables(testTempDir);
@@ -77,11 +77,11 @@ describe("create-gen-app", () => {
7777
});
7878

7979
it("should extract variables from nested directories", async () => {
80-
const nestedDir = path.join(testTempDir, "src", "____MODULE_NAME____");
80+
const nestedDir = path.join(testTempDir, "src", "____moduleName____");
8181
fs.mkdirSync(nestedDir, { recursive: true });
8282
fs.writeFileSync(
83-
path.join(nestedDir, "____FILE_NAME____.ts"),
84-
'export const ____CONSTANT____ = "value";'
83+
path.join(nestedDir, "____fileName____.ts"),
84+
'export const ____constant____ = "value";'
8585
);
8686

8787
const result = await extractVariables(testTempDir);
@@ -163,7 +163,7 @@ module.exports = {
163163
it("should skip .questions.json and .questions.js from variable extraction", async () => {
164164
fs.writeFileSync(
165165
path.join(testTempDir, ".questions.json"),
166-
'{"questions": [{"name": "____SHOULD_NOT_EXTRACT____"}]}'
166+
'{"questions": [{"name": "____shouldNotExtract____"}]}'
167167
);
168168

169169
const result = await extractVariables(testTempDir);
@@ -176,7 +176,7 @@ module.exports = {
176176
it("should handle variables with different casings", async () => {
177177
fs.writeFileSync(
178178
path.join(testTempDir, "test.txt"),
179-
"____lowercase____ ____UPPERCASE____ ____CamelCase____ ____snake_case____"
179+
"____lowercase____ ____uppercase____ ____CamelCase____ ____snake_case____"
180180
);
181181

182182
const result = await extractVariables(testTempDir);
@@ -210,9 +210,9 @@ module.exports = {
210210

211211
const extractedVariables: ExtractedVariables = {
212212
fileReplacers: [
213-
{ variable: "PROJECT_NAME", pattern: /____PROJECT_NAME____/g },
213+
{ variable: "projectName", pattern: /____projectName____/g },
214214
],
215-
contentReplacers: [{ variable: "AUTHOR", pattern: /____AUTHOR____/g }],
215+
contentReplacers: [{ variable: "author", pattern: /____author____/g }],
216216
projectQuestions: null,
217217
};
218218

@@ -272,7 +272,7 @@ module.exports = {
272272

273273
const extractedVariables: ExtractedVariables = {
274274
fileReplacers: [
275-
{ variable: "PROJECT_NAME", pattern: /____PROJECT_NAME____/g },
275+
{ variable: "projectName", pattern: /____projectName____/g },
276276
],
277277
contentReplacers: [],
278278
projectQuestions: null,
@@ -298,7 +298,7 @@ module.exports = {
298298
const extractedVariables: ExtractedVariables = {
299299
fileReplacers: [],
300300
contentReplacers: [
301-
{ variable: "USERFULLNAME", pattern: /____USERFULLNAME____/g },
301+
{ variable: "fullName", pattern: /____fullName____/g },
302302
],
303303
projectQuestions: {
304304
questions: [
@@ -330,7 +330,7 @@ module.exports = {
330330
const extractedVariables: ExtractedVariables = {
331331
fileReplacers: [],
332332
contentReplacers: [
333-
{ variable: "MODULEDESC", pattern: /____MODULEDESC____/g },
333+
{ variable: "moduleDesc", pattern: /____moduleDesc____/g },
334334
],
335335
projectQuestions: {
336336
questions: [
@@ -363,7 +363,7 @@ module.exports = {
363363
const extractedVariables: ExtractedVariables = {
364364
fileReplacers: [],
365365
contentReplacers: [
366-
{ variable: "USERFULLNAME", pattern: /____USERFULLNAME____/g },
366+
{ variable: "fullName", pattern: /____fullName____/g },
367367
],
368368
projectQuestions: {
369369
questions: [
@@ -394,7 +394,7 @@ module.exports = {
394394
const extractedVariables: ExtractedVariables = {
395395
fileReplacers: [],
396396
contentReplacers: [
397-
{ variable: "MODULEDESC", pattern: /____MODULEDESC____/g },
397+
{ variable: "moduleDesc", pattern: /____moduleDesc____/g },
398398
],
399399
projectQuestions: {
400400
questions: [
@@ -417,7 +417,7 @@ module.exports = {
417417
it("should replace variables in file contents", async () => {
418418
fs.writeFileSync(
419419
path.join(testTempDir, "README.md"),
420-
"# ____PROJECT_NAME____\n\nBy ____AUTHOR____"
420+
"# ____projectName____\n\nBy ____author____"
421421
);
422422

423423
const extractedVariables = await extractVariables(testTempDir);
@@ -443,7 +443,7 @@ module.exports = {
443443

444444
it("should replace variables in filenames", async () => {
445445
fs.writeFileSync(
446-
path.join(testTempDir, "____PROJECT_NAME____.config.js"),
446+
path.join(testTempDir, "____projectName____.config.js"),
447447
"module.exports = {};"
448448
);
449449

@@ -466,11 +466,11 @@ module.exports = {
466466
});
467467

468468
it("should replace variables in nested directory names", async () => {
469-
const nestedDir = path.join(testTempDir, "src", "____MODULE_NAME____");
469+
const nestedDir = path.join(testTempDir, "src", "____moduleName____");
470470
fs.mkdirSync(nestedDir, { recursive: true });
471471
fs.writeFileSync(
472472
path.join(nestedDir, "index.ts"),
473-
'export const name = "____MODULE_NAME____";'
473+
'export const name = "____moduleName____";'
474474
);
475475

476476
const extractedVariables = await extractVariables(testTempDir);
@@ -517,7 +517,7 @@ module.exports = {
517517
it("should handle multiple occurrences of the same variable", async () => {
518518
fs.writeFileSync(
519519
path.join(testTempDir, "test.txt"),
520-
"____NAME____ loves ____NAME____ and ____NAME____ is great!"
520+
"____name____ loves ____name____ and ____name____ is great!"
521521
);
522522

523523
const extractedVariables = await extractVariables(testTempDir);
@@ -578,7 +578,7 @@ module.exports = {
578578
fs.mkdirSync(ignoredDir);
579579
fs.writeFileSync(
580580
path.join(ignoredDir, "example.txt"),
581-
"This file has ____IGNORED____ variable"
581+
"This file has ____ignored____ variable"
582582
);
583583
fs.writeFileSync(
584584
path.join(testTempDir, ".questions.json"),

packages/create-gen-app/src/extract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
const PLACEHOLDER_BOUNDARY = "____";
1212

1313
/**
14-
* Pattern to match ____VARIABLE____ in filenames and content
14+
* Pattern to match ____variable____ in filenames and content
1515
*/
1616
const VARIABLE_PATTERN = new RegExp(
1717
`${PLACEHOLDER_BOUNDARY}([A-Za-z_][A-Za-z0-9_]*)${PLACEHOLDER_BOUNDARY}`,

packages/create-gen-app/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ export interface Questions {
1111
}
1212

1313
/**
14-
* Variable extracted from filename patterns like ____VARIABLE____
14+
* Variable extracted from filename patterns like ____variable____
1515
*/
1616
export interface FileReplacer {
1717
variable: string;
1818
pattern: RegExp;
1919
}
2020

2121
/**
22-
* Variable extracted from file content patterns like ____VARIABLE____
22+
* Variable extracted from file content patterns like ____variable____
2323
*/
2424
export interface ContentReplacer {
2525
variable: string;

0 commit comments

Comments
 (0)