import util from 'node:util'; import { PageSizes } from 'pdf-lib'; export type formatConfig = { /** * Page format - Letter, Legal, A4, etc */ format?: string }; export function parseFormat(cmdOptions: any, config: formatConfig): formatConfig { if (typeof cmdOptions.format !== 'undefined') { if (typeof cmdOptions.format === 'string') { if (!(cmdOptions.format in PageSizes)) { throw new Error(`Invalid --format value ${util.inspect(cmdOptions.format)}`); } config.format = cmdOptions.format; } else { throw new Error(`Invalid --format type ${util.inspect(cmdOptions.format)}`); } } return config; } export type rotateConfig = { rotate?: number; }; export function parseRotate(cmdOptions: any, config: rotateConfig): rotateConfig { if (typeof cmdOptions.rotate !== 'undefined') { if (typeof cmdOptions.rotate === 'string') { if (cmdOptions.rotate === '0') { // no rotation } else if (cmdOptions.rotate === '90') { config.rotate = 90; } else if (cmdOptions.rotate === '180') { config.rotate = 180; } else if (cmdOptions.rotate === '270') { config.rotate = 270; } else { throw new Error(`Invalid --rotate value ${util.inspect(cmdOptions.rotate)}`); } } else { throw new Error(`Invalid --rotate type ${util.inspect(cmdOptions.rotate)}`) } } return config; } /** * Container for the instructions to render one or more PDFs. * Normally this is generated by the `render` sub-command, * but could be generated by other code. */ export type renderConfig = { files: Array<{ /** * VPath of the document file, meaning it is the * pathname within the virtual file system comprised * of the document directories. * * Each vpath generates a PDF file. */ vpath: string, /** * Object derived from YAML that is metadata to * be used for this document. */ // metadata?: any, /** * Override the layout template for a specific file */ // layout?: string, /** * Document files to be incorporated into * the document in vpath, and added to the PDF. * * This is a placeholder for if/when this feature * is implemented. */ // attachments?: Array<{ // vpath: string, // metadata: any // }> }>, /** * Page format - Letter, Legal, A4, etc */ // format: string, /** * Directory where PDF files land */ pdfOutput: string, /** * Directory where HTML/CSS/etc files land. This is the * same as the AkashaCMS rendering output directory. */ htmlOutput: string, /** * Enable/disable autoconversion of link-like text to a link. */ linkify: boolean, /** * File name, referenced to root of project directory, of * the template for the PDF header */ templateHeader: string, /** * Height, in pixels, of the header. TBD is this to be a number? */ heightHeader: string, /** * File name, referenced to root of project directory, of * the template for the PDF footer. */ templateFooter: string, /** * Height, in pixels, of the footer. TBD is this to be a number? */ heightFooter: string, /** * Date to record as the publication date. * * TODO make sure this becomes the creationDate metadata */ publicationDate: Date, /** * Date to record as the modification date * * TODO make sure this becomes the modificationDate metadata * * TODO make sure there's a render option for this */ modificationDate: Date, /** * Directory names where layout templates live. This corresponds * to the AkashaCMS layoutDirs configuration setting. */ layoutDirs?: Array, /** * Directory names where asset files live. This corresponds * to the AkashaCMS assetDirs configuration setting. */ assetDirs?: Array /** * Directory names where partial templates live. This corresponds * to the AkashaCMS partialDirs configuration setting. */ partialDirs?: Array, /** * Directory names where document files live. This corresponds * to the AkashaCMS documentDirs configuration setting. */ documentDirs?: Array, /** * File name for a JavaScript module containing a Mahafunk array. * This will be plugged into the configuraion to support * custom processing of the documents. */ funcs?: string, /** * Print extra information as the documents are processed. */ verbose?: boolean, } & formatConfig ;