Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,29 @@ exports[`cached template integration tests first clone with variable replacement
"package.json": {
"author": "Test User test <tester-test@example.com>",
"bugs": {
"url": "https://github.com/Test User test/Test User test/issues",
"url": "https://github.com/tester-test/integration-test/issues",
},
"description": "Test Module test",
"description": "Integration test module test",
"devDependencies": {
"pgsql-test": "^2.13.2",
"makage": "0.1.8",
"pgsql-test": "^2.14.12",
},
"homepage": "https://github.com/Test User test/Test User test",
"homepage": "https://github.com/tester-test/integration-test",
"keywords": [],
"license": "MIT",
"name": "integration-test",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "public",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/Test User test/Test User test",
"url": "https://github.com/tester-test/integration-test",
},
"scripts": {
"lint": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:watch": "makage test --watch deploy --ext sql",
},
"version": "0.0.1",
},
Expand All @@ -65,33 +61,29 @@ exports[`cached template integration tests second clone from cache should snapsh
"package.json": {
"author": "Test User cached <tester-cached@example.com>",
"bugs": {
"url": "https://github.com/Test User cached/Test User cached/issues",
"url": "https://github.com/tester-cached/integration-cached/issues",
},
"description": "Test Module cached",
"description": "Integration test module cached",
"devDependencies": {
"pgsql-test": "^2.13.2",
"makage": "0.1.8",
"pgsql-test": "^2.14.12",
},
"homepage": "https://github.com/Test User cached/Test User cached",
"homepage": "https://github.com/tester-cached/integration-cached",
"keywords": [],
"license": "MIT",
"name": "integration-cached",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "public",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/Test User cached/Test User cached",
"url": "https://github.com/tester-cached/integration-cached",
},
"scripts": {
"lint": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:watch": "makage test --watch deploy --ext sql",
},
"version": "0.0.1",
},
Expand Down
6 changes: 3 additions & 3 deletions packages/create-gen-app-test/src/__tests__/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ describe("CLI integration via create-gen-app-test harness", () => {
expect(fs.existsSync(pkgPath)).toBe(true);

const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
expect(pkg.name).toBe(answers.PACKAGE_IDENTIFIER);
expect(pkg.license).toBe(answers.LICENSE);
expect(pkg.name).toBe(answers.packageIdentifier);
expect(pkg.license).toBe(answers.license);

const licenseContent = fs.readFileSync(
path.join(workspace.outputDir, "LICENSE"),
"utf8"
);
expect(licenseContent).toContain("MIT License");
expect(licenseContent).toContain(answers.USERFULLNAME);
expect(licenseContent).toContain(answers.fullName);
} finally {
cleanupWorkspace(workspace);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/create-gen-app-test/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ export async function runCli(

const answerOverrides = extractAnswerOverrides(args);
const noTty = Boolean(
args["no-tty"] ?? (args as Record<string, unknown>).noTty
args["no-tty"] ??
(args as Record<string, unknown>).noTty ??
(args as Record<string, unknown>).tty === false
);

// Use the createFromTemplate function which will use the same cache
Expand Down
21 changes: 10 additions & 11 deletions packages/create-gen-app-test/src/test-utils/integration-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ export function buildAnswers(
): Record<string, string> {
const safeSuffix = suffix.replace(/[^a-z0-9]/gi, "-").toLowerCase();
return {
USERFULLNAME: `Test User ${suffix}`,
USEREMAIL: `tester-${safeSuffix}@example.com`,
MODULENAME: `Test Module ${suffix}`,
MODULEDESC: `Integration test module ${suffix}`,
REPONAME: `integration-${safeSuffix}`,
USERNAME: `tester-${safeSuffix}`,
ACCESS: "public",
LICENSE: "MIT",
PACKAGE_IDENTIFIER: `integration-${safeSuffix}`,
fullName: `Test User ${suffix}`,
email: `tester-${safeSuffix}@example.com`,
moduleName: `integration-${safeSuffix}`,
moduleDesc: `Integration test module ${suffix}`,
description: `Integration test module ${suffix}`,
repoName: `integration-${safeSuffix}`,
username: `tester-${safeSuffix}`,
access: "public",
license: "MIT",
packageIdentifier: `integration-${safeSuffix}`,
...overrides,
};
}


49 changes: 8 additions & 41 deletions packages/create-gen-app/__tests__/create-gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ module.exports = {
);
});

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

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

const passedArgv = mockPrompt.mock.calls[0][0];
expect(passedArgv.fullName).toBe("CLI User");
expect(passedArgv.fullName).toBeUndefined();
expect(passedArgv.USERFULLNAME).toBe("CLI User");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do these ALL CAPS come from?

});

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

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

