cwresdev 0.2.2 → 0.2.3
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/package.json +1 -1
- package/src/cwgit.js +38 -8
package/package.json
CHANGED
package/src/cwgit.js
CHANGED
|
@@ -267,7 +267,10 @@ async function detectChanges(projectDir, docRoot) {
|
|
|
267
267
|
const currentPaths = await collectFiles(resolvedProject, resolvedProject);
|
|
268
268
|
const currentFiles = {};
|
|
269
269
|
|
|
270
|
-
process.stderr.write(`\r[cwgit]
|
|
270
|
+
process.stderr.write(`\r[cwgit] 0%`);
|
|
271
|
+
|
|
272
|
+
let scanned = 0;
|
|
273
|
+
let lastScanPercent = -1;
|
|
271
274
|
|
|
272
275
|
for (const filePath of currentPaths) {
|
|
273
276
|
const relFilePath = path.relative(resolvedProject, filePath).replace(/\\/g, "/");
|
|
@@ -281,6 +284,14 @@ async function detectChanges(projectDir, docRoot) {
|
|
|
281
284
|
|
|
282
285
|
throw err;
|
|
283
286
|
}
|
|
287
|
+
|
|
288
|
+
scanned += 1;
|
|
289
|
+
const pct = Math.floor((scanned / currentPaths.length) * 100);
|
|
290
|
+
|
|
291
|
+
if (pct !== lastScanPercent) {
|
|
292
|
+
lastScanPercent = pct;
|
|
293
|
+
process.stderr.write(`\r[cwgit] ${pct}%`);
|
|
294
|
+
}
|
|
284
295
|
}
|
|
285
296
|
|
|
286
297
|
process.stderr.write("\n");
|
|
@@ -290,16 +301,32 @@ async function detectChanges(projectDir, docRoot) {
|
|
|
290
301
|
// Check for modified and deleted files
|
|
291
302
|
for (const [file, hash] of Object.entries(baseFiles)) {
|
|
292
303
|
if (!(file in currentFiles)) {
|
|
293
|
-
changes.push({ file, status: "D" });
|
|
304
|
+
changes.push({ file, status: "D", mtime: null });
|
|
294
305
|
} else if (currentFiles[file] !== hash) {
|
|
295
|
-
|
|
306
|
+
const fullPath = path.join(resolvedProject, file.replace(/\//g, path.sep));
|
|
307
|
+
let mtime = null;
|
|
308
|
+
|
|
309
|
+
try {
|
|
310
|
+
const stat = await fs.promises.stat(fullPath);
|
|
311
|
+
mtime = stat.mtime;
|
|
312
|
+
} catch (_) {}
|
|
313
|
+
|
|
314
|
+
changes.push({ file, status: "M", mtime });
|
|
296
315
|
}
|
|
297
316
|
}
|
|
298
317
|
|
|
299
318
|
// Check for new/untracked files
|
|
300
319
|
for (const file of Object.keys(currentFiles)) {
|
|
301
320
|
if (!(file in baseFiles)) {
|
|
302
|
-
|
|
321
|
+
const fullPath = path.join(resolvedProject, file.replace(/\//g, path.sep));
|
|
322
|
+
let mtime = null;
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
const stat = await fs.promises.stat(fullPath);
|
|
326
|
+
mtime = stat.mtime;
|
|
327
|
+
} catch (_) {}
|
|
328
|
+
|
|
329
|
+
changes.push({ file, status: "U", mtime });
|
|
303
330
|
}
|
|
304
331
|
}
|
|
305
332
|
|
|
@@ -332,20 +359,23 @@ function sanitizeCsvCell(value) {
|
|
|
332
359
|
return value;
|
|
333
360
|
}
|
|
334
361
|
|
|
362
|
+
const STATUS_LABELS = { M: "Modified", U: "Untracked", D: "Deleted" };
|
|
363
|
+
|
|
335
364
|
/**
|
|
336
365
|
* Export changes to a CSV file.
|
|
337
366
|
*/
|
|
338
367
|
async function exportCsv(changes, outputDir) {
|
|
339
368
|
const csvPath = path.join(outputDir, "cwgit-changes.csv");
|
|
340
|
-
const lines = ["file,status"];
|
|
369
|
+
const lines = ["file,status,date"];
|
|
341
370
|
|
|
342
|
-
for (const { file, status } of changes) {
|
|
371
|
+
for (const { file, status, mtime } of changes) {
|
|
343
372
|
const safeFile = sanitizeCsvCell(file);
|
|
344
|
-
// Escape double quotes in file path and wrap in quotes if contains comma
|
|
345
373
|
const escaped = safeFile.includes(",") || safeFile.includes('"')
|
|
346
374
|
? `"${safeFile.replace(/"/g, '""')}"`
|
|
347
375
|
: safeFile;
|
|
348
|
-
|
|
376
|
+
const label = STATUS_LABELS[status] || status;
|
|
377
|
+
const date = mtime ? mtime.toISOString().replace("T", " ").slice(0, 19) : "";
|
|
378
|
+
lines.push(`${escaped},${label},${date}`);
|
|
349
379
|
}
|
|
350
380
|
|
|
351
381
|
await fs.promises.writeFile(csvPath, lines.join("\n") + "\n", "utf8");
|