litmus-cli 1.0.3 → 1.0.5
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/dist/lib/tracker.d.ts +1 -1
- package/dist/lib/tracker.js +5 -5
- package/dist/lib/tracker.js.map +1 -1
- package/dist/watcher.cjs +45 -24
- package/package.json +1 -2
- package/src/lib/tracker.ts +5 -5
- package/src/lib/watcher.cjs +45 -24
package/dist/lib/tracker.d.ts
CHANGED
package/dist/lib/tracker.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { spawn } from "child_process";
|
|
2
|
-
import { mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { mkdirSync, openSync, writeFileSync } from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
6
|
/**
|
|
7
|
-
* Start the
|
|
7
|
+
* Start the file watcher in the background.
|
|
8
8
|
* Spawns dist/watcher.cjs as a detached process; logs file events to
|
|
9
9
|
* <projectDir>/.litmus/activity.jsonl for later inclusion in the submission ZIP.
|
|
10
10
|
*/
|
|
@@ -12,6 +12,7 @@ export function startTracker(projectDir) {
|
|
|
12
12
|
const litmusDir = path.join(projectDir, ".litmus");
|
|
13
13
|
const activityLog = path.join(litmusDir, "activity.jsonl");
|
|
14
14
|
const pidFile = path.join(litmusDir, "tracker.pid");
|
|
15
|
+
const errLog = path.join(litmusDir, "tracker.log");
|
|
15
16
|
const watcherScript = path.join(__dirname, "watcher.cjs");
|
|
16
17
|
try {
|
|
17
18
|
mkdirSync(litmusDir, { recursive: true });
|
|
@@ -19,11 +20,10 @@ export function startTracker(projectDir) {
|
|
|
19
20
|
catch {
|
|
20
21
|
// Non-critical
|
|
21
22
|
}
|
|
22
|
-
const
|
|
23
|
+
const errFd = openSync(errLog, "a");
|
|
23
24
|
const child = spawn("node", [watcherScript, projectDir, activityLog], {
|
|
24
25
|
detached: true,
|
|
25
|
-
stdio: "ignore",
|
|
26
|
-
cwd: packageRoot,
|
|
26
|
+
stdio: ["ignore", "ignore", errFd],
|
|
27
27
|
});
|
|
28
28
|
if (child.pid) {
|
|
29
29
|
child.unref();
|
package/dist/lib/tracker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/lib/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/lib/tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AACvD,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAE9D;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,UAAkB;IAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAA;IAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IACnD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAClD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAEzD,IAAI,CAAC;QACH,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,eAAe;IACjB,CAAC;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEnC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,aAAa,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE;QACpE,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC;KACnC,CAAC,CAAA;IAEF,IAAI,KAAK,CAAC,GAAG,EAAE,CAAC;QACd,KAAK,CAAC,KAAK,EAAE,CAAA;QACb,IAAI,CAAC;YACH,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAA;QACnD,CAAC;QAAC,MAAM,CAAC;YACP,eAAe;QACjB,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/watcher.cjs
CHANGED
|
@@ -4,18 +4,26 @@
|
|
|
4
4
|
* Runs as a detached background process started by `litmus init`.
|
|
5
5
|
* Usage: node watcher.cjs <projectDir> <activityLogPath>
|
|
6
6
|
*
|
|
7
|
+
* Uses Node's built-in fs.watch (no external dependencies).
|
|
7
8
|
* Writes newline-delimited JSON to the activity log:
|
|
8
|
-
* { "ts": "ISO-8601", "type": "
|
|
9
|
+
* { "ts": "ISO-8601", "type": "rename"|"change", "path": "relative/path" }
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
const chokidar = require("chokidar")
|
|
12
12
|
const fs = require("fs")
|
|
13
13
|
const path = require("path")
|
|
14
14
|
|
|
15
15
|
const [, , projectDir, activityLogPath] = process.argv
|
|
16
16
|
|
|
17
|
+
process.stderr.write(`[watcher] starting: projectDir=${projectDir} log=${activityLogPath}\n`)
|
|
18
|
+
process.stderr.write(`[watcher] node ${process.version}, platform=${process.platform}, arch=${process.arch}\n`)
|
|
19
|
+
|
|
17
20
|
if (!projectDir || !activityLogPath) {
|
|
18
|
-
process.stderr.write("
|
|
21
|
+
process.stderr.write("[watcher] missing arguments\n")
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!fs.existsSync(projectDir)) {
|
|
26
|
+
process.stderr.write(`[watcher] projectDir does not exist: ${projectDir}\n`)
|
|
19
27
|
process.exit(1)
|
|
20
28
|
}
|
|
21
29
|
|
|
@@ -25,34 +33,47 @@ fs.mkdirSync(path.dirname(activityLogPath), { recursive: true })
|
|
|
25
33
|
// Open the log file for appending
|
|
26
34
|
const log = fs.createWriteStream(activityLogPath, { flags: "a" })
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
const IGNORED = [
|
|
37
|
+
/[/\\]\./, // dotfiles and dotdirs (including .git, .litmus)
|
|
38
|
+
/node_modules/,
|
|
39
|
+
/__pycache__/,
|
|
40
|
+
/\.pyc$/,
|
|
41
|
+
/\.class$/,
|
|
42
|
+
/[/\\]venv[/\\]/,
|
|
43
|
+
/[/\\]\.venv[/\\]/,
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
function shouldIgnore(relPath) {
|
|
47
|
+
return IGNORED.some((re) => re.test(relPath))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function write(type, relPath) {
|
|
29
51
|
const event = JSON.stringify({
|
|
30
52
|
ts: new Date().toISOString(),
|
|
31
53
|
type,
|
|
32
|
-
path:
|
|
54
|
+
path: relPath,
|
|
33
55
|
})
|
|
34
56
|
log.write(event + "\n")
|
|
35
57
|
}
|
|
36
58
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/\.pyc$/,
|
|
42
|
-
/\.class$/,
|
|
43
|
-
]
|
|
59
|
+
process.on("uncaughtException", (err) => {
|
|
60
|
+
process.stderr.write(`[watcher] uncaughtException: ${err.stack || err}\n`)
|
|
61
|
+
process.exit(1)
|
|
62
|
+
})
|
|
44
63
|
|
|
45
|
-
|
|
46
|
-
.watch(projectDir, {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },
|
|
64
|
+
try {
|
|
65
|
+
const watcher = fs.watch(projectDir, { recursive: true }, (eventType, filename) => {
|
|
66
|
+
if (!filename) return
|
|
67
|
+
if (shouldIgnore(filename)) return
|
|
68
|
+
write(eventType, filename)
|
|
51
69
|
})
|
|
52
|
-
|
|
53
|
-
.on("
|
|
54
|
-
|
|
55
|
-
.on("error", (err) => {
|
|
56
|
-
// Log errors but don't crash — tracking is non-critical
|
|
57
|
-
process.stderr.write(`[watcher] error: ${err}\n`)
|
|
70
|
+
|
|
71
|
+
watcher.on("error", (err) => {
|
|
72
|
+
process.stderr.write(`[watcher] fs.watch error: ${err}\n`)
|
|
58
73
|
})
|
|
74
|
+
|
|
75
|
+
process.stderr.write("[watcher] started successfully\n")
|
|
76
|
+
} catch (err) {
|
|
77
|
+
process.stderr.write(`[watcher] failed to start: ${err.stack || err}\n`)
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "litmus-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "CLI tool for Litmus engineering assessments",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "elenazhao",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"chalk": "^5.3.0",
|
|
20
|
-
"chokidar": "^3.6.0",
|
|
21
20
|
"commander": "^12.1.0",
|
|
22
21
|
"fast-glob": "^3.3.3",
|
|
23
22
|
"ora": "^8.1.1",
|
package/src/lib/tracker.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { spawn } from "child_process"
|
|
2
|
-
import { mkdirSync, writeFileSync } from "fs"
|
|
2
|
+
import { mkdirSync, openSync, writeFileSync } from "fs"
|
|
3
3
|
import path from "path"
|
|
4
4
|
import { fileURLToPath } from "url"
|
|
5
5
|
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Start the
|
|
9
|
+
* Start the file watcher in the background.
|
|
10
10
|
* Spawns dist/watcher.cjs as a detached process; logs file events to
|
|
11
11
|
* <projectDir>/.litmus/activity.jsonl for later inclusion in the submission ZIP.
|
|
12
12
|
*/
|
|
@@ -14,6 +14,7 @@ export function startTracker(projectDir: string): void {
|
|
|
14
14
|
const litmusDir = path.join(projectDir, ".litmus")
|
|
15
15
|
const activityLog = path.join(litmusDir, "activity.jsonl")
|
|
16
16
|
const pidFile = path.join(litmusDir, "tracker.pid")
|
|
17
|
+
const errLog = path.join(litmusDir, "tracker.log")
|
|
17
18
|
const watcherScript = path.join(__dirname, "watcher.cjs")
|
|
18
19
|
|
|
19
20
|
try {
|
|
@@ -22,12 +23,11 @@ export function startTracker(projectDir: string): void {
|
|
|
22
23
|
// Non-critical
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
+
const errFd = openSync(errLog, "a")
|
|
26
27
|
|
|
27
28
|
const child = spawn("node", [watcherScript, projectDir, activityLog], {
|
|
28
29
|
detached: true,
|
|
29
|
-
stdio: "ignore",
|
|
30
|
-
cwd: packageRoot,
|
|
30
|
+
stdio: ["ignore", "ignore", errFd],
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
if (child.pid) {
|
package/src/lib/watcher.cjs
CHANGED
|
@@ -4,18 +4,26 @@
|
|
|
4
4
|
* Runs as a detached background process started by `litmus init`.
|
|
5
5
|
* Usage: node watcher.cjs <projectDir> <activityLogPath>
|
|
6
6
|
*
|
|
7
|
+
* Uses Node's built-in fs.watch (no external dependencies).
|
|
7
8
|
* Writes newline-delimited JSON to the activity log:
|
|
8
|
-
* { "ts": "ISO-8601", "type": "
|
|
9
|
+
* { "ts": "ISO-8601", "type": "rename"|"change", "path": "relative/path" }
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
const chokidar = require("chokidar")
|
|
12
12
|
const fs = require("fs")
|
|
13
13
|
const path = require("path")
|
|
14
14
|
|
|
15
15
|
const [, , projectDir, activityLogPath] = process.argv
|
|
16
16
|
|
|
17
|
+
process.stderr.write(`[watcher] starting: projectDir=${projectDir} log=${activityLogPath}\n`)
|
|
18
|
+
process.stderr.write(`[watcher] node ${process.version}, platform=${process.platform}, arch=${process.arch}\n`)
|
|
19
|
+
|
|
17
20
|
if (!projectDir || !activityLogPath) {
|
|
18
|
-
process.stderr.write("
|
|
21
|
+
process.stderr.write("[watcher] missing arguments\n")
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!fs.existsSync(projectDir)) {
|
|
26
|
+
process.stderr.write(`[watcher] projectDir does not exist: ${projectDir}\n`)
|
|
19
27
|
process.exit(1)
|
|
20
28
|
}
|
|
21
29
|
|
|
@@ -25,34 +33,47 @@ fs.mkdirSync(path.dirname(activityLogPath), { recursive: true })
|
|
|
25
33
|
// Open the log file for appending
|
|
26
34
|
const log = fs.createWriteStream(activityLogPath, { flags: "a" })
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
const IGNORED = [
|
|
37
|
+
/[/\\]\./, // dotfiles and dotdirs (including .git, .litmus)
|
|
38
|
+
/node_modules/,
|
|
39
|
+
/__pycache__/,
|
|
40
|
+
/\.pyc$/,
|
|
41
|
+
/\.class$/,
|
|
42
|
+
/[/\\]venv[/\\]/,
|
|
43
|
+
/[/\\]\.venv[/\\]/,
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
function shouldIgnore(relPath) {
|
|
47
|
+
return IGNORED.some((re) => re.test(relPath))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function write(type, relPath) {
|
|
29
51
|
const event = JSON.stringify({
|
|
30
52
|
ts: new Date().toISOString(),
|
|
31
53
|
type,
|
|
32
|
-
path:
|
|
54
|
+
path: relPath,
|
|
33
55
|
})
|
|
34
56
|
log.write(event + "\n")
|
|
35
57
|
}
|
|
36
58
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
/\.pyc$/,
|
|
42
|
-
/\.class$/,
|
|
43
|
-
]
|
|
59
|
+
process.on("uncaughtException", (err) => {
|
|
60
|
+
process.stderr.write(`[watcher] uncaughtException: ${err.stack || err}\n`)
|
|
61
|
+
process.exit(1)
|
|
62
|
+
})
|
|
44
63
|
|
|
45
|
-
|
|
46
|
-
.watch(projectDir, {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50 },
|
|
64
|
+
try {
|
|
65
|
+
const watcher = fs.watch(projectDir, { recursive: true }, (eventType, filename) => {
|
|
66
|
+
if (!filename) return
|
|
67
|
+
if (shouldIgnore(filename)) return
|
|
68
|
+
write(eventType, filename)
|
|
51
69
|
})
|
|
52
|
-
|
|
53
|
-
.on("
|
|
54
|
-
|
|
55
|
-
.on("error", (err) => {
|
|
56
|
-
// Log errors but don't crash — tracking is non-critical
|
|
57
|
-
process.stderr.write(`[watcher] error: ${err}\n`)
|
|
70
|
+
|
|
71
|
+
watcher.on("error", (err) => {
|
|
72
|
+
process.stderr.write(`[watcher] fs.watch error: ${err}\n`)
|
|
58
73
|
})
|
|
74
|
+
|
|
75
|
+
process.stderr.write("[watcher] started successfully\n")
|
|
76
|
+
} catch (err) {
|
|
77
|
+
process.stderr.write(`[watcher] failed to start: ${err.stack || err}\n`)
|
|
78
|
+
process.exit(1)
|
|
79
|
+
}
|