fix(smartfs): replace smartfile with smartfs, update file reading to use SmartFs, remove GraphicsMagick/Ghostscript dependency checks, bump dev and runtime dependencies, update tests and docs, and adjust npmextra configuration
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartpdf',
|
||||
version: '3.2.2',
|
||||
version: '4.1.2',
|
||||
description: 'A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.'
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ import * as paths from './smartpdf.paths.js';
|
||||
import { Server } from 'http';
|
||||
import { PdfCandidate } from './smartpdf.classes.pdfcandidate.js';
|
||||
import { type IPdf } from '@tsclass/tsclass/dist_ts/business/pdf.js';
|
||||
import { execFile } from 'child_process';
|
||||
|
||||
declare const document: any;
|
||||
|
||||
export interface ISmartPdfOptions {
|
||||
@@ -272,7 +270,9 @@ export class SmartPdf {
|
||||
public async readFileToPdfObject(pathArg: string): Promise<plugins.tsclass.business.IPdf> {
|
||||
const absolutePath = plugins.smartpath.transform.makeAbsolute(pathArg);
|
||||
const parsedPath = plugins.path.parse(absolutePath);
|
||||
const buffer = await plugins.smartfile.fs.toBuffer(absolutePath);
|
||||
const smartfsInstance = new plugins.smartfs.SmartFs(new plugins.smartfs.SmartFsProviderNode());
|
||||
const fileContent = await smartfsInstance.file(absolutePath).read();
|
||||
const buffer = Buffer.from(fileContent);
|
||||
return {
|
||||
name: parsedPath.base,
|
||||
buffer,
|
||||
@@ -299,31 +299,6 @@ export class SmartPdf {
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for the presence of required dependencies: GraphicsMagick and Ghostscript.
|
||||
*/
|
||||
private async checkDependencies(): Promise<void> {
|
||||
await Promise.all([
|
||||
this.checkCommandExists('gm', ['version']),
|
||||
this.checkCommandExists('gs', ['--version']),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given command exists by trying to execute it.
|
||||
*/
|
||||
private checkCommandExists(command: string, args: string[]): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
execFile(command, args, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(new Error(`Dependency check failed: ${command} is not installed or not in the PATH. ${error.message}`));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a PDF to PNG bytes for each page using Puppeteer and PDF.js.
|
||||
* This method creates a temporary HTML page that loads PDF.js from a CDN,
|
||||
|
||||
@@ -6,7 +6,7 @@ export { http, path };
|
||||
|
||||
// @pushrocks
|
||||
import * as smartbuffer from '@push.rocks/smartbuffer';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
import * as smartfs from '@push.rocks/smartfs';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartpath from '@push.rocks/smartpath';
|
||||
@@ -17,7 +17,7 @@ import * as smartjimp from '@push.rocks/smartjimp';
|
||||
|
||||
export {
|
||||
smartbuffer,
|
||||
smartfile,
|
||||
smartfs,
|
||||
smartdelay,
|
||||
smartpromise,
|
||||
smartpath,
|
||||
|
||||
Reference in New Issue
Block a user