@gordonkit/docforge 0.0.0-stage → 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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +46 -3
- package/README.zh-TW.md +36 -0
- package/THIRD_PARTY_NOTICES.md +169 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +3 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.js +182 -0
- package/dist/exporters/docx.d.ts +44 -0
- package/dist/exporters/docx.js +138 -0
- package/dist/exporters/gordon-doc.d.ts +28 -0
- package/dist/exporters/gordon-doc.js +77 -0
- package/dist/exporters/style.d.ts +10 -0
- package/dist/exporters/style.js +62 -0
- package/dist/images.d.ts +16 -0
- package/dist/images.js +22 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/load.d.ts +14 -0
- package/dist/load.js +34 -0
- package/dist/renderers/html.d.ts +19 -0
- package/dist/renderers/html.js +133 -0
- package/dist/schemas/document.d.ts +231 -0
- package/dist/schemas/document.js +142 -0
- package/dist/templates/default.d.ts +50 -0
- package/dist/templates/default.js +96 -0
- package/dist/validators/lint.d.ts +19 -0
- package/dist/validators/lint.js +148 -0
- package/examples/assets/small.png +0 -0
- package/examples/assets/wide.png +0 -0
- package/examples/report.json +61 -0
- package/package.json +61 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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 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 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 those 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
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 SlideForge contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# DocForge
|
|
2
|
+
|
|
3
|
+
> **Status: early release (v0.1.2).** The CLI, schema, lint and DOCX export work and are
|
|
4
|
+
> verified in Word. See the [roadmap](docs/plan.md) and [changelog](CHANGELOG.md).
|
|
5
|
+
|
|
6
|
+
DocForge is an AI-ready framework for creating consistent, **editable Word (DOCX)**
|
|
7
|
+
documents. It is the document sibling of [SlideForge](https://github.com/gordonkit/slideforge)
|
|
8
|
+
(HTML/CSS → PPTX): an AI writes strict, validated content, and DocForge renders,
|
|
9
|
+
previews, lints and exports it.
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
strict content (JSON) ─► validate + lint ─► HTML ─► gordon-doc (Pandoc) ─► DOCX ─► verify
|
|
13
|
+
└─► HTML preview └─► PDF + PNG pages (Word)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick start
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @gordonkit/docforge
|
|
20
|
+
docforge init document.json
|
|
21
|
+
docforge check document.json
|
|
22
|
+
docforge export document.json --output document.docx
|
|
23
|
+
docforge preview document.json --engine word-com
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Requires Node.js 24+, [Pandoc](https://pandoc.org/installing.html) and
|
|
27
|
+
[gordon-doc](https://github.com/gordonkit/gordon-doc-converter) 1.0.0 or later
|
|
28
|
+
(`pip install "gordon-doc-converter[images]"`), or use the [container image](docker/README.md)
|
|
29
|
+
`gordonkit/docforge`, which has all of them. See [`docs/cli.md`](docs/cli.md).
|
|
30
|
+
|
|
31
|
+
## Principles
|
|
32
|
+
|
|
33
|
+
- **Constrained input.** AI authors a strict JSON schema, never HTML or CSS.
|
|
34
|
+
- **Real Word structure.** Headings map to Heading 1–4, lists use numbering definitions, TOC is a field. Users can keep editing in Word.
|
|
35
|
+
- **Template driven.** Six built-in templates are design tokens applied to the DOCX styles; restyle without touching content.
|
|
36
|
+
- **Feedback loop.** Lint and preview results are machine-readable so an AI can fix its own output.
|
|
37
|
+
- **Honest limits.** Do not claim pixel-perfect conversion; document what is unsupported.
|
|
38
|
+
|
|
39
|
+
## Relationship to other repos
|
|
40
|
+
|
|
41
|
+
- [`gordon-doc-converter`](https://github.com/gordonkit/gordon-doc-converter) — conversion orchestration (Pandoc, LibreOffice, Word COM, page images). DocForge uses it for HTML → DOCX (Phase 1), DOCX → PDF and page-image previews.
|
|
42
|
+
- [`slideforge`](https://github.com/gordonkit/slideforge) — presentations. Shares design-token ideas and the AI workflow; code sharing is deferred until both stabilize.
|
|
43
|
+
|
|
44
|
+
[繁體中文](README.zh-TW.md)
|
|
45
|
+
|
|
46
|
+
Docs: [CLI](docs/cli.md) · [schema](docs/schema.md) · [templates](docs/templates.md) · [validation](docs/validation.md) · [AI workflow](docs/ai-workflow.md) · [limitations](docs/limitations.md) · [fidelity study](docs/fidelity.md) · [architecture](docs/architecture.md) · [roadmap](docs/plan.md) · [changelog](CHANGELOG.md).
|
package/README.zh-TW.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# DocForge
|
|
2
|
+
|
|
3
|
+
[English](README.md) · 繁體中文
|
|
4
|
+
|
|
5
|
+
> **狀態:早期版本(v0.1.2)。** CLI、schema、lint 與 DOCX 匯出已可使用,並在 Word 中驗證過。詳見[路線圖](docs/plan.md)與[變更紀錄](CHANGELOG.md)。
|
|
6
|
+
|
|
7
|
+
DocForge 是一個讓 AI 能穩定產生**可編輯 Word(DOCX)**文件的框架,是 [SlideForge](https://github.com/gordonkit/slideforge)(HTML/CSS → PPTX)的文件版姊妹專案:AI 只撰寫嚴格驗證的 JSON 內容,由 DocForge 負責渲染、預覽、lint 與匯出。
|
|
8
|
+
|
|
9
|
+
```text
|
|
10
|
+
嚴格 JSON ─► 驗證 + lint ─► HTML ─► gordon-doc (Pandoc) ─► DOCX ─► 結構驗證
|
|
11
|
+
└─► HTML 預覽 └─► PDF + PNG 頁面(Word)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## 快速開始
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @gordonkit/docforge
|
|
18
|
+
docforge init document.json
|
|
19
|
+
docforge check document.json
|
|
20
|
+
docforge export document.json --output document.docx
|
|
21
|
+
docforge preview document.json --engine word-com
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
需求:Node.js 24+、[Pandoc](https://pandoc.org/installing.html)、[gordon-doc](https://github.com/gordonkit/gordon-doc-converter) 1.0.0 以上(`pip install "gordon-doc-converter[images]"`);也可以改用已包含這些工具的[容器映像檔](docker/README.md) `gordonkit/docforge`。詳見 [`docs/zh-TW/guide.md`](docs/zh-TW/guide.md)。
|
|
25
|
+
|
|
26
|
+
## 原則
|
|
27
|
+
|
|
28
|
+
- **受限輸入**:AI 只寫嚴格的 JSON,不寫 HTML 或 CSS。
|
|
29
|
+
- **真正的 Word 結構**:標題對應 Heading 1–4,清單使用編號定義,目錄是欄位,使用者可繼續在 Word 編輯。
|
|
30
|
+
- **範本驅動**:內建六個範本(`default`、`classic`、`compact`、`minutes`、`proposal`、`letter`),換範本不必改內容。
|
|
31
|
+
- **回饋迴圈**:lint 與預覽結果可由機器讀取,AI 能自行修正。
|
|
32
|
+
- **誠實揭露限制**:不宣稱像素級一致,未支援的項目都有文件說明。
|
|
33
|
+
|
|
34
|
+
## 文件
|
|
35
|
+
|
|
36
|
+
[繁體中文指南](docs/zh-TW/guide.md) · [CLI](docs/cli.md) · [schema](docs/schema.md) · [範本](docs/templates.md) · [驗證](docs/validation.md) · [AI 工作流程](docs/ai-workflow.md) · [限制](docs/limitations.md) · [路線圖](docs/plan.md) · [變更紀錄](CHANGELOG.md)(其餘文件為英文)。
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
DocForge's own code is licensed under the Apache License 2.0 (see `LICENSE` and `NOTICE`).
|
|
4
|
+
Third-party packages keep their own copyrights and license terms; this document does not
|
|
5
|
+
relicense them.
|
|
6
|
+
|
|
7
|
+
## Scope
|
|
8
|
+
|
|
9
|
+
The production inventory is generated from the checked-in `package-lock.json` and the installed
|
|
10
|
+
package manifests. License files are reproduced verbatim. No third-party source is copied into
|
|
11
|
+
this repository, with one exception: the documentation site (`site/build.mjs`) embeds a few
|
|
12
|
+
icon outlines from [Heroicons](https://heroicons.com/) (MIT, Copyright (c) Tailwind Labs, Inc.;
|
|
13
|
+
the MIT terms are the ones reproduced under fflate below). They are not part of the npm package.
|
|
14
|
+
|
|
15
|
+
## External tools (not bundled)
|
|
16
|
+
|
|
17
|
+
DocForge runs these as separate processes and does not redistribute them:
|
|
18
|
+
|
|
19
|
+
- [Pandoc](https://pandoc.org/) (GPL-2.0-or-later), used through gordon-doc-converter.
|
|
20
|
+
- [gordon-doc-converter](https://github.com/gordonkit/gordon-doc-converter) (check its own license).
|
|
21
|
+
- Microsoft Word (optional, for previews on Windows) and LibreOffice (optional).
|
|
22
|
+
|
|
23
|
+
## Production dependencies
|
|
24
|
+
|
|
25
|
+
### fflate@0.8.3 (MIT)
|
|
26
|
+
|
|
27
|
+
https://101arrowz.github.io/fflate
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
MIT License
|
|
31
|
+
|
|
32
|
+
Copyright (c) 2026 Arjun Barrett
|
|
33
|
+
|
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
35
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
36
|
+
in the Software without restriction, including without limitation the rights
|
|
37
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
38
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
39
|
+
furnished to do so, subject to the following conditions:
|
|
40
|
+
|
|
41
|
+
The above copyright notice and this permission notice shall be included in all
|
|
42
|
+
copies or substantial portions of the Software.
|
|
43
|
+
|
|
44
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
45
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
46
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
47
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
48
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
49
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
50
|
+
SOFTWARE.
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### zod@4.6.7 (MIT)
|
|
54
|
+
|
|
55
|
+
https://zod.dev
|
|
56
|
+
|
|
57
|
+
```text
|
|
58
|
+
MIT License
|
|
59
|
+
|
|
60
|
+
Copyright (c) 2025 Colin McDonnell
|
|
61
|
+
|
|
62
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
63
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
64
|
+
in the Software without restriction, including without limitation the rights
|
|
65
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
66
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
67
|
+
furnished to do so, subject to the following conditions:
|
|
68
|
+
|
|
69
|
+
The above copyright notice and this permission notice shall be included in all
|
|
70
|
+
copies or substantial portions of the Software.
|
|
71
|
+
|
|
72
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
73
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
74
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
75
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
76
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
77
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
78
|
+
SOFTWARE.
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Development-only dependencies
|
|
82
|
+
|
|
83
|
+
Used to build and test; not shipped in the package.
|
|
84
|
+
|
|
85
|
+
| Package | Version | License |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| @jridgewell/resolve-uri | 3.1.2 | MIT |
|
|
88
|
+
| @jridgewell/sourcemap-codec | 1.6.0 | MIT |
|
|
89
|
+
| @jridgewell/trace-mapping | 0.3.31 | MIT |
|
|
90
|
+
| @oxc-project/types | 0.156.0 | MIT |
|
|
91
|
+
| @rolldown/binding-android-arm-eabi | 1.2.16 | MIT |
|
|
92
|
+
| @rolldown/binding-android-arm64 | 1.2.16 | MIT |
|
|
93
|
+
| @rolldown/binding-darwin-arm64 | 1.2.16 | MIT |
|
|
94
|
+
| @rolldown/binding-darwin-x64 | 1.2.16 | MIT |
|
|
95
|
+
| @rolldown/binding-freebsd-x64 | 1.2.16 | MIT |
|
|
96
|
+
| @rolldown/binding-linux-arm-gnueabihf | 1.2.16 | MIT |
|
|
97
|
+
| @rolldown/binding-linux-arm64-gnu | 1.2.16 | MIT |
|
|
98
|
+
| @rolldown/binding-linux-arm64-musl | 1.2.16 | MIT |
|
|
99
|
+
| @rolldown/binding-linux-ppc64-gnu | 1.2.16 | MIT |
|
|
100
|
+
| @rolldown/binding-linux-s390x-gnu | 1.2.16 | MIT |
|
|
101
|
+
| @rolldown/binding-linux-x64-gnu | 1.2.16 | MIT |
|
|
102
|
+
| @rolldown/binding-linux-x64-musl | 1.2.16 | MIT |
|
|
103
|
+
| @rolldown/binding-openharmony-arm64 | 1.2.16 | MIT |
|
|
104
|
+
| @rolldown/binding-win32-arm64-msvc | 1.2.16 | MIT |
|
|
105
|
+
| @rolldown/binding-win32-x64-msvc | 1.2.16 | MIT |
|
|
106
|
+
| @rolldown/pluginutils | 1.0.1 | MIT |
|
|
107
|
+
| @types/chai | 5.2.3 | MIT |
|
|
108
|
+
| @types/deep-eql | 4.0.2 | MIT |
|
|
109
|
+
| @types/estree | 1.0.10 | MIT |
|
|
110
|
+
| @types/node | 26.6.6 | MIT |
|
|
111
|
+
| @typescript/typescript-aix-ppc64 | 7.0.2 | Apache-2.0 |
|
|
112
|
+
| @typescript/typescript-darwin-arm64 | 7.0.2 | Apache-2.0 |
|
|
113
|
+
| @typescript/typescript-darwin-x64 | 7.0.2 | Apache-2.0 |
|
|
114
|
+
| @typescript/typescript-freebsd-arm64 | 7.0.2 | Apache-2.0 |
|
|
115
|
+
| @typescript/typescript-freebsd-x64 | 7.0.2 | Apache-2.0 |
|
|
116
|
+
| @typescript/typescript-linux-arm | 7.0.2 | Apache-2.0 |
|
|
117
|
+
| @typescript/typescript-linux-arm64 | 7.0.2 | Apache-2.0 |
|
|
118
|
+
| @typescript/typescript-linux-loong64 | 7.0.2 | Apache-2.0 |
|
|
119
|
+
| @typescript/typescript-linux-mips64el | 7.0.2 | Apache-2.0 |
|
|
120
|
+
| @typescript/typescript-linux-ppc64 | 7.0.2 | Apache-2.0 |
|
|
121
|
+
| @typescript/typescript-linux-riscv64 | 7.0.2 | Apache-2.0 |
|
|
122
|
+
| @typescript/typescript-linux-s390x | 7.0.2 | Apache-2.0 |
|
|
123
|
+
| @typescript/typescript-linux-x64 | 7.0.2 | Apache-2.0 |
|
|
124
|
+
| @typescript/typescript-netbsd-arm64 | 7.0.2 | Apache-2.0 |
|
|
125
|
+
| @typescript/typescript-netbsd-x64 | 7.0.2 | Apache-2.0 |
|
|
126
|
+
| @typescript/typescript-openbsd-arm64 | 7.0.2 | Apache-2.0 |
|
|
127
|
+
| @typescript/typescript-openbsd-x64 | 7.0.2 | Apache-2.0 |
|
|
128
|
+
| @typescript/typescript-sunos-x64 | 7.0.2 | Apache-2.0 |
|
|
129
|
+
| @typescript/typescript-win32-arm64 | 7.0.2 | Apache-2.0 |
|
|
130
|
+
| @typescript/typescript-win32-x64 | 7.0.2 | Apache-2.0 |
|
|
131
|
+
| @vitest/mocker | 5.0.5 | MIT |
|
|
132
|
+
| @vitest/spy | 5.0.5 | MIT |
|
|
133
|
+
| assertion-error | 2.0.1 | MIT |
|
|
134
|
+
| chai | 6.3.0 | MIT |
|
|
135
|
+
| detect-libc | 2.1.2 | Apache-2.0 |
|
|
136
|
+
| es-module-lexer | 2.3.2 | MIT |
|
|
137
|
+
| estree-walker | 3.0.3 | MIT |
|
|
138
|
+
| expect-type | 1.4.0 | Apache-2.0 |
|
|
139
|
+
| fdir | 6.5.0 | MIT |
|
|
140
|
+
| fsevents | 2.3.3 | MIT |
|
|
141
|
+
| lightningcss | 1.33.0 | MPL-2.0 |
|
|
142
|
+
| lightningcss-android-arm64 | 1.33.0 | MPL-2.0 |
|
|
143
|
+
| lightningcss-darwin-arm64 | 1.33.0 | MPL-2.0 |
|
|
144
|
+
| lightningcss-darwin-x64 | 1.33.0 | MPL-2.0 |
|
|
145
|
+
| lightningcss-freebsd-x64 | 1.33.0 | MPL-2.0 |
|
|
146
|
+
| lightningcss-linux-arm-gnueabihf | 1.33.0 | MPL-2.0 |
|
|
147
|
+
| lightningcss-linux-arm64-gnu | 1.33.0 | MPL-2.0 |
|
|
148
|
+
| lightningcss-linux-arm64-musl | 1.33.0 | MPL-2.0 |
|
|
149
|
+
| lightningcss-linux-x64-gnu | 1.33.0 | MPL-2.0 |
|
|
150
|
+
| lightningcss-linux-x64-musl | 1.33.0 | MPL-2.0 |
|
|
151
|
+
| lightningcss-win32-arm64-msvc | 1.33.0 | MPL-2.0 |
|
|
152
|
+
| lightningcss-win32-x64-msvc | 1.33.0 | MPL-2.0 |
|
|
153
|
+
| magic-string | 1.4.5 | MIT |
|
|
154
|
+
| nanoid | 3.3.20 | MIT |
|
|
155
|
+
| obug | 3.0.0 | MIT |
|
|
156
|
+
| picocolors | 1.1.1 | ISC |
|
|
157
|
+
| picomatch | 4.0.7 | MIT |
|
|
158
|
+
| postcss | 8.5.32 | MIT |
|
|
159
|
+
| rolldown | 1.2.16 | MIT |
|
|
160
|
+
| source-map-js | 1.2.2 | BSD-3-Clause |
|
|
161
|
+
| std-env | 4.3.0 | MIT |
|
|
162
|
+
| tinybench | 6.2.3 | MIT |
|
|
163
|
+
| tinyexec | 1.3.1 | MIT |
|
|
164
|
+
| tinyglobby | 0.2.17 | MIT |
|
|
165
|
+
| typescript | 7.0.2 | Apache-2.0 |
|
|
166
|
+
| undici-types | 8.9.0 | MIT |
|
|
167
|
+
| vite | 8.3.6 | MIT |
|
|
168
|
+
| vitest | 5.0.5 | MIT |
|
|
169
|
+
| why-is-node-running | 3.2.1 | MIT |
|
package/dist/cli/run.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, extname, join, resolve } from 'node:path';
|
|
4
|
+
import { parseArgs } from 'node:util';
|
|
5
|
+
import { ExportError, exportDocx, previewDocx } from '../exporters/docx.js';
|
|
6
|
+
import { ToolError } from '../exporters/gordon-doc.js';
|
|
7
|
+
import { DocumentError, loadDocument } from '../load.js';
|
|
8
|
+
import { renderHtml } from '../renderers/html.js';
|
|
9
|
+
import { getTemplate } from '../templates/default.js';
|
|
10
|
+
import { hasErrors } from '../validators/lint.js';
|
|
11
|
+
const help = `DocForge — editable Word documents from structured content
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
docforge init [document.json]
|
|
15
|
+
docforge check <document.json> [--json]
|
|
16
|
+
docforge build <document.json> [--output document.html]
|
|
17
|
+
docforge export <document.json> --output document.docx [--overwrite]
|
|
18
|
+
docforge preview <document.json> [--output-dir <directory>] [--engine word-com|libreoffice] [--json]
|
|
19
|
+
|
|
20
|
+
check validates the schema and lints the content. build writes an HTML preview. export
|
|
21
|
+
writes DOCX through gordon-doc (Pandoc required) and verifies the result. preview exports,
|
|
22
|
+
then renders PDF and PNG pages. Use --engine word-com for authoritative previews: only Word fills
|
|
23
|
+
the table of contents; LibreOffice shows a placeholder.
|
|
24
|
+
Set DOCFORGE_GORDON_DOC to the full path of gordon-doc if it is not on PATH.
|
|
25
|
+
Exit codes: 0 success, 1 operation/validation failure, 2 invalid CLI usage.`;
|
|
26
|
+
class UsageError extends Error {
|
|
27
|
+
}
|
|
28
|
+
const starter = {
|
|
29
|
+
version: 1,
|
|
30
|
+
title: 'Untitled document',
|
|
31
|
+
language: 'en',
|
|
32
|
+
footer: 'Page {page} of {pages}',
|
|
33
|
+
blocks: [
|
|
34
|
+
{ type: 'heading', level: 1, text: 'Untitled document' },
|
|
35
|
+
{ type: 'paragraph', text: ['Replace this text. Add ', { text: 'bold', bold: true }, ' words and a footnote.', { footnote: 'Footnotes are numbered automatically.' }] },
|
|
36
|
+
{ type: 'heading', level: 2, text: 'Section' },
|
|
37
|
+
{ type: 'list', ordered: false, items: ['First point', { text: 'Second point', children: ['Nested point'] }] },
|
|
38
|
+
{
|
|
39
|
+
type: 'table',
|
|
40
|
+
columns: [
|
|
41
|
+
{ header: 'Item', width: 60 },
|
|
42
|
+
{ header: 'Value', width: 40 },
|
|
43
|
+
],
|
|
44
|
+
rows: [
|
|
45
|
+
['Alpha', '1'],
|
|
46
|
+
['Beta', '2'],
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
function parseCli(args) {
|
|
52
|
+
try {
|
|
53
|
+
return parseArgs({
|
|
54
|
+
args,
|
|
55
|
+
allowPositionals: true,
|
|
56
|
+
options: {
|
|
57
|
+
output: { type: 'string', short: 'o' },
|
|
58
|
+
'output-dir': { type: 'string' },
|
|
59
|
+
engine: { type: 'string' },
|
|
60
|
+
overwrite: { type: 'boolean' },
|
|
61
|
+
json: { type: 'boolean' },
|
|
62
|
+
help: { type: 'boolean', short: 'h' },
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw new UsageError(error.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function main(args) {
|
|
71
|
+
const parsed = parseCli(args);
|
|
72
|
+
const { values, positionals } = parsed;
|
|
73
|
+
const [command, input] = positionals;
|
|
74
|
+
if (values.help || command === undefined) {
|
|
75
|
+
console.log(help);
|
|
76
|
+
return command === undefined && !values.help ? 2 : 0;
|
|
77
|
+
}
|
|
78
|
+
if (command === 'init') {
|
|
79
|
+
const target = resolve(input ?? 'document.json');
|
|
80
|
+
if (existsSync(target))
|
|
81
|
+
throw new UsageError(`${target} already exists`);
|
|
82
|
+
await mkdir(dirname(target), { recursive: true });
|
|
83
|
+
await writeFile(target, `${JSON.stringify(starter, null, 2)}\n`, 'utf8');
|
|
84
|
+
console.log(`Created ${target}`);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
if (!['check', 'build', 'export', 'preview'].includes(command))
|
|
88
|
+
throw new UsageError(`unknown command "${command}"`);
|
|
89
|
+
if (input === undefined)
|
|
90
|
+
throw new UsageError(`${command} needs a document JSON file`);
|
|
91
|
+
const loaded = await loadDocument(input);
|
|
92
|
+
const errors = hasErrors(loaded.issues);
|
|
93
|
+
if (command === 'check') {
|
|
94
|
+
if (values.json) {
|
|
95
|
+
console.log(JSON.stringify({ ok: !errors, file: loaded.file, issues: loaded.issues }, null, 2));
|
|
96
|
+
}
|
|
97
|
+
else if (loaded.issues.length === 0) {
|
|
98
|
+
console.log(`${loaded.file}: OK`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
for (const issue of loaded.issues) {
|
|
102
|
+
console.log(`${issue.severity.toUpperCase()} ${issue.code} ${issue.path}: ${issue.message}${issue.fix ? ` (${issue.fix})` : ''}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return errors ? 1 : 0;
|
|
106
|
+
}
|
|
107
|
+
if (errors) {
|
|
108
|
+
for (const issue of loaded.issues.filter((item) => item.severity === 'error')) {
|
|
109
|
+
console.error(`ERROR ${issue.code} ${issue.path}: ${issue.message}`);
|
|
110
|
+
}
|
|
111
|
+
console.error('Fix the errors above (run "docforge check") before continuing.');
|
|
112
|
+
return 1;
|
|
113
|
+
}
|
|
114
|
+
for (const issue of loaded.issues)
|
|
115
|
+
console.error(`${issue.severity.toUpperCase()} ${issue.code} ${issue.path}: ${issue.message}`);
|
|
116
|
+
const template = getTemplate(loaded.document.template);
|
|
117
|
+
const stem = basename(loaded.file, extname(loaded.file));
|
|
118
|
+
if (command === 'build') {
|
|
119
|
+
const output = resolve(values.output ?? join(dirname(loaded.file), `${stem}.html`));
|
|
120
|
+
const html = renderHtml(loaded.document, {
|
|
121
|
+
...(template ? { template } : {}),
|
|
122
|
+
mode: 'preview',
|
|
123
|
+
baseDir: loaded.baseDir,
|
|
124
|
+
outputDir: dirname(output),
|
|
125
|
+
});
|
|
126
|
+
await mkdir(dirname(output), { recursive: true });
|
|
127
|
+
await writeFile(output, html, 'utf8');
|
|
128
|
+
console.log(`Wrote ${output}`);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
if (command === 'export') {
|
|
132
|
+
if (!values.output)
|
|
133
|
+
throw new UsageError('export needs --output <file>.docx');
|
|
134
|
+
const result = await exportDocx(loaded.document, {
|
|
135
|
+
baseDir: loaded.baseDir,
|
|
136
|
+
output: values.output,
|
|
137
|
+
overwrite: values.overwrite === true,
|
|
138
|
+
});
|
|
139
|
+
console.log(`Wrote ${result.output}`);
|
|
140
|
+
console.log(`Verified: ${result.verified.length > 0 ? result.verified.join(', ') : 'structure (no optional features used)'}`);
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
const result = await previewDocx(loaded.document, {
|
|
144
|
+
baseDir: loaded.baseDir,
|
|
145
|
+
outputDir: values['output-dir'] ?? join(dirname(loaded.file), `${stem}-preview`),
|
|
146
|
+
...(values.engine ? { engine: values.engine } : {}),
|
|
147
|
+
});
|
|
148
|
+
if (values.json) {
|
|
149
|
+
console.log(JSON.stringify(result, null, 2));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.log(`Rendered ${result.pages.length} page(s) with ${result.engine}`);
|
|
153
|
+
console.log(`DOCX: ${result.docx}\nPDF: ${result.pdf}`);
|
|
154
|
+
for (const page of result.pages)
|
|
155
|
+
console.log(`Page: ${page}`);
|
|
156
|
+
}
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
159
|
+
/** Run the CLI with the given arguments and return the process exit code. */
|
|
160
|
+
export async function runCli(args) {
|
|
161
|
+
try {
|
|
162
|
+
return await main(args);
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
if (error instanceof UsageError) {
|
|
166
|
+
console.error(`${error.message}\n\n${help}`);
|
|
167
|
+
return 2;
|
|
168
|
+
}
|
|
169
|
+
if (error instanceof DocumentError) {
|
|
170
|
+
console.error(error.message);
|
|
171
|
+
for (const issue of error.schemaIssues)
|
|
172
|
+
console.error(` ${issue.path}: ${issue.message}`);
|
|
173
|
+
}
|
|
174
|
+
else if (error instanceof ExportError || error instanceof ToolError) {
|
|
175
|
+
console.error(error.message);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
console.error(error);
|
|
179
|
+
}
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
}
|