• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

gflohr / e-invoice-eu / 14053294363

25 Mar 2025 06:41AM UTC coverage: 68.943%. First build
14053294363

Pull #110

github

web-flow
Merge 38ab38b43 into fbaf9faed
Pull Request #110: Move logic into core library

233 of 371 branches covered (62.8%)

Branch coverage included in aggregate %.

427 of 556 new or added lines in 22 files covered. (76.8%)

726 of 1020 relevant lines covered (71.18%)

72.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.22
/packages/core/src/utils/render-spreadsheet.ts
1
import { spawn } from 'child_process';
39✔
2
import { promises as fs } from 'fs';
39✔
3
import * as path from 'path';
39✔
4
import * as tmp from 'tmp-promise';
39✔
5
import * as url from 'url';
39✔
6

7
import { Logger } from '../logger.interface';
8

9
export const renderSpreadsheet = async (
39✔
10
        filename: string,
11
        buffer: Buffer,
12
        libreoffice: string,
13
        logger: Logger,
14
): Promise<Buffer> => {
NEW
15
        const userDir = await tmp.tmpName();
×
NEW
16
        const userDirUrl = url.pathToFileURL(path.resolve(userDir));
×
NEW
17
        const parsedOriginalFilename = path.parse(filename);
×
NEW
18
        const inputFilename = (
×
19
                await tmp.file({ postfix: parsedOriginalFilename.ext })
20
        ).path;
NEW
21
        await fs.writeFile(inputFilename, buffer);
×
NEW
22
        const outputDir = (await tmp.dir()).path;
×
23

NEW
24
        const args = [
×
25
                '--headless',
26
                `-env:UserInstallation=${userDirUrl.href}`,
27
                '--convert-to',
28
                'pdf',
29
                '--outdir',
30
                outputDir,
31
                inputFilename,
32
        ];
NEW
33
        logger.log(
×
34
                `Executing command '${libreoffice}' with args '${args.join(' ')}'`,
35
        );
36

NEW
37
        await new Promise<void>((resolve, reject) => {
×
NEW
38
                const child = spawn(libreoffice, args, { stdio: 'inherit' });
×
39

NEW
40
                child.on('error', err => {
×
NEW
41
                        logger.error(`Error spawning process: ${err.message}`);
×
NEW
42
                        reject(err);
×
43
                });
44

NEW
45
                child.on('close', code => {
×
NEW
46
                        if (code === 0) {
×
NEW
47
                                logger.log(`LibreOffice command executed successfully`);
×
NEW
48
                                resolve();
×
49
                        } else {
NEW
50
                                const errorMsg = `LibreOffice command failed with exit code ${code}`;
×
NEW
51
                                logger.error(errorMsg);
×
NEW
52
                                reject(new Error(errorMsg));
×
53
                        }
54
                });
55
        });
56

NEW
57
        const parsedInputFilename = path.parse(inputFilename);
×
NEW
58
        const outputFilename = path.join(
×
59
                outputDir,
60
                parsedInputFilename.name + '.pdf',
61
        );
62

NEW
63
        logger.log(`Reading converted file from '${outputFilename}'`);
×
64

NEW
65
        try {
×
NEW
66
                const pdfBuffer = await fs.readFile(outputFilename);
×
NEW
67
                return pdfBuffer;
×
68
        } catch (error) {
NEW
69
                logger.error(`Error reading output PDF: ${error.message}`);
×
NEW
70
                throw error;
×
71
        }
72
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc