gitwrit 0.2.6 → 0.2.7
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/gitwrit.js +12 -4
- package/package.json +1 -1
- package/src/commands/status.js +67 -23
package/bin/gitwrit.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
+
import { createRequire } from 'module';
|
|
5
|
+
import { fileURLToPath } from 'url';
|
|
6
|
+
import { dirname, join } from 'path';
|
|
4
7
|
import { init } from '../src/commands/init.js';
|
|
5
8
|
import { start } from '../src/commands/start.js';
|
|
6
9
|
import { stop } from '../src/commands/stop.js';
|
|
@@ -15,12 +18,18 @@ import { checkForUpdate, currentVersion } from '../src/updater.js';
|
|
|
15
18
|
import chalk from 'chalk';
|
|
16
19
|
import { TEAL, PINK } from '../src/ui.js';
|
|
17
20
|
|
|
21
|
+
// ── dynamic version from package.json ────────────────────────────────────────
|
|
22
|
+
// never hardcode the version — read it directly from package.json so
|
|
23
|
+
// gitwrit --version always matches the published version automatically.
|
|
24
|
+
const require = createRequire(import.meta.url);
|
|
25
|
+
const PKG = require(join(dirname(fileURLToPath(import.meta.url)), '../package.json'));
|
|
26
|
+
|
|
18
27
|
const program = new Command();
|
|
19
28
|
|
|
20
29
|
program
|
|
21
30
|
.name('gitwrit')
|
|
22
31
|
.description('Private, versioned writing for people who live in the terminal.')
|
|
23
|
-
.version(
|
|
32
|
+
.version(PKG.version)
|
|
24
33
|
.addHelpCommand(false)
|
|
25
34
|
.helpOption(false);
|
|
26
35
|
|
|
@@ -76,8 +85,7 @@ if (process.argv.length <= 2) {
|
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
// ── run command then check for updates ───────────────────────────────────────
|
|
79
|
-
//
|
|
80
|
-
// shows a single hint line at the bottom if a newer version is available.
|
|
88
|
+
// runs after the command completes — never blocks or delays the user.
|
|
81
89
|
program.parseAsync(process.argv).then(async () => {
|
|
82
90
|
const latest = await checkForUpdate();
|
|
83
91
|
if (latest) {
|
|
@@ -88,7 +96,7 @@ program.parseAsync(process.argv).then(async () => {
|
|
|
88
96
|
chalk.dim(' → ') +
|
|
89
97
|
chalk.hex(PINK).bold(latest) +
|
|
90
98
|
chalk.dim(' Run ') +
|
|
91
|
-
chalk.white('npm install -g gitwrit') +
|
|
99
|
+
chalk.white('npm install -g gitwrit@latest') +
|
|
92
100
|
chalk.dim(' to update.')
|
|
93
101
|
);
|
|
94
102
|
}
|
package/package.json
CHANGED
package/src/commands/status.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { readFile } from 'fs/promises';
|
|
2
|
-
import
|
|
2
|
+
import boxen from 'boxen';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { print, timeAgo, TEAL, PINK } from '../ui.js';
|
|
3
5
|
import { PID_FILE } from '../paths.js';
|
|
4
6
|
import { readState, STATE } from '../state.js';
|
|
5
7
|
import { loadGlobalConfig, globalConfigExists } from '../settings.js';
|
|
6
8
|
|
|
9
|
+
// ─── helpers ──────────────────────────────────────────────────────────────────
|
|
10
|
+
|
|
7
11
|
async function getLivePid() {
|
|
8
12
|
try {
|
|
9
13
|
const raw = await readFile(PID_FILE, 'utf8');
|
|
@@ -23,6 +27,27 @@ function formatUptime(startedAt) {
|
|
|
23
27
|
return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
|
|
24
28
|
}
|
|
25
29
|
|
|
30
|
+
// left-padded label + white value — used inside the box
|
|
31
|
+
function row(label, value) {
|
|
32
|
+
return chalk.dim(` ${label.padEnd(13)}`) + chalk.white(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ─── boxen options ────────────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
const BOX_OPTS = {
|
|
38
|
+
padding: { top: 0, bottom: 0, left: 1, right: 2 },
|
|
39
|
+
borderStyle: 'round',
|
|
40
|
+
borderColor: TEAL,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const BOX_OPTS_PINK = {
|
|
44
|
+
padding: { top: 0, bottom: 0, left: 1, right: 2 },
|
|
45
|
+
borderStyle: 'round',
|
|
46
|
+
borderColor: PINK,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ─── main ─────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
26
51
|
export async function status() {
|
|
27
52
|
if (!(await globalConfigExists())) {
|
|
28
53
|
print.gap();
|
|
@@ -32,63 +57,82 @@ export async function status() {
|
|
|
32
57
|
return;
|
|
33
58
|
}
|
|
34
59
|
|
|
35
|
-
const pid
|
|
36
|
-
const state
|
|
60
|
+
const pid = await getLivePid();
|
|
61
|
+
const state = await readState();
|
|
37
62
|
const config = await loadGlobalConfig();
|
|
38
63
|
|
|
39
64
|
print.gap();
|
|
40
65
|
|
|
66
|
+
// ── not running ─────────────────────────────────────────────────────────────
|
|
67
|
+
|
|
41
68
|
if (!pid) {
|
|
42
69
|
if (state.status === STATE.PAUSED) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
const lines = [
|
|
71
|
+
'',
|
|
72
|
+
chalk.hex(PINK).bold(' gitwrit is paused.'),
|
|
73
|
+
'',
|
|
74
|
+
chalk.dim(` Last active ${timeAgo(state.pausedAt)}.`),
|
|
75
|
+
chalk.dim(' Run gitwrit start to resume watching.'),
|
|
76
|
+
'',
|
|
77
|
+
];
|
|
78
|
+
console.log(boxen(lines.join('\n'), BOX_OPTS_PINK));
|
|
48
79
|
} else {
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
const lines = [
|
|
81
|
+
'',
|
|
82
|
+
chalk.dim(' gitwrit is not running.'),
|
|
83
|
+
'',
|
|
84
|
+
chalk.dim(' Run gitwrit start to begin watching.'),
|
|
85
|
+
'',
|
|
86
|
+
];
|
|
87
|
+
console.log(boxen(lines.join('\n'), { ...BOX_OPTS, borderColor: 'gray' }));
|
|
51
88
|
}
|
|
52
89
|
print.gap();
|
|
53
90
|
return;
|
|
54
91
|
}
|
|
55
92
|
|
|
93
|
+
// ── running ──────────────────────────────────────────────────────────────────
|
|
94
|
+
|
|
56
95
|
const resumedAfterSleep = state.resumedAt &&
|
|
57
96
|
(Date.now() - new Date(state.resumedAt)) < 60000;
|
|
58
97
|
|
|
98
|
+
const lines = [''];
|
|
99
|
+
|
|
59
100
|
if (resumedAfterSleep) {
|
|
60
|
-
|
|
101
|
+
lines.push(chalk.hex(TEAL).bold(' gitwrit is running') + chalk.dim(' — resumed after sleep.'));
|
|
61
102
|
} else {
|
|
62
|
-
|
|
103
|
+
lines.push(chalk.hex(TEAL).bold(' gitwrit is running.'));
|
|
63
104
|
}
|
|
64
105
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
106
|
+
lines.push('');
|
|
107
|
+
lines.push(row('Uptime', formatUptime(state.startedAt)));
|
|
108
|
+
lines.push(row('Watching', config.watch.map(w => w.path).join(', ')));
|
|
68
109
|
|
|
69
110
|
if (state.sessionBranch) {
|
|
70
|
-
|
|
111
|
+
lines.push(row('Branch', state.sessionBranch) + chalk.hex(PINK).dim(' (autogenerated)'));
|
|
71
112
|
} else {
|
|
72
|
-
|
|
113
|
+
lines.push(row('Branch', 'Current branch'));
|
|
73
114
|
}
|
|
74
115
|
|
|
75
116
|
if (state.sessionCommits > 0) {
|
|
76
|
-
|
|
117
|
+
lines.push(row('Commits', `${state.sessionCommits} this session`));
|
|
77
118
|
}
|
|
78
119
|
|
|
79
120
|
if (state.lastCommittedAt) {
|
|
80
121
|
const fileLabel = state.lastCommittedFile ? ` (${state.lastCommittedFile})` : '';
|
|
81
|
-
|
|
122
|
+
lines.push(row('Last commit', `${timeAgo(state.lastCommittedAt)}${fileLabel}`));
|
|
82
123
|
}
|
|
83
124
|
|
|
84
125
|
if (state.lastPushedAt) {
|
|
85
|
-
|
|
126
|
+
lines.push(row('Last push', timeAgo(state.lastPushedAt)));
|
|
86
127
|
}
|
|
87
128
|
|
|
88
129
|
if (resumedAfterSleep && state.catchUpCommits > 0) {
|
|
89
|
-
|
|
90
|
-
|
|
130
|
+
lines.push('');
|
|
131
|
+
lines.push(chalk.hex(TEAL)(` ✔ ${state.catchUpCommits} file${state.catchUpCommits !== 1 ? 's' : ''} committed on wake.`));
|
|
91
132
|
}
|
|
92
133
|
|
|
134
|
+
lines.push('');
|
|
135
|
+
|
|
136
|
+
console.log(boxen(lines.join('\n'), BOX_OPTS));
|
|
93
137
|
print.gap();
|
|
94
|
-
}
|
|
138
|
+
}
|