Skip to content

Commit 12fc02c

Browse files
authored
Merge pull request #13 from hyperweb-io/issue240
Issue240
2 parents fe43943 + 5fe54b5 commit 12fc02c

File tree

17 files changed

+3038
-5233
lines changed

17 files changed

+3038
-5233
lines changed

packages/create-gen-app/dev/README.md renamed to packages/create-gen-app-test/dev/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This script helps you test `create-gen-app` locally with the pgpm-boilerplates r
44

55
## Usage
66

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

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

76+

packages/create-gen-app/dev/index.ts renamed to packages/create-gen-app-test/dev/index.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { Inquirerer, ListQuestion } from "inquirerer";
33
import minimist from "minimist";
44
import * as path from "path";
55

6-
import { cloneRepo } from "../src/clone";
7-
import { extractVariables } from "../src/extract";
8-
import { promptUser } from "../src/prompt";
9-
import { replaceVariables } from "../src/replace";
6+
import { cloneRepo, extractVariables, promptUser, replaceVariables } from "create-gen-app";
107

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

4138
const templateDir = path.join(tempDir, argv.path);
4239
if (!fs.existsSync(templateDir)) {
43-
throw new Error(
44-
`Template path "${argv.path}" does not exist in ${argv.repo}`
45-
);
40+
throw new Error(`Template path "${argv.path}" does not exist in ${argv.repo}`);
4641
}
4742
const folders = fs
4843
.readdirSync(templateDir, { withFileTypes: true })
@@ -53,9 +48,7 @@ async function main() {
5348
throw new Error("No template folders found in repository");
5449
}
5550

56-
console.log(
57-
`\nFound ${folders.length} template(s): ${folders.join(", ")}\n`
58-
);
51+
console.log(`\nFound ${folders.length} template(s): ${folders.join(", ")}\n`);
5952

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

94-
console.log(
95-
`Found ${extractedVariables.fileReplacers.length} file replacers`
96-
);
97-
console.log(
98-
`Found ${extractedVariables.contentReplacers.length} content replacers`
99-
);
87+
console.log(`Found ${extractedVariables.fileReplacers.length} file replacers`);
88+
console.log(`Found ${extractedVariables.contentReplacers.length} content replacers`);
10089
if (extractedVariables.projectQuestions) {
101-
console.log(
102-
`Found ${extractedVariables.projectQuestions.questions.length} project questions`
103-
);
90+
console.log(`Found ${extractedVariables.projectQuestions.questions.length} project questions`);
10491
}
10592

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

115102
console.log(`\nGenerating project in ${absoluteOutputDir}...`);
116-
await replaceVariables(
117-
selectedTemplateDir,
118-
absoluteOutputDir,
119-
extractedVariables,
120-
variableAnswers
121-
);
103+
await replaceVariables(selectedTemplateDir, absoluteOutputDir, extractedVariables, variableAnswers);
122104

123105
console.log("\n✅ Project created successfully!");
124106
console.log(`📁 Output directory: ${absoluteOutputDir}\n`);
@@ -127,13 +109,11 @@ async function main() {
127109
fs.rmSync(tempDir, { recursive: true, force: true });
128110
}
129111
} catch (error) {
130-
console.error(
131-
"\n❌ Error:",
132-
error instanceof Error ? error.message : String(error)
133-
);
112+
console.error("\n❌ Error:", error instanceof Error ? error.message : String(error));
134113
process.exit(1);
135114
}
136115
}
137116

138117
main();
139118

119+

