Skip to content

Commit ffd8c30

Browse files
authored
Merge pull request #16 from hyperweb-io/eason/fix
Create Gen App – tighten prompt mapping, simplify extraction, and refresh integration tests
2 parents 872fb2a + 1769f30 commit ffd8c30

File tree

11 files changed

+118
-350
lines changed

11 files changed

+118
-350
lines changed

packages/create-gen-app-test/src/__tests__/__snapshots__/cached-template.test.ts.snap

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,29 @@ exports[`cached template integration tests first clone with variable replacement
1616
"package.json": {
1717
"author": "Test User test <[email protected]>",
1818
"bugs": {
19-
"url": "https://github.com/Test User test/Test User test/issues",
19+
"url": "https://github.com/tester-test/integration-test/issues",
2020
},
21-
"description": "Test Module test",
21+
"description": "Integration test module test",
2222
"devDependencies": {
23-
"pgsql-test": "^2.13.2",
23+
"makage": "0.1.8",
24+
"pgsql-test": "^2.14.12",
2425
},
25-
"homepage": "https://github.com/Test User test/Test User test",
26+
"homepage": "https://github.com/tester-test/integration-test",
2627
"keywords": [],
2728
"license": "MIT",
2829
"name": "integration-test",
29-
"pnpm": {
30-
"overrides": {
31-
"graphql": "14.7.0",
32-
},
33-
},
3430
"publishConfig": {
3531
"access": "public",
3632
"directory": "dist",
3733
},
3834
"repository": {
3935
"type": "git",
40-
"url": "https://github.com/Test User test/Test User test",
36+
"url": "https://github.com/tester-test/integration-test",
4137
},
4238
"scripts": {
4339
"lint": "eslint . --fix",
4440
"test": "jest",
45-
"test:watch": "jest --watch",
41+
"test:watch": "makage test --watch deploy --ext sql",
4642
},
4743
"version": "0.0.1",
4844
},
@@ -65,33 +61,29 @@ exports[`cached template integration tests second clone from cache should snapsh
6561
"package.json": {
6662
"author": "Test User cached <[email protected]>",
6763
"bugs": {
68-
"url": "https://github.com/Test User cached/Test User cached/issues",
64+
"url": "https://github.com/tester-cached/integration-cached/issues",
6965
},
70-
"description": "Test Module cached",
66+
"description": "Integration test module cached",
7167
"devDependencies": {
72-
"pgsql-test": "^2.13.2",
68+
"makage": "0.1.8",
69+
"pgsql-test": "^2.14.12",
7370
},
74-
"homepage": "https://github.com/Test User cached/Test User cached",
71+
"homepage": "https://github.com/tester-cached/integration-cached",
7572
"keywords": [],
7673
"license": "MIT",
7774
"name": "integration-cached",
78-
"pnpm": {
79-
"overrides": {
80-
"graphql": "14.7.0",
81-
},
82-
},
8375
"publishConfig": {
8476
"access": "public",
8577
"directory": "dist",
8678
},
8779
"repository": {
8880
"type": "git",
89-
"url": "https://github.com/Test User cached/Test User cached",
81+
"url": "https://github.com/tester-cached/integration-cached",
9082
},
9183
"scripts": {
9284
"lint": "eslint . --fix",
9385
"test": "jest",
94-
"test:watch": "jest --watch",
86+
"test:watch": "makage test --watch deploy --ext sql",
9587
},
9688
"version": "0.0.1",
9789
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ describe("CLI integration via create-gen-app-test harness", () => {
5050
expect(fs.existsSync(pkgPath)).toBe(true);
5151

5252
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
53-
expect(pkg.name).toBe(answers.PACKAGE_IDENTIFIER);
54-
expect(pkg.license).toBe(answers.LICENSE);
53+
expect(pkg.name).toBe(answers.packageIdentifier);
54+
expect(pkg.license).toBe(answers.license);
5555

5656
const licenseContent = fs.readFileSync(
5757
path.join(workspace.outputDir, "LICENSE"),
5858
"utf8"
5959
);
6060
expect(licenseContent).toContain("MIT License");
61-
expect(licenseContent).toContain(answers.USERFULLNAME);
61+
expect(licenseContent).toContain(answers.fullName);
6262
} finally {
6363
cleanupWorkspace(workspace);
6464
}

packages/create-gen-app-test/src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ export async function runCli(
208208

209209
const answerOverrides = extractAnswerOverrides(args);
210210
const noTty = Boolean(
211-
args["no-tty"] ?? (args as Record<string, unknown>).noTty
211+
args["no-tty"] ??
212+
(args as Record<string, unknown>).noTty ??
213+
(args as Record<string, unknown>).tty === false
212214
);
213215

214216
// Use the createFromTemplate function which will use the same cache

packages/create-gen-app-test/src/test-utils/integration-helpers.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ export function buildAnswers(
3131
): Record<string, string> {
3232
const safeSuffix = suffix.replace(/[^a-z0-9]/gi, "-").toLowerCase();
3333
return {
34-
USERFULLNAME: `Test User ${suffix}`,
35-
USEREMAIL: `tester-${safeSuffix}@example.com`,
36-
MODULENAME: `Test Module ${suffix}`,
37-
MODULEDESC: `Integration test module ${suffix}`,
38-
REPONAME: `integration-${safeSuffix}`,
39-
USERNAME: `tester-${safeSuffix}`,
40-
ACCESS: "public",
41-
LICENSE: "MIT",
42-
PACKAGE_IDENTIFIER: `integration-${safeSuffix}`,
34+
fullName: `Test User ${suffix}`,
35+
email: `tester-${safeSuffix}@example.com`,
36+
moduleName: `integration-${safeSuffix}`,
37+
moduleDesc: `Integration test module ${suffix}`,
38+
description: `Integration test module ${suffix}`,
39+
repoName: `integration-${safeSuffix}`,
40+
username: `tester-${safeSuffix}`,
41+
access: "public",
42+
license: "MIT",
43+
packageIdentifier: `integration-${safeSuffix}`,
4344
...overrides,
4445
};
4546
}
46-
47-

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

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ module.exports = {
284284
);
285285
});
286286

287-
it("should map CLI overrides with similar names to project questions", async () => {
287+
it("should require exact CLI override names", async () => {
288288
const { Inquirerer } = require("inquirerer");
289289
const mockPrompt = jest.fn().mockResolvedValue({});
290290

@@ -312,10 +312,11 @@ module.exports = {
312312
await promptUser(extractedVariables, argv, false);
313313

314314
const passedArgv = mockPrompt.mock.calls[0][0];
315-
expect(passedArgv.fullName).toBe("CLI User");
315+
expect(passedArgv.fullName).toBeUndefined();
316+
expect(passedArgv.USERFULLNAME).toBe("CLI User");
316317
});
317318

318-
it("should match CLI overrides sharing substrings", async () => {
319+
it("should not map CLI overrides sharing substrings", async () => {
319320
const { Inquirerer } = require("inquirerer");
320321
const mockPrompt = jest.fn().mockResolvedValue({});
321322

@@ -343,7 +344,8 @@ module.exports = {
343344
await promptUser(extractedVariables, argv, false);
344345

345346
const passedArgv = mockPrompt.mock.calls[0][0];
346-
expect(passedArgv.description).toBe("CLI description");
347+
expect(passedArgv.description).toBeUndefined();
348+
expect(passedArgv.MODULEDESC).toBe("CLI description");
347349
});
348350

349351
it("should hydrate template variables from alias answers", async () => {
@@ -376,7 +378,7 @@ module.exports = {
376378
expect(answers.fullName).toBe("Prompted User");
377379
});
378380

379-
it("should hydrate overlapping template variables from answers", async () => {
381+
it("should not hydrate overlapping template variables implicitly", async () => {
380382
const { Inquirerer } = require("inquirerer");
381383
const mockPrompt = jest.fn().mockResolvedValue({
382384
description: "Prompted description",
@@ -404,7 +406,7 @@ module.exports = {
404406

405407
const answers = await promptUser(extractedVariables, {}, false);
406408
expect(answers.description).toBe("Prompted description");
407-
expect(answers.moduleDesc).toBe("Prompted description");
409+
expect(answers.moduleDesc).toBeUndefined();
408410
});
409411
});
410412

@@ -564,39 +566,4 @@ module.exports = {
564566
});
565567
});
566568

567-
it("should respect ignore patterns from questions", async () => {
568-
const ignoredDir = path.join(testTempDir, "__tests__");
569-
fs.mkdirSync(ignoredDir);
570-
fs.writeFileSync(
571-
path.join(ignoredDir, "example.txt"),
572-
"This file has ____ignored____ variable"
573-
);
574-
fs.writeFileSync(
575-
path.join(testTempDir, ".questions.json"),
576-
JSON.stringify({
577-
ignore: ["__tests__"],
578-
questions: [],
579-
})
580-
);
581-
582-
const result = await extractVariables(testTempDir);
583-
584-
expect(result.fileReplacers.map((r) => r.variable)).not.toContain("tests");
585-
expect(result.contentReplacers.map((r) => r.variable)).not.toContain(
586-
"IGNORED"
587-
);
588-
});
589-
590-
it("should skip default ignored content tokens", async () => {
591-
fs.writeFileSync(
592-
path.join(testTempDir, "jest.config.js"),
593-
"// Match both __tests__ and colocated test files"
594-
);
595-
596-
const result = await extractVariables(testTempDir);
597-
598-
expect(result.contentReplacers.map((r) => r.variable)).not.toContain(
599-
"tests"
600-
);
601-
});
602569
});

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ type LicenseTemplateMap = Record<string, string>;
1414
let cachedTemplates: LicenseTemplateMap | null = null;
1515

1616
export type SupportedLicense = string;
17+
export const LICENSE_VALUE_KEYS = ["LICENSE", "license"];
18+
export const LICENSE_AUTHOR_KEYS = [
19+
"USERFULLNAME",
20+
"AUTHOR",
21+
"AUTHORFULLNAME",
22+
"USERNAME",
23+
"fullName",
24+
"author",
25+
"authorFullName",
26+
"userName",
27+
];
28+
export const LICENSE_EMAIL_KEYS = ["USEREMAIL", "EMAIL", "email", "userEmail"];
1729

1830
export function isSupportedLicense(name: string): name is SupportedLicense {
1931
if (!name) {
@@ -58,6 +70,24 @@ export function listSupportedLicenses(): string[] {
5870
return Object.keys(loadLicenseTemplates());
5971
}
6072

73+
export function findLicenseValue(
74+
answers: Record<string, any>
75+
): string | undefined {
76+
return getAnswerValue(answers, LICENSE_VALUE_KEYS);
77+
}
78+
79+
export function findLicenseAuthor(
80+
answers: Record<string, any>
81+
): string | undefined {
82+
return getAnswerValue(answers, LICENSE_AUTHOR_KEYS);
83+
}
84+
85+
export function findLicenseEmail(
86+
answers: Record<string, any>
87+
): string | undefined {
88+
return getAnswerValue(answers, LICENSE_EMAIL_KEYS);
89+
}
90+
6191
function loadLicenseTemplates(): LicenseTemplateMap {
6292
if (cachedTemplates) {
6393
return cachedTemplates;
@@ -106,3 +136,15 @@ function findTemplatesDir(): string | null {
106136
return null;
107137
}
108138

139+
function getAnswerValue(
140+
answers: Record<string, any>,
141+
keys: string[]
142+
): string | undefined {
143+
for (const key of keys) {
144+
const value = answers?.[key];
145+
if (typeof value === "string" && value.trim() !== "") {
146+
return value;
147+
}
148+
}
149+
return undefined;
150+
}

0 commit comments

Comments
 (0)