project-mgr 0.1.1 → 0.1.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/.env_sample +5 -3
- package/CHANGELOG.md +6 -0
- package/README.md +11 -9
- package/README_CN.md +11 -9
- package/dist/db.js +2 -1
- package/docs/architecture.md +1 -1
- package/package.json +1 -1
- package/src/db.ts +2 -1
- package/test/core.test.ts +6 -3
package/.env_sample
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
# SQLite database
|
|
2
|
-
|
|
1
|
+
# Optional SQLite database override. When unset, the database is stored at
|
|
2
|
+
# ~/.local/share/project-mgr/project-mgr.sqlite.
|
|
3
|
+
# Use a literal absolute path here; .env files do not expand ~ or $HOME.
|
|
4
|
+
# PMGR_DB_PATH=/absolute/path/to/project-mgr.sqlite
|
|
3
5
|
|
|
4
6
|
# For isolated manual testing, use a separate database instead:
|
|
5
|
-
# PMGR_DB_PATH
|
|
7
|
+
# PMGR_DB_PATH=/tmp/project-mgr-manual-test.sqlite
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -23,7 +23,9 @@ npm install --global project-mgr
|
|
|
23
23
|
pmgr current
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
The database defaults to
|
|
26
|
+
The database defaults to `~/.local/share/project-mgr/project-mgr.sqlite`, regardless of the directory where `pmgr` is executed. The CLI resolves this to an absolute path using the current user's home directory and creates the parent directory automatically.
|
|
27
|
+
|
|
28
|
+
Set `PMGR_DB_PATH` to use another location:
|
|
27
29
|
|
|
28
30
|
```bash
|
|
29
31
|
PMGR_DB_PATH=/absolute/path/projects.sqlite npx --yes project-mgr current
|
|
@@ -53,26 +55,26 @@ During development, run the TypeScript CLI directly:
|
|
|
53
55
|
pnpm pmgr current
|
|
54
56
|
```
|
|
55
57
|
|
|
56
|
-
The default
|
|
58
|
+
The default database path is:
|
|
57
59
|
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
+
```text
|
|
61
|
+
~/.local/share/project-mgr/project-mgr.sqlite
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
`PMGR_DB_PATH` is optional in `.env_sample`. Set it in `.env` to use another location, or override it for one command:
|
|
63
65
|
|
|
64
66
|
```bash
|
|
65
67
|
PMGR_DB_PATH=/absolute/path/projects.sqlite pnpm start current
|
|
66
68
|
```
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
Use a literal absolute path in `.env`; `.env` files do not expand `~` or `$HOME`. The database is created automatically when the first valid command runs.
|
|
69
71
|
|
|
70
72
|
### Use an isolated test database
|
|
71
73
|
|
|
72
74
|
For manual testing, set a persistent path in `.env` that is separate from production data:
|
|
73
75
|
|
|
74
76
|
```dotenv
|
|
75
|
-
PMGR_DB_PATH
|
|
77
|
+
PMGR_DB_PATH=/tmp/project-mgr-manual-test.sqlite
|
|
76
78
|
```
|
|
77
79
|
|
|
78
80
|
Then run commands normally:
|
|
@@ -88,7 +90,7 @@ pnpm start history --project test-project
|
|
|
88
90
|
|
|
89
91
|
Project keys must match exactly: a record added to `test-project` is not part of `project-mgr` history. Empty human-readable list queries print `No entries found.`; with `--json`, they print `[]`.
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
Delete `/tmp/project-mgr-manual-test.sqlite` when it is no longer needed.
|
|
92
94
|
|
|
93
95
|
Automated tests use an in-memory database or SQLite files in the system temporary directory; they do not read or write the default database. `PMGR_DB_PATH=:memory:` also works for one command, but each CLI command runs in a separate process and its data disappears when the command exits, so it is not suitable for consecutive manual tests.
|
|
94
96
|
|
|
@@ -189,7 +191,7 @@ Exports omit the database-internal `id` and `recordedAt` fields and can be impor
|
|
|
189
191
|
```bash
|
|
190
192
|
pnpm start export --format jsonl > project-statuses.jsonl
|
|
191
193
|
|
|
192
|
-
PMGR_DB_PATH
|
|
194
|
+
PMGR_DB_PATH=/tmp/project-mgr-restored.sqlite \
|
|
193
195
|
pnpm start import project-statuses.jsonl
|
|
194
196
|
```
|
|
195
197
|
|
package/README_CN.md
CHANGED
|
@@ -23,7 +23,9 @@ npm install --global project-mgr
|
|
|
23
23
|
pmgr current
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
无论在哪个目录执行 `pmgr`,数据库都默认位于 `~/.local/share/project-mgr/project-mgr.sqlite`。CLI 会根据当前用户的主目录将其解析为绝对路径,并自动创建父目录。
|
|
27
|
+
|
|
28
|
+
通过 `PMGR_DB_PATH` 指定其他位置:
|
|
27
29
|
|
|
28
30
|
```bash
|
|
29
31
|
PMGR_DB_PATH=/absolute/path/projects.sqlite npx --yes project-mgr current
|
|
@@ -53,26 +55,26 @@ pnpm start current
|
|
|
53
55
|
pnpm pmgr current
|
|
54
56
|
```
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
默认数据库路径是:
|
|
57
59
|
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
+
```text
|
|
61
|
+
~/.local/share/project-mgr/project-mgr.sqlite
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
`.env_sample` 中的 `PMGR_DB_PATH` 是可选配置。可以在 `.env` 中指定其他位置,也可以为单条命令临时覆盖:
|
|
63
65
|
|
|
64
66
|
```bash
|
|
65
67
|
PMGR_DB_PATH=/absolute/path/projects.sqlite pnpm start current
|
|
66
68
|
```
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
在 `.env` 中应填写字面量绝对路径;`.env` 文件不会展开 `~` 或 `$HOME`。数据库会在第一次执行有效命令时自动创建。
|
|
69
71
|
|
|
70
72
|
### 使用独立测试数据库
|
|
71
73
|
|
|
72
74
|
手工测试时,建议在 `.env` 中固定设置一个与正式数据分离的路径:
|
|
73
75
|
|
|
74
76
|
```dotenv
|
|
75
|
-
PMGR_DB_PATH
|
|
77
|
+
PMGR_DB_PATH=/tmp/project-mgr-manual-test.sqlite
|
|
76
78
|
```
|
|
77
79
|
|
|
78
80
|
随后正常执行命令:
|
|
@@ -88,7 +90,7 @@ pnpm start history --project test-project
|
|
|
88
90
|
|
|
89
91
|
项目键必须完全一致:写入 `test-project` 的记录不会出现在 `project-mgr` 的历史中。人类可读的空列表查询会输出 `No entries found.`;使用 `--json` 时则输出 `[]`。
|
|
90
92
|
|
|
91
|
-
|
|
93
|
+
不需要保留时,可以删除 `/tmp/project-mgr-manual-test.sqlite`。
|
|
92
94
|
|
|
93
95
|
自动化测试会使用内存数据库或系统临时目录中的 SQLite 文件,不会读写默认数据库。`PMGR_DB_PATH=:memory:` 也可用于单条命令,但每个 CLI 命令都是独立进程,命令结束后数据就会消失,不适合连续手工测试。
|
|
94
96
|
|
|
@@ -189,7 +191,7 @@ pnpm start import --file statuses.jsonl --json
|
|
|
189
191
|
```bash
|
|
190
192
|
pnpm start export --format jsonl > project-statuses.jsonl
|
|
191
193
|
|
|
192
|
-
PMGR_DB_PATH
|
|
194
|
+
PMGR_DB_PATH=/tmp/project-mgr-restored.sqlite \
|
|
193
195
|
pnpm start import project-statuses.jsonl
|
|
194
196
|
```
|
|
195
197
|
|
package/dist/db.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
2
|
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, resolve } from "node:path";
|
|
4
5
|
import { validateStatusEntry, ValidationError, } from "./domain.js";
|
|
5
6
|
const migration = `
|
|
@@ -28,7 +29,7 @@ CREATE INDEX IF NOT EXISTS idx_status_entries_project_occurred ON status_entries
|
|
|
28
29
|
`;
|
|
29
30
|
export function databasePath() {
|
|
30
31
|
return (process.env.PMGR_DB_PATH ||
|
|
31
|
-
resolve(
|
|
32
|
+
resolve(homedir(), ".local", "share", "project-mgr", "project-mgr.sqlite"));
|
|
32
33
|
}
|
|
33
34
|
export function openLedger(path = databasePath()) {
|
|
34
35
|
if (path !== ":memory:")
|
package/docs/architecture.md
CHANGED
|
@@ -57,7 +57,7 @@ The `project_id, occurred_at DESC, id DESC` index supports current-status and hi
|
|
|
57
57
|
|
|
58
58
|
After opening the database, `openLedger()` enables foreign keys, creates the migration table, and checks for and applies migration 1 within a `BEGIN IMMEDIATE` transaction. The immediate transaction prevents migration checks and writes from interleaving when several local processes open the database for the first time at once.
|
|
59
59
|
|
|
60
|
-
The database path is read from `PMGR_DB_PATH` first; otherwise, it uses
|
|
60
|
+
The database path is read from `PMGR_DB_PATH` first; otherwise, it uses the absolute path `~/.local/share/project-mgr/project-mgr.sqlite`, resolved from the current user's home directory. Non-memory databases create their parent directory automatically.
|
|
61
61
|
|
|
62
62
|
## Write flow
|
|
63
63
|
|
package/package.json
CHANGED
package/src/db.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Database from "better-sqlite3";
|
|
2
2
|
import { mkdirSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import { dirname, resolve } from "node:path";
|
|
4
5
|
import {
|
|
5
6
|
type Source,
|
|
@@ -46,7 +47,7 @@ CREATE INDEX IF NOT EXISTS idx_status_entries_project_occurred ON status_entries
|
|
|
46
47
|
export function databasePath(): string {
|
|
47
48
|
return (
|
|
48
49
|
process.env.PMGR_DB_PATH ||
|
|
49
|
-
resolve(
|
|
50
|
+
resolve(homedir(), ".local", "share", "project-mgr", "project-mgr.sqlite")
|
|
50
51
|
);
|
|
51
52
|
}
|
|
52
53
|
|
package/test/core.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
3
|
+
import { homedir, tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import test from "node:test";
|
|
6
6
|
import { run } from "../src/cli.js";
|
|
@@ -171,7 +171,7 @@ test("import validates before transaction and default source is import", () => {
|
|
|
171
171
|
db.close();
|
|
172
172
|
});
|
|
173
173
|
|
|
174
|
-
test("database path
|
|
174
|
+
test("database path has a stable default and environment override creates its parent directory", () => {
|
|
175
175
|
const directory = mkdtempSync(join(tmpdir(), "pmgr-"));
|
|
176
176
|
const previous = process.env.PMGR_DB_PATH;
|
|
177
177
|
process.env.PMGR_DB_PATH = join(directory, "nested", "ledger.sqlite");
|
|
@@ -180,7 +180,10 @@ test("database path uses environment override and file migration creates parent
|
|
|
180
180
|
db.close();
|
|
181
181
|
if (previous === undefined) delete process.env.PMGR_DB_PATH;
|
|
182
182
|
else process.env.PMGR_DB_PATH = previous;
|
|
183
|
-
assert.
|
|
183
|
+
assert.equal(
|
|
184
|
+
databasePath(),
|
|
185
|
+
join(homedir(), ".local", "share", "project-mgr", "project-mgr.sqlite"),
|
|
186
|
+
);
|
|
184
187
|
rmSync(directory, { recursive: true, force: true });
|
|
185
188
|
});
|
|
186
189
|
|