cwresdev 0.2.0 → 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.
- package/bin/cwgit.js +13 -16
- package/package.json +1 -1
- package/src/cwgit.js +10 -7
package/bin/cwgit.js
CHANGED
|
@@ -15,29 +15,28 @@ async function main() {
|
|
|
15
15
|
|
|
16
16
|
if (!command || command === "--help" || command === "-h") {
|
|
17
17
|
process.stdout.write([
|
|
18
|
-
"cwgit <command>",
|
|
18
|
+
"cwgit <command> [path]",
|
|
19
19
|
"",
|
|
20
20
|
"Commands:",
|
|
21
|
-
" init Snapshot the
|
|
22
|
-
" changes Detect and export changed files as CSV",
|
|
21
|
+
" init [path] Snapshot the project as the base version",
|
|
22
|
+
" changes [path] Detect and export changed files as CSV",
|
|
23
23
|
"",
|
|
24
|
-
"
|
|
25
|
-
" Run from inside a project folder (under the docRoot).",
|
|
26
|
-
" The tool locates the workspace root (package.json with cwrespro config)",
|
|
27
|
-
" and resolves docRoot from that config.",
|
|
24
|
+
"If [path] is omitted, the current working directory is used.",
|
|
28
25
|
"",
|
|
29
26
|
"Examples:",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
27
|
+
" cwgit init",
|
|
28
|
+
" cwgit init ./virtual_env/IC",
|
|
29
|
+
" cwgit changes ./virtual_env/IC",
|
|
32
30
|
"",
|
|
33
31
|
].join("\n"));
|
|
34
32
|
return;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
35
|
const cwd = process.cwd();
|
|
36
|
+
const targetPath = args[1] ? path.resolve(cwd, args[1]) : cwd;
|
|
38
37
|
|
|
39
38
|
// Find the workspace root by walking up
|
|
40
|
-
const workspaceRoot = findWorkspaceRoot(
|
|
39
|
+
const workspaceRoot = findWorkspaceRoot(targetPath);
|
|
41
40
|
|
|
42
41
|
if (!workspaceRoot) {
|
|
43
42
|
throw new Error(
|
|
@@ -50,22 +49,20 @@ async function main() {
|
|
|
50
49
|
const docRoot = resolveDocRoot(workspaceRoot);
|
|
51
50
|
|
|
52
51
|
if (command === "init") {
|
|
53
|
-
|
|
54
|
-
process.stdout.write(
|
|
55
|
-
process.stdout.write(`[cwgit] Stored at: ${basePath}\n`);
|
|
56
|
-
process.stdout.write(`[cwgit] Tip: add .cwgit/ to .gitignore if using Git.\n`);
|
|
52
|
+
await initBase(targetPath, docRoot);
|
|
53
|
+
process.stdout.write("[cwgit] Successfully initiated.\n");
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
56
|
|
|
60
57
|
if (command === "changes") {
|
|
61
|
-
const changes = await detectChanges(
|
|
58
|
+
const changes = await detectChanges(targetPath, docRoot);
|
|
62
59
|
|
|
63
60
|
if (changes.length === 0) {
|
|
64
61
|
process.stdout.write("[cwgit] No changes detected.\n");
|
|
65
62
|
return;
|
|
66
63
|
}
|
|
67
64
|
|
|
68
|
-
const csvPath = await exportCsv(changes,
|
|
65
|
+
const csvPath = await exportCsv(changes, targetPath);
|
|
69
66
|
|
|
70
67
|
// Print summary
|
|
71
68
|
const deleted = changes.filter((c) => c.status === "D").length;
|
package/package.json
CHANGED
package/src/cwgit.js
CHANGED
|
@@ -195,10 +195,9 @@ async function initBase(projectDir, docRoot) {
|
|
|
195
195
|
const filePaths = await collectFiles(resolvedProject, resolvedProject);
|
|
196
196
|
const fileCount = filePaths.length;
|
|
197
197
|
|
|
198
|
-
process.stderr.write(`[cwgit] Hashing ${fileCount} files...\n`);
|
|
199
|
-
|
|
200
198
|
const files = {};
|
|
201
199
|
let processed = 0;
|
|
200
|
+
let lastPercent = -1;
|
|
202
201
|
|
|
203
202
|
for (const filePath of filePaths) {
|
|
204
203
|
const relFilePath = path.relative(resolvedProject, filePath).replace(/\\/g, "/");
|
|
@@ -207,7 +206,6 @@ async function initBase(projectDir, docRoot) {
|
|
|
207
206
|
files[relFilePath] = await hashFile(filePath);
|
|
208
207
|
} catch (err) {
|
|
209
208
|
if (err.code === "EBUSY" || err.code === "EPERM" || err.code === "ENOENT") {
|
|
210
|
-
process.stderr.write(`[cwgit] Warning: skipped inaccessible file: ${relFilePath}\n`);
|
|
211
209
|
continue;
|
|
212
210
|
}
|
|
213
211
|
|
|
@@ -215,12 +213,16 @@ async function initBase(projectDir, docRoot) {
|
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
processed += 1;
|
|
216
|
+
const percent = Math.floor((processed / fileCount) * 100);
|
|
218
217
|
|
|
219
|
-
if (
|
|
220
|
-
|
|
218
|
+
if (percent !== lastPercent) {
|
|
219
|
+
lastPercent = percent;
|
|
220
|
+
process.stderr.write(`\r[cwgit] ${percent}%`);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
process.stderr.write("\n");
|
|
225
|
+
|
|
224
226
|
const baseData = {
|
|
225
227
|
version: 1,
|
|
226
228
|
createdAt: new Date().toISOString(),
|
|
@@ -265,7 +267,7 @@ async function detectChanges(projectDir, docRoot) {
|
|
|
265
267
|
const currentPaths = await collectFiles(resolvedProject, resolvedProject);
|
|
266
268
|
const currentFiles = {};
|
|
267
269
|
|
|
268
|
-
process.stderr.write(
|
|
270
|
+
process.stderr.write(`\r[cwgit] Scanning...`);
|
|
269
271
|
|
|
270
272
|
for (const filePath of currentPaths) {
|
|
271
273
|
const relFilePath = path.relative(resolvedProject, filePath).replace(/\\/g, "/");
|
|
@@ -274,7 +276,6 @@ async function detectChanges(projectDir, docRoot) {
|
|
|
274
276
|
currentFiles[relFilePath] = await hashFile(filePath);
|
|
275
277
|
} catch (err) {
|
|
276
278
|
if (err.code === "EBUSY" || err.code === "EPERM" || err.code === "ENOENT") {
|
|
277
|
-
process.stderr.write(`[cwgit] Warning: skipped inaccessible file: ${relFilePath}\n`);
|
|
278
279
|
continue;
|
|
279
280
|
}
|
|
280
281
|
|
|
@@ -282,6 +283,8 @@ async function detectChanges(projectDir, docRoot) {
|
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
285
|
|
|
286
|
+
process.stderr.write("\n");
|
|
287
|
+
|
|
285
288
|
const changes = [];
|
|
286
289
|
|
|
287
290
|
// Check for modified and deleted files
|