Skip to content

Commit fad1d13

Browse files
committed
chore: Remove DEFAULT_REPO constant and update create-gen-app README to detail modular API components and remove ignore pattern references.
1 parent b219839 commit fad1d13

File tree

2 files changed

+69
-49
lines changed

2 files changed

+69
-49
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { GitCloner } from 'create-gen-app';
44
import { Templatizer } from 'create-gen-app';
55

66
// Configuration constants (top-most layer owns defaults)
7-
const DEFAULT_REPO = 'launchql/boilerplates';
87
const DEFAULT_TTL = 604800000; // 1 week in milliseconds
98
const DEFAULT_TOOL_NAME = 'pgpm';
109

packages/create-gen-app/README.md

Lines changed: 69 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A TypeScript-first library for cloning template repositories, asking the user fo
2222

2323
- Clone any Git repo (or GitHub `org/repo` shorthand) and optionally select a branch + subdirectory
2424
- Extract template variables from filenames and file contents using the safer `____variable____` convention
25-
- Merge auto-discovered variables with `.questions.{json,js}` (questions win, including `ignore` patterns)
25+
- Merge auto-discovered variables with `.questions.{json,js}` (questions win)
2626
- Interactive prompts powered by `inquirerer`, with flexible override mapping (`argv` support) and non-TTY mode for CI
2727
- License scaffolding: choose from MIT, Apache-2.0, ISC, GPL-3.0, BSD-3-Clause, Unlicense, or MPL-2.0 and generate a populated `LICENSE`
2828
- Built-in template caching powered by `appstash`, so repeat runs skip `git clone` (configurable via `cache` options)
@@ -37,51 +37,65 @@ npm install create-gen-app
3737
3838
## Library Usage
3939

40-
```typescript
41-
import * as os from "os";
42-
import * as path from "path";
43-
44-
import { createGen } from "create-gen-app";
45-
46-
await createGen({
47-
templateUrl: "https://github.com/user/template-repo",
48-
fromBranch: "main",
49-
fromPath: "templates/module",
50-
outputDir: "./my-new-project",
51-
argv: {
52-
USERFULLNAME: "Jane Dev",
53-
USEREMAIL: "jane@example.com",
54-
MODULENAME: "awesome-module",
55-
LICENSE: "MIT",
56-
},
57-
noTty: true,
58-
cache: {
59-
// optional: override tool/baseDir (defaults to pgpm + ~/.pgpm)
60-
toolName: "pgpm",
61-
baseDir: path.join(os.tmpdir(), "create-gen-cache"),
62-
},
63-
});
64-
```
40+
`create-gen-app` provides a modular set of classes to handle template cloning, caching, and processing.
6541

66-
### Template Caching
42+
### Core Components
6743

