@nowline/export-mermaid 0.2.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/LICENSE +190 -0
- package/README.md +96 -0
- package/dist/duration.d.ts +7 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +49 -0
- package/dist/duration.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +253 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
- package/src/duration.ts +49 -0
- package/src/index.ts +324 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Lolay, Inc.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# @nowline/export-mermaid
|
|
2
|
+
|
|
3
|
+
Markdown + Mermaid `gantt` export. Transpiles a Nowline AST into a Markdown
|
|
4
|
+
page that renders in any Mermaid-aware viewer (GitHub, GitLab, Obsidian,
|
|
5
|
+
mermaid.live, etc.). Pure strings — no Node-only dependencies.
|
|
6
|
+
|
|
7
|
+
**License:** Apache 2.0
|
|
8
|
+
**Part of:** [`lolay/nowline`](../../) monorepo
|
|
9
|
+
**Spec:** [`specs/handoffs/m2c.md`](../../specs/handoffs/m2c.md) § 6
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @nowline/export-mermaid @nowline/export-core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { exportMermaid } from '@nowline/export-mermaid';
|
|
21
|
+
|
|
22
|
+
const md = exportMermaid(inputs, {
|
|
23
|
+
lossyComment: true, // default; emits the trailing `%%` comment
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// `md` is a Markdown string. Write to disk as roadmap.md, or stdin → stdout.
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
CLI:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
nowline roadmap.nowline -f mermaid -o roadmap.md
|
|
33
|
+
nowline roadmap.nowline -f md -o - # alias; stdout
|
|
34
|
+
nowline roadmap.nowline -o roadmap.md # extension-inferred
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`md` and `markdown` are CLI aliases for `mermaid`.
|
|
38
|
+
|
|
39
|
+
## Output shape
|
|
40
|
+
|
|
41
|
+
```markdown
|
|
42
|
+
# <Roadmap title>
|
|
43
|
+
|
|
44
|
+
<description paragraph if any>
|
|
45
|
+
|
|
46
|
+
```mermaid
|
|
47
|
+
gantt
|
|
48
|
+
title <title>
|
|
49
|
+
dateFormat YYYY-MM-DD
|
|
50
|
+
axisFormat %b %d
|
|
51
|
+
section <swimlane>
|
|
52
|
+
Item one : done, item-one, 2026-01-06, 5d
|
|
53
|
+
Item two : active, item-two, after item-one, 10d
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
%% Lossy export — Mermaid does not support: labels (3), footnotes (1)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The first line of the Markdown is the roadmap title. The fenced
|
|
60
|
+
```` ```mermaid ```` block contains a valid `gantt` diagram; the trailing
|
|
61
|
+
`%%` comment line lists Nowline features that don't have a Mermaid
|
|
62
|
+
equivalent and have been dropped.
|
|
63
|
+
|
|
64
|
+
## Lossy export policy
|
|
65
|
+
|
|
66
|
+
Mermaid `gantt` is intentionally a much simpler model than Nowline. The
|
|
67
|
+
following Nowline features are dropped (silently inside the gantt block,
|
|
68
|
+
named in the trailing `%%` comment):
|
|
69
|
+
|
|
70
|
+
- `label`, `style` declarations
|
|
71
|
+
- `footnote` annotations
|
|
72
|
+
- `description` directives on items
|
|
73
|
+
- Custom `status` definitions beyond Mermaid's `done` / `active` /
|
|
74
|
+
`crit`
|
|
75
|
+
- Per-`person` / `team` ownership styling
|
|
76
|
+
|
|
77
|
+
Per spec Resolution 4, `--strict` does *not* escalate these drops to
|
|
78
|
+
errors. The export succeeds on any valid AST and the comment makes the
|
|
79
|
+
loss visible to the reader.
|
|
80
|
+
|
|
81
|
+
## Options
|
|
82
|
+
|
|
83
|
+
| Option | Default | Notes |
|
|
84
|
+
|----------------|---------|-------|
|
|
85
|
+
| `lossyComment` | `true` | Append the trailing `%%` comment listing dropped features. Set `false` to omit (e.g., for snapshots in environments where Mermaid is the canonical view). |
|
|
86
|
+
|
|
87
|
+
## Determinism
|
|
88
|
+
|
|
89
|
+
- No `new Date()`, no random.
|
|
90
|
+
- Item ordering follows AST order (already deterministic from
|
|
91
|
+
`@nowline/core`).
|
|
92
|
+
- Snapshots in `test/__snapshots__/` regenerate via `vitest -u`.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
Apache-2.0.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert a duration literal to a Mermaid token (`5d`, `2w`, …).
|
|
3
|
+
* Returns `undefined` when the literal is missing — caller emits no duration
|
|
4
|
+
* and Mermaid uses its default 1d.
|
|
5
|
+
*/
|
|
6
|
+
export declare function durationToMermaid(literal: string | undefined): string | undefined;
|
|
7
|
+
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAwBjF"}
|
package/dist/duration.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Convert Nowline duration tokens (e.g. `2w`, `1m`, `xl`) into Mermaid's
|
|
2
|
+
// duration syntax. Mermaid `gantt` accepts day / week / hour units.
|
|
3
|
+
//
|
|
4
|
+
// Spec: specs/handoffs/m2c.md § 6 + the bridge rules in
|
|
5
|
+
// specs/rendering.md § Markdown+Mermaid Bridge.
|
|
6
|
+
const SIZE_BUCKET_DAYS = {
|
|
7
|
+
xs: 1,
|
|
8
|
+
sm: 3,
|
|
9
|
+
s: 3,
|
|
10
|
+
md: 5,
|
|
11
|
+
m: 5,
|
|
12
|
+
lg: 10,
|
|
13
|
+
l: 10,
|
|
14
|
+
xl: 15,
|
|
15
|
+
};
|
|
16
|
+
const NUMERIC_RE = /^(\d+(?:\.\d+)?)\s*(d|w|m|y)?$/i;
|
|
17
|
+
/**
|
|
18
|
+
* Convert a duration literal to a Mermaid token (`5d`, `2w`, …).
|
|
19
|
+
* Returns `undefined` when the literal is missing — caller emits no duration
|
|
20
|
+
* and Mermaid uses its default 1d.
|
|
21
|
+
*/
|
|
22
|
+
export function durationToMermaid(literal) {
|
|
23
|
+
if (!literal)
|
|
24
|
+
return undefined;
|
|
25
|
+
const trimmed = literal.trim().toLowerCase();
|
|
26
|
+
if (!trimmed)
|
|
27
|
+
return undefined;
|
|
28
|
+
// Size buckets resolve to working-day counts.
|
|
29
|
+
if (trimmed in SIZE_BUCKET_DAYS) {
|
|
30
|
+
return `${SIZE_BUCKET_DAYS[trimmed]}d`;
|
|
31
|
+
}
|
|
32
|
+
const match = NUMERIC_RE.exec(trimmed);
|
|
33
|
+
if (!match)
|
|
34
|
+
return undefined;
|
|
35
|
+
const value = match[1];
|
|
36
|
+
const unit = (match[2] ?? 'd').toLowerCase();
|
|
37
|
+
if (unit === 'd' || unit === 'w')
|
|
38
|
+
return `${value}${unit}`;
|
|
39
|
+
if (unit === 'm') {
|
|
40
|
+
const days = Math.round(Number(value) * 22);
|
|
41
|
+
return `${days}d`;
|
|
42
|
+
}
|
|
43
|
+
if (unit === 'y') {
|
|
44
|
+
const days = Math.round(Number(value) * 252);
|
|
45
|
+
return `${days}d`;
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=duration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duration.js","sourceRoot":"","sources":["../src/duration.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,oEAAoE;AACpE,EAAE;AACF,wDAAwD;AACxD,gDA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M,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC;QAC7C,OAAO,GAAG,IAAI,GAAG,CAAC;IACtB,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExportInputs } from '@nowline/export-core';
|
|
2
|
+
export interface MermaidOptions {
|
|
3
|
+
/** Append the trailing `%%` lossy comment. Defaults to true. */
|
|
4
|
+
lossyComment?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function exportMermaid(inputs: ExportInputs, options?: MermaidOptions): string;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAKzD,MAAM,WAAW,cAAc;IAC3B,gEAAgE;IAChE,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AA8BD,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,cAAmB,GAAG,MAAM,CAmExF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// Markdown+Mermaid exporter.
|
|
2
|
+
//
|
|
3
|
+
// Spec: specs/handoffs/m2c.md § 6 "Markdown+Mermaid".
|
|
4
|
+
// Decisions:
|
|
5
|
+
// - Resolution 4 (Mermaid loss discipline): drops are silent in the gantt
|
|
6
|
+
// block; a trailing `%%` comment enumerates dropped features with stable
|
|
7
|
+
// counts; `--strict` does NOT escalate.
|
|
8
|
+
// - Lossy export policy: succeeds on any valid AST regardless of `--strict`.
|
|
9
|
+
//
|
|
10
|
+
// Output shape:
|
|
11
|
+
// # <Roadmap title>
|
|
12
|
+
//
|
|
13
|
+
// <description paragraph if any>
|
|
14
|
+
//
|
|
15
|
+
// ```mermaid
|
|
16
|
+
// gantt
|
|
17
|
+
// title <title>
|
|
18
|
+
// dateFormat YYYY-MM-DD
|
|
19
|
+
// axisFormat ...
|
|
20
|
+
// section <swimlane>
|
|
21
|
+
// <Task name>: <status>, <id>, <after-or-date>, <duration>
|
|
22
|
+
// ```
|
|
23
|
+
//
|
|
24
|
+
// <%% lossy comment %%>
|
|
25
|
+
import { displayLabel, getProp, getProps, hasProp, roadmapTitle } from '@nowline/export-core';
|
|
26
|
+
import { durationToMermaid } from './duration.js';
|
|
27
|
+
function emptyCounts() {
|
|
28
|
+
return {
|
|
29
|
+
labels: 0,
|
|
30
|
+
footnote: 0,
|
|
31
|
+
remaining: 0,
|
|
32
|
+
owner: 0,
|
|
33
|
+
before: 0,
|
|
34
|
+
parallel: 0,
|
|
35
|
+
group: 0,
|
|
36
|
+
nestedSwimlanes: 0,
|
|
37
|
+
description: 0,
|
|
38
|
+
style: 0,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function exportMermaid(inputs, options = {}) {
|
|
42
|
+
const ast = inputs.ast;
|
|
43
|
+
const title = roadmapTitle(ast.roadmapDecl ?? undefined);
|
|
44
|
+
const drops = emptyCounts();
|
|
45
|
+
const out = [];
|
|
46
|
+
out.push(`# ${title}`);
|
|
47
|
+
out.push('');
|
|
48
|
+
out.push('```mermaid');
|
|
49
|
+
out.push('gantt');
|
|
50
|
+
out.push(` title ${escapeMermaidText(title)}`);
|
|
51
|
+
out.push(' dateFormat YYYY-MM-DD');
|
|
52
|
+
// Footnotes are file-level; counted once.
|
|
53
|
+
drops.footnote += ast.roadmapEntries.filter((e) => e.$type === 'FootnoteDeclaration').length;
|
|
54
|
+
// Anchors → milestone entries (Mermaid doesn't support standalone anchors).
|
|
55
|
+
const anchors = ast.roadmapEntries.filter((e) => e.$type === 'AnchorDeclaration');
|
|
56
|
+
if (anchors.length > 0) {
|
|
57
|
+
out.push(' section Anchors');
|
|
58
|
+
for (const anchor of anchors) {
|
|
59
|
+
const date = getProp(anchor, 'date');
|
|
60
|
+
const id = anchor.name ?? slugify(displayLabel(anchor));
|
|
61
|
+
if (date) {
|
|
62
|
+
out.push(` ${escapeTaskName(displayLabel(anchor))} :milestone, ${id}, ${date}, 0d`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
out.push(` ${escapeTaskName(displayLabel(anchor))} :milestone, ${id}, after , 0d`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Swimlanes → sections; their items become tasks.
|
|
70
|
+
const swimlanes = ast.roadmapEntries.filter((e) => e.$type === 'SwimlaneDeclaration');
|
|
71
|
+
for (const lane of swimlanes) {
|
|
72
|
+
emitSwimlane(lane, [lane.name ?? slugify(displayLabel(lane))], drops, out);
|
|
73
|
+
}
|
|
74
|
+
// Top-level milestones.
|
|
75
|
+
const milestones = ast.roadmapEntries.filter((e) => e.$type === 'MilestoneDeclaration');
|
|
76
|
+
if (milestones.length > 0) {
|
|
77
|
+
out.push(' section Milestones');
|
|
78
|
+
for (const m of milestones) {
|
|
79
|
+
emitMilestone(m, drops, out);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
out.push('```');
|
|
83
|
+
if (options.lossyComment !== false) {
|
|
84
|
+
const summary = formatDrops(drops);
|
|
85
|
+
if (summary) {
|
|
86
|
+
out.push('');
|
|
87
|
+
out.push(summary);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return out.join('\n');
|
|
91
|
+
}
|
|
92
|
+
function emitSwimlane(lane, breadcrumb, drops, out) {
|
|
93
|
+
const sectionLabel = breadcrumb.join('.');
|
|
94
|
+
out.push(` section ${escapeMermaidText(sectionLabel)}`);
|
|
95
|
+
for (const child of lane.content) {
|
|
96
|
+
emitSwimlaneChild(child, breadcrumb, drops, out);
|
|
97
|
+
}
|
|
98
|
+
// Nested swimlanes — count for the lossy report.
|
|
99
|
+
// SwimlaneContent doesn't include nested swimlanes per the grammar, so
|
|
100
|
+
// there's nothing to recurse into here. If `nested` lives on the
|
|
101
|
+
// roadmap-level layout model, that's a separate count tracked elsewhere.
|
|
102
|
+
}
|
|
103
|
+
function emitSwimlaneChild(child, breadcrumb, drops, out) {
|
|
104
|
+
if (child.$type === 'ItemDeclaration') {
|
|
105
|
+
emitItem(child, drops, out);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (child.$type === 'GroupBlock') {
|
|
109
|
+
drops.group += 1;
|
|
110
|
+
emitGroup(child, breadcrumb, drops, out);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (child.$type === 'ParallelBlock') {
|
|
114
|
+
drops.parallel += 1;
|
|
115
|
+
emitParallel(child, breadcrumb, drops, out);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (child.$type === 'DescriptionDirective') {
|
|
119
|
+
drops.description += 1;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function emitGroup(group, breadcrumb, drops, out) {
|
|
124
|
+
for (const child of group.content) {
|
|
125
|
+
if (child.$type === 'ItemDeclaration') {
|
|
126
|
+
emitItem(child, drops, out);
|
|
127
|
+
}
|
|
128
|
+
else if (child.$type === 'GroupBlock') {
|
|
129
|
+
drops.group += 1;
|
|
130
|
+
emitGroup(child, breadcrumb, drops, out);
|
|
131
|
+
}
|
|
132
|
+
else if (child.$type === 'ParallelBlock') {
|
|
133
|
+
drops.parallel += 1;
|
|
134
|
+
emitParallel(child, breadcrumb, drops, out);
|
|
135
|
+
}
|
|
136
|
+
else if (child.$type === 'DescriptionDirective') {
|
|
137
|
+
drops.description += 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function emitParallel(parallel, breadcrumb, drops, out) {
|
|
142
|
+
for (const child of parallel.content) {
|
|
143
|
+
if (child.$type === 'ItemDeclaration') {
|
|
144
|
+
emitItem(child, drops, out);
|
|
145
|
+
}
|
|
146
|
+
else if (child.$type === 'GroupBlock') {
|
|
147
|
+
drops.group += 1;
|
|
148
|
+
emitGroup(child, breadcrumb, drops, out);
|
|
149
|
+
}
|
|
150
|
+
else if (child.$type === 'DescriptionDirective') {
|
|
151
|
+
drops.description += 1;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function emitItem(item, drops, out) {
|
|
156
|
+
countDrops(item, drops);
|
|
157
|
+
const id = item.name ?? slugify(displayLabel(item));
|
|
158
|
+
const status = mapStatus(getProp(item, 'status'));
|
|
159
|
+
const after = getProps(item, 'after');
|
|
160
|
+
const duration = durationToMermaid(getProp(item, 'duration') ?? getProp(item, 'size')) ?? '1d';
|
|
161
|
+
const _ref = after.length > 0 ? `after ${after.join(' ')}` : 'after , 0d'.replace(', 0d', '');
|
|
162
|
+
const meta = [status, id, after.length > 0 ? `after ${after.join(' ')}` : '', duration]
|
|
163
|
+
.filter((s) => s !== '')
|
|
164
|
+
.join(', ');
|
|
165
|
+
out.push(` ${escapeTaskName(displayLabel(item))} :${meta}`);
|
|
166
|
+
}
|
|
167
|
+
function emitMilestone(milestone, drops, out) {
|
|
168
|
+
const id = milestone.name ?? slugify(displayLabel(milestone));
|
|
169
|
+
const date = getProp(milestone, 'date');
|
|
170
|
+
if (date) {
|
|
171
|
+
out.push(` ${escapeTaskName(displayLabel(milestone))} :milestone, ${id}, ${date}, 0d`);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const after = getProps(milestone, 'depends');
|
|
175
|
+
if (after.length > 0) {
|
|
176
|
+
out.push(` ${escapeTaskName(displayLabel(milestone))} :milestone, ${id}, after ${after.join(' ')}, 0d`);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
out.push(` ${escapeTaskName(displayLabel(milestone))} :milestone, ${id}, 0d`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (hasProp(milestone, 'style'))
|
|
183
|
+
drops.style += 1;
|
|
184
|
+
}
|
|
185
|
+
function countDrops(item, drops) {
|
|
186
|
+
if (getProps(item, 'labels').length > 0)
|
|
187
|
+
drops.labels += 1;
|
|
188
|
+
if (hasProp(item, 'remaining'))
|
|
189
|
+
drops.remaining += 1;
|
|
190
|
+
if (hasProp(item, 'owner'))
|
|
191
|
+
drops.owner += 1;
|
|
192
|
+
if (getProps(item, 'before').length > 0)
|
|
193
|
+
drops.before += 1;
|
|
194
|
+
if (hasProp(item, 'style'))
|
|
195
|
+
drops.style += 1;
|
|
196
|
+
if (item.description)
|
|
197
|
+
drops.description += 1;
|
|
198
|
+
}
|
|
199
|
+
function mapStatus(status) {
|
|
200
|
+
switch (status) {
|
|
201
|
+
case 'done':
|
|
202
|
+
return 'done';
|
|
203
|
+
case 'in-progress':
|
|
204
|
+
return 'active';
|
|
205
|
+
case 'blocked':
|
|
206
|
+
case 'at-risk':
|
|
207
|
+
return 'crit';
|
|
208
|
+
default:
|
|
209
|
+
return '';
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function slugify(s) {
|
|
213
|
+
return (s
|
|
214
|
+
.toLowerCase()
|
|
215
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
216
|
+
.replace(/^-+|-+$/g, '') || 'item');
|
|
217
|
+
}
|
|
218
|
+
function escapeMermaidText(s) {
|
|
219
|
+
return s.replace(/[\r\n]+/g, ' ').replace(/"/g, '\u201c');
|
|
220
|
+
}
|
|
221
|
+
function escapeTaskName(s) {
|
|
222
|
+
// Mermaid splits the task line on `:` and `,` — strip them from the name.
|
|
223
|
+
return s.replace(/[\r\n]+/g, ' ').replace(/[:,]+/g, ' ');
|
|
224
|
+
}
|
|
225
|
+
function formatDrops(drops) {
|
|
226
|
+
const order = [
|
|
227
|
+
'labels',
|
|
228
|
+
'footnote',
|
|
229
|
+
'remaining',
|
|
230
|
+
'owner',
|
|
231
|
+
'before',
|
|
232
|
+
'parallel',
|
|
233
|
+
'group',
|
|
234
|
+
'nestedSwimlanes',
|
|
235
|
+
'description',
|
|
236
|
+
'style',
|
|
237
|
+
];
|
|
238
|
+
const parts = order
|
|
239
|
+
.filter((key) => drops[key] > 0)
|
|
240
|
+
.map((key) => `${formatDropKey(key)} (${drops[key]})`);
|
|
241
|
+
if (parts.length === 0)
|
|
242
|
+
return null;
|
|
243
|
+
const lines = [];
|
|
244
|
+
lines.push('%% Mermaid lossy export — Nowline features dropped:');
|
|
245
|
+
lines.push(`%% ${parts.join(', ')}`);
|
|
246
|
+
return lines.join('\n');
|
|
247
|
+
}
|
|
248
|
+
function formatDropKey(key) {
|
|
249
|
+
if (key === 'nestedSwimlanes')
|
|
250
|
+
return 'nested-swimlanes';
|
|
251
|
+
return key;
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,EAAE;AACF,sDAAsD;AACtD,aAAa;AACb,4EAA4E;AAC5E,6EAA6E;AAC7E,4CAA4C;AAC5C,+EAA+E;AAC/E,EAAE;AACF,gBAAgB;AAChB,sBAAsB;AACtB,EAAE;AACF,mCAAmC;AACnC,EAAE;AACF,eAAe;AACf,UAAU;AACV,sBAAsB;AACtB,8BAA8B;AAC9B,uBAAuB;AACvB,2BAA2B;AAC3B,iEAAiE;AACjE,QAAQ;AACR,EAAE;AACF,0BAA0B;AAa1B,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAoBlD,SAAS,WAAW;IAChB,OAAO;QACH,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;QACX,SAAS,EAAE,CAAC;QACZ,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;QACX,KAAK,EAAE,CAAC;QACR,eAAe,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,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,WAAW,CAAC,KAAiB;IAClC,MAAM,KAAK,GAAyB;QAChC,QAAQ;QACR,UAAU;QACV,WAAW;QACX,OAAO;QACP,QAAQ;QACR,UAAU;QACV,OAAO;QACP,iBAAiB;QACjB,aAAa;QACb,OAAO;KACV,CAAC;IACF,MAAM,KAAK,GAAG,KAAK;SACd,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC/B,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAC;IAClE,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,aAAa,CAAC,GAAqB;IACxC,IAAI,GAAG,KAAK,iBAAiB;QAAE,OAAO,kBAAkB,CAAC;IACzD,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nowline/export-mermaid",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Nowline Mermaid exporter — Markdown+Mermaid gantt transpilation",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"src/"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@nowline/core": "0.2.0",
|
|
21
|
+
"@nowline/export-core": "0.2.0",
|
|
22
|
+
"@nowline/layout": "0.2.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^22.0.0",
|
|
26
|
+
"langium": "~4.2.2",
|
|
27
|
+
"typescript": "~5.7.0",
|
|
28
|
+
"vitest": "^3.1.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -b tsconfig.json",
|
|
32
|
+
"watch": "tsc -b tsconfig.json --watch",
|
|
33
|
+
"test": "vitest run",
|
|
34
|
+
"test:watch": "vitest"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/duration.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Convert Nowline duration tokens (e.g. `2w`, `1m`, `xl`) into Mermaid's
|
|
2
|
+
// duration syntax. Mermaid `gantt` accepts day / week / hour units.
|
|
3
|
+
//
|
|
4
|
+
// Spec: specs/handoffs/m2c.md § 6 + the bridge rules in
|
|
5
|
+
// specs/rendering.md § Markdown+Mermaid Bridge.
|
|
6
|
+
|
|
7
|
+
const SIZE_BUCKET_DAYS: Readonly<Record<string, number>> = {
|
|
8
|
+
xs: 1,
|
|
9
|
+
sm: 3,
|
|
10
|
+
s: 3,
|
|
11
|
+
md: 5,
|
|
12
|
+
m: 5,
|
|
13
|
+
lg: 10,
|
|
14
|
+
l: 10,
|
|
15
|
+
xl: 15,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const NUMERIC_RE = /^(\d+(?:\.\d+)?)\s*(d|w|m|y)?$/i;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Convert a duration literal to a Mermaid token (`5d`, `2w`, …).
|
|
22
|
+
* Returns `undefined` when the literal is missing — caller emits no duration
|
|
23
|
+
* and Mermaid uses its default 1d.
|
|
24
|
+
*/
|
|
25
|
+
export function durationToMermaid(literal: string | undefined): string | undefined {
|
|
26
|
+
if (!literal) return undefined;
|
|
27
|
+
const trimmed = literal.trim().toLowerCase();
|
|
28
|
+
if (!trimmed) return undefined;
|
|
29
|
+
|
|
30
|
+
// Size buckets resolve to working-day counts.
|
|
31
|
+
if (trimmed in SIZE_BUCKET_DAYS) {
|
|
32
|
+
return `${SIZE_BUCKET_DAYS[trimmed]}d`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const match = NUMERIC_RE.exec(trimmed);
|
|
36
|
+
if (!match) return undefined;
|
|
37
|
+
const value = match[1];
|
|
38
|
+
const unit = (match[2] ?? 'd').toLowerCase();
|
|
39
|
+
if (unit === 'd' || unit === 'w') return `${value}${unit}`;
|
|
40
|
+
if (unit === 'm') {
|
|
41
|
+
const days = Math.round(Number(value) * 22);
|
|
42
|
+
return `${days}d`;
|
|
43
|
+
}
|
|
44
|
+
if (unit === 'y') {
|
|
45
|
+
const days = Math.round(Number(value) * 252);
|
|
46
|
+
return `${days}d`;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// Markdown+Mermaid exporter.
|
|
2
|
+
//
|
|
3
|
+
// Spec: specs/handoffs/m2c.md § 6 "Markdown+Mermaid".
|
|
4
|
+
// Decisions:
|
|
5
|
+
// - Resolution 4 (Mermaid loss discipline): drops are silent in the gantt
|
|
6
|
+
// block; a trailing `%%` comment enumerates dropped features with stable
|
|
7
|
+
// counts; `--strict` does NOT escalate.
|
|
8
|
+
// - Lossy export policy: succeeds on any valid AST regardless of `--strict`.
|
|
9
|
+
//
|
|
10
|
+
// Output shape:
|
|
11
|
+
// # <Roadmap title>
|
|
12
|
+
//
|
|
13
|
+
// <description paragraph if any>
|
|
14
|
+
//
|
|
15
|
+
// ```mermaid
|
|
16
|
+
// gantt
|
|
17
|
+
// title <title>
|
|
18
|
+
// dateFormat YYYY-MM-DD
|
|
19
|
+
// axisFormat ...
|
|
20
|
+
// section <swimlane>
|
|
21
|
+
// <Task name>: <status>, <id>, <after-or-date>, <duration>
|
|
22
|
+
// ```
|
|
23
|
+
//
|
|
24
|
+
// <%% lossy comment %%>
|
|
25
|
+
|
|
26
|
+
import type {
|
|
27
|
+
AnchorDeclaration,
|
|
28
|
+
GroupBlock,
|
|
29
|
+
GroupContent,
|
|
30
|
+
ItemDeclaration,
|
|
31
|
+
MilestoneDeclaration,
|
|
32
|
+
ParallelBlock,
|
|
33
|
+
SwimlaneContent,
|
|
34
|
+
SwimlaneDeclaration,
|
|
35
|
+
} from '@nowline/core';
|
|
36
|
+
import type { ExportInputs } from '@nowline/export-core';
|
|
37
|
+
import { displayLabel, getProp, getProps, hasProp, roadmapTitle } from '@nowline/export-core';
|
|
38
|
+
|
|
39
|
+
import { durationToMermaid } from './duration.js';
|
|
40
|
+
|
|
41
|
+
export interface MermaidOptions {
|
|
42
|
+
/** Append the trailing `%%` lossy comment. Defaults to true. */
|
|
43
|
+
lossyComment?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface DropCounts {
|
|
47
|
+
labels: number;
|
|
48
|
+
footnote: number;
|
|
49
|
+
remaining: number;
|
|
50
|
+
owner: number;
|
|
51
|
+
before: number;
|
|
52
|
+
parallel: number;
|
|
53
|
+
group: number;
|
|
54
|
+
nestedSwimlanes: number;
|
|
55
|
+
description: number;
|
|
56
|
+
style: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function emptyCounts(): DropCounts {
|
|
60
|
+
return {
|
|
61
|
+
labels: 0,
|
|
62
|
+
footnote: 0,
|
|
63
|
+
remaining: 0,
|
|
64
|
+
owner: 0,
|
|
65
|
+
before: 0,
|
|
66
|
+
parallel: 0,
|
|
67
|
+
group: 0,
|
|
68
|
+
nestedSwimlanes: 0,
|
|
69
|
+
description: 0,
|
|
70
|
+
style: 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function exportMermaid(inputs: ExportInputs, options: MermaidOptions = {}): string {
|
|
75
|
+
const ast = inputs.ast;
|
|
76
|
+
const title = roadmapTitle(ast.roadmapDecl ?? undefined);
|
|
77
|
+
const drops = emptyCounts();
|
|
78
|
+
|
|
79
|
+
const out: string[] = [];
|
|
80
|
+
out.push(`# ${title}`);
|
|
81
|
+
out.push('');
|
|
82
|
+
out.push('```mermaid');
|
|
83
|
+
out.push('gantt');
|
|
84
|
+
out.push(` title ${escapeMermaidText(title)}`);
|
|
85
|
+
out.push(' dateFormat YYYY-MM-DD');
|
|
86
|
+
|
|
87
|
+
// Footnotes are file-level; counted once.
|
|
88
|
+
drops.footnote += ast.roadmapEntries.filter((e) => e.$type === 'FootnoteDeclaration').length;
|
|
89
|
+
|
|
90
|
+
// Anchors → milestone entries (Mermaid doesn't support standalone anchors).
|
|
91
|
+
const anchors = ast.roadmapEntries.filter(
|
|
92
|
+
(e): e is AnchorDeclaration => e.$type === 'AnchorDeclaration',
|
|
93
|
+
);
|
|
94
|
+
if (anchors.length > 0) {
|
|
95
|
+
out.push(' section Anchors');
|
|
96
|
+
for (const anchor of anchors) {
|
|
97
|
+
const date = getProp(anchor, 'date');
|
|
98
|
+
const id = anchor.name ?? slugify(displayLabel(anchor));
|
|
99
|
+
if (date) {
|
|
100
|
+
out.push(
|
|
101
|
+
` ${escapeTaskName(displayLabel(anchor))} :milestone, ${id}, ${date}, 0d`,
|
|
102
|
+
);
|
|
103
|
+
} else {
|
|
104
|
+
out.push(
|
|
105
|
+
` ${escapeTaskName(displayLabel(anchor))} :milestone, ${id}, after , 0d`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Swimlanes → sections; their items become tasks.
|
|
112
|
+
const swimlanes = ast.roadmapEntries.filter(
|
|
113
|
+
(e): e is SwimlaneDeclaration => e.$type === 'SwimlaneDeclaration',
|
|
114
|
+
);
|
|
115
|
+
for (const lane of swimlanes) {
|
|
116
|
+
emitSwimlane(lane, [lane.name ?? slugify(displayLabel(lane))], drops, out);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Top-level milestones.
|
|
120
|
+
const milestones = ast.roadmapEntries.filter(
|
|
121
|
+
(e): e is MilestoneDeclaration => e.$type === 'MilestoneDeclaration',
|
|
122
|
+
);
|
|
123
|
+
if (milestones.length > 0) {
|
|
124
|
+
out.push(' section Milestones');
|
|
125
|
+
for (const m of milestones) {
|
|
126
|
+
emitMilestone(m, drops, out);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
out.push('```');
|
|
131
|
+
|
|
132
|
+
if (options.lossyComment !== false) {
|
|
133
|
+
const summary = formatDrops(drops);
|
|
134
|
+
if (summary) {
|
|
135
|
+
out.push('');
|
|
136
|
+
out.push(summary);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return out.join('\n');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function emitSwimlane(
|
|
144
|
+
lane: SwimlaneDeclaration,
|
|
145
|
+
breadcrumb: readonly string[],
|
|
146
|
+
drops: DropCounts,
|
|
147
|
+
out: string[],
|
|
148
|
+
): void {
|
|
149
|
+
const sectionLabel = breadcrumb.join('.');
|
|
150
|
+
out.push(` section ${escapeMermaidText(sectionLabel)}`);
|
|
151
|
+
for (const child of lane.content) {
|
|
152
|
+
emitSwimlaneChild(child, breadcrumb, drops, out);
|
|
153
|
+
}
|
|
154
|
+
// Nested swimlanes — count for the lossy report.
|
|
155
|
+
// SwimlaneContent doesn't include nested swimlanes per the grammar, so
|
|
156
|
+
// there's nothing to recurse into here. If `nested` lives on the
|
|
157
|
+
// roadmap-level layout model, that's a separate count tracked elsewhere.
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function emitSwimlaneChild(
|
|
161
|
+
child: SwimlaneContent,
|
|
162
|
+
breadcrumb: readonly string[],
|
|
163
|
+
drops: DropCounts,
|
|
164
|
+
out: string[],
|
|
165
|
+
): void {
|
|
166
|
+
if (child.$type === 'ItemDeclaration') {
|
|
167
|
+
emitItem(child, drops, out);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (child.$type === 'GroupBlock') {
|
|
171
|
+
drops.group += 1;
|
|
172
|
+
emitGroup(child, breadcrumb, drops, out);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (child.$type === 'ParallelBlock') {
|
|
176
|
+
drops.parallel += 1;
|
|
177
|
+
emitParallel(child, breadcrumb, drops, out);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (child.$type === 'DescriptionDirective') {
|
|
181
|
+
drops.description += 1;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function emitGroup(
|
|
187
|
+
group: GroupBlock,
|
|
188
|
+
breadcrumb: readonly string[],
|
|
189
|
+
drops: DropCounts,
|
|
190
|
+
out: string[],
|
|
191
|
+
): void {
|
|
192
|
+
for (const child of group.content as GroupContent[]) {
|
|
193
|
+
if (child.$type === 'ItemDeclaration') {
|
|
194
|
+
emitItem(child, drops, out);
|
|
195
|
+
} else if (child.$type === 'GroupBlock') {
|
|
196
|
+
drops.group += 1;
|
|
197
|
+
emitGroup(child, breadcrumb, drops, out);
|
|
198
|
+
} else if (child.$type === 'ParallelBlock') {
|
|
199
|
+
drops.parallel += 1;
|
|
200
|
+
emitParallel(child, breadcrumb, drops, out);
|
|
201
|
+
} else if (child.$type === 'DescriptionDirective') {
|
|
202
|
+
drops.description += 1;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function emitParallel(
|
|
208
|
+
parallel: ParallelBlock,
|
|
209
|
+
breadcrumb: readonly string[],
|
|
210
|
+
drops: DropCounts,
|
|
211
|
+
out: string[],
|
|
212
|
+
): void {
|
|
213
|
+
for (const child of parallel.content) {
|
|
214
|
+
if (child.$type === 'ItemDeclaration') {
|
|
215
|
+
emitItem(child, drops, out);
|
|
216
|
+
} else if (child.$type === 'GroupBlock') {
|
|
217
|
+
drops.group += 1;
|
|
218
|
+
emitGroup(child, breadcrumb, drops, out);
|
|
219
|
+
} else if (child.$type === 'DescriptionDirective') {
|
|
220
|
+
drops.description += 1;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function emitItem(item: ItemDeclaration, drops: DropCounts, out: string[]): void {
|
|
226
|
+
countDrops(item, drops);
|
|
227
|
+
const id = item.name ?? slugify(displayLabel(item));
|
|
228
|
+
const status = mapStatus(getProp(item, 'status'));
|
|
229
|
+
const after = getProps(item, 'after');
|
|
230
|
+
const duration = durationToMermaid(getProp(item, 'duration') ?? getProp(item, 'size')) ?? '1d';
|
|
231
|
+
const _ref = after.length > 0 ? `after ${after.join(' ')}` : 'after , 0d'.replace(', 0d', '');
|
|
232
|
+
|
|
233
|
+
const meta = [status, id, after.length > 0 ? `after ${after.join(' ')}` : '', duration]
|
|
234
|
+
.filter((s) => s !== '')
|
|
235
|
+
.join(', ');
|
|
236
|
+
out.push(` ${escapeTaskName(displayLabel(item))} :${meta}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function emitMilestone(milestone: MilestoneDeclaration, drops: DropCounts, out: string[]): void {
|
|
240
|
+
const id = milestone.name ?? slugify(displayLabel(milestone));
|
|
241
|
+
const date = getProp(milestone, 'date');
|
|
242
|
+
if (date) {
|
|
243
|
+
out.push(` ${escapeTaskName(displayLabel(milestone))} :milestone, ${id}, ${date}, 0d`);
|
|
244
|
+
} else {
|
|
245
|
+
const after = getProps(milestone, 'depends');
|
|
246
|
+
if (after.length > 0) {
|
|
247
|
+
out.push(
|
|
248
|
+
` ${escapeTaskName(displayLabel(milestone))} :milestone, ${id}, after ${after.join(' ')}, 0d`,
|
|
249
|
+
);
|
|
250
|
+
} else {
|
|
251
|
+
out.push(` ${escapeTaskName(displayLabel(milestone))} :milestone, ${id}, 0d`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (hasProp(milestone, 'style')) drops.style += 1;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function countDrops(item: ItemDeclaration, drops: DropCounts): void {
|
|
258
|
+
if (getProps(item, 'labels').length > 0) drops.labels += 1;
|
|
259
|
+
if (hasProp(item, 'remaining')) drops.remaining += 1;
|
|
260
|
+
if (hasProp(item, 'owner')) drops.owner += 1;
|
|
261
|
+
if (getProps(item, 'before').length > 0) drops.before += 1;
|
|
262
|
+
if (hasProp(item, 'style')) drops.style += 1;
|
|
263
|
+
if (item.description) drops.description += 1;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function mapStatus(status: string | undefined): string {
|
|
267
|
+
switch (status) {
|
|
268
|
+
case 'done':
|
|
269
|
+
return 'done';
|
|
270
|
+
case 'in-progress':
|
|
271
|
+
return 'active';
|
|
272
|
+
case 'blocked':
|
|
273
|
+
case 'at-risk':
|
|
274
|
+
return 'crit';
|
|
275
|
+
default:
|
|
276
|
+
return '';
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function slugify(s: string): string {
|
|
281
|
+
return (
|
|
282
|
+
s
|
|
283
|
+
.toLowerCase()
|
|
284
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
285
|
+
.replace(/^-+|-+$/g, '') || 'item'
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function escapeMermaidText(s: string): string {
|
|
290
|
+
return s.replace(/[\r\n]+/g, ' ').replace(/"/g, '\u201c');
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function escapeTaskName(s: string): string {
|
|
294
|
+
// Mermaid splits the task line on `:` and `,` — strip them from the name.
|
|
295
|
+
return s.replace(/[\r\n]+/g, ' ').replace(/[:,]+/g, ' ');
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function formatDrops(drops: DropCounts): string | null {
|
|
299
|
+
const order: (keyof DropCounts)[] = [
|
|
300
|
+
'labels',
|
|
301
|
+
'footnote',
|
|
302
|
+
'remaining',
|
|
303
|
+
'owner',
|
|
304
|
+
'before',
|
|
305
|
+
'parallel',
|
|
306
|
+
'group',
|
|
307
|
+
'nestedSwimlanes',
|
|
308
|
+
'description',
|
|
309
|
+
'style',
|
|
310
|
+
];
|
|
311
|
+
const parts = order
|
|
312
|
+
.filter((key) => drops[key] > 0)
|
|
313
|
+
.map((key) => `${formatDropKey(key)} (${drops[key]})`);
|
|
314
|
+
if (parts.length === 0) return null;
|
|
315
|
+
const lines: string[] = [];
|
|
316
|
+
lines.push('%% Mermaid lossy export — Nowline features dropped:');
|
|
317
|
+
lines.push(`%% ${parts.join(', ')}`);
|
|
318
|
+
return lines.join('\n');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function formatDropKey(key: keyof DropCounts): string {
|
|
322
|
+
if (key === 'nestedSwimlanes') return 'nested-swimlanes';
|
|
323
|
+
return key;
|
|
324
|
+
}
|