libreoffice-convert 1.5.1 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Readme.md +2 -1
- package/index.d.ts +1 -0
- package/index.js +10 -6
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -4,7 +4,8 @@ A simple and fast node.js module for converting office documents to different fo
|
|
|
4
4
|
|
|
5
5
|
## Dependency
|
|
6
6
|
|
|
7
|
-
Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows)
|
|
7
|
+
Please install libreoffice in /Applications (Mac), with your favorite package manager (Linux), or with the msi (Windows)
|
|
8
|
+
(On Windows, add `PROGRAMFILES` environment variable for Windows program files path to your local project)
|
|
8
9
|
|
|
9
10
|
## Usage example
|
|
10
11
|
|
package/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare module "libreoffice-convert" {
|
|
|
14
14
|
tmpOptions?: Record<string | number | symbol, unknown>;
|
|
15
15
|
asyncOptions?: { times?: number; interval?: number };
|
|
16
16
|
sofficeBinaryPaths?: string[];
|
|
17
|
+
fileName?: string;
|
|
17
18
|
},
|
|
18
19
|
callback: (err: NodeJS.ErrnoException | null, data: Buffer) => void
|
|
19
20
|
): void;
|
package/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
11
11
|
const tmpOptions = (options || {}).tmpOptions || {};
|
|
12
12
|
const asyncOptions = (options || {}).asyncOptions || {};
|
|
13
13
|
const execOptions = (options || {}).execOptions || {};
|
|
14
|
+
const fileName = (options || {}).fileName || 'source';
|
|
14
15
|
const tempDir = tmp.dirSync({prefix: 'libreofficeConvert_', unsafeCleanup: true, ...tmpOptions});
|
|
15
16
|
const installDir = tmp.dirSync({prefix: 'soffice', unsafeCleanup: true, ...tmpOptions});
|
|
16
17
|
return async.auto({
|
|
@@ -23,9 +24,12 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
23
24
|
break;
|
|
24
25
|
case 'win32': paths = [
|
|
25
26
|
...paths,
|
|
26
|
-
path.join(process.env['PROGRAMFILES(X86)'], 'LIBREO~1/program/soffice.exe'),
|
|
27
|
-
path.join(process.env['PROGRAMFILES(X86)'], 'LibreOffice/program/soffice.exe'),
|
|
28
|
-
path.join(process.env.
|
|
27
|
+
path.join(process.env['PROGRAMFILES(X86)'] || '', 'LIBREO~1/program/soffice.exe'),
|
|
28
|
+
path.join(process.env['PROGRAMFILES(X86)'] || '', 'LibreOffice/program/soffice.exe'),
|
|
29
|
+
path.join(process.env.PROGRAMFILES_X86 || '', 'LibreOffice/program/soffice.exe'),
|
|
30
|
+
path.join(process.env.PROGRAMFILES || '', 'LibreOffice/program/soffice.exe'),
|
|
31
|
+
process.env.LIBRE_OFFICE_EXE || '',
|
|
32
|
+
'C:/Program Files/LibreOffice/program/soffice.exe'
|
|
29
33
|
];
|
|
30
34
|
break;
|
|
31
35
|
default:
|
|
@@ -44,7 +48,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
44
48
|
}
|
|
45
49
|
);
|
|
46
50
|
},
|
|
47
|
-
saveSource: callback => fs.writeFile(path.join(tempDir.name,
|
|
51
|
+
saveSource: callback => fs.writeFile(path.join(tempDir.name, fileName), document, callback),
|
|
48
52
|
convert: ['soffice', 'saveSource', (results, callback) => {
|
|
49
53
|
let filterParam = filter?.length ? `:${filter}` : "";
|
|
50
54
|
let fmt = !(filter ?? "").includes(" ") ? `${format}${filterParam}` : `"${format}${filterParam}"`;
|
|
@@ -55,7 +59,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
55
59
|
args.push(fmt);
|
|
56
60
|
args.push('--outdir');
|
|
57
61
|
args.push(tempDir.name);
|
|
58
|
-
args.push(path.join(tempDir.name,
|
|
62
|
+
args.push(path.join(tempDir.name, fileName));
|
|
59
63
|
|
|
60
64
|
return execFile(results.soffice, args, execOptions, callback);
|
|
61
65
|
}],
|
|
@@ -63,7 +67,7 @@ const convertWithOptions = (document, format, filter, options, callback) => {
|
|
|
63
67
|
async.retry({
|
|
64
68
|
times: asyncOptions.times || 3,
|
|
65
69
|
interval: asyncOptions.interval || 200
|
|
66
|
-
}, (callback) => fs.readFile(path.join(tempDir.name,
|
|
70
|
+
}, (callback) => fs.readFile(path.join(tempDir.name, `${fileName}.${format.split(":")[0]}`), callback), callback)
|
|
67
71
|
]
|
|
68
72
|
}).then( (res) => {
|
|
69
73
|
return callback(null, res.loadDestination);
|