create-reactwright-doc 0.1.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 +21 -0
- package/README.md +36 -0
- package/package.json +35 -0
- package/src/index.js +306 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reactwright contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# create-reactwright-doc
|
|
2
|
+
|
|
3
|
+
Scaffolds a new Reactwright document with the template of your choice.
|
|
4
|
+
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm create reactwright-doc@latest my-doc -- --template=essay
|
|
9
|
+
cd my-doc
|
|
10
|
+
npm install
|
|
11
|
+
npm run build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Templates
|
|
15
|
+
|
|
16
|
+
| Flag | Package | Description |
|
|
17
|
+
|------|---------|-------------|
|
|
18
|
+
| `--template=essay` (default) | `@reactwright/template-essay` | MLA-style academic essay, Times 12pt double-spaced, Works Cited bibliography |
|
|
19
|
+
| `--template=ieee` | `@reactwright/template-ieee` | IEEE conference paper, two-column, numbered sections, numeric citations |
|
|
20
|
+
| `--template=report` | `@reactwright/template-report` | Technical/business report, single-spaced, decimal section numbering |
|
|
21
|
+
|
|
22
|
+
## What you get
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
my-doc/
|
|
26
|
+
├── package.json # deps: reactwright + chosen template + react
|
|
27
|
+
├── my-doc.tsx # starter document using <Template />
|
|
28
|
+
└── README.md # build + edit instructions
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The starter is intentionally minimal — replace the bodies, add sections,
|
|
32
|
+
ship.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "create-reactwright-doc",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffolder for new Reactwright documents.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Reactwright contributors",
|
|
7
|
+
"homepage": "https://github.com/PurpleReverie/reactwright/tree/main/packages/create-reactwright-doc#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/PurpleReverie/reactwright.git",
|
|
11
|
+
"directory": "packages/create-reactwright-doc"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/PurpleReverie/reactwright/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": ["reactwright", "scaffolder", "create-app"],
|
|
17
|
+
"type": "module",
|
|
18
|
+
"bin": {
|
|
19
|
+
"create-reactwright-doc": "./src/index.js"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"src",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"check": "node --check src/index.js"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Scaffolder for new Reactwright documents.
|
|
3
|
+
//
|
|
4
|
+
// Usage:
|
|
5
|
+
// npm create reactwright-doc my-doc -- --template=essay
|
|
6
|
+
// npx create-reactwright-doc my-doc --template=ieee
|
|
7
|
+
//
|
|
8
|
+
// Creates <my-doc>/ with:
|
|
9
|
+
// - package.json declaring deps on reactwright + the chosen template
|
|
10
|
+
// - <my-doc>.tsx using <Template /> from the template package
|
|
11
|
+
// - README.md with build instructions
|
|
12
|
+
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import process from "node:process";
|
|
16
|
+
|
|
17
|
+
const TEMPLATES = {
|
|
18
|
+
essay: {
|
|
19
|
+
pkg: "@reactwright/template-essay",
|
|
20
|
+
description: "MLA-style academic essay (Times 12pt double-spaced, Works Cited)"
|
|
21
|
+
},
|
|
22
|
+
ieee: {
|
|
23
|
+
pkg: "@reactwright/template-ieee",
|
|
24
|
+
description: "IEEE conference paper (two-column, numbered sections, numeric citations)"
|
|
25
|
+
},
|
|
26
|
+
"ieee-report": {
|
|
27
|
+
pkg: "@reactwright/template-ieee-report",
|
|
28
|
+
description: "IEEE technical report (single-column long-form, Roman section numbering)"
|
|
29
|
+
},
|
|
30
|
+
report: {
|
|
31
|
+
pkg: "@reactwright/template-report",
|
|
32
|
+
description: "Technical/business report (single-spaced, decimal section numbering)"
|
|
33
|
+
},
|
|
34
|
+
book: {
|
|
35
|
+
pkg: "@reactwright/template-book",
|
|
36
|
+
description: "Long-form chaptered book (5.5×8.5 trade paperback, Georgia serif)"
|
|
37
|
+
},
|
|
38
|
+
letter: {
|
|
39
|
+
pkg: "@reactwright/template-letter",
|
|
40
|
+
description: "Formal business letter (one-page, named regions: letterhead, addressee, …)"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const REACTWRIGHT_VERSION = "^0.2.0";
|
|
45
|
+
const TEMPLATE_VERSION = "^0.1.0";
|
|
46
|
+
|
|
47
|
+
function parseArgs(argv) {
|
|
48
|
+
let name = null;
|
|
49
|
+
let template = "essay";
|
|
50
|
+
for (const arg of argv) {
|
|
51
|
+
if (arg.startsWith("--template=")) {
|
|
52
|
+
template = arg.slice("--template=".length);
|
|
53
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
54
|
+
return { help: true };
|
|
55
|
+
} else if (!arg.startsWith("--") && name == null) {
|
|
56
|
+
name = arg;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { name, template };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function printHelp() {
|
|
63
|
+
console.log(`create-reactwright-doc — scaffold a new Reactwright document
|
|
64
|
+
|
|
65
|
+
Usage:
|
|
66
|
+
npm create reactwright-doc <name> -- --template=<template>
|
|
67
|
+
npx create-reactwright-doc <name> --template=<template>
|
|
68
|
+
|
|
69
|
+
Templates:
|
|
70
|
+
${Object.entries(TEMPLATES).map(([k, v]) => ` ${k.padEnd(12)} ${v.description}`).join("\n")}
|
|
71
|
+
|
|
72
|
+
Defaults: --template=essay
|
|
73
|
+
|
|
74
|
+
After scaffolding:
|
|
75
|
+
cd <name>
|
|
76
|
+
npm install
|
|
77
|
+
npm run build
|
|
78
|
+
`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function fail(message) {
|
|
82
|
+
console.error(`Error: ${message}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function main() {
|
|
87
|
+
const args = parseArgs(process.argv.slice(2));
|
|
88
|
+
if (args.help) {
|
|
89
|
+
printHelp();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!args.name) {
|
|
93
|
+
fail("Missing project name.\nUsage: npm create reactwright-doc my-doc -- --template=essay");
|
|
94
|
+
}
|
|
95
|
+
const template = TEMPLATES[args.template];
|
|
96
|
+
if (!template) {
|
|
97
|
+
fail(`Unknown template '${args.template}'. Available: ${Object.keys(TEMPLATES).join(", ")}.`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const targetDir = path.resolve(process.cwd(), args.name);
|
|
101
|
+
if (fs.existsSync(targetDir)) {
|
|
102
|
+
fail(`Directory already exists: ${targetDir}`);
|
|
103
|
+
}
|
|
104
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
105
|
+
|
|
106
|
+
const entryFile = `${args.name}.tsx`;
|
|
107
|
+
const pkg = {
|
|
108
|
+
name: args.name,
|
|
109
|
+
version: "0.1.0",
|
|
110
|
+
private: true,
|
|
111
|
+
type: "module",
|
|
112
|
+
scripts: {
|
|
113
|
+
build: `reactwright ${entryFile} --format html,pdf --out .`
|
|
114
|
+
},
|
|
115
|
+
dependencies: {
|
|
116
|
+
[template.pkg]: TEMPLATE_VERSION,
|
|
117
|
+
react: "^19.0.0",
|
|
118
|
+
reactwright: REACTWRIGHT_VERSION
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
fs.writeFileSync(
|
|
123
|
+
path.join(targetDir, "package.json"),
|
|
124
|
+
JSON.stringify(pkg, null, 2) + "\n"
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
fs.writeFileSync(
|
|
128
|
+
path.join(targetDir, entryFile),
|
|
129
|
+
starterTsx(args.template, args.name)
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
fs.writeFileSync(
|
|
133
|
+
path.join(targetDir, "README.md"),
|
|
134
|
+
starterReadme(args.name, args.template, entryFile)
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
console.log(`✓ Created ${args.name}/
|
|
138
|
+
|
|
139
|
+
${args.name}/
|
|
140
|
+
├── package.json
|
|
141
|
+
├── ${entryFile}
|
|
142
|
+
└── README.md
|
|
143
|
+
|
|
144
|
+
Next steps:
|
|
145
|
+
cd ${args.name}
|
|
146
|
+
npm install
|
|
147
|
+
npm run build
|
|
148
|
+
|
|
149
|
+
The build outputs ${args.name.replace(/\W/g, "_")}.html and ${args.name.replace(/\W/g, "_")}.pdf alongside the source.
|
|
150
|
+
`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function starterTsx(templateKey, name) {
|
|
154
|
+
const template = TEMPLATES[templateKey];
|
|
155
|
+
if (templateKey === "letter") {
|
|
156
|
+
return `import "reactwright/jsx";
|
|
157
|
+
import { Template } from "${template.pkg}";
|
|
158
|
+
|
|
159
|
+
export { Template };
|
|
160
|
+
|
|
161
|
+
export default function Document() {
|
|
162
|
+
return (
|
|
163
|
+
<document title="${name}" author="Sender Name">
|
|
164
|
+
<section role="letterhead" title="Sender Name">
|
|
165
|
+
<p>123 Example Street</p>
|
|
166
|
+
<p>City, ST 00000</p>
|
|
167
|
+
<p>sender@example.com</p>
|
|
168
|
+
</section>
|
|
169
|
+
|
|
170
|
+
<section role="date" title="">
|
|
171
|
+
<p>1 January 2026</p>
|
|
172
|
+
</section>
|
|
173
|
+
|
|
174
|
+
<section role="addressee" title="">
|
|
175
|
+
<p>Recipient Name</p>
|
|
176
|
+
<p>Recipient Title</p>
|
|
177
|
+
<p>Organization</p>
|
|
178
|
+
<p>Recipient Address</p>
|
|
179
|
+
</section>
|
|
180
|
+
|
|
181
|
+
<section role="salutation" title="">
|
|
182
|
+
<p>Dear Recipient,</p>
|
|
183
|
+
</section>
|
|
184
|
+
|
|
185
|
+
<p>
|
|
186
|
+
Write your opening paragraph here. Replace this starter prose
|
|
187
|
+
with the substance of your letter.
|
|
188
|
+
</p>
|
|
189
|
+
|
|
190
|
+
<section role="closing" title="">
|
|
191
|
+
<p>Sincerely,</p>
|
|
192
|
+
</section>
|
|
193
|
+
|
|
194
|
+
<section role="signature" title="">
|
|
195
|
+
<p>Sender Name</p>
|
|
196
|
+
<p>Sender Title</p>
|
|
197
|
+
</section>
|
|
198
|
+
</document>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
if (templateKey === "book") {
|
|
204
|
+
return `import "reactwright/jsx";
|
|
205
|
+
import { Template } from "${template.pkg}";
|
|
206
|
+
|
|
207
|
+
export { Template };
|
|
208
|
+
|
|
209
|
+
export default function Document() {
|
|
210
|
+
return (
|
|
211
|
+
<document title="${name}" author="A. Author">
|
|
212
|
+
<section role="title-page" title="${name}">
|
|
213
|
+
<p>A. Author</p>
|
|
214
|
+
</section>
|
|
215
|
+
|
|
216
|
+
<section role="front-matter" title="Copyright">
|
|
217
|
+
<p>Copyright © 2026 A. Author. All rights reserved.</p>
|
|
218
|
+
</section>
|
|
219
|
+
|
|
220
|
+
<section role="chapter" title="The First Chapter">
|
|
221
|
+
<set running="chapter-title" value="The First Chapter" />
|
|
222
|
+
<p>
|
|
223
|
+
Welcome to your new book. Replace this opening paragraph with
|
|
224
|
+
your prose. Each <code>{"<section role=\\"chapter\\">"}</code> becomes
|
|
225
|
+
a chapter that starts on a fresh page.
|
|
226
|
+
</p>
|
|
227
|
+
</section>
|
|
228
|
+
|
|
229
|
+
<section role="back-matter" title="Acknowledgments">
|
|
230
|
+
<p>Thanks to everyone who made this possible.</p>
|
|
231
|
+
</section>
|
|
232
|
+
</document>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
`;
|
|
236
|
+
}
|
|
237
|
+
return `import "reactwright/jsx";
|
|
238
|
+
import { Template } from "${template.pkg}";
|
|
239
|
+
|
|
240
|
+
export { Template };
|
|
241
|
+
|
|
242
|
+
export default function Document() {
|
|
243
|
+
return (
|
|
244
|
+
<document title="${name}" author="Anonymous">
|
|
245
|
+
<section title="Introduction">
|
|
246
|
+
<p>
|
|
247
|
+
Welcome to your new Reactwright document. Edit this file to
|
|
248
|
+
replace the starter content. Anything you can express in JSX
|
|
249
|
+
flows through the engine to paginated HTML and PDF.
|
|
250
|
+
</p>
|
|
251
|
+
<p>
|
|
252
|
+
See <a href="https://github.com/PurpleReverie/reactwright">the
|
|
253
|
+
documentation</a> for the full primitive vocabulary.
|
|
254
|
+
</p>
|
|
255
|
+
</section>
|
|
256
|
+
|
|
257
|
+
<section title="Next steps">
|
|
258
|
+
<p>
|
|
259
|
+
Try editing this section. Add more sections. Drop in figures,
|
|
260
|
+
tables, citations. Run <code>npm run build</code> to regenerate
|
|
261
|
+
the PDF.
|
|
262
|
+
</p>
|
|
263
|
+
</section>
|
|
264
|
+
|
|
265
|
+
<refs>
|
|
266
|
+
<ref-entry refKey="example">
|
|
267
|
+
Example, A. (2026). <em>A Placeholder Reference</em>. Publisher.
|
|
268
|
+
</ref-entry>
|
|
269
|
+
</refs>
|
|
270
|
+
</document>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
`;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function starterReadme(name, templateKey, entryFile) {
|
|
277
|
+
return `# ${name}
|
|
278
|
+
|
|
279
|
+
A Reactwright document scaffolded with \`create-reactwright-doc --template=${templateKey}\`.
|
|
280
|
+
|
|
281
|
+
## Build
|
|
282
|
+
|
|
283
|
+
\`\`\`sh
|
|
284
|
+
npm install
|
|
285
|
+
npm run build
|
|
286
|
+
\`\`\`
|
|
287
|
+
|
|
288
|
+
This produces \`${entryFile.replace(/\.tsx$/, ".html")}\` and \`${entryFile.replace(/\.tsx$/, ".pdf")}\`.
|
|
289
|
+
|
|
290
|
+
## Edit
|
|
291
|
+
|
|
292
|
+
Edit \`${entryFile}\` to write your document. Reactwright primitives like
|
|
293
|
+
\`<section>\`, \`<p>\`, \`<figure>\`, \`<table>\`, and \`<cite>\` are
|
|
294
|
+
declared in JSX; the engine compiles them to paginated HTML + PDF.
|
|
295
|
+
|
|
296
|
+
Replace the bibliography stub with your real references in the
|
|
297
|
+
\`<refs>\` block, then cite them via \`<cite cite="key" />\`.
|
|
298
|
+
|
|
299
|
+
## Learn more
|
|
300
|
+
|
|
301
|
+
- Reactwright docs: https://github.com/PurpleReverie/reactwright
|
|
302
|
+
- Template (${templateKey}): https://github.com/PurpleReverie/reactwright/tree/main/packages/template-${templateKey}
|
|
303
|
+
`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
main();
|