cwresdev 0.2.2 → 0.2.4
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 +48 -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,33 @@ function sanitizeCsvCell(value) {
|
|
|
332
359
|
return value;
|
|
333
360
|
}
|
|
334
361
|
|
|
362
|
+
const STATUS_LABELS = { M: "Modified", U: "Untracked", D: "Deleted" };
|
|
363
|
+
|
|
364
|
+
function formatLocalDate(date) {
|
|
365
|
+
const y = date.getFullYear();
|
|
366
|
+
const m = String(date.getMonth() + 1).padStart(2, "0");
|
|
367
|
+
const d = String(date.getDate()).padStart(2, "0");
|
|
368
|
+
const h = String(date.getHours()).padStart(2, "0");
|
|
369
|
+
const min = String(date.getMinutes()).padStart(2, "0");
|
|
370
|
+
const s = String(date.getSeconds()).padStart(2, "0");
|
|
371
|
+
return `${y}-${m}-${d} ${h}:${min}:${s}`;
|
|
372
|
+
}
|
|
373
|
+
|
|
335
374
|
/**
|
|
336
375
|
* Export changes to a CSV file.
|
|
337
376
|
*/
|
|
338
377
|
async function exportCsv(changes, outputDir) {
|
|
339
378
|
const csvPath = path.join(outputDir, "cwgit-changes.csv");
|
|
340
|
-
const lines = ["
|
|
379
|
+
const lines = ["File,Status,Date"];
|
|
341
380
|
|
|
342
|
-
for (const { file, status } of changes) {
|
|
381
|
+
for (const { file, status, mtime } of changes) {
|
|
343
382
|
const safeFile = sanitizeCsvCell(file);
|
|
344
|
-
// Escape double quotes in file path and wrap in quotes if contains comma
|
|
345
383
|
const escaped = safeFile.includes(",") || safeFile.includes('"')
|
|
346
384
|
? `"${safeFile.replace(/"/g, '""')}"`
|
|
347
385
|
: safeFile;
|
|
348
|
-
|
|
386
|
+
const label = STATUS_LABELS[status] || status;
|
|
387
|
+
const date = mtime ? formatLocalDate(mtime) : "";
|
|
388
|
+
lines.push(`${escaped},${label},${date}`);
|
|
349
389
|
}
|
|
350
390
|
|
|
351
391
|
await fs.promises.writeFile(csvPath, lines.join("\n") + "\n", "utf8");
|