const passedArgv = mockPrompt.mock.calls[0][0];
expect(passedArgv.description).toBe("CLI description");
expect(passedArgv.description).toBeUndefined();
expect(passedArgv.MODULEDESC).toBe("CLI description");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do these ALL CAPS come from?

});

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

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

const answers = await promptUser(extractedVariables, {}, false);
expect(answers.description).toBe("Prompted description");
expect(answers.moduleDesc).toBe("Prompted description");
expect(answers.moduleDesc).toBeUndefined();
});
});

Expand Down Expand Up @@ -564,39 +566,4 @@ module.exports = {
});
});

it("should respect ignore patterns from questions", async () => {
const ignoredDir = path.join(testTempDir, "__tests__");
fs.mkdirSync(ignoredDir);
fs.writeFileSync(
path.join(ignoredDir, "example.txt"),
"This file has ____ignored____ variable"
);
fs.writeFileSync(
path.join(testTempDir, ".questions.json"),
JSON.stringify({
ignore: ["__tests__"],
questions: [],
})
);

const result = await extractVariables(testTempDir);

expect(result.fileReplacers.map((r) => r.variable)).not.toContain("tests");
expect(result.contentReplacers.map((r) => r.variable)).not.toContain(
"IGNORED"
);
});

it("should skip default ignored content tokens", async () => {
fs.writeFileSync(
path.join(testTempDir, "jest.config.js"),
"// Match both __tests__ and colocated test files"
);

const result = await extractVariables(testTempDir);

expect(result.contentReplacers.map((r) => r.variable)).not.toContain(
"tests"
);
});
});
42 changes: 42 additions & 0 deletions packages/create-gen-app/src/licenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ type LicenseTemplateMap = Record<string, string>;
let cachedTemplates: LicenseTemplateMap | null = null;

export type SupportedLicense = string;
export const LICENSE_VALUE_KEYS = ["LICENSE", "license"];
export const LICENSE_AUTHOR_KEYS = [
"USERFULLNAME",
"AUTHOR",
"AUTHORFULLNAME",
"USERNAME",
"fullName",
"author",
"authorFullName",
"userName",
];
export const LICENSE_EMAIL_KEYS = ["USEREMAIL", "EMAIL", "email", "userEmail"];

export function isSupportedLicense(name: string): name is SupportedLicense {
if (!name) {
Expand Down Expand Up @@ -58,6 +70,24 @@ export function listSupportedLicenses(): string[] {
return Object.keys(loadLicenseTemplates());
}

export function findLicenseValue(
answers: Record<string, any>
): string | undefined {
return getAnswerValue(answers, LICENSE_VALUE_KEYS);
}

export function findLicenseAuthor(
answers: Record<string, any>
): string | undefined {
return getAnswerValue(answers, LICENSE_AUTHOR_KEYS);
}

export function findLicenseEmail(
answers: Record<string, any>
): string | undefined {
return getAnswerValue(answers, LICENSE_EMAIL_KEYS);
}

function loadLicenseTemplates(): LicenseTemplateMap {
if (cachedTemplates) {
return cachedTemplates;
Expand Down Expand Up @@ -106,3 +136,15 @@ function findTemplatesDir(): string | null {
return null;
}

function getAnswerValue(
answers: Record<string, any>,
keys: string[]
): string | undefined {
for (const key of keys) {
const value = answers?.[key];
if (typeof value === "string" && value.trim() !== "") {
return value;
}
}
return undefined;
}
Loading