docs-coderef 0.2.0 → 0.4.0

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,36 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ # [0.4.0](https://github.com/cawpea/docs-coderef/compare/v0.3.0...v0.4.0) (2026-01-02)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * correct diff display for UPDATE_LINE_NUMBERS from CODE_CONTENT_MISMATCH ([1984d23](https://github.com/cawpea/docs-coderef/commit/1984d238e2e176980cfde79fe2dd296ee7a16be6))
14
+ * show actual vs kept code diff for UPDATE_LINE_NUMBERS in CODE_CONTENT_MISMATCH ([44c34cb](https://github.com/cawpea/docs-coderef/commit/44c34cb097d3e431eb10d90802e80666680f2d27))
15
+
16
+
17
+ ### Features
18
+
19
+ * add color highlighting to CODE_REF preview in fix options ([11e8e84](https://github.com/cawpea/docs-coderef/commit/11e8e848126e3731dd015b84c7bb891ba70b7cc3))
20
+ * add syntax highlighting to code blocks in fix preview ([37bbebe](https://github.com/cawpea/docs-coderef/commit/37bbebe7b9c9bb1ada72874de9fbc22d9139a983))
21
+ * group diff display by change type for better readability ([3f891eb](https://github.com/cawpea/docs-coderef/commit/3f891eb5bf5a460a6eed5cbcdec2b57c80fda835))
22
+ * simplify Option 2 preview to show only CODE_REF change ([294e2e4](https://github.com/cawpea/docs-coderef/commit/294e2e424b00f51caf9aa7580d3f2e7eca0a6ecf))
23
+ * unify error message styling with centralized formatter ([4735c23](https://github.com/cawpea/docs-coderef/commit/4735c2392ae2b57154d0ddfea91c139634f3648a))
24
+
25
+ # [0.3.0](https://github.com/cawpea/docs-coderef/compare/v0.2.0...v0.3.0) (2026-01-01)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * update demo valid docs to pass all validations ([2caab53](https://github.com/cawpea/docs-coderef/commit/2caab535a936d118efff7bedfadbd4a5b8d85c19))
31
+
32
+
33
+ ### Features
34
+
35
+ * add demo environment for local CODE_REF testing ([b845f99](https://github.com/cawpea/docs-coderef/commit/b845f997368ef898ad315f3dfdd43506cfdb5679))
36
+ * add demo:reset npm script for quick demo restoration ([3bceb6e](https://github.com/cawpea/docs-coderef/commit/3bceb6e00b72421c193495f506a6a1428123978a))
37
+
8
38
  # [0.2.0](https://github.com/cawpea/docs-coderef/compare/v0.1.0...v0.2.0) (2026-01-01)
9
39
 
10
40
 
package/README.md CHANGED
@@ -159,6 +159,33 @@ This references lines 15-35 of the file. If the code changes, `coderef` will det
159
159
 
160
160
  For more examples and usage patterns, see [docs/user-guide/](docs/user-guide/).
161
161
 
162
+ ## Demo Environment
163
+
164
+ Try out `docs-coderef` with the included demo environment:
165
+
166
+ ```bash
167
+ # Clone the repository
168
+ git clone https://github.com/cawpea/docs-coderef.git
169
+ cd docs-coderef
170
+
171
+ # Install dependencies and build
172
+ npm install
173
+ npm run build
174
+
175
+ # Try the demo
176
+ npm run demo:validate:valid # See valid CODE_REF examples
177
+ npm run demo:validate:invalid # See error detection
178
+ npm run demo:fix:dry # Preview auto-fix
179
+ ```
180
+
181
+ The `demo/` directory includes:
182
+
183
+ - Sample TypeScript files with various code patterns
184
+ - Documentation with valid and invalid CODE_REF examples
185
+ - Scripts for testing validation and fixing
186
+
187
+ See [demo/README.md](demo/README.md) for detailed instructions.
188
+
162
189
  ## Configuration
163
190
 
164
191
  Create `.docs-coderefrc.json` in your project root:
@@ -0,0 +1,268 @@
1
+ // src/utils/message-formatter.ts
2
+ import chalk from "chalk";
3
+ var COLOR_SCHEMES = {
4
+ error: chalk.redBright,
5
+ warning: chalk.yellow,
6
+ info: chalk.cyan,
7
+ success: chalk.green,
8
+ debug: chalk.gray,
9
+ neutral: chalk.white,
10
+ // Accent colors
11
+ highlight: chalk.cyan.bold,
12
+ dim: chalk.dim,
13
+ code: chalk.yellow
14
+ };
15
+ var EMOJIS = {
16
+ error: "\u274C",
17
+ warning: "\u26A0\uFE0F",
18
+ success: "\u2705",
19
+ info: "\u2139\uFE0F",
20
+ search: "\u{1F50D}",
21
+ fix: "\u{1F527}",
22
+ file: "\u{1F4C4}",
23
+ stats: "\u{1F4CA}",
24
+ backup: "\u{1F4BE}",
25
+ skip: "\u23ED\uFE0F"
26
+ };
27
+ var MessageFormatter = class {
28
+ /**
29
+ * Set verbose mode
30
+ * @param enabled Whether verbose mode is enabled
31
+ */
32
+ static setVerbose(enabled) {
33
+ this.verboseMode = enabled;
34
+ }
35
+ /**
36
+ * Format error message
37
+ * @param text Error message text
38
+ * @returns Formatted error message with emoji and color
39
+ */
40
+ static error(text) {
41
+ return `${COLOR_SCHEMES.error(`${EMOJIS.error} ${text}`)}`;
42
+ }
43
+ /**
44
+ * Format warning message
45
+ * @param text Warning message text
46
+ * @returns Formatted warning message with emoji and color
47
+ */
48
+ static warning(text) {
49
+ return `${COLOR_SCHEMES.warning(`${EMOJIS.warning} ${text}`)}`;
50
+ }
51
+ /**
52
+ * Format info message
53
+ * @param text Info message text
54
+ * @returns Formatted info message with emoji and color
55
+ */
56
+ static info(text) {
57
+ return `${COLOR_SCHEMES.info(`${EMOJIS.info} ${text}`)}`;
58
+ }
59
+ /**
60
+ * Format success message
61
+ * @param text Success message text
62
+ * @returns Formatted success message with emoji and color
63
+ */
64
+ static success(text) {
65
+ return `${COLOR_SCHEMES.success(`${EMOJIS.success} ${text}`)}`;
66
+ }
67
+ /**
68
+ * Format debug message (only shown in verbose mode)
69
+ * @param text Debug message text
70
+ * @returns Formatted debug message if verbose mode is enabled, empty string otherwise
71
+ */
72
+ static debug(text) {
73
+ if (!this.verboseMode) {
74
+ return "";
75
+ }
76
+ return COLOR_SCHEMES.debug(text);
77
+ }
78
+ /**
79
+ * Format neutral message (no emoji, white color)
80
+ * @param text Neutral message text
81
+ * @returns Formatted neutral message
82
+ */
83
+ static neutral(text) {
84
+ return COLOR_SCHEMES.neutral(text);
85
+ }
86
+ /**
87
+ * Format error detail with type, message, and optional location
88
+ * @param type Error type (e.g., 'CODE_CONTENT_MISMATCH')
89
+ * @param message Error message
90
+ * @param location Optional file location
91
+ * @returns Formatted error detail
92
+ */
93
+ static errorDetail(type, message, location) {
94
+ const lines = [];
95
+ lines.push(this.error(`${type}: ${message}`));
96
+ if (location) {
97
+ lines.push(` ${COLOR_SCHEMES.dim(`Reference: ${location}`)}`);
98
+ }
99
+ return lines.join("\n");
100
+ }
101
+ /**
102
+ * Format summary section
103
+ * @param successful Number of successful operations
104
+ * @param failed Number of failed operations
105
+ * @param backupPaths Array of backup file paths
106
+ * @returns Formatted summary section
107
+ */
108
+ static summary(successful, failed, backupPaths) {
109
+ const lines = [];
110
+ const separator = COLOR_SCHEMES.dim("\u2501".repeat(60));
111
+ lines.push("");
112
+ lines.push(separator);
113
+ lines.push(`${EMOJIS.stats} Fix Results Summary`);
114
+ lines.push("");
115
+ lines.push(COLOR_SCHEMES.success(`${EMOJIS.success} Successful: ${successful}`));
116
+ lines.push(COLOR_SCHEMES.error(`${EMOJIS.error} Failed: ${failed}`));
117
+ if (backupPaths.length > 0) {
118
+ lines.push("");
119
+ lines.push(`${EMOJIS.backup} Backup files: ${backupPaths.length}`);
120
+ backupPaths.forEach((path) => {
121
+ lines.push(` ${COLOR_SCHEMES.dim(path)}`);
122
+ });
123
+ }
124
+ return lines.join("\n");
125
+ }
126
+ /**
127
+ * Format start message for fix operation
128
+ * @param text Start message text
129
+ * @returns Formatted start message with fix emoji
130
+ */
131
+ static startFix(text) {
132
+ return `${COLOR_SCHEMES.info(`${EMOJIS.fix} ${text}`)}`;
133
+ }
134
+ /**
135
+ * Format start message for validation operation
136
+ * @param text Start message text
137
+ * @returns Formatted start message with search emoji
138
+ */
139
+ static startValidation(text) {
140
+ return `${COLOR_SCHEMES.info(`${EMOJIS.search} ${text}`)}`;
141
+ }
142
+ /**
143
+ * Format file reference
144
+ * @param text File path or reference
145
+ * @returns Formatted file reference with emoji
146
+ */
147
+ static file(text) {
148
+ return `${EMOJIS.file} ${COLOR_SCHEMES.neutral(text)}`;
149
+ }
150
+ /**
151
+ * Format backup notification
152
+ * @param text Backup message text
153
+ * @returns Formatted backup message with emoji
154
+ */
155
+ static backup(text) {
156
+ return `${COLOR_SCHEMES.info(`${EMOJIS.backup} ${text}`)}`;
157
+ }
158
+ /**
159
+ * Format skip notification
160
+ * @param text Skip message text
161
+ * @returns Formatted skip message with emoji
162
+ */
163
+ static skip(text) {
164
+ return `${COLOR_SCHEMES.neutral(`${EMOJIS.skip} ${text}`)}`;
165
+ }
166
+ /**
167
+ * Format context line (indented with dim color)
168
+ * @param text Context text
169
+ * @returns Formatted context line with 3 spaces indentation
170
+ */
171
+ static context(text) {
172
+ return ` ${COLOR_SCHEMES.dim(text)}`;
173
+ }
174
+ };
175
+ MessageFormatter.verboseMode = false;
176
+ var msg = {
177
+ error: (text) => MessageFormatter.error(text),
178
+ warning: (text) => MessageFormatter.warning(text),
179
+ info: (text) => MessageFormatter.info(text),
180
+ success: (text) => MessageFormatter.success(text),
181
+ debug: (text) => MessageFormatter.debug(text),
182
+ neutral: (text) => MessageFormatter.neutral(text),
183
+ errorDetail: (type, message, location) => MessageFormatter.errorDetail(type, message, location),
184
+ summary: (successful, failed, backupPaths) => MessageFormatter.summary(successful, failed, backupPaths),
185
+ startFix: (text) => MessageFormatter.startFix(text),
186
+ startValidation: (text) => MessageFormatter.startValidation(text),
187
+ file: (text) => MessageFormatter.file(text),
188
+ backup: (text) => MessageFormatter.backup(text),
189
+ skip: (text) => MessageFormatter.skip(text),
190
+ context: (text) => MessageFormatter.context(text),
191
+ setVerbose: (enabled) => MessageFormatter.setVerbose(enabled)
192
+ };
193
+
194
+ // src/utils/diff-display.ts
195
+ function displayCodeDiff(expected, actual) {
196
+ const expectedLines = expected.split("\n");
197
+ const actualLines = actual.split("\n");
198
+ const output = [];
199
+ const maxLines = Math.max(expectedLines.length, actualLines.length);
200
+ output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
201
+ output.push(COLOR_SCHEMES.error("- Expected code (in document)"));
202
+ output.push(COLOR_SCHEMES.success("+ Actual code (in file)"));
203
+ output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
204
+ const removedLines = [];
205
+ const addedLines = [];
206
+ const flushChanges = () => {
207
+ removedLines.forEach((line) => {
208
+ output.push(COLOR_SCHEMES.error(`- ${line}`));
209
+ });
210
+ addedLines.forEach((line) => {
211
+ output.push(COLOR_SCHEMES.success(`+ ${line}`));
212
+ });
213
+ removedLines.length = 0;
214
+ addedLines.length = 0;
215
+ };
216
+ for (let i = 0; i < maxLines; i++) {
217
+ const expectedLine = expectedLines[i];
218
+ const actualLine = actualLines[i];
219
+ if (expectedLine === actualLine) {
220
+ if (removedLines.length > 0 || addedLines.length > 0) {
221
+ flushChanges();
222
+ }
223
+ if (expectedLine !== void 0) {
224
+ output.push(` ${expectedLine}`);
225
+ }
226
+ } else {
227
+ if (expectedLine !== void 0) {
228
+ removedLines.push(expectedLine);
229
+ }
230
+ if (actualLine !== void 0) {
231
+ addedLines.push(actualLine);
232
+ }
233
+ }
234
+ }
235
+ if (removedLines.length > 0 || addedLines.length > 0) {
236
+ flushChanges();
237
+ }
238
+ output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
239
+ return output.join("\n");
240
+ }
241
+ function displayLineRangeDiff(code, expectedRange, actualRange) {
242
+ const output = [];
243
+ output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
244
+ output.push(
245
+ COLOR_SCHEMES.error(`- Expected line range: ${expectedRange.start}-${expectedRange.end}`)
246
+ );
247
+ output.push(
248
+ COLOR_SCHEMES.success(`+ Actual line range: ${actualRange.start}-${actualRange.end}`)
249
+ );
250
+ output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
251
+ const codeLines = code.split("\n");
252
+ codeLines.forEach((line, index) => {
253
+ const expectedLineNum = expectedRange.start + index;
254
+ const actualLineNum = actualRange.start + index;
255
+ output.push(
256
+ `${COLOR_SCHEMES.error(expectedLineNum.toString().padStart(4))} | ${COLOR_SCHEMES.success(actualLineNum.toString().padStart(4))} | ${line}`
257
+ );
258
+ });
259
+ output.push(COLOR_SCHEMES.dim("\u2501".repeat(64)));
260
+ return output.join("\n");
261
+ }
262
+
263
+ export {
264
+ COLOR_SCHEMES,
265
+ msg,
266
+ displayCodeDiff,
267
+ displayLineRangeDiff
268
+ };