68-
`create-gen-app` caches repositories under `~/.pgpm/cache/repos/<hash>` by default (using [`appstash`](https://github.com/hyperweb-io/dev-utils/tree/main/packages/appstash)). The first run clones & stores the repo, subsequent runs re-use the cached directory.
44+
- **CacheManager**: Handles local caching of git repositories with TTL (Time-To-Live) support.
45+
- **GitCloner**: Handles cloning git repositories.
46+
- **Templatizer**: Handles variable extraction, user prompting, and template generation.
6947

70-
- Disable caching with `cache: false` or `cache: { enabled: false }`
71-
- Override the tool name or base directory with `cache: { toolName, baseDir }`
72-
- For tests/CI, point `baseDir` to a temporary folder so the suite does not touch the developer’s real home directory:
48+
### Example: Orchestration
7349

74-
```ts
75-
const tempBase = fs.mkdtempSync(path.join(os.tmpdir(), "create-gen-cache-"));
50+
Here is how you can combine these components to create a full CLI pipeline (similar to `create-gen-app-test`):
7651

77-
await createGen({
78-
...options,
79-
cache: { baseDir: tempBase, toolName: "pgpm-test-suite" },
80-
});
52+
```typescript
53+
import * as path from "path";
54+
import { CacheManager, GitCloner, Templatizer } from "create-gen-app";
55+
56+
async function main() {
57+
const repoUrl = "https://github.com/user/template-repo";
58+
const outputDir = "./my-new-project";
59+
60+
// 1. Initialize components
61+
const cacheManager = new CacheManager({
62+
toolName: "my-cli", // ~/.my-cli/cache
63+
ttl: 604800000, // 1 week
64+
});
65+
const gitCloner = new GitCloner();
66+
const templatizer = new Templatizer();
67+
68+
// 2. Resolve template path (Cache or Clone)
69+
const normalizedUrl = gitCloner.normalizeUrl(repoUrl);
70+
const cacheKey = cacheManager.createKey(normalizedUrl);
71+
72+
// Check cache
73+
let templateDir = cacheManager.get(cacheKey);
74+
const isExpired = cacheManager.checkExpiration(cacheKey);
75+
76+
if (!templateDir || isExpired) {
77+
console.log("Cloning template...");
78+
if (isExpired) cacheManager.clear(cacheKey);
79+
80+
// Clone to a temporary location managed by CacheManager
81+
const tempDest = path.join(cacheManager.reposDir, cacheKey);
82+
await gitCloner.clone(normalizedUrl, tempDest, { depth: 1 });
83+
84+
// Register and update cache
85+
cacheManager.set(cacheKey, tempDest);
86+
templateDir = tempDest;
87+
}
88+
89+
// 3. Process Template
90+
await templatizer.process(templateDir, outputDir, {
91+
argv: {
92+
PROJECT_NAME: "my-app",
93+
LICENSE: "MIT"
94+
}
95+
});
96+
}
8197
```
8298

83-
The cache directory never mutates the template, so reusing the same cached repo across many runs is safe.
84-
8599
### Template Variables
86100

87101
Variables should be wrapped in four underscores on each side:
@@ -97,13 +111,12 @@ export const projectName = "____projectName____";
97111
export const author = "____fullName____";
98112
```
99113

100-
### Custom Questions & Ignore Rules
114+
### Custom Questions
101115

102116
Create a `.questions.json`:
103117

104118
```json
105119
{
106-
"ignore": ["__tests__", "docs/drafts"],
107120
"questions": [
108121
{
109122
"name": "____fullName____",
@@ -133,11 +146,19 @@ No code changes are needed; the generator discovers templates at runtime and wil
133146

134147
## API Overview
135148

136-
- `createGen(options)` – full pipeline (clone → extract → prompt → replace)
137-
- `cloneRepo(url, { branch })` – clone to a temp dir
138-
- `normalizeCacheOptions(cache)` / `prepareTemplateDirectory(...)` – inspect or reuse cached template repos
139-
- `extractVariables(dir)` – parse file/folder names + content for variables, load `.questions`
140-
- `promptUser(extracted, argv, noTty)` – run interactive questions with override alias deduping
141-
- `replaceVariables(templateDir, outputDir, extracted, answers)` – copy files, rename paths, render licenses
149+
### CacheManager
150+
- `new CacheManager(config)`: Initialize with `toolName` and `ttl`.
151+
- `get(key)`: Get path to cached repo if exists.
152+
- `set(key, path)`: Register a path in the cache.
153+
- `checkExpiration(key)`: Check if a cache entry is expired.
154+
- `clear(key)`: Remove a specific cache entry.
155+
- `clearAll()`: Clear all cached repos.
156+
157+
### GitCloner
158+
- `clone(url, dest, options)`: Clone a repo to a destination.
159+
- `normalizeUrl(url)`: Normalize a git URL for consistency.
160+
161+
### Templatizer
162+
- `process(templateDir, outputDir, options)`: Run the full template generation pipeline (extract -> prompt -> replace).
142163

143-
See `packages/create-gen-app-test/dev/README.md` for the local development helper script (`pnpm --filter create-gen-app-test dev`).
164+
See `packages/create-gen-app-test` for a complete reference implementation.

0 commit comments

Comments
 (0)