create-gen-app 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +73 -49
  2. package/cache/cache-manager.d.ts +60 -0
  3. package/cache/cache-manager.js +228 -0
  4. package/cache/types.d.ts +22 -0
  5. package/cache/types.js +2 -0
  6. package/esm/cache/cache-manager.js +191 -0
  7. package/esm/cache/types.js +1 -0
  8. package/esm/git/git-cloner.js +92 -0
  9. package/esm/git/types.js +1 -0
  10. package/esm/index.js +26 -53
  11. package/esm/{replace.js → template/replace.js} +2 -2
  12. package/esm/template/templatizer.js +69 -0
  13. package/esm/template/types.js +1 -0
  14. package/esm/utils/npm-version-check.js +52 -0
  15. package/esm/utils/types.js +1 -0
  16. package/git/git-cloner.d.ts +32 -0
  17. package/git/git-cloner.js +129 -0
  18. package/git/types.d.ts +15 -0
  19. package/git/types.js +2 -0
  20. package/index.d.ts +19 -6
  21. package/index.js +27 -75
  22. package/package.json +5 -5
  23. package/{extract.d.ts → template/extract.d.ts} +1 -1
  24. package/{prompt.d.ts → template/prompt.d.ts} +1 -1
  25. package/{replace.d.ts → template/replace.d.ts} +1 -1
  26. package/{replace.js → template/replace.js} +2 -2
  27. package/template/templatizer.d.ts +29 -0
  28. package/template/templatizer.js +106 -0
  29. package/template/types.d.ts +11 -0
  30. package/template/types.js +2 -0
  31. package/utils/npm-version-check.d.ts +17 -0
  32. package/utils/npm-version-check.js +57 -0
  33. package/utils/types.d.ts +6 -0
  34. package/utils/types.js +2 -0
  35. package/cache.d.ts +0 -13
  36. package/cache.js +0 -76
  37. package/clone.d.ts +0 -15
  38. package/clone.js +0 -86
  39. package/esm/cache.js +0 -38
  40. package/esm/clone.js +0 -49
  41. package/esm/template-cache.js +0 -223
  42. package/template-cache.d.ts +0 -59
  43. package/template-cache.js +0 -260
  44. /package/esm/{extract.js → template/extract.js} +0 -0
  45. /package/esm/{prompt.js → template/prompt.js} +0 -0
  46. /package/{extract.js → template/extract.js} +0 -0
  47. /package/{prompt.js → template/prompt.js} +0 -0
