litmus-cli 1.0.5 → 1.0.6
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/watcher.cjs +79 -0
- package/package.json +2 -2
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Litmus file activity watcher.
|
|
4
|
+
* Runs as a detached background process started by `litmus init`.
|
|
5
|
+
* Usage: node watcher.cjs <projectDir> <activityLogPath>
|
|
6
|
+
*
|
|
7
|
+
* Uses Node's built-in fs.watch (no external dependencies).
|
|
8
|
+
* Writes newline-delimited JSON to the activity log:
|
|
9
|
+
* { "ts": "ISO-8601", "type": "rename"|"change", "path": "relative/path" }
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require("fs")
|
|
13
|
+
const path = require("path")
|
|
14
|
+
|
|
15
|
+
const [, , projectDir, activityLogPath] = process.argv
|
|
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
|
+
|
|
20
|
+
if (!projectDir || !activityLogPath) {
|
|
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`)
|
|
27
|
+
process.exit(1)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Ensure the log directory exists
|
|
31
|
+
fs.mkdirSync(path.dirname(activityLogPath), { recursive: true })
|
|
32
|
+
|
|
33
|
+
// Open the log file for appending
|
|
34
|
+
const log = fs.createWriteStream(activityLogPath, { flags: "a" })
|
|
35
|
+
|
|
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) {
|
|
51
|
+
const event = JSON.stringify({
|
|
52
|
+
ts: new Date().toISOString(),
|
|
53
|
+
type,
|
|
54
|
+
path: relPath,
|
|
55
|
+
})
|
|
56
|
+
log.write(event + "\n")
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
process.on("uncaughtException", (err) => {
|
|
60
|
+
process.stderr.write(`[watcher] uncaughtException: ${err.stack || err}\n`)
|
|
61
|
+
process.exit(1)
|
|
62
|
+
})
|
|
63
|
+
|
|
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)
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
watcher.on("error", (err) => {
|
|
72
|
+
process.stderr.write(`[watcher] fs.watch error: ${err}\n`)
|
|
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.6",
|
|
4
4
|
"description": "CLI tool for Litmus engineering assessments",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "elenazhao",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"litmus": "dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "tsc && cp src/lib/watcher.cjs dist/watcher.cjs",
|
|
13
|
+
"build": "tsc && cp src/lib/watcher.cjs dist/lib/watcher.cjs",
|
|
14
14
|
"dev": "tsc --watch",
|
|
15
15
|
"start": "node dist/index.js",
|
|
16
16
|
"prepublishOnly": "npm run build"
|