-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinspect.ts
43 lines (39 loc) · 1.42 KB
/
inspect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @file
* Dump the structure of a Docx instance to console.
*
* Use as;
* deno run --allow-read inspect.ts test/simple.docx
*/
import Docx, { FooterXml, HeaderXml, RelationshipType } from './mod.ts';
import { getColorizedJsxForComponent } from './src/utilities/debug.ts';
const docx = await Docx.fromArchive(Deno.args[0]);
async function jsxifyHeaderFooter(file: FooterXml | HeaderXml) {
(await file.children).forEach((child) =>
console.log(getColorizedJsxForComponent(child).join('\n')),
);
}
if (Deno.args.includes('--settings')) {
console.dir(
docx.document.relationships.findInstance((meta) => meta.type === RelationshipType.settings),
{ depth: 50 },
);
} else if (Deno.args.includes('--custom-properties')) {
console.dir(docx.customProperties, { depth: 50 });
} else if (Deno.args.includes('--footer')) {
const footer = await docx.document.relationships.filterInstances<FooterXml>(
(meta) => meta.type === RelationshipType.footer,
)[1];
await jsxifyHeaderFooter(footer);
} else if (Deno.args.includes('--header')) {
const footer = await docx.document.relationships.filterInstances<HeaderXml>(
(meta) => meta.type === RelationshipType.header,
)[0];
await jsxifyHeaderFooter(footer);
} else if (Deno.args.includes('--json')) {
console.log(JSON.stringify(await docx.document.children, null, ' '));
} else {
console.dir(getColorizedJsxForComponent((await docx.document.children)[0]).join('\n'), {
depth: 50,
});
}