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 @@ -4,7 +4,7 @@ This script helps you test `create-gen-app` locally with the pgpm-boilerplates r

## Usage

From the `packages/create-gen-app` directory, run:
From the `packages/create-gen-app-test` directory, run:

```bash
pnpm dev [--repo url] [--branch name] [--path dir] [--template name] [--output dir]
Expand Down Expand Up @@ -73,3 +73,4 @@ Extracting template variables...
- The temporary clone directory is automatically cleaned up after generation
- You can test different templates without affecting your workspace


Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { Inquirerer, ListQuestion } from "inquirerer";
import minimist from "minimist";
import * as path from "path";

import { cloneRepo } from "../src/clone";
import { extractVariables } from "../src/extract";
import { promptUser } from "../src/prompt";
import { replaceVariables } from "../src/replace";
import { cloneRepo, extractVariables, promptUser, replaceVariables } from "create-gen-app";

const DEFAULT_REPO = "https://github.com/launchql/pgpm-boilerplates/";
const DEFAULT_DIRECTORY = ".";
Expand Down Expand Up @@ -40,9 +37,7 @@ async function main() {

const templateDir = path.join(tempDir, argv.path);
if (!fs.existsSync(templateDir)) {
throw new Error(
`Template path "${argv.path}" does not exist in ${argv.repo}`
);
throw new Error(`Template path "${argv.path}" does not exist in ${argv.repo}`);
}
const folders = fs
.readdirSync(templateDir, { withFileTypes: true })
Expand All @@ -53,9 +48,7 @@ async function main() {
throw new Error("No template folders found in repository");
}

console.log(
`\nFound ${folders.length} template(s): ${folders.join(", ")}\n`
);
console.log(`\nFound ${folders.length} template(s): ${folders.join(", ")}\n`);

let selectedFolder = argv.template;
if (selectedFolder) {
Expand Down Expand Up @@ -91,16 +84,10 @@ async function main() {
console.log("Extracting template variables...");
const extractedVariables = await extractVariables(selectedTemplateDir);

console.log(
`Found ${extractedVariables.fileReplacers.length} file replacers`
);
console.log(
`Found ${extractedVariables.contentReplacers.length} content replacers`
);
console.log(`Found ${extractedVariables.fileReplacers.length} file replacers`);
console.log(`Found ${extractedVariables.contentReplacers.length} content replacers`);
if (extractedVariables.projectQuestions) {
console.log(
`Found ${extractedVariables.projectQuestions.questions.length} project questions`
);
console.log(`Found ${extractedVariables.projectQuestions.questions.length} project questions`);
}

console.log("\nPrompting for variable values...");
Expand All @@ -113,12 +100,7 @@ async function main() {
}

console.log(`\nGenerating project in ${absoluteOutputDir}...`);
await replaceVariables(
selectedTemplateDir,
absoluteOutputDir,
extractedVariables,
variableAnswers
);
await replaceVariables(selectedTemplateDir, absoluteOutputDir, extractedVariables, variableAnswers);

console.log("\n✅ Project created successfully!");
console.log(`📁 Output directory: ${absoluteOutputDir}\n`);
Expand All @@ -127,13 +109,11 @@ async function main() {
fs.rmSync(tempDir, { recursive: true, force: true });
}
} catch (error) {
console.error(
"\n❌ Error:",
error instanceof Error ? error.message : String(error)
);
console.error("\n❌ Error:", error instanceof Error ? error.message : String(error));
process.exit(1);
}
}

main();


8 changes: 6 additions & 2 deletions packages/create-gen-app-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@
"clean": "makage clean",
"prepublishOnly": "npm run build",
"build": "npm run clean && makage build-ts && npm run copy",
"dev": "node -r ts-node/register dev/index.ts",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"appstash": "workspace:*",
"create-gen-app": "workspace:*"
"create-gen-app": "workspace:*",
"inquirerer": "workspace:*",
"minimist": "^1.2.8"
},
"devDependencies": {
"@types/minimist": "^1.2.5",
"makage": "0.1.5"
},
"keywords": []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@ exports[`cached template integration tests first clone with variable replacement
exports[`cached template integration tests first clone with variable replacement should snapshot package.json files if they exist 1`] = `
{
"module/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"author": "____fullName____ <____email____>",
"bugs": {
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
"url": "https://github.com/____username____/____repoName____/issues",
},
"description": "__MODULEDESC__",
"description": "____moduleDesc____",
"devDependencies": {
"pgsql-test": "^2.13.2",
},
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
"homepage": "https://github.com/____username____/____repoName____",
"keywords": [],
"license": "SEE LICENSE IN LICENSE",
"name": "__PACKAGE_IDENTIFIER__",
"license": "____license____",
"name": "____packageIdentifier____",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "__ACCESS__",
"access": "____access____",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__REPONAME__",
"url": "https://github.com/____username____/____repoName____",
},
"scripts": {
"lint": "eslint . --fix",
Expand All @@ -66,7 +66,7 @@ exports[`cached template integration tests first clone with variable replacement
"version": "0.0.1",
},
"workspace/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"author": "____fullName____ <____email____>",
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
Expand All @@ -85,7 +85,7 @@ exports[`cached template integration tests first clone with variable replacement
"typescript": "^5.6.3",
},
"license": "SEE LICENSE IN LICENSE",
"name": "__MODULENAME__",
"name": "____moduleName____",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
Expand All @@ -97,7 +97,7 @@ exports[`cached template integration tests first clone with variable replacement
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__MODULENAME__",
"url": "https://github.com/____username____/____moduleName____",
},
"scripts": {
"lint": "pnpm -r run lint",
Expand Down Expand Up @@ -143,30 +143,30 @@ exports[`cached template integration tests second clone from cache should snapsh
exports[`cached template integration tests second clone from cache should snapshot package.json files from cached template 1`] = `
{
"module/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"author": "____fullName____ <____email____>",
"bugs": {
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
"url": "https://github.com/____username____/____repoName____/issues",
},
"description": "__MODULEDESC__",
"description": "____moduleDesc____",
"devDependencies": {
"pgsql-test": "^2.13.2",
},
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
"homepage": "https://github.com/____username____/____repoName____",
"keywords": [],
"license": "SEE LICENSE IN LICENSE",
"name": "__PACKAGE_IDENTIFIER__",
"license": "____license____",
"name": "____packageIdentifier____",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
},
},
"publishConfig": {
"access": "__ACCESS__",
"access": "____access____",
"directory": "dist",
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__REPONAME__",
"url": "https://github.com/____username____/____repoName____",
},
"scripts": {
"lint": "eslint . --fix",
Expand All @@ -176,7 +176,7 @@ exports[`cached template integration tests second clone from cache should snapsh
"version": "0.0.1",
},
"workspace/package.json": {
"author": "__USERFULLNAME__ <__USEREMAIL__>",
"author": "____fullName____ <____email____>",
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
Expand All @@ -195,7 +195,7 @@ exports[`cached template integration tests second clone from cache should snapsh
"typescript": "^5.6.3",
},
"license": "SEE LICENSE IN LICENSE",
"name": "__MODULENAME__",
"name": "____moduleName____",
"pnpm": {
"overrides": {
"graphql": "14.7.0",
Expand All @@ -207,7 +207,7 @@ exports[`cached template integration tests second clone from cache should snapsh
},
"repository": {
"type": "git",
"url": "https://github.com/__USERNAME__/__MODULENAME__",
"url": "https://github.com/____username____/____moduleName____",
},
"scripts": {
"lint": "pnpm -r run lint",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "fs";
import * as path from "path";

import { runCli } from "../src/cli";
import { runCli } from "../cli";
import {
TEST_BRANCH,
TEST_REPO,
Expand All @@ -13,7 +13,7 @@ import {

jest.setTimeout(180_000);

describe("CLI integration (GitHub templates)", () => {
describe("CLI integration via create-gen-app-test harness", () => {
it("generates a project using the real repo", async () => {
const workspace = createTempWorkspace("cli");
const answers = buildAnswers("cli");
Expand Down Expand Up @@ -65,12 +65,15 @@ describe("CLI integration (GitHub templates)", () => {
});

it("prints version and exits when --version is provided", async () => {
const logSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);
const logSpy = jest
.spyOn(console, "log")
.mockImplementation(() => undefined);

await runCli(["--version"]);

expect(logSpy).toHaveBeenCalledWith(expect.stringMatching(/create-gen-app v/));
expect(logSpy).toHaveBeenCalledWith(
expect.stringMatching(/create-gen-app v/)
);
logSpy.mockRestore();
});
});

Loading