codesyncer 3.0.1 → 3.1.1

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 (50) hide show
  1. package/README.ko.md +24 -0
  2. package/README.md +24 -0
  3. package/dist/commands/update.d.ts.map +1 -1
  4. package/dist/commands/update.js +137 -0
  5. package/dist/commands/update.js.map +1 -1
  6. package/dist/templates/en/architecture.md +2 -0
  7. package/dist/templates/en/claude.md +14 -0
  8. package/dist/templates/en/comment_guide.md +2 -0
  9. package/dist/templates/en/decisions.md +2 -0
  10. package/dist/templates/en/master.md +2 -0
  11. package/dist/templates/en/root_claude.md +2 -0
  12. package/dist/templates/en/setup_guide.md +2 -0
  13. package/dist/templates/en/setup_guide_monorepo.md +2 -0
  14. package/dist/templates/en/setup_guide_single.md +2 -0
  15. package/dist/templates/ko/architecture.md +2 -0
  16. package/dist/templates/ko/claude.md +14 -0
  17. package/dist/templates/ko/comment_guide.md +2 -0
  18. package/dist/templates/ko/decisions.md +2 -0
  19. package/dist/templates/ko/master.md +2 -0
  20. package/dist/templates/ko/root_claude.md +2 -0
  21. package/dist/templates/ko/setup_guide.md +2 -0
  22. package/dist/templates/ko/setup_guide_monorepo.md +2 -0
  23. package/dist/templates/ko/setup_guide_single.md +2 -0
  24. package/dist/utils/template-upgrader.d.ts +133 -0
  25. package/dist/utils/template-upgrader.d.ts.map +1 -0
  26. package/dist/utils/template-upgrader.js +400 -0
  27. package/dist/utils/template-upgrader.js.map +1 -0
  28. package/dist/utils/template-version.d.ts +64 -0
  29. package/dist/utils/template-version.d.ts.map +1 -0
  30. package/dist/utils/template-version.js +177 -0
  31. package/dist/utils/template-version.js.map +1 -0
  32. package/package.json +1 -1
  33. package/src/templates/en/architecture.md +2 -0
  34. package/src/templates/en/claude.md +14 -0
  35. package/src/templates/en/comment_guide.md +2 -0
  36. package/src/templates/en/decisions.md +2 -0
  37. package/src/templates/en/master.md +2 -0
  38. package/src/templates/en/root_claude.md +2 -0
  39. package/src/templates/en/setup_guide.md +2 -0
  40. package/src/templates/en/setup_guide_monorepo.md +2 -0
  41. package/src/templates/en/setup_guide_single.md +2 -0
  42. package/src/templates/ko/architecture.md +2 -0
  43. package/src/templates/ko/claude.md +14 -0
  44. package/src/templates/ko/comment_guide.md +2 -0
  45. package/src/templates/ko/decisions.md +2 -0
  46. package/src/templates/ko/master.md +2 -0
  47. package/src/templates/ko/root_claude.md +2 -0
  48. package/src/templates/ko/setup_guide.md +2 -0
  49. package/src/templates/ko/setup_guide_monorepo.md +2 -0
  50. package/src/templates/ko/setup_guide_single.md +2 -0
