@doist/cli-core 0.5.0 → 0.6.0
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/CHANGELOG.md +6 -0
- package/README.md +94 -4
- package/dist/commands/changelog.d.ts +56 -0
- package/dist/commands/changelog.d.ts.map +1 -0
- package/dist/commands/changelog.js +159 -0
- package/dist/commands/changelog.js.map +1 -0
- package/dist/commands/errors.d.ts +7 -0
- package/dist/commands/errors.d.ts.map +1 -0
- package/dist/commands/errors.js +2 -0
- package/dist/commands/errors.js.map +1 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +2 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/markdown.d.ts +53 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +71 -0
- package/dist/markdown.js.map +1 -0
- package/package.json +24 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [0.6.0](https://github.com/Doist/cli-core/compare/v0.5.0...v0.6.0) (2026-05-09)
|
|
2
|
+
|
|
3
|
+
### Features
|
|
4
|
+
|
|
5
|
+
* add ./markdown and ./commands subpaths (optional peer-dep extractions) ([#8](https://github.com/Doist/cli-core/issues/8)) ([6b2ad9d](https://github.com/Doist/cli-core/commit/6b2ad9d5a23b5d1d9ae83a2272e959e927a82d40))
|
|
6
|
+
|
|
1
7
|
## [0.5.0](https://github.com/Doist/cli-core/compare/v0.4.0...v0.5.0) (2026-05-08)
|
|
2
8
|
|
|
3
9
|
### Features
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Shared core utilities for Doist CLI projects ([todoist-cli](https://github.com/Doist/todoist-cli), [twist-cli](https://github.com/Doist/twist-cli), [outline-cli](https://github.com/Doist/outline-cli)).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
TypeScript, ESM-only, Node ≥ 20.18.1.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -10,17 +10,107 @@ Shared core utilities for Doist CLI projects ([todoist-cli](https://github.com/D
|
|
|
10
10
|
npm install @doist/cli-core
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## What's in it
|
|
14
|
+
|
|
15
|
+
| Module | Key exports | Purpose |
|
|
16
|
+
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
17
|
+
| `commands` (subpath) | `registerChangelogCommand` (more to come) | Commander wiring for cli-core's standard commands (e.g. `<cli> changelog`). **Requires** `commander` as an optional peer-dep. |
|
|
18
|
+
| `config` | `getConfigPath`, `readConfig`, `readConfigStrict`, `writeConfig`, `updateConfig` | Read / write a per-CLI JSON config file with typed error codes for broken or missing state. |
|
|
19
|
+
| `empty` | `printEmpty` | Print an empty-state message gated on `--json` / `--ndjson` so machine consumers never see human strings on stdout. |
|
|
20
|
+
| `errors` | `CliError` | Typed CLI error class with `code` and exit-code mapping. |
|
|
21
|
+
| `global-args` | `parseGlobalArgs`, `createGlobalArgsStore`, `createAccessibleGate`, `createSpinnerGate`, `getProgressJsonlPath`, `isProgressJsonlEnabled` | Parse well-known global flags (`--json`, `--ndjson`, `--quiet`, `--verbose`, `--accessible`, `--no-spinner`, `--progress-jsonl`) and derive predicates from them. |
|
|
22
|
+
| `json` | `formatJson`, `formatNdjson` | Stable JSON / newline-delimited JSON formatting for stdout. |
|
|
23
|
+
| `markdown` (subpath) | `preloadMarkdown`, `renderMarkdown`, `TerminalRendererOptions` | Lazy-init terminal markdown renderer. **Requires** `marked` and `marked-terminal-renderer` as peer-deps — install only if your CLI uses this subpath. |
|
|
24
|
+
| `options` | `ViewOptions` | Type contract for `{ json?, ndjson? }` per-command options that machine-output gates derive from. |
|
|
25
|
+
| `spinner` | `createSpinner` | Loading spinner factory wrapping `yocto-spinner` with disable gates. |
|
|
26
|
+
| `terminal` | `isCI`, `isStderrTTY`, `isStdinTTY`, `isStdoutTTY` | TTY / CI detection helpers. |
|
|
27
|
+
| `testing` (subpath) | `describeEmptyMachineOutput` | Vitest helpers reusable by consuming CLIs (e.g. parametrised empty-state suite covering `--json` / `--ndjson` / human modes). |
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Global args + spinner gate
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createGlobalArgsStore, createSpinnerGate, createSpinner } from '@doist/cli-core'
|
|
35
|
+
|
|
36
|
+
const store = createGlobalArgsStore()
|
|
37
|
+
export const isJsonMode = () => store.get().json
|
|
38
|
+
|
|
39
|
+
const shouldDisableSpinner = createSpinnerGate({
|
|
40
|
+
envVar: 'TD_SPINNER',
|
|
41
|
+
getArgs: store.get,
|
|
42
|
+
})
|
|
43
|
+
const { withSpinner } = createSpinner({ isDisabled: shouldDisableSpinner })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Empty-state print
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import { printEmpty } from '@doist/cli-core'
|
|
50
|
+
|
|
51
|
+
if (tasks.length === 0) {
|
|
52
|
+
printEmpty({ options, message: 'No tasks found.' })
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Markdown rendering (optional subpath)
|
|
58
|
+
|
|
59
|
+
Install the peer-deps in the consuming CLI:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install marked marked-terminal-renderer
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { preloadMarkdown, renderMarkdown } from '@doist/cli-core/markdown'
|
|
69
|
+
|
|
70
|
+
if (!options.json && !options.raw) {
|
|
71
|
+
await preloadMarkdown()
|
|
72
|
+
}
|
|
73
|
+
console.log(await renderMarkdown(comment.body))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
If the peer-deps are missing, `preloadMarkdown` throws a clear error pointing to the install command. TypeScript will also fail to resolve the subpath's types until the peers are installed.
|
|
77
|
+
|
|
78
|
+
### Standard commands (optional subpath)
|
|
79
|
+
|
|
80
|
+
Install the peer-dep in the consuming CLI:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install commander
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then wire `<cli> changelog` in one call:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { dirname, join } from 'node:path'
|
|
90
|
+
import { fileURLToPath } from 'node:url'
|
|
91
|
+
import { registerChangelogCommand } from '@doist/cli-core/commands'
|
|
92
|
+
import packageJson from '../package.json' with { type: 'json' }
|
|
93
|
+
|
|
94
|
+
registerChangelogCommand(program, {
|
|
95
|
+
path: join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'CHANGELOG.md'),
|
|
96
|
+
repoUrl: 'https://github.com/Doist/todoist-cli',
|
|
97
|
+
version: packageJson.version,
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The helper throws `CliError` (`INVALID_TYPE` for a bad `--count`, `FILE_READ_ERROR` if the file can't be read) so the CLI's top-level error handler formats and exits.
|
|
102
|
+
|
|
13
103
|
## Development
|
|
14
104
|
|
|
15
105
|
```bash
|
|
16
106
|
npm install
|
|
17
107
|
npm run build
|
|
18
108
|
npm test
|
|
19
|
-
npm run check #
|
|
20
|
-
npm run fix #
|
|
109
|
+
npm run check # oxlint + oxfmt --check (PR gate)
|
|
110
|
+
npm run fix # oxlint --fix + oxfmt
|
|
21
111
|
```
|
|
22
112
|
|
|
23
|
-
|
|
113
|
+
See [AGENTS.md](AGENTS.md) for project conventions, including the rule that this README is kept in sync with public API changes.
|
|
24
114
|
|
|
25
115
|
## License
|
|
26
116
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
export type ChangelogHeadingLevel = 1 | 2 | 'flexible';
|
|
3
|
+
export type ChangelogBulletMarker = '*' | '-';
|
|
4
|
+
export type ChangelogCommandOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Absolute path to the consuming CLI's `CHANGELOG.md`. Resolve from the
|
|
7
|
+
* caller's `import.meta.url` so it works in both `src/` and built `dist/`.
|
|
8
|
+
*/
|
|
9
|
+
path: string;
|
|
10
|
+
/** Repo URL with no trailing slash; the `/blob/v<version>/CHANGELOG.md` suffix is appended. */
|
|
11
|
+
repoUrl: string;
|
|
12
|
+
/** Package version embedded in the "View full changelog" link. */
|
|
13
|
+
version: string;
|
|
14
|
+
/** Default value for the `-n/--count` flag. Default: `5`. */
|
|
15
|
+
defaultCount?: number;
|
|
16
|
+
/** Heading level used for version rows. Default: `2` (i.e. `## 1.2.3`). */
|
|
17
|
+
headingLevel?: ChangelogHeadingLevel;
|
|
18
|
+
/** Bullet markers parsed and rendered. Default: `['*']`. */
|
|
19
|
+
bulletMarkers?: ReadonlyArray<ChangelogBulletMarker>;
|
|
20
|
+
/** Indent continuation lines after a bullet (twist-style wrapped bullets). Default: `false`. */
|
|
21
|
+
continuationIndent?: boolean;
|
|
22
|
+
/** Drop versions empty after cleaning (e.g. deps-only releases). Default: `false`. */
|
|
23
|
+
filterEmptyVersions?: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare function formatInline(text: string): string;
|
|
26
|
+
export declare function formatForTerminal(text: string, options: ChangelogCommandOptions): string;
|
|
27
|
+
export declare function cleanChangelog(text: string, options: ChangelogCommandOptions): string;
|
|
28
|
+
export declare function parseChangelog(content: string, count: number, options: ChangelogCommandOptions): {
|
|
29
|
+
text: string;
|
|
30
|
+
hasMore: boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Register the standard `<cli> changelog` command on a Commander program. The
|
|
34
|
+
* command reads `options.path`, prints the latest `--count` versions with
|
|
35
|
+
* conventional-commit boilerplate stripped, and appends a "View full
|
|
36
|
+
* changelog" link to the matching tag on GitHub.
|
|
37
|
+
*
|
|
38
|
+
* Errors as `CliError`: `INVALID_TYPE` for a non-positive `--count`,
|
|
39
|
+
* `FILE_READ_ERROR` if the file cannot be read. The consumer's top-level
|
|
40
|
+
* error handler is expected to format and exit.
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { dirname, join } from 'node:path'
|
|
44
|
+
* import { fileURLToPath } from 'node:url'
|
|
45
|
+
* import { registerChangelogCommand } from '@doist/cli-core/commands'
|
|
46
|
+
* import packageJson from '../package.json' with { type: 'json' }
|
|
47
|
+
*
|
|
48
|
+
* registerChangelogCommand(program, {
|
|
49
|
+
* path: join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'CHANGELOG.md'),
|
|
50
|
+
* repoUrl: 'https://github.com/Doist/todoist-cli',
|
|
51
|
+
* version: packageJson.version,
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function registerChangelogCommand(program: Command, options: ChangelogCommandOptions): void;
|
|
56
|
+
//# sourceMappingURL=changelog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog.d.ts","sourceRoot":"","sources":["../../src/commands/changelog.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGxC,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAA;AACtD,MAAM,MAAM,qBAAqB,GAAG,GAAG,GAAG,GAAG,CAAA;AAE7C,MAAM,MAAM,uBAAuB,GAAG;IAClC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ,+FAA+F;IAC/F,OAAO,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAA;IACf,6DAA6D;IAC7D,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,4DAA4D;IAC5D,aAAa,CAAC,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAA;IACpD,gGAAgG;IAChG,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,sFAAsF;IACtF,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AA6BD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,MAAM,CA8BxF;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAwBrF;AASD,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,uBAAuB,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAoBpC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,uBAAuB,GAAG,IAAI,CA2BjG"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { CliError } from '../errors.js';
|
|
4
|
+
function resolve(options) {
|
|
5
|
+
return {
|
|
6
|
+
path: options.path,
|
|
7
|
+
repoUrl: options.repoUrl,
|
|
8
|
+
version: options.version,
|
|
9
|
+
defaultCount: options.defaultCount ?? 5,
|
|
10
|
+
headingLevel: options.headingLevel ?? 2,
|
|
11
|
+
bulletMarkers: options.bulletMarkers ?? ['*'],
|
|
12
|
+
continuationIndent: options.continuationIndent ?? false,
|
|
13
|
+
filterEmptyVersions: options.filterEmptyVersions ?? false,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function headingPrefixSrc(level) {
|
|
17
|
+
if (level === 1)
|
|
18
|
+
return '#';
|
|
19
|
+
if (level === 2)
|
|
20
|
+
return '##';
|
|
21
|
+
return '#{1,2}';
|
|
22
|
+
}
|
|
23
|
+
function bulletCharClass(markers) {
|
|
24
|
+
if (markers.length === 1)
|
|
25
|
+
return markers[0] === '*' ? '\\*' : '-';
|
|
26
|
+
return '[*-]';
|
|
27
|
+
}
|
|
28
|
+
export function formatInline(text) {
|
|
29
|
+
return text
|
|
30
|
+
.replace(/\*\*([^*]+)\*\*/g, (_, content) => chalk.bold(content))
|
|
31
|
+
.replace(/`([^`]+)`/g, (_, code) => chalk.cyan(code));
|
|
32
|
+
}
|
|
33
|
+
export function formatForTerminal(text, options) {
|
|
34
|
+
const { headingLevel, bulletMarkers, continuationIndent } = resolve(options);
|
|
35
|
+
const headerRe = new RegExp(`^${headingPrefixSrc(headingLevel)} `);
|
|
36
|
+
const isBulletLine = (line) => bulletMarkers.some((m) => line.startsWith(`${m} `));
|
|
37
|
+
let inBullet = false;
|
|
38
|
+
return text
|
|
39
|
+
.split('\n')
|
|
40
|
+
.map((line) => {
|
|
41
|
+
if (headerRe.test(line)) {
|
|
42
|
+
inBullet = false;
|
|
43
|
+
return chalk.green.bold(line.replace(headerRe, ''));
|
|
44
|
+
}
|
|
45
|
+
if (line.startsWith('### ')) {
|
|
46
|
+
inBullet = false;
|
|
47
|
+
return chalk.bold(line.slice(4));
|
|
48
|
+
}
|
|
49
|
+
if (isBulletLine(line)) {
|
|
50
|
+
inBullet = true;
|
|
51
|
+
return ` ${chalk.dim('•')} ${formatInline(line.slice(2))}`;
|
|
52
|
+
}
|
|
53
|
+
if (continuationIndent && inBullet && line.length > 0) {
|
|
54
|
+
return ` ${formatInline(line)}`;
|
|
55
|
+
}
|
|
56
|
+
if (line.length === 0) {
|
|
57
|
+
inBullet = false;
|
|
58
|
+
}
|
|
59
|
+
return formatInline(line);
|
|
60
|
+
})
|
|
61
|
+
.join('\n');
|
|
62
|
+
}
|
|
63
|
+
export function cleanChangelog(text, options) {
|
|
64
|
+
const { headingLevel, bulletMarkers } = resolve(options);
|
|
65
|
+
const bullets = bulletCharClass(bulletMarkers);
|
|
66
|
+
const headerSrc = headingPrefixSrc(headingLevel);
|
|
67
|
+
return (text
|
|
68
|
+
// Version headers: `## [1.2.3](url)` → `## 1.2.3` (heading level honoured).
|
|
69
|
+
.replace(new RegExp(`(${headerSrc}) \\[([^\\]]+)\\]\\([^)]*\\)`, 'g'), '$1 $2')
|
|
70
|
+
// Plain commit-hash parens: ` (abc1234)` and ` ([abc1234](url))`.
|
|
71
|
+
.replace(/ \([a-f0-9]{7}\)/g, '')
|
|
72
|
+
.replace(/ \(\[[a-f0-9]{7}\]\([^)]*\)\)/g, '')
|
|
73
|
+
// Issue / PR links: `[#nnn](url)` → `#nnn`.
|
|
74
|
+
.replace(/\[#(\d+)\]\([^)]*\)/g, '#$1')
|
|
75
|
+
// Drop `**deps:**` lines wholesale; not useful to end users.
|
|
76
|
+
.replace(new RegExp(`^${bullets} \\*\\*deps:\\*\\*.*$`, 'gm'), '')
|
|
77
|
+
// Drop `**scope:**` prefixes, keep the content: `**task:** foo` → `foo`.
|
|
78
|
+
.replace(/\*\*[\w-]+:\*\* /g, '')
|
|
79
|
+
// Collapse blank-line runs left by removed deps lines.
|
|
80
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
81
|
+
// Drop now-empty section headers (e.g. `### Bug Fixes` with no items).
|
|
82
|
+
// The lookahead includes `### ` so consecutive empty sections all peel
|
|
83
|
+
// away, not just the last one before a version row.
|
|
84
|
+
.replace(new RegExp(`### [\\w ]+\\n\\n(?=${headerSrc} |### |$)`, 'gm'), ''));
|
|
85
|
+
}
|
|
86
|
+
function isEmptyAfterClean(section, options) {
|
|
87
|
+
const { headingLevel } = resolve(options);
|
|
88
|
+
const cleaned = cleanChangelog(section, options);
|
|
89
|
+
const headerRe = new RegExp(`^${headingPrefixSrc(headingLevel)} .+$`, 'm');
|
|
90
|
+
return cleaned.replace(headerRe, '').trim().length === 0;
|
|
91
|
+
}
|
|
92
|
+
export function parseChangelog(content, count, options) {
|
|
93
|
+
const { headingLevel, filterEmptyVersions } = resolve(options);
|
|
94
|
+
const versionHeaderSrc = `${headingPrefixSrc(headingLevel)} (?:\\d|\\[)`;
|
|
95
|
+
const splitRe = new RegExp(`\\n(?=${versionHeaderSrc})`);
|
|
96
|
+
const matchRe = new RegExp(`^${versionHeaderSrc}`);
|
|
97
|
+
const allVersions = content.split(splitRe).filter((s) => matchRe.test(s));
|
|
98
|
+
const versionSections = filterEmptyVersions
|
|
99
|
+
? allVersions.filter((s) => !isEmptyAfterClean(s, options))
|
|
100
|
+
: allVersions;
|
|
101
|
+
const selected = versionSections.slice(0, count);
|
|
102
|
+
if (selected.length === 0) {
|
|
103
|
+
return { text: 'No changelog entries found.', hasMore: false };
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
text: cleanChangelog(selected.join('\n').trimEnd(), options),
|
|
107
|
+
hasMore: versionSections.length > count,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Register the standard `<cli> changelog` command on a Commander program. The
|
|
112
|
+
* command reads `options.path`, prints the latest `--count` versions with
|
|
113
|
+
* conventional-commit boilerplate stripped, and appends a "View full
|
|
114
|
+
* changelog" link to the matching tag on GitHub.
|
|
115
|
+
*
|
|
116
|
+
* Errors as `CliError`: `INVALID_TYPE` for a non-positive `--count`,
|
|
117
|
+
* `FILE_READ_ERROR` if the file cannot be read. The consumer's top-level
|
|
118
|
+
* error handler is expected to format and exit.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { dirname, join } from 'node:path'
|
|
122
|
+
* import { fileURLToPath } from 'node:url'
|
|
123
|
+
* import { registerChangelogCommand } from '@doist/cli-core/commands'
|
|
124
|
+
* import packageJson from '../package.json' with { type: 'json' }
|
|
125
|
+
*
|
|
126
|
+
* registerChangelogCommand(program, {
|
|
127
|
+
* path: join(dirname(fileURLToPath(import.meta.url)), '..', '..', 'CHANGELOG.md'),
|
|
128
|
+
* repoUrl: 'https://github.com/Doist/todoist-cli',
|
|
129
|
+
* version: packageJson.version,
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function registerChangelogCommand(program, options) {
|
|
134
|
+
const resolved = resolve(options);
|
|
135
|
+
program
|
|
136
|
+
.command('changelog')
|
|
137
|
+
.description('Show recent changelog entries')
|
|
138
|
+
.option('-n, --count <number>', 'Number of versions to show', String(resolved.defaultCount))
|
|
139
|
+
.action(async (commandOptions) => {
|
|
140
|
+
const count = Number(commandOptions.count);
|
|
141
|
+
if (!Number.isInteger(count) || count < 1) {
|
|
142
|
+
throw new CliError('INVALID_TYPE', 'Count must be a positive integer');
|
|
143
|
+
}
|
|
144
|
+
let content;
|
|
145
|
+
try {
|
|
146
|
+
content = await readFile(options.path, 'utf-8');
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw new CliError('FILE_READ_ERROR', 'Could not read changelog file');
|
|
150
|
+
}
|
|
151
|
+
const { text, hasMore } = parseChangelog(content, count, options);
|
|
152
|
+
console.log(formatForTerminal(text, options));
|
|
153
|
+
if (hasMore) {
|
|
154
|
+
const url = `${options.repoUrl}/blob/v${options.version}/CHANGELOG.md`;
|
|
155
|
+
console.log(chalk.dim(`\nView full changelog: ${url}`));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=changelog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changelog.js","sourceRoot":"","sources":["../../src/commands/changelog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AA8BvC,SAAS,OAAO,CAAC,OAAgC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YACtE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,0BAA0B,GAAG,EAAE,CAAC,CAAC,CAAA;QAC3D,CAAC;IACL,CAAC,CAAC,CAAA;AACV,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes thrown by `@doist/cli-core/commands` registration helpers. Folded
|
|
3
|
+
* into the `CliErrorCode` aggregator in `../errors.ts` so consumers don't have
|
|
4
|
+
* to redeclare them in their own `TCode` union when catching.
|
|
5
|
+
*/
|
|
6
|
+
export type CommandErrorCode = 'INVALID_TYPE' | 'FILE_READ_ERROR';
|
|
7
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/commands/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/commands/errors.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACzD,YAAY,EACR,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,GACxB,MAAM,gBAAgB,CAAA;AACvB,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CommandErrorCode } from './commands/errors.js';
|
|
1
2
|
import type { ConfigErrorCode } from './config.js';
|
|
2
3
|
export type ErrorType = 'error' | 'info';
|
|
3
4
|
export type CliErrorOptions = {
|
|
@@ -15,7 +16,7 @@ export type CliErrorOptions = {
|
|
|
15
16
|
* export type CliErrorCode = ConfigErrorCode | SpinnerErrorCode | …
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
|
-
export type CliErrorCode = ConfigErrorCode;
|
|
19
|
+
export type CliErrorCode = CommandErrorCode | ConfigErrorCode;
|
|
19
20
|
/**
|
|
20
21
|
* Generic CLI error carrying a structured code, optional hints, and a severity
|
|
21
22
|
* type.
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAA;AAExC,MAAM,MAAM,eAAe,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,CAAC,EAAE,SAAS,CAAA;CACnB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,CAAA;AAExC,MAAM,MAAM,eAAe,GAAG;IAC1B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,IAAI,CAAC,EAAE,SAAS,CAAA;CACnB,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,eAAe,CAAA;AAE7D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,QAAQ,CAAC,KAAK,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;IAC9D,QAAQ,CAAC,IAAI,EAAE,KAAK,GAAG,YAAY,CAAA;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;gBAEZ,IAAI,EAAE,KAAK,GAAG,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB;CAOzF"}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,QAAwC,SAAQ,KAAK;IACrD,IAAI,CAAsB;IAC1B,KAAK,CAAW;IAChB,IAAI,CAAW;IAExB,YAAY,IAA0B,EAAE,OAAe,EAAE,UAA2B,EAAE;QAClF,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAA;IACvC,CAAC;CACJ"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { TerminalRendererOptions } from 'marked-terminal-renderer';
|
|
2
|
+
export type { TerminalRendererOptions } from 'marked-terminal-renderer';
|
|
3
|
+
export type PreloadMarkdownOptions = {
|
|
4
|
+
/** Theme to drive the renderer; defaults to `darkTheme()`. */
|
|
5
|
+
theme?: TerminalRendererOptions;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Lazy-init a shared `marked` renderer for terminal output. Idempotent — safe
|
|
9
|
+
* to call multiple times; later calls are no-ops once initialised, so the
|
|
10
|
+
* `theme` from the first call wins.
|
|
11
|
+
*
|
|
12
|
+
* Defer the dynamic import to the call site so CLIs that never render
|
|
13
|
+
* markdown (e.g. `--json` / `--ndjson` runs) don't pay the load cost. The
|
|
14
|
+
* peer-dep packages (`marked`, `marked-terminal-renderer`) are loaded only
|
|
15
|
+
* inside this function — a missing peer surfaces here as a friendly error,
|
|
16
|
+
* never as a module-link crash on `import`.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { preloadMarkdown, renderMarkdown } from '@doist/cli-core/markdown'
|
|
20
|
+
*
|
|
21
|
+
* if (!options.json && !options.raw) {
|
|
22
|
+
* await preloadMarkdown()
|
|
23
|
+
* }
|
|
24
|
+
* console.log(await renderMarkdown(comment.body))
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Custom theme — import directly from the renderer package, which the
|
|
28
|
+
* consumer already has installed as a peer-dep:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { preloadMarkdown } from '@doist/cli-core/markdown'
|
|
32
|
+
* import { lightTheme } from 'marked-terminal-renderer'
|
|
33
|
+
* await preloadMarkdown({ theme: lightTheme() })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function preloadMarkdown(options?: PreloadMarkdownOptions): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Render a markdown string to ANSI-styled terminal output.
|
|
39
|
+
*
|
|
40
|
+
* Returns the input unchanged if `preloadMarkdown` has not yet run — keeps
|
|
41
|
+
* call sites simple in code paths that may execute before init (e.g. early
|
|
42
|
+
* errors). Trailing whitespace from the renderer is trimmed so callers can
|
|
43
|
+
* `console.log` the result without a stray blank line.
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { preloadMarkdown, renderMarkdown } from '@doist/cli-core/markdown'
|
|
47
|
+
*
|
|
48
|
+
* await preloadMarkdown()
|
|
49
|
+
* console.log(await renderMarkdown('# Title\n\n- one\n- two'))
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function renderMarkdown(text: string): Promise<string>;
|
|
53
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAEvE,YAAY,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAEvE,MAAM,MAAM,sBAAsB,GAAG;IACjC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,uBAAuB,CAAA;CAClC,CAAA;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,eAAe,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBrF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIlE"}
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
let markedInstance = null;
|
|
2
|
+
/**
|
|
3
|
+
* Lazy-init a shared `marked` renderer for terminal output. Idempotent — safe
|
|
4
|
+
* to call multiple times; later calls are no-ops once initialised, so the
|
|
5
|
+
* `theme` from the first call wins.
|
|
6
|
+
*
|
|
7
|
+
* Defer the dynamic import to the call site so CLIs that never render
|
|
8
|
+
* markdown (e.g. `--json` / `--ndjson` runs) don't pay the load cost. The
|
|
9
|
+
* peer-dep packages (`marked`, `marked-terminal-renderer`) are loaded only
|
|
10
|
+
* inside this function — a missing peer surfaces here as a friendly error,
|
|
11
|
+
* never as a module-link crash on `import`.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { preloadMarkdown, renderMarkdown } from '@doist/cli-core/markdown'
|
|
15
|
+
*
|
|
16
|
+
* if (!options.json && !options.raw) {
|
|
17
|
+
* await preloadMarkdown()
|
|
18
|
+
* }
|
|
19
|
+
* console.log(await renderMarkdown(comment.body))
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* Custom theme — import directly from the renderer package, which the
|
|
23
|
+
* consumer already has installed as a peer-dep:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { preloadMarkdown } from '@doist/cli-core/markdown'
|
|
27
|
+
* import { lightTheme } from 'marked-terminal-renderer'
|
|
28
|
+
* await preloadMarkdown({ theme: lightTheme() })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export async function preloadMarkdown(options) {
|
|
32
|
+
if (markedInstance)
|
|
33
|
+
return;
|
|
34
|
+
let modules;
|
|
35
|
+
try {
|
|
36
|
+
modules = await Promise.all([import('marked'), import('marked-terminal-renderer')]);
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (err instanceof Error && 'code' in err && err.code === 'ERR_MODULE_NOT_FOUND') {
|
|
40
|
+
throw new Error("@doist/cli-core/markdown requires 'marked' and 'marked-terminal-renderer' as peer dependencies. " +
|
|
41
|
+
'Install them with: npm install marked marked-terminal-renderer', { cause: err });
|
|
42
|
+
}
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
const [{ Marked }, { createTerminalRenderer, darkTheme }] = modules;
|
|
46
|
+
const instance = new Marked();
|
|
47
|
+
instance.use(createTerminalRenderer(options?.theme ?? darkTheme()));
|
|
48
|
+
markedInstance = instance;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Render a markdown string to ANSI-styled terminal output.
|
|
52
|
+
*
|
|
53
|
+
* Returns the input unchanged if `preloadMarkdown` has not yet run — keeps
|
|
54
|
+
* call sites simple in code paths that may execute before init (e.g. early
|
|
55
|
+
* errors). Trailing whitespace from the renderer is trimmed so callers can
|
|
56
|
+
* `console.log` the result without a stray blank line.
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { preloadMarkdown, renderMarkdown } from '@doist/cli-core/markdown'
|
|
60
|
+
*
|
|
61
|
+
* await preloadMarkdown()
|
|
62
|
+
* console.log(await renderMarkdown('# Title\n\n- one\n- two'))
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export async function renderMarkdown(text) {
|
|
66
|
+
if (!markedInstance)
|
|
67
|
+
return text;
|
|
68
|
+
const rendered = await markedInstance.parse(text);
|
|
69
|
+
return typeof rendered === 'string' ? rendered.trimEnd() : text;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAUA,IAAI,cAAc,GAAkB,IAAI,CAAA;AAExC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,OAAgC;IAClE,IAAI,cAAc;QAAE,OAAM;IAC1B,IAAI,OAA6E,CAAA;IACjF,IAAI,CAAC;QACD,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAA;IACvF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,IAAI,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;YAC/E,MAAM,IAAI,KAAK,CACX,kGAAkG;gBAC9F,gEAAgE,EACpE,EAAE,KAAK,EAAE,GAAG,EAAE,CACjB,CAAA;QACL,CAAC;QACD,MAAM,GAAG,CAAA;IACb,CAAC;IACD,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,sBAAsB,EAAE,SAAS,EAAE,CAAC,GAAG,OAAO,CAAA;IACnE,MAAM,QAAQ,GAAG,IAAI,MAAM,EAAE,CAAA;IAC7B,QAAQ,CAAC,GAAG,CAAC,sBAAsB,CAAC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,CAAC,CAAC,CAAA;IACnE,cAAc,GAAG,QAAQ,CAAA;AAC7B,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAC7C,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAA;IAChC,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACjD,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doist/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Shared core utilities for Doist CLI projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
},
|
|
13
|
+
"./commands": {
|
|
14
|
+
"types": "./dist/commands/index.d.ts",
|
|
15
|
+
"import": "./dist/commands/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./markdown": {
|
|
18
|
+
"types": "./dist/markdown.d.ts",
|
|
19
|
+
"import": "./dist/markdown.js"
|
|
20
|
+
},
|
|
13
21
|
"./testing": {
|
|
14
22
|
"types": "./dist/testing.d.ts",
|
|
15
23
|
"import": "./dist/testing.js"
|
|
@@ -55,8 +63,11 @@
|
|
|
55
63
|
"@semantic-release/exec": "7.1.0",
|
|
56
64
|
"@semantic-release/git": "10.0.1",
|
|
57
65
|
"@types/node": "25.6.0",
|
|
66
|
+
"commander": "14.0.3",
|
|
58
67
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
59
68
|
"lefthook": "2.1.6",
|
|
69
|
+
"marked": "18.0.3",
|
|
70
|
+
"marked-terminal-renderer": "2.2.0",
|
|
60
71
|
"oxfmt": "0.46.0",
|
|
61
72
|
"oxlint": "1.61.0",
|
|
62
73
|
"semantic-release": "25.0.3",
|
|
@@ -68,9 +79,21 @@
|
|
|
68
79
|
"yocto-spinner": "1.1.0"
|
|
69
80
|
},
|
|
70
81
|
"peerDependencies": {
|
|
82
|
+
"commander": ">=14",
|
|
83
|
+
"marked": ">=18",
|
|
84
|
+
"marked-terminal-renderer": ">=2",
|
|
71
85
|
"vitest": ">=4.1"
|
|
72
86
|
},
|
|
73
87
|
"peerDependenciesMeta": {
|
|
88
|
+
"commander": {
|
|
89
|
+
"optional": true
|
|
90
|
+
},
|
|
91
|
+
"marked": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"marked-terminal-renderer": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
74
97
|
"vitest": {
|
|
75
98
|
"optional": true
|
|
76
99
|
}
|