@@ -1,223 +0,0 @@
1
- import { execSync } from "child_process";
2
- import * as crypto from "crypto";
3
- import * as fs from "fs";
4
- import * as path from "path";
5
- import { appstash, resolve as resolveAppstash } from "appstash";
6
- import { normalizeGitUrl } from "./clone";
7
- const DEFAULT_TOOL = "pgpm";
8
- /**
9
- * Manages template repository caching with TTL support
10
- */
11
- export class TemplateCache {
12
- config;
13
- reposDir;
14
- metadataDir;
15
- constructor(options) {
16
- this.config = this.normalizeConfig(options);
17
- if (this.config.enabled) {
18
- const dirs = appstash(this.config.toolName, {
19
- ensure: true,
20
- baseDir: this.config.baseDir,
21
- });
22
- this.reposDir = resolveAppstash(dirs, "cache", "repos");
23
- this.metadataDir = resolveAppstash(dirs, "cache", "metadata");
24
- if (!fs.existsSync(this.reposDir)) {
25
- fs.mkdirSync(this.reposDir, { recursive: true });
26
- }
27
- if (!fs.existsSync(this.metadataDir)) {
28
- fs.mkdirSync(this.metadataDir, { recursive: true });
29
- }
30
- }
31
- else {
32
- this.reposDir = "";
33
- this.metadataDir = "";
34
- }
35
- }
36
- normalizeConfig(options) {
37
- if (options === false) {
38
- return {
39
- enabled: false,
40
- toolName: DEFAULT_TOOL,
41
- };
42
- }
43
- const { enabled, toolName, baseDir, ttl, maxAge } = options ?? {};
44
- return {
45
- enabled: enabled !== false,
46
- toolName: toolName ?? DEFAULT_TOOL,
47
- baseDir,
48
- ttl: ttl ?? maxAge,
49
- };
50
- }
51
- /**
52
- * Get cached template if it exists and is not expired
53
- */
54
- get(templateUrl, branch) {
55
- if (!this.config.enabled) {
56
- return null;
57
- }
58
- const key = this.createCacheKey(templateUrl, branch);
59
- const cachePath = path.join(this.reposDir, key);
60
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
61
- if (!fs.existsSync(cachePath)) {
62
- return null;
63
- }
64
- if (this.config.ttl && fs.existsSync(metadataPath)) {
65
- try {
66
- const metadata = JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
67
- if (this.isExpired(metadata)) {
68
- this.clear(templateUrl, branch);
69
- return null;
70
- }
71
- }
72
- catch (error) {
73
- // If metadata is corrupted, treat as expired
74
- this.clear(templateUrl, branch);
75
- return null;
76
- }
77
- }
78
- return cachePath;
79
- }
80
- /**
81
- * Cache a template repository
82
- */
83
- set(templateUrl, branch) {
84
- if (!this.config.enabled) {
85
- throw new Error("Cache is disabled");
86
- }
87
- const key = this.createCacheKey(templateUrl, branch);
88
- const cachePath = path.join(this.reposDir, key);
89
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
90
- // Clone the repository
91
- this.cloneInto(templateUrl, cachePath, branch);
92
- // Write metadata
93
- const metadata = {
94
- templateUrl,
95
- branch,
96
- timestamp: Date.now(),
97
- gitUrl: normalizeGitUrl(templateUrl),
98
- };
99
- fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
100
- return cachePath;
101
- }
102
- /**
103
- * Clear a specific cached template
104
- */
105
- clear(templateUrl, branch) {
106
- if (!this.config.enabled) {
107
- return;
108
- }
109
- const key = this.createCacheKey(templateUrl, branch);
110
- const cachePath = path.join(this.reposDir, key);
111
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
112
- if (fs.existsSync(cachePath)) {
113
- fs.rmSync(cachePath, { recursive: true, force: true });
114
- }
115
- if (fs.existsSync(metadataPath)) {
116
- fs.rmSync(metadataPath, { force: true });
117
- }
118
- }
119
- /**
120
- * Clear all cached templates
121
- */
122
- clearAll() {
123
- if (!this.config.enabled) {
124
- return;
125
- }
126
- if (fs.existsSync(this.reposDir)) {
127
- fs.rmSync(this.reposDir, { recursive: true, force: true });
128
- fs.mkdirSync(this.reposDir, { recursive: true });
129
- }
130
- if (fs.existsSync(this.metadataDir)) {
131
- fs.rmSync(this.metadataDir, { recursive: true, force: true });
132
- fs.mkdirSync(this.metadataDir, { recursive: true });
133
- }
134
- }
135
- /**
136
- * Check if cache metadata is expired
137
- */
138
- isExpired(metadata) {
139
- if (!this.config.ttl) {
140
- return false;
141
- }
142
- const age = Date.now() - metadata.timestamp;
143
- return age > this.config.ttl;
144
- }
145
- /**
146
- * Get cache metadata for a template
147
- */
148
- getMetadata(templateUrl, branch) {
149
- if (!this.config.enabled) {
150
- return null;
151
- }
152
- const key = this.createCacheKey(templateUrl, branch);
153
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
154
- if (!fs.existsSync(metadataPath)) {
155
- return null;
156
- }
157
- try {
158
- return JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
159
- }
160
- catch {
161
- return null;
162
- }
163
- }
164
- /**
165
- * List all cached templates with their metadata
166
- */
167
- listAll() {
168
- if (!this.config.enabled) {
169
- return [];
170
- }
171
- if (!fs.existsSync(this.metadataDir)) {
172
- return [];
173
- }
174
- const results = [];
175
- const files = fs.readdirSync(this.metadataDir);
176
- for (const file of files) {
177
- if (!file.endsWith(".json")) {
178
- continue;
179
- }
180
- const metadataPath = path.join(this.metadataDir, file);
181
- try {
182
- const metadata = JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
183
- results.push({
184
- ...metadata,
185
- key: path.basename(file, ".json"),
186
- expired: this.isExpired(metadata),
187
- });
188
- }
189
- catch {
190
- // Skip corrupted metadata
191
- }
192
- }
193
- return results;
194
- }
195
- createCacheKey(templateUrl, branch) {
196
- const gitUrl = normalizeGitUrl(templateUrl);
197
- return crypto
198
- .createHash("md5")
199
- .update(`${gitUrl}#${branch ?? "default"}`)
200
- .digest("hex");
201
- }
202
- cloneInto(templateUrl, destination, branch) {
203
- if (fs.existsSync(destination)) {
204
- fs.rmSync(destination, { recursive: true, force: true });
205
- }
206
- const gitUrl = normalizeGitUrl(templateUrl);
207
- const branchArgs = branch ? ` --branch ${branch} --single-branch` : "";
208
- const depthArgs = " --depth 1";
209
- execSync(`git clone${branchArgs}${depthArgs} ${gitUrl} ${destination}`, {
210
- stdio: "inherit",
211
- });
212
- const gitDir = path.join(destination, ".git");
213
- if (fs.existsSync(gitDir)) {
214
- fs.rmSync(gitDir, { recursive: true, force: true });
215
- }
216
- }
217
- isEnabled() {
218
- return this.config.enabled;
219
- }
220
- getConfig() {
221
- return { ...this.config };
222
- }
223
- }
@@ -1,59 +0,0 @@
1
- import { CacheOptions } from "./types";
2
- interface CacheMetadata {
3
- templateUrl: string;
4
- branch?: string;
5
- timestamp: number;
6
- gitUrl: string;
7
- }
8
- export interface TemplateCacheConfig {
9
- enabled: boolean;
10
- toolName: string;
11
- baseDir?: string;
12
- ttl?: number;
13
- }
14
- /**
15
- * Manages template repository caching with TTL support
16
- */
17
- export declare class TemplateCache {
18
- private config;
19
- private reposDir;
20
- private metadataDir;
21
- constructor(options?: CacheOptions | false);
22
- private normalizeConfig;
23
- /**
24
- * Get cached template if it exists and is not expired
25
- */
26
- get(templateUrl: string, branch?: string): string | null;
27
- /**
28
- * Cache a template repository
29
- */
30
- set(templateUrl: string, branch?: string): string;
31
- /**
32
- * Clear a specific cached template
33
- */
34
- clear(templateUrl: string, branch?: string): void;
35
- /**
36
- * Clear all cached templates
37
- */
38
- clearAll(): void;
39
- /**
40
- * Check if cache metadata is expired
41
- */
42
- isExpired(metadata: CacheMetadata): boolean;
43
- /**
44
- * Get cache metadata for a template
45
- */
46
- getMetadata(templateUrl: string, branch?: string): CacheMetadata | null;
47
- /**
48
- * List all cached templates with their metadata
49
- */
50
- listAll(): Array<CacheMetadata & {
51
- key: string;
52
- expired: boolean;
53
- }>;
54
- private createCacheKey;
55
- private cloneInto;
56
- isEnabled(): boolean;
57
- getConfig(): TemplateCacheConfig;
58
- }
59
- export {};
package/template-cache.js DELETED
@@ -1,260 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TemplateCache = void 0;
37
- const child_process_1 = require("child_process");
38
- const crypto = __importStar(require("crypto"));
39
- const fs = __importStar(require("fs"));
40
- const path = __importStar(require("path"));
41
- const appstash_1 = require("appstash");
42
- const clone_1 = require("./clone");
43
- const DEFAULT_TOOL = "pgpm";
44
- /**
45
- * Manages template repository caching with TTL support
46
- */
47
- class TemplateCache {
48
- config;
49
- reposDir;
50
- metadataDir;
51
- constructor(options) {
52
- this.config = this.normalizeConfig(options);
53
- if (this.config.enabled) {
54
- const dirs = (0, appstash_1.appstash)(this.config.toolName, {
55
- ensure: true,
56
- baseDir: this.config.baseDir,
57
- });
58
- this.reposDir = (0, appstash_1.resolve)(dirs, "cache", "repos");
59
- this.metadataDir = (0, appstash_1.resolve)(dirs, "cache", "metadata");
60
- if (!fs.existsSync(this.reposDir)) {
61
- fs.mkdirSync(this.reposDir, { recursive: true });
62
- }
63
- if (!fs.existsSync(this.metadataDir)) {
64
- fs.mkdirSync(this.metadataDir, { recursive: true });
65
- }
66
- }
67
- else {
68
- this.reposDir = "";
69
- this.metadataDir = "";
70
- }
71
- }
72
- normalizeConfig(options) {
73
- if (options === false) {
74
- return {
75
- enabled: false,
76
- toolName: DEFAULT_TOOL,
77
- };
78
- }
79
- const { enabled, toolName, baseDir, ttl, maxAge } = options ?? {};
80
- return {
81
- enabled: enabled !== false,
82
- toolName: toolName ?? DEFAULT_TOOL,
83
- baseDir,
84
- ttl: ttl ?? maxAge,
85
- };
86
- }
87
- /**
88
- * Get cached template if it exists and is not expired
89
- */
90
- get(templateUrl, branch) {
91
- if (!this.config.enabled) {
92
- return null;
93
- }
94
- const key = this.createCacheKey(templateUrl, branch);
95
- const cachePath = path.join(this.reposDir, key);
96
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
97
- if (!fs.existsSync(cachePath)) {
98
- return null;
99
- }
100
- if (this.config.ttl && fs.existsSync(metadataPath)) {
101
- try {
102
- const metadata = JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
103
- if (this.isExpired(metadata)) {
104
- this.clear(templateUrl, branch);
105
- return null;
106
- }
107
- }
108
- catch (error) {
109
- // If metadata is corrupted, treat as expired
110
- this.clear(templateUrl, branch);
111
- return null;
112
- }
113
- }
114
- return cachePath;
115
- }
116
- /**
117
- * Cache a template repository
118
- */
119
- set(templateUrl, branch) {
120
- if (!this.config.enabled) {
121
- throw new Error("Cache is disabled");
122
- }
123
- const key = this.createCacheKey(templateUrl, branch);
124
- const cachePath = path.join(this.reposDir, key);
125
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
126
- // Clone the repository
127
- this.cloneInto(templateUrl, cachePath, branch);
128
- // Write metadata
129
- const metadata = {
130
- templateUrl,
131
- branch,
132
- timestamp: Date.now(),
133
- gitUrl: (0, clone_1.normalizeGitUrl)(templateUrl),
134
- };
135
- fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
136
- return cachePath;
137
- }
138
- /**
139
- * Clear a specific cached template
140
- */
141
- clear(templateUrl, branch) {
142
- if (!this.config.enabled) {
143
- return;
144
- }
145
- const key = this.createCacheKey(templateUrl, branch);
146
- const cachePath = path.join(this.reposDir, key);
147
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
148
- if (fs.existsSync(cachePath)) {
149
- fs.rmSync(cachePath, { recursive: true, force: true });
150
- }
151
- if (fs.existsSync(metadataPath)) {
152
- fs.rmSync(metadataPath, { force: true });
153
- }
154
- }
155
- /**
156
- * Clear all cached templates
157
- */
158
- clearAll() {
159
- if (!this.config.enabled) {
160
- return;
161
- }
162
- if (fs.existsSync(this.reposDir)) {
163
- fs.rmSync(this.reposDir, { recursive: true, force: true });
164
- fs.mkdirSync(this.reposDir, { recursive: true });
165
- }
166
- if (fs.existsSync(this.metadataDir)) {
167
- fs.rmSync(this.metadataDir, { recursive: true, force: true });
168
- fs.mkdirSync(this.metadataDir, { recursive: true });
169
- }
170
- }
171
- /**
172
- * Check if cache metadata is expired
173
- */
174
- isExpired(metadata) {
175
- if (!this.config.ttl) {
176
- return false;
177
- }
178
- const age = Date.now() - metadata.timestamp;
179
- return age > this.config.ttl;
180
- }
181
- /**
182
- * Get cache metadata for a template
183
- */
184
- getMetadata(templateUrl, branch) {
185
- if (!this.config.enabled) {
186
- return null;
187
- }
188
- const key = this.createCacheKey(templateUrl, branch);
189
- const metadataPath = path.join(this.metadataDir, `${key}.json`);
190
- if (!fs.existsSync(metadataPath)) {
191
- return null;
192
- }
193
- try {
194
- return JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
195
- }
196
- catch {
197
- return null;
198
- }
199
- }
200
- /**
201
- * List all cached templates with their metadata
202
- */
203
- listAll() {
204
- if (!this.config.enabled) {
205
- return [];
206
- }
207
- if (!fs.existsSync(this.metadataDir)) {
208
- return [];
209
- }
210
- const results = [];
211
- const files = fs.readdirSync(this.metadataDir);
212
- for (const file of files) {
213
- if (!file.endsWith(".json")) {
214
- continue;
215
- }
216
- const metadataPath = path.join(this.metadataDir, file);
217
- try {
218
- const metadata = JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
219
- results.push({
220
- ...metadata,
221
- key: path.basename(file, ".json"),
222
- expired: this.isExpired(metadata),
223
- });
224
- }
225
- catch {
226
- // Skip corrupted metadata
227
- }
228
- }
229
- return results;
230
- }
231
- createCacheKey(templateUrl, branch) {
232
- const gitUrl = (0, clone_1.normalizeGitUrl)(templateUrl);
233
- return crypto
234
- .createHash("md5")
235
- .update(`${gitUrl}#${branch ?? "default"}`)
236
- .digest("hex");
237
- }
238
- cloneInto(templateUrl, destination, branch) {
239
- if (fs.existsSync(destination)) {
240
- fs.rmSync(destination, { recursive: true, force: true });
241
- }
242
- const gitUrl = (0, clone_1.normalizeGitUrl)(templateUrl);
243
- const branchArgs = branch ? ` --branch ${branch} --single-branch` : "";
244
- const depthArgs = " --depth 1";
245
- (0, child_process_1.execSync)(`git clone${branchArgs}${depthArgs} ${gitUrl} ${destination}`, {
246
- stdio: "inherit",
247
- });
248
- const gitDir = path.join(destination, ".git");
249
- if (fs.existsSync(gitDir)) {
250
- fs.rmSync(gitDir, { recursive: true, force: true });
251
- }
252
- }
253
- isEnabled() {
254
- return this.config.enabled;
255
- }
256
- getConfig() {
257
- return { ...this.config };
258
- }
259
- }
260
- exports.TemplateCache = TemplateCache;
File without changes
File without changes
File without changes
File without changes