@@ -0,0 +1,133 @@
1
+ import { Language } from '../types';
2
+ import { TemplateStatus } from './template-version';
3
+ /**
4
+ * Template upgrade utilities
5
+ *
6
+ * @codesyncer-context Handles backing up existing templates and applying new versions
7
+ * @codesyncer-decision [2026-01-17] Always backup before upgrading (user data safety)
8
+ * @codesyncer-decision [2026-01-17] Smart merge - only update section-marked content
9
+ */
10
+ /**
11
+ * Parsed section from template content
12
+ */
13
+ export interface ParsedSection {
14
+ name: string;
15
+ content: string;
16
+ startIndex: number;
17
+ endIndex: number;
18
+ }
19
+ /**
20
+ * Result of parsing template into sections and user content
21
+ */
22
+ export interface ParsedTemplate {
23
+ sections: ParsedSection[];
24
+ userContent: Array<{
25
+ content: string;
26
+ afterSection: string | null;
27
+ }>;
28
+ rawContent: string;
29
+ }
30
+ /**
31
+ * Result of a template upgrade operation
32
+ */
33
+ export interface UpgradeResult {
34
+ success: boolean;
35
+ file: string;
36
+ backupPath?: string;
37
+ error?: string;
38
+ }
39
+ /**
40
+ * Options for template upgrade
41
+ */
42
+ export interface UpgradeOptions {
43
+ lang: Language;
44
+ vars: Record<string, string>;
45
+ dryRun?: boolean;
46
+ }
47
+ /**
48
+ * Create a backup of a file before upgrading
49
+ *
50
+ * @param filePath - Path to the file to backup
51
+ * @returns Path to the backup file
52
+ */
53
+ export declare function backupFile(filePath: string): Promise<string>;
54
+ /**
55
+ * Upgrade a single template file
56
+ *
57
+ * @param templateStatus - Template status from version check
58
+ * @param options - Upgrade options
59
+ * @returns Promise resolving to UpgradeResult
60
+ */
61
+ export declare function upgradeTemplate(templateStatus: TemplateStatus, options: UpgradeOptions): Promise<UpgradeResult>;
62
+ /**
63
+ * Upgrade multiple templates
64
+ *
65
+ * @param templates - Array of template statuses to upgrade
66
+ * @param options - Upgrade options
67
+ * @returns Promise resolving to array of UpgradeResults
68
+ */
69
+ export declare function upgradeTemplates(templates: TemplateStatus[], options: UpgradeOptions): Promise<UpgradeResult[]>;
70
+ /**
71
+ * Extract variables from existing file for re-use during upgrade
72
+ *
73
+ * @param filePath - Path to existing file
74
+ * @returns Record of extracted variables
75
+ */
76
+ export declare function extractVarsFromFile(filePath: string): Promise<Record<string, string>>;
77
+ /**
78
+ * Get template variables from .claude directory context
79
+ *
80
+ * @param claudeDir - Path to .claude directory
81
+ * @param lang - Language to use
82
+ * @returns Record of template variables
83
+ */
84
+ export declare function getTemplateVarsFromContext(claudeDir: string, lang: Language): Promise<Record<string, string>>;
85
+ /**
86
+ * Format upgrade summary for display
87
+ *
88
+ * @param results - Array of upgrade results
89
+ * @param lang - Language for messages
90
+ * @returns Formatted summary string
91
+ */
92
+ export declare function formatUpgradeSummary(results: UpgradeResult[], lang: Language): string;
93
+ /**
94
+ * Extract marked sections from template content
95
+ *
96
+ * @codesyncer-context Sections are marked with <!-- codesyncer-section-start:name --> and <!-- codesyncer-section-end:name -->
97
+ * @param content - Template content to parse
98
+ * @returns Array of parsed sections
99
+ */
100
+ export declare function extractSections(content: string): ParsedSection[];
101
+ /**
102
+ * Check if a template supports smart merge (has section markers)
103
+ *
104
+ * @param content - Template content to check
105
+ * @returns True if template has at least one section marker
106
+ */
107
+ export declare function supportsSmartMerge(content: string): boolean;
108
+ /**
109
+ * Smart merge: Update only CodeSyncer-managed sections while preserving user content
110
+ *
111
+ * @codesyncer-decision [2026-01-17] Preserve all user content outside marked sections
112
+ * @param existingContent - Current file content (may have user modifications)
113
+ * @param newTemplateContent - New template content with updated sections
114
+ * @returns Merged content with updated sections and preserved user content
115
+ */
116
+ export declare function smartMergeContent(existingContent: string, newTemplateContent: string): string;
117
+ /**
118
+ * Upgrade a template using smart merge to preserve user content
119
+ *
120
+ * @param templateStatus - Template status from version check
121
+ * @param options - Upgrade options
122
+ * @returns Promise resolving to UpgradeResult
123
+ */
124
+ export declare function upgradeTemplateWithSmartMerge(templateStatus: TemplateStatus, options: UpgradeOptions): Promise<UpgradeResult>;
125
+ /**
126
+ * Upgrade multiple templates using smart merge
127
+ *
128
+ * @param templates - Array of template statuses to upgrade
129
+ * @param options - Upgrade options
130
+ * @returns Promise resolving to array of UpgradeResults
131
+ */
132
+ export declare function upgradeTemplatesWithSmartMerge(templates: TemplateStatus[], options: UpgradeOptions): Promise<UpgradeResult[]>;
133
+ //# sourceMappingURL=template-upgrader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-upgrader.d.ts","sourceRoot":"","sources":["../../src/utils/template-upgrader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC,OAAO,EAAE,cAAc,EAAqB,MAAM,oBAAoB,CAAC;AAEvE;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,WAAW,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC;IACrE,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACj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BAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CA+C7F;AAED;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,CAAC,CAsDxB;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CAClD,SAAS,EAAE,cAAc,EAAE,EAC3B,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,EAAE,CAAC,CAS1B"}
@@ -0,0 +1,400 @@
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.backupFile = backupFile;
37
+ exports.upgradeTemplate = upgradeTemplate;
38
+ exports.upgradeTemplates = upgradeTemplates;
39
+ exports.extractVarsFromFile = extractVarsFromFile;
40
+ exports.getTemplateVarsFromContext = getTemplateVarsFromContext;
41
+ exports.formatUpgradeSummary = formatUpgradeSummary;
42
+ exports.extractSections = extractSections;
43
+ exports.supportsSmartMerge = supportsSmartMerge;
44
+ exports.smartMergeContent = smartMergeContent;
45
+ exports.upgradeTemplateWithSmartMerge = upgradeTemplateWithSmartMerge;
46
+ exports.upgradeTemplatesWithSmartMerge = upgradeTemplatesWithSmartMerge;
47
+ const fs = __importStar(require("fs-extra"));
48
+ const path = __importStar(require("path"));
49
+ const template_loader_1 = require("./template-loader");
50
+ /**
51
+ * Create a backup of a file before upgrading
52
+ *
53
+ * @param filePath - Path to the file to backup
54
+ * @returns Path to the backup file
55
+ */
56
+ async function backupFile(filePath) {
57
+ const dir = path.dirname(filePath);
58
+ const fileName = path.basename(filePath);
59
+ const today = new Date().toISOString().split('T')[0];
60
+ const backupFileName = `${fileName}.backup.${today}`;
61
+ const backupPath = path.join(dir, backupFileName);
62
+ // If backup already exists today, add a numeric suffix
63
+ let finalBackupPath = backupPath;
64
+ let counter = 1;
65
+ while (await fs.pathExists(finalBackupPath)) {
66
+ finalBackupPath = path.join(dir, `${fileName}.backup.${today}.${counter}`);
67
+ counter++;
68
+ }
69
+ await fs.copy(filePath, finalBackupPath);
70
+ return finalBackupPath;
71
+ }
72
+ /**
73
+ * Upgrade a single template file
74
+ *
75
+ * @param templateStatus - Template status from version check
76
+ * @param options - Upgrade options
77
+ * @returns Promise resolving to UpgradeResult
78
+ */
79
+ async function upgradeTemplate(templateStatus, options) {
80
+ const { file, templateName } = templateStatus;
81
+ const { lang, vars, dryRun } = options;
82
+ try {
83
+ // Skip if dry run
84
+ if (dryRun) {
85
+ return {
86
+ success: true,
87
+ file,
88
+ backupPath: `${file}.backup.${new Date().toISOString().split('T')[0]} (dry run)`,
89
+ };
90
+ }
91
+ // Backup existing file
92
+ let backupPath;
93
+ if (await fs.pathExists(file)) {
94
+ backupPath = await backupFile(file);
95
+ }
96
+ // Load and render new template
97
+ const template = await (0, template_loader_1.loadTemplate)(templateName, lang);
98
+ const content = (0, template_loader_1.replaceTemplateVars)(template, vars);
99
+ // Write the upgraded template
100
+ await fs.writeFile(file, content, 'utf-8');
101
+ return {
102
+ success: true,
103
+ file,
104
+ backupPath,
105
+ };
106
+ }
107
+ catch (error) {
108
+ return {
109
+ success: false,
110
+ file,
111
+ error: error instanceof Error ? error.message : String(error),
112
+ };
113
+ }
114
+ }
115
+ /**
116
+ * Upgrade multiple templates
117
+ *
118
+ * @param templates - Array of template statuses to upgrade
119
+ * @param options - Upgrade options
120
+ * @returns Promise resolving to array of UpgradeResults
121
+ */
122
+ async function upgradeTemplates(templates, options) {
123
+ const results = [];
124
+ for (const template of templates) {
125
+ const result = await upgradeTemplate(template, options);
126
+ results.push(result);
127
+ }
128
+ return results;
129
+ }
130
+ /**
131
+ * Extract variables from existing file for re-use during upgrade
132
+ *
133
+ * @param filePath - Path to existing file
134
+ * @returns Record of extracted variables
135
+ */
136
+ async function extractVarsFromFile(filePath) {
137
+ const vars = {};
138
+ try {
139
+ const content = await fs.readFile(filePath, 'utf-8');
140
+ // Extract project name
141
+ const projectNameMatch = content.match(/\*\*(?:프로젝트명|Project Name)\*\*:\s*([^\n]+)/);
142
+ if (projectNameMatch) {
143
+ vars['PROJECT_NAME'] = projectNameMatch[1].trim();
144
+ vars['프로젝트명'] = projectNameMatch[1].trim();
145
+ }
146
+ // Extract tech stack
147
+ const techStackMatch = content.match(/\*\*(?:기술 스택|Tech Stack)\*\*:\s*([^\n]+)/);
148
+ if (techStackMatch) {
149
+ vars['TECH_STACK'] = techStackMatch[1].trim();
150
+ vars['기술 스택'] = techStackMatch[1].trim();
151
+ }
152
+ // Extract project type
153
+ const projectTypeMatch = content.match(/\*\*(?:프로젝트 타입|Project Type)\*\*:\s*([^\n]+)/);
154
+ if (projectTypeMatch) {
155
+ vars['PROJECT_TYPE'] = projectTypeMatch[1].trim();
156
+ vars['프로젝트 타입'] = projectTypeMatch[1].trim();
157
+ }
158
+ // Extract GitHub username
159
+ const githubMatch = content.match(/github\.com\/([^/\s]+)/i);
160
+ if (githubMatch) {
161
+ vars['GITHUB_USERNAME'] = githubMatch[1];
162
+ }
163
+ }
164
+ catch (error) {
165
+ // Ignore extraction errors
166
+ }
167
+ return vars;
168
+ }
169
+ /**
170
+ * Get template variables from .claude directory context
171
+ *
172
+ * @param claudeDir - Path to .claude directory
173
+ * @param lang - Language to use
174
+ * @returns Record of template variables
175
+ */
176
+ async function getTemplateVarsFromContext(claudeDir, lang) {
177
+ const vars = {};
178
+ // Try to extract from CLAUDE.md first
179
+ const claudeMdPath = path.join(claudeDir, 'CLAUDE.md');
180
+ if (await fs.pathExists(claudeMdPath)) {
181
+ const extracted = await extractVarsFromFile(claudeMdPath);
182
+ Object.assign(vars, extracted);
183
+ }
184
+ // Default values if not found
185
+ const projectDir = path.dirname(claudeDir);
186
+ if (!vars['PROJECT_NAME']) {
187
+ vars['PROJECT_NAME'] = path.basename(projectDir);
188
+ vars['프로젝트명'] = path.basename(projectDir);
189
+ }
190
+ if (!vars['TECH_STACK']) {
191
+ vars['TECH_STACK'] = 'TypeScript';
192
+ vars['기술 스택'] = 'TypeScript';
193
+ }
194
+ if (!vars['GITHUB_USERNAME']) {
195
+ vars['GITHUB_USERNAME'] = 'your-username';
196
+ }
197
+ // Add date
198
+ const today = new Date().toISOString().split('T')[0];
199
+ vars['TODAY'] = today;
200
+ vars['오늘 날짜'] = today;
201
+ return vars;
202
+ }
203
+ /**
204
+ * Format upgrade summary for display
205
+ *
206
+ * @param results - Array of upgrade results
207
+ * @param lang - Language for messages
208
+ * @returns Formatted summary string
209
+ */
210
+ function formatUpgradeSummary(results, lang) {
211
+ const successful = results.filter((r) => r.success);
212
+ const failed = results.filter((r) => !r.success);
213
+ const lines = [];
214
+ if (lang === 'ko') {
215
+ if (successful.length > 0) {
216
+ lines.push(`✅ ${successful.length}개 파일 업그레이드 완료:`);
217
+ successful.forEach((r) => {
218
+ const fileName = path.basename(r.file);
219
+ lines.push(` • ${fileName}`);
220
+ if (r.backupPath) {
221
+ lines.push(` 백업: ${path.basename(r.backupPath)}`);
222
+ }
223
+ });
224
+ }
225
+ if (failed.length > 0) {
226
+ lines.push(`❌ ${failed.length}개 파일 업그레이드 실패:`);
227
+ failed.forEach((r) => {
228
+ const fileName = path.basename(r.file);
229
+ lines.push(` • ${fileName}: ${r.error}`);
230
+ });
231
+ }
232
+ }
233
+ else {
234
+ if (successful.length > 0) {
235
+ lines.push(`✅ ${successful.length} file(s) upgraded:`);
236
+ successful.forEach((r) => {
237
+ const fileName = path.basename(r.file);
238
+ lines.push(` • ${fileName}`);
239
+ if (r.backupPath) {
240
+ lines.push(` Backup: ${path.basename(r.backupPath)}`);
241
+ }
242
+ });
243
+ }
244
+ if (failed.length > 0) {
245
+ lines.push(`❌ ${failed.length} file(s) failed:`);
246
+ failed.forEach((r) => {
247
+ const fileName = path.basename(r.file);
248
+ lines.push(` • ${fileName}: ${r.error}`);
249
+ });
250
+ }
251
+ }
252
+ return lines.join('\n');
253
+ }
254
+ /**
255
+ * Extract marked sections from template content
256
+ *
257
+ * @codesyncer-context Sections are marked with <!-- codesyncer-section-start:name --> and <!-- codesyncer-section-end:name -->
258
+ * @param content - Template content to parse
259
+ * @returns Array of parsed sections
260
+ */
261
+ function extractSections(content) {
262
+ const sections = [];
263
+ const sectionRegex = /<!--\s*codesyncer-section-start:(\w+)\s*-->([\s\S]*?)<!--\s*codesyncer-section-end:\1\s*-->/g;
264
+ let match;
265
+ while ((match = sectionRegex.exec(content)) !== null) {
266
+ sections.push({
267
+ name: match[1],
268
+ content: match[0], // Full content including markers
269
+ startIndex: match.index,
270
+ endIndex: match.index + match[0].length,
271
+ });
272
+ }
273
+ return sections;
274
+ }
275
+ /**
276
+ * Check if a template supports smart merge (has section markers)
277
+ *
278
+ * @param content - Template content to check
279
+ * @returns True if template has at least one section marker
280
+ */
281
+ function supportsSmartMerge(content) {
282
+ return /<!--\s*codesyncer-section-start:\w+\s*-->/.test(content);
283
+ }
284
+ /**
285
+ * Smart merge: Update only CodeSyncer-managed sections while preserving user content
286
+ *
287
+ * @codesyncer-decision [2026-01-17] Preserve all user content outside marked sections
288
+ * @param existingContent - Current file content (may have user modifications)
289
+ * @param newTemplateContent - New template content with updated sections
290
+ * @returns Merged content with updated sections and preserved user content
291
+ */
292
+ function smartMergeContent(existingContent, newTemplateContent) {
293
+ // Extract sections from both contents
294
+ const existingSections = extractSections(existingContent);
295
+ const newSections = extractSections(newTemplateContent);
296
+ // If either doesn't have sections, can't do smart merge
297
+ if (existingSections.length === 0 || newSections.length === 0) {
298
+ return newTemplateContent;
299
+ }
300
+ // Create a map of new sections by name
301
+ const newSectionMap = new Map();
302
+ for (const section of newSections) {
303
+ newSectionMap.set(section.name, section);
304
+ }
305
+ // Replace each existing section with the new version
306
+ let result = existingContent;
307
+ let offset = 0;
308
+ for (const existingSection of existingSections) {
309
+ const newSection = newSectionMap.get(existingSection.name);
310
+ if (newSection) {
311
+ // Calculate adjusted positions based on accumulated offset
312
+ const adjustedStart = existingSection.startIndex + offset;
313
+ const adjustedEnd = existingSection.endIndex + offset;
314
+ // Replace the section
315
+ result =
316
+ result.substring(0, adjustedStart) +
317
+ newSection.content +
318
+ result.substring(adjustedEnd);
319
+ // Update offset for next replacement
320
+ offset += newSection.content.length - (existingSection.endIndex - existingSection.startIndex);
321
+ }
322
+ }
323
+ // Update the version comment at the end
324
+ const versionRegex = /<!--\s*codesyncer-version:\s*[\d.]+\s*-->/g;
325
+ const newVersionMatch = newTemplateContent.match(versionRegex);
326
+ if (newVersionMatch) {
327
+ result = result.replace(versionRegex, newVersionMatch[newVersionMatch.length - 1]);
328
+ }
329
+ return result;
330
+ }
331
+ /**
332
+ * Upgrade a template using smart merge to preserve user content
333
+ *
334
+ * @param templateStatus - Template status from version check
335
+ * @param options - Upgrade options
336
+ * @returns Promise resolving to UpgradeResult
337
+ */
338
+ async function upgradeTemplateWithSmartMerge(templateStatus, options) {
339
+ const { file, templateName } = templateStatus;
340
+ const { lang, vars, dryRun } = options;
341
+ try {
342
+ // Skip if dry run
343
+ if (dryRun) {
344
+ return {
345
+ success: true,
346
+ file,
347
+ backupPath: `${file}.backup.${new Date().toISOString().split('T')[0]} (dry run)`,
348
+ };
349
+ }
350
+ // Check if file exists
351
+ if (!(await fs.pathExists(file))) {
352
+ // No existing file, just use regular upgrade
353
+ return upgradeTemplate(templateStatus, options);
354
+ }
355
+ // Read existing content
356
+ const existingContent = await fs.readFile(file, 'utf-8');
357
+ // Check if existing content supports smart merge
358
+ if (!supportsSmartMerge(existingContent)) {
359
+ // Fall back to regular upgrade (full replacement with backup)
360
+ return upgradeTemplate(templateStatus, options);
361
+ }
362
+ // Create backup
363
+ const backupPath = await backupFile(file);
364
+ // Load and render new template
365
+ const template = await (0, template_loader_1.loadTemplate)(templateName, lang);
366
+ const newContent = (0, template_loader_1.replaceTemplateVars)(template, vars);
367
+ // Perform smart merge
368
+ const mergedContent = smartMergeContent(existingContent, newContent);
369
+ // Write the merged content
370
+ await fs.writeFile(file, mergedContent, 'utf-8');
371
+ return {
372
+ success: true,
373
+ file,
374
+ backupPath,
375
+ };
376
+ }
377
+ catch (error) {
378
+ return {
379
+ success: false,
380
+ file,
381
+ error: error instanceof Error ? error.message : String(error),
382
+ };
383
+ }
384
+ }
385
+ /**
386
+ * Upgrade multiple templates using smart merge
387
+ *
388
+ * @param templates - Array of template statuses to upgrade
389
+ * @param options - Upgrade options
390
+ * @returns Promise resolving to array of UpgradeResults
391
+ */
392
+ async function upgradeTemplatesWithSmartMerge(templates, options) {
393
+ const results = [];
394
+ for (const template of templates) {
395
+ const result = await upgradeTemplateWithSmartMerge(template, options);
396
+ results.push(result);
397
+ }
398
+ return results;
399
+ }
400
+ //# sourceMappingURL=template-upgrader.js.map
@@ -0,0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,CAAC;QAErE,2BAA2B;QAC3B,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;QAEjD,OAAO;YACL,OAAO,EAAE,IAAI;YACb,IAAI;YACJ,UAAU;SACX,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,IAAI;YACJ,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,8BAA8B,CAClD,SAA2B,EAC3B,OAAuB;IAEvB,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Mapping of .claude file names to template names
3
+ */
4
+ export declare const TEMPLATE_FILE_MAP: Record<string, string>;
5
+ /**
6
+ * Template status information for upgrade checks
7
+ */
8
+ export interface TemplateStatus {
9
+ file: string;
10
+ templateName: string;
11
+ currentVersion: string | null;
12
+ latestVersion: string;
13
+ isOutdated: boolean;
14
+ }
15
+ /**
16
+ * Extract template version from file content
17
+ *
18
+ * @param content - File content to extract version from
19
+ * @returns Version string or null if not found
20
+ */
21
+ export declare function extractTemplateVersion(content: string): string | null;
22
+ /**
23
+ * Compare two semantic versions
24
+ *
25
+ * @param v1 - First version string (e.g., "3.0.0")
26
+ * @param v2 - Second version string (e.g., "3.0.1")
27
+ * @returns -1 if v1 < v2, 0 if v1 === v2, 1 if v1 > v2
28
+ */
29
+ export declare function compareVersions(v1: string, v2: string): number;
30
+ /**
31
+ * Check if a file's template version is outdated compared to current package version
32
+ *
33
+ * @param filePath - Path to the file to check
34
+ * @returns Promise resolving to TemplateStatus
35
+ */
36
+ export declare function checkTemplateVersion(filePath: string): Promise<TemplateStatus>;
37
+ /**
38
+ * Scan a .claude directory for template files and check their versions
39
+ *
40
+ * @param claudeDir - Path to the .claude directory
41
+ * @returns Promise resolving to array of TemplateStatus objects
42
+ */
43
+ export declare function scanTemplateVersions(claudeDir: string): Promise<TemplateStatus[]>;
44
+ /**
45
+ * Get all outdated templates from a .claude directory
46
+ *
47
+ * @param claudeDir - Path to the .claude directory
48
+ * @returns Promise resolving to array of outdated TemplateStatus objects
49
+ */
50
+ export declare function getOutdatedTemplates(claudeDir: string): Promise<TemplateStatus[]>;
51
+ /**
52
+ * Check if any templates in a .claude directory need upgrading
53
+ *
54
+ * @param claudeDir - Path to the .claude directory
55
+ * @returns Promise resolving to boolean
56
+ */
57
+ export declare function hasOutdatedTemplates(claudeDir: string): Promise<boolean>;
58
+ /**
59
+ * Get the current package version (for display purposes)
60
+ *
61
+ * @returns Current package version string
62
+ */
63
+ export declare function getCurrentVersion(): string;
64
+ //# sourceMappingURL=template-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-version.d.ts","sourceRoot":"","sources":["../../src/utils/template-version.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKpD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGrE;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAa9D;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA8BpF;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAavF;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAGvF;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAG9E;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}