Skip to content

Commit

Permalink
chore: put docx and xlsx into their own folders
Browse files Browse the repository at this point in the history
  • Loading branch information
iyxan23 committed Sep 26, 2024
1 parent 8b2da57 commit 24899dc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"exports": {
"./package.json": "./package.json",
"./xlsx": {
"require": "./dist/xlsx.js",
"types": "./dist/xlsx.d.ts",
"import": "./dist/xlsx.mjs",
"default": "./dist/xlsx.mjs"
"require": "./dist/xlsx/index.js",
"types": "./dist/xlsx/index.d.ts",
"import": "./dist/xlsx/index.mjs",
"default": "./dist/xlsx/index.mjs"
},
"./docx": {
"require": "./dist/docx.js",
"types": "./dist/docx.d.ts",
"import": "./dist/docx.mjs",
"default": "./dist/docx.mjs"
"require": "./dist/docx/index.js",
"types": "./dist/docx/index.d.ts",
"import": "./dist/docx/index.mjs",
"default": "./dist/docx/index.mjs"
}
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fileURLToPath } from "url";
import type { RollupOptions } from "rollup";
import { buildConfig } from "./scripts/getRollupConfig";

export const input = ["src/docx.ts", "src/xlsx.ts"];
export const input = ["src/docx/index.ts", "src/xlsx/index.ts"];

export default function rollup(): RollupOptions[] {
return buildConfig({
Expand Down
File renamed without changes.
12 changes: 9 additions & 3 deletions src/docx.ts → src/docx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "fast-xml-parser";
import { BlobReader, BlobWriter, ZipReader, ZipWriter } from "@zip.js/zip.js";
import { docxClosingTags } from "./docx-closing-tags-list";
import { startVisiting } from "./visitor-editor";
import { startVisiting } from "../visitor-editor";

export async function docxFillTemplate(
docx: ReadableStream,
Expand Down Expand Up @@ -169,12 +169,18 @@ async function templateDocument(xml: any, input: any): Promise<any> {
if (!body) return xml;

const items = await collectBodyElements(body);
const newBodyItems = rebuildBodyElements(items);
const templatedItems = performTemplating(items, input);
const newBodyItems = rebuildBodyElements(templatedItems);

return await startVisiting(xml, {
return startVisiting(xml, {
before: {},
after: {
"w:body": [() => ({ newObj: newBodyItems })],
},
});
}

function performTemplating(items: BodyElement[], input: any): BodyElement[] {
console.log(JSON.stringify(input, null, 2));
return items;
}
12 changes: 6 additions & 6 deletions src/xlsx.ts → src/xlsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
XmlBuilderOptions,
XMLParser,
} from "fast-xml-parser";
import { startVisiting } from "./visitor-editor";
import { Sheet } from "./sheet/sheet";
import { SheetTemplater, TemplatableCell } from "./sheet/sheet-templater";
import { TemplaterFunction } from "./expression/evaluate";
import { Issue } from "./result";
import { isNumeric } from "./utils";
import { startVisiting } from "../visitor-editor";
import { Sheet } from "../sheet/sheet";
import { SheetTemplater, TemplatableCell } from "../sheet/sheet-templater";
import { TemplaterFunction } from "../expression/evaluate";
import { Issue } from "../result";
import { isNumeric } from "../utils";

const SHARED_STRINGS_ENTRY = "xl/sharedStrings.xml";

Expand Down

0 comments on commit 24899dc

Please sign in to comment.