packages/create-gen-app-test/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,19 @@
2525
"clean": "makage clean",
2626
"prepublishOnly": "npm run build",
2727
"build": "npm run clean && makage build-ts && npm run copy",
28+
"dev": "node -r ts-node/register dev/index.ts",
2829
"test": "jest",
2930
"test:watch": "jest --watch"
3031
},
3132
"dependencies": {
3233
"appstash": "workspace:*",
33-
"create-gen-app": "workspace:*"
34+
"create-gen-app": "workspace:*",
35+
"inquirerer": "workspace:*",
36+
"minimist": "^1.2.8"
3437
},
3538
"devDependencies": {
39+
"@types/minimist": "^1.2.5",
3640
"makage": "0.1.5"
3741
},
3842
"keywords": []
39-
}
43+
}

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,30 @@ exports[`cached template integration tests first clone with variable replacement
3333
exports[`cached template integration tests first clone with variable replacement should snapshot package.json files if they exist 1`] = `
3434
{
3535
"module/package.json": {
36-
"author": "__USERFULLNAME__ <__USEREMAIL__>",
36+
"author": "____fullName____ <____email____>",
3737
"bugs": {
38-
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
38+
"url": "https://github.com/____username____/____repoName____/issues",
3939
},
40-
"description": "__MODULEDESC__",
40+
"description": "____moduleDesc____",
4141
"devDependencies": {
4242
"pgsql-test": "^2.13.2",
4343
},
44-
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
44+
"homepage": "https://github.com/____username____/____repoName____",
4545
"keywords": [],
46-
"license": "SEE LICENSE IN LICENSE",
47-
"name": "__PACKAGE_IDENTIFIER__",
46+
"license": "____license____",
47+
"name": "____packageIdentifier____",
4848
"pnpm": {
4949
"overrides": {
5050
"graphql": "14.7.0",
5151
},
5252
},
5353
"publishConfig": {
54-
"access": "__ACCESS__",
54+
"access": "____access____",
5555
"directory": "dist",
5656
},
5757
"repository": {
5858
"type": "git",
59-
"url": "https://github.com/__USERNAME__/__REPONAME__",
59+
"url": "https://github.com/____username____/____repoName____",
6060
},
6161
"scripts": {
6262
"lint": "eslint . --fix",
@@ -66,7 +66,7 @@ exports[`cached template integration tests first clone with variable replacement
6666
"version": "0.0.1",
6767
},
6868
"workspace/package.json": {
69-
"author": "__USERFULLNAME__ <__USEREMAIL__>",
69+
"author": "____fullName____ <____email____>",
7070
"devDependencies": {
7171
"@types/jest": "^29.5.14",
7272
"@types/node": "^22.10.2",
@@ -85,7 +85,7 @@ exports[`cached template integration tests first clone with variable replacement
8585
"typescript": "^5.6.3",
8686
},
8787
"license": "SEE LICENSE IN LICENSE",
88-
"name": "__MODULENAME__",
88+
"name": "____moduleName____",
8989
"pnpm": {
9090
"overrides": {
9191
"graphql": "14.7.0",
@@ -97,7 +97,7 @@ exports[`cached template integration tests first clone with variable replacement
9797
},
9898
"repository": {
9999
"type": "git",
100-
"url": "https://github.com/__USERNAME__/__MODULENAME__",
100+
"url": "https://github.com/____username____/____moduleName____",
101101
},
102102
"scripts": {
103103
"lint": "pnpm -r run lint",
@@ -143,30 +143,30 @@ exports[`cached template integration tests second clone from cache should snapsh
143143
exports[`cached template integration tests second clone from cache should snapshot package.json files from cached template 1`] = `
144144
{
145145
"module/package.json": {
146-
"author": "__USERFULLNAME__ <__USEREMAIL__>",
146+
"author": "____fullName____ <____email____>",
147147
"bugs": {
148-
"url": "https://github.com/__USERNAME__/__REPONAME__/issues",
148+
"url": "https://github.com/____username____/____repoName____/issues",
149149
},
150-
"description": "__MODULEDESC__",
150+
"description": "____moduleDesc____",
151151
"devDependencies": {
152152
"pgsql-test": "^2.13.2",
153153
},
154-
"homepage": "https://github.com/__USERNAME__/__REPONAME__",
154+
"homepage": "https://github.com/____username____/____repoName____",
155155
"keywords": [],
156-
"license": "SEE LICENSE IN LICENSE",
157-
"name": "__PACKAGE_IDENTIFIER__",
156+
"license": "____license____",
157+
"name": "____packageIdentifier____",
158158
"pnpm": {
159159
"overrides": {
160160
"graphql": "14.7.0",
161161
},
162162
},
163163
"publishConfig": {
164-
"access": "__ACCESS__",
164+
"access": "____access____",
165165
"directory": "dist",
166166
},
167167
"repository": {
168168
"type": "git",
169-
"url": "https://github.com/__USERNAME__/__REPONAME__",
169+
"url": "https://github.com/____username____/____repoName____",
170170
},
171171
"scripts": {
172172
"lint": "eslint . --fix",
@@ -176,7 +176,7 @@ exports[`cached template integration tests second clone from cache should snapsh
176176
"version": "0.0.1",
177177
},
178178
"workspace/package.json": {
179-
"author": "__USERFULLNAME__ <__USEREMAIL__>",
179+
"author": "____fullName____ <____email____>",
180180
"devDependencies": {
181181
"@types/jest": "^29.5.14",
182182
"@types/node": "^22.10.2",
@@ -195,7 +195,7 @@ exports[`cached template integration tests second clone from cache should snapsh
195195
"typescript": "^5.6.3",
196196
},
197197
"license": "SEE LICENSE IN LICENSE",
198-
"name": "__MODULENAME__",
198+
"name": "____moduleName____",
199199
"pnpm": {
200200
"overrides": {
201201
"graphql": "14.7.0",
@@ -207,7 +207,7 @@ exports[`cached template integration tests second clone from cache should snapsh
207207
},
208208
"repository": {
209209
"type": "git",
210-
"url": "https://github.com/__USERNAME__/__MODULENAME__",
210+
"url": "https://github.com/____username____/____moduleName____",
211211
},
212212
"scripts": {
213213
"lint": "pnpm -r run lint",

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "fs";
22
import * as path from "path";
33

4-
import { runCli } from "../src/cli";
4+
import { runCli } from "../cli";
55
import {
66
TEST_BRANCH,
77
TEST_REPO,
@@ -13,7 +13,7 @@ import {
1313

1414
jest.setTimeout(180_000);
1515

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

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

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

72-
expect(logSpy).toHaveBeenCalledWith(expect.stringMatching(/create-gen-app v/));
74+
expect(logSpy).toHaveBeenCalledWith(
75+
expect.stringMatching(/create-gen-app v/)
76+
);
7377
logSpy.mockRestore();
7478
});
7579
});
76-

0 commit comments

Comments
 (0)