@jbrowse/img 3.6.5 → 4.0.0
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/package.json +32 -26
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +0 -11
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -146
- package/dist/parseArgv.d.ts +0 -8
- package/dist/parseArgv.js +0 -33
- package/dist/renderRegion.d.ts +0 -34
- package/dist/renderRegion.js +0 -385
- package/dist/setupEnv.d.ts +0 -1
- package/dist/setupEnv.js +0 -66
- package/dist/util.d.ts +0 -5
- package/dist/util.js +0 -30
- package/esm/bin.d.ts +0 -2
- package/esm/bin.js +0 -11
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -141
- package/esm/parseArgv.d.ts +0 -8
- package/esm/parseArgv.js +0 -29
- package/esm/renderRegion.d.ts +0 -34
- package/esm/renderRegion.js +0 -378
- package/esm/setupEnv.d.ts +0 -1
- package/esm/setupEnv.js +0 -30
- package/esm/util.d.ts +0 -5
- package/esm/util.js +0 -23
package/esm/renderRegion.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Entry } from './parseArgv';
|
|
2
|
-
export interface Opts {
|
|
3
|
-
noRasterize?: boolean;
|
|
4
|
-
loc?: string;
|
|
5
|
-
width?: number;
|
|
6
|
-
session?: string;
|
|
7
|
-
assembly?: string;
|
|
8
|
-
config?: string;
|
|
9
|
-
fasta?: string;
|
|
10
|
-
aliases?: string;
|
|
11
|
-
cytobands?: string;
|
|
12
|
-
defaultSession?: string;
|
|
13
|
-
trackList?: Entry[];
|
|
14
|
-
tracks?: string;
|
|
15
|
-
}
|
|
16
|
-
interface Assembly {
|
|
17
|
-
name: string;
|
|
18
|
-
sequence: Record<string, unknown>;
|
|
19
|
-
refNameAliases?: Record<string, unknown>;
|
|
20
|
-
cytobands?: Record<string, unknown>;
|
|
21
|
-
}
|
|
22
|
-
interface Track {
|
|
23
|
-
trackId: string;
|
|
24
|
-
[key: string]: unknown;
|
|
25
|
-
}
|
|
26
|
-
interface Config {
|
|
27
|
-
assemblies: Assembly[];
|
|
28
|
-
assembly: Assembly;
|
|
29
|
-
tracks: Track[];
|
|
30
|
-
[key: string]: unknown;
|
|
31
|
-
}
|
|
32
|
-
export declare function readData({ assembly: asm, config, session, fasta, aliases, cytobands, defaultSession, tracks, trackList, }: Opts): Config;
|
|
33
|
-
export declare function renderRegion(opts: Opts): Promise<string>;
|
|
34
|
-
export {};
|
package/esm/renderRegion.js
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { renderToSvg } from '@jbrowse/plugin-linear-genome-view';
|
|
4
|
-
import { createViewState } from '@jbrowse/react-linear-genome-view2';
|
|
5
|
-
import { booleanize } from './util';
|
|
6
|
-
function read(file) {
|
|
7
|
-
let res;
|
|
8
|
-
try {
|
|
9
|
-
res = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
throw new Error(`Failed to parse ${file} as JSON, use --fasta if you mean to pass a FASTA file`, { cause: e });
|
|
13
|
-
}
|
|
14
|
-
return res;
|
|
15
|
-
}
|
|
16
|
-
function makeLocation(file) {
|
|
17
|
-
return file.startsWith('http') ? { uri: file } : { localPath: file };
|
|
18
|
-
}
|
|
19
|
-
function addRelativePaths(config, configPath) {
|
|
20
|
-
if (typeof config === 'object') {
|
|
21
|
-
for (const key of Object.keys(config)) {
|
|
22
|
-
if (typeof config[key] === 'object') {
|
|
23
|
-
addRelativePaths(config[key], configPath);
|
|
24
|
-
}
|
|
25
|
-
else if (key === 'localPath') {
|
|
26
|
-
config.localPath = path.resolve(configPath, config.localPath);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function readData({ assembly: asm, config, session, fasta, aliases, cytobands, defaultSession, tracks, trackList = [], }) {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
const assemblyData = asm && fs.existsSync(asm) ? read(asm) : undefined;
|
|
34
|
-
const tracksData = tracks ? read(tracks) : undefined;
|
|
35
|
-
const configData = config ? read(config) : {};
|
|
36
|
-
let sessionData = session
|
|
37
|
-
? read(session)
|
|
38
|
-
: undefined;
|
|
39
|
-
if (config) {
|
|
40
|
-
addRelativePaths(configData, path.dirname(path.resolve(config)));
|
|
41
|
-
}
|
|
42
|
-
if (sessionData === null || sessionData === void 0 ? void 0 : sessionData.session) {
|
|
43
|
-
sessionData = sessionData.session;
|
|
44
|
-
}
|
|
45
|
-
if (sessionData === null || sessionData === void 0 ? void 0 : sessionData.views) {
|
|
46
|
-
sessionData.view = sessionData.views[0];
|
|
47
|
-
}
|
|
48
|
-
if (assemblyData) {
|
|
49
|
-
configData.assembly = assemblyData;
|
|
50
|
-
}
|
|
51
|
-
else if ((_a = configData.assemblies) === null || _a === void 0 ? void 0 : _a.length) {
|
|
52
|
-
configData.assemblies.find(entry => entry.name === asm);
|
|
53
|
-
if (asm) {
|
|
54
|
-
const assembly = configData.assemblies.find(entry => entry.name === asm);
|
|
55
|
-
if (!assembly) {
|
|
56
|
-
throw new Error(`assembly ${asm} not found in config`);
|
|
57
|
-
}
|
|
58
|
-
configData.assembly = assembly;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
configData.assembly = configData.assemblies[0];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else if (fasta) {
|
|
65
|
-
const bgzip = fasta.endsWith('gz');
|
|
66
|
-
configData.assembly = {
|
|
67
|
-
name: path.basename(fasta),
|
|
68
|
-
sequence: {
|
|
69
|
-
type: 'ReferenceSequenceTrack',
|
|
70
|
-
trackId: 'refseq',
|
|
71
|
-
adapter: {
|
|
72
|
-
type: bgzip ? 'BgzipFastaAdapter' : 'IndexedFastaAdapter',
|
|
73
|
-
fastaLocation: makeLocation(fasta),
|
|
74
|
-
faiLocation: makeLocation(`${fasta}.fai`),
|
|
75
|
-
gziLocation: bgzip ? makeLocation(`${fasta}.gzi`) : undefined,
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
if (aliases) {
|
|
80
|
-
configData.assembly.refNameAliases = {
|
|
81
|
-
adapter: {
|
|
82
|
-
type: 'RefNameAliasAdapter',
|
|
83
|
-
location: makeLocation(aliases),
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (cytobands) {
|
|
88
|
-
configData.assembly.cytobands = {
|
|
89
|
-
adapter: {
|
|
90
|
-
type: 'CytobandAdapter',
|
|
91
|
-
location: makeLocation(cytobands),
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (!configData.assembly) {
|
|
97
|
-
throw new Error('no assembly specified, use --fasta to supply an indexed FASTA file (generated with samtools faidx yourfile.fa). see README for alternatives with --assembly and --config');
|
|
98
|
-
}
|
|
99
|
-
if (tracksData) {
|
|
100
|
-
configData.tracks = tracksData;
|
|
101
|
-
}
|
|
102
|
-
else if (!configData.tracks) {
|
|
103
|
-
configData.tracks = [];
|
|
104
|
-
}
|
|
105
|
-
for (const track of trackList) {
|
|
106
|
-
const [type, opts] = track;
|
|
107
|
-
const [file, ...rest] = opts;
|
|
108
|
-
const index = (_b = rest.find(r => r.startsWith('index:'))) === null || _b === void 0 ? void 0 : _b.replace('index:', '');
|
|
109
|
-
if (!file) {
|
|
110
|
-
throw new Error('no file specified');
|
|
111
|
-
}
|
|
112
|
-
if (type === 'bam') {
|
|
113
|
-
configData.tracks = [
|
|
114
|
-
...configData.tracks,
|
|
115
|
-
{
|
|
116
|
-
type: 'AlignmentsTrack',
|
|
117
|
-
trackId: path.basename(file),
|
|
118
|
-
name: path.basename(file),
|
|
119
|
-
assemblyNames: [configData.assembly.name],
|
|
120
|
-
adapter: {
|
|
121
|
-
type: 'BamAdapter',
|
|
122
|
-
bamLocation: makeLocation(file),
|
|
123
|
-
index: {
|
|
124
|
-
location: makeLocation(index || `${file}.bai`),
|
|
125
|
-
indexType: (index === null || index === void 0 ? void 0 : index.endsWith('.csi')) ? 'CSI' : 'BAI',
|
|
126
|
-
},
|
|
127
|
-
sequenceAdapter: configData.assembly.sequence.adapter,
|
|
128
|
-
},
|
|
129
|
-
...(opts.includes('snpcov')
|
|
130
|
-
? {
|
|
131
|
-
displays: [
|
|
132
|
-
{
|
|
133
|
-
type: 'LinearSNPCoverageDisplay',
|
|
134
|
-
displayId: `${path.basename(file)}-${Math.random()}`,
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
}
|
|
138
|
-
: {}),
|
|
139
|
-
},
|
|
140
|
-
];
|
|
141
|
-
}
|
|
142
|
-
if (type === 'cram') {
|
|
143
|
-
configData.tracks = [
|
|
144
|
-
...configData.tracks,
|
|
145
|
-
{
|
|
146
|
-
type: 'AlignmentsTrack',
|
|
147
|
-
trackId: path.basename(file),
|
|
148
|
-
name: path.basename(file),
|
|
149
|
-
assemblyNames: [configData.assembly.name],
|
|
150
|
-
adapter: {
|
|
151
|
-
type: 'CramAdapter',
|
|
152
|
-
cramLocation: makeLocation(file),
|
|
153
|
-
craiLocation: makeLocation(index || `${file}.crai`),
|
|
154
|
-
sequenceAdapter: configData.assembly.sequence.adapter,
|
|
155
|
-
},
|
|
156
|
-
...(opts.includes('snpcov')
|
|
157
|
-
? {
|
|
158
|
-
displays: [
|
|
159
|
-
{
|
|
160
|
-
type: 'LinearSNPCoverageDisplay',
|
|
161
|
-
displayId: `${path.basename(file)}-${Math.random()}`,
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
}
|
|
165
|
-
: {}),
|
|
166
|
-
},
|
|
167
|
-
];
|
|
168
|
-
}
|
|
169
|
-
if (type === 'bigwig') {
|
|
170
|
-
configData.tracks = [
|
|
171
|
-
...configData.tracks,
|
|
172
|
-
{
|
|
173
|
-
type: 'QuantitativeTrack',
|
|
174
|
-
trackId: path.basename(file),
|
|
175
|
-
name: path.basename(file),
|
|
176
|
-
assemblyNames: [configData.assembly.name],
|
|
177
|
-
adapter: {
|
|
178
|
-
type: 'BigWigAdapter',
|
|
179
|
-
bigWigLocation: makeLocation(file),
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
];
|
|
183
|
-
}
|
|
184
|
-
if (type === 'vcfgz') {
|
|
185
|
-
configData.tracks = [
|
|
186
|
-
...configData.tracks,
|
|
187
|
-
{
|
|
188
|
-
type: 'VariantTrack',
|
|
189
|
-
trackId: path.basename(file),
|
|
190
|
-
name: path.basename(file),
|
|
191
|
-
assemblyNames: [configData.assembly.name],
|
|
192
|
-
adapter: {
|
|
193
|
-
type: 'VcfTabixAdapter',
|
|
194
|
-
vcfGzLocation: makeLocation(file),
|
|
195
|
-
index: {
|
|
196
|
-
location: makeLocation(index || `${file}.tbi`),
|
|
197
|
-
indexType: (index === null || index === void 0 ? void 0 : index.endsWith('.csi')) ? 'CSI' : 'TBI',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
];
|
|
202
|
-
}
|
|
203
|
-
if (type === 'gffgz') {
|
|
204
|
-
configData.tracks = [
|
|
205
|
-
...configData.tracks,
|
|
206
|
-
{
|
|
207
|
-
type: 'FeatureTrack',
|
|
208
|
-
trackId: path.basename(file),
|
|
209
|
-
name: path.basename(file),
|
|
210
|
-
assemblyNames: [configData.assembly.name],
|
|
211
|
-
adapter: {
|
|
212
|
-
type: 'Gff3TabixAdapter',
|
|
213
|
-
gffGzLocation: makeLocation(file),
|
|
214
|
-
index: {
|
|
215
|
-
location: makeLocation(index || `${file}.tbi`),
|
|
216
|
-
indexType: (index === null || index === void 0 ? void 0 : index.endsWith('.csi')) ? 'CSI' : 'TBI',
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
];
|
|
221
|
-
}
|
|
222
|
-
if (type === 'hic') {
|
|
223
|
-
configData.tracks = [
|
|
224
|
-
...configData.tracks,
|
|
225
|
-
{
|
|
226
|
-
type: 'HicTrack',
|
|
227
|
-
trackId: path.basename(file),
|
|
228
|
-
name: path.basename(file),
|
|
229
|
-
assemblyNames: [configData.assembly.name],
|
|
230
|
-
adapter: {
|
|
231
|
-
type: 'HicAdapter',
|
|
232
|
-
hicLocation: makeLocation(file),
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
];
|
|
236
|
-
}
|
|
237
|
-
if (type === 'bigbed') {
|
|
238
|
-
configData.tracks = [
|
|
239
|
-
...configData.tracks,
|
|
240
|
-
{
|
|
241
|
-
type: 'FeatureTrack',
|
|
242
|
-
trackId: path.basename(file),
|
|
243
|
-
name: path.basename(file),
|
|
244
|
-
assemblyNames: [configData.assembly.name],
|
|
245
|
-
adapter: {
|
|
246
|
-
type: 'BigBedAdapter',
|
|
247
|
-
bigBedLocation: makeLocation(file),
|
|
248
|
-
},
|
|
249
|
-
},
|
|
250
|
-
];
|
|
251
|
-
}
|
|
252
|
-
if (type === 'bedgz') {
|
|
253
|
-
configData.tracks = [
|
|
254
|
-
...configData.tracks,
|
|
255
|
-
{
|
|
256
|
-
type: 'FeatureTrack',
|
|
257
|
-
trackId: path.basename(file),
|
|
258
|
-
name: path.basename(file),
|
|
259
|
-
assemblyNames: [configData.assembly.name],
|
|
260
|
-
adapter: {
|
|
261
|
-
type: 'BedTabixAdapter',
|
|
262
|
-
bedGzLocation: makeLocation(file),
|
|
263
|
-
index: {
|
|
264
|
-
location: makeLocation(index || `${file}.tbi`),
|
|
265
|
-
indexType: (index === null || index === void 0 ? void 0 : index.endsWith('.csi')) ? 'CSI' : 'TBI',
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
},
|
|
269
|
-
];
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (!defaultSession) {
|
|
273
|
-
configData.defaultSession = undefined;
|
|
274
|
-
}
|
|
275
|
-
if (sessionData) {
|
|
276
|
-
configData.defaultSession = sessionData;
|
|
277
|
-
}
|
|
278
|
-
return configData;
|
|
279
|
-
}
|
|
280
|
-
function process(trackEntry, view, extra = c => c) {
|
|
281
|
-
const [, [track, ...opts]] = trackEntry;
|
|
282
|
-
if (!track) {
|
|
283
|
-
throw new Error('invalid command line args');
|
|
284
|
-
}
|
|
285
|
-
const currentTrack = view.showTrack(extra(track));
|
|
286
|
-
const display = currentTrack.displays[0];
|
|
287
|
-
for (const opt of opts) {
|
|
288
|
-
if (opt.startsWith('height:')) {
|
|
289
|
-
const [, height] = opt.split(':');
|
|
290
|
-
if (height) {
|
|
291
|
-
display.setHeight(+height);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
else if (opt.startsWith('sort:')) {
|
|
295
|
-
const [, type, tag] = opt.split(':');
|
|
296
|
-
display.PileupDisplay.setSortedBy(type, tag);
|
|
297
|
-
}
|
|
298
|
-
else if (opt.startsWith('color:')) {
|
|
299
|
-
const [, type, tag] = opt.split(':');
|
|
300
|
-
if (display.PileupDisplay) {
|
|
301
|
-
display.PileupDisplay.setColorScheme({ type, tag });
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
display.setColor(type);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
else if (opt.startsWith('force:')) {
|
|
308
|
-
const [, force] = opt.split(':');
|
|
309
|
-
if (force) {
|
|
310
|
-
display.setFeatureDensityStatsLimit({ bytes: Number.MAX_VALUE });
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
else if (opt.startsWith('autoscale:')) {
|
|
314
|
-
const [, autoscale] = opt.split(':');
|
|
315
|
-
display.setAutoscale(autoscale);
|
|
316
|
-
}
|
|
317
|
-
else if (opt.startsWith('minmax:')) {
|
|
318
|
-
const [, min, max] = opt.split(':');
|
|
319
|
-
if (min) {
|
|
320
|
-
display.setMinScore(+min);
|
|
321
|
-
}
|
|
322
|
-
if (max) {
|
|
323
|
-
display.setMaxScore(+max);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else if (opt.startsWith('scaletype:')) {
|
|
327
|
-
const [, scaletype] = opt.split(':');
|
|
328
|
-
display.setScaleType(scaletype);
|
|
329
|
-
}
|
|
330
|
-
else if (opt.startsWith('crosshatch:')) {
|
|
331
|
-
const [, val = 'false'] = opt.split(':');
|
|
332
|
-
display.setCrossHatches(booleanize(val));
|
|
333
|
-
}
|
|
334
|
-
else if (opt.startsWith('fill:')) {
|
|
335
|
-
const [, val = 'true'] = opt.split(':');
|
|
336
|
-
display.setFill(booleanize(val));
|
|
337
|
-
}
|
|
338
|
-
else if (opt.startsWith('resolution:')) {
|
|
339
|
-
let [, val = 1] = opt.split(':');
|
|
340
|
-
if (val === 'fine') {
|
|
341
|
-
val = '10';
|
|
342
|
-
}
|
|
343
|
-
else if (val === 'superfine') {
|
|
344
|
-
val = '100';
|
|
345
|
-
}
|
|
346
|
-
display.setResolution(+val);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
export async function renderRegion(opts) {
|
|
351
|
-
const model = createViewState({
|
|
352
|
-
...readData(opts),
|
|
353
|
-
});
|
|
354
|
-
const { loc, width = 1500, trackList = [], session: sessionParam, defaultSession, } = opts;
|
|
355
|
-
const { session } = model;
|
|
356
|
-
const { view } = session;
|
|
357
|
-
const { assemblyManager } = model;
|
|
358
|
-
view.setWidth(width);
|
|
359
|
-
if (loc) {
|
|
360
|
-
const { name } = assemblyManager.assemblies[0];
|
|
361
|
-
if (loc === 'all') {
|
|
362
|
-
view.showAllRegionsInAssembly(name);
|
|
363
|
-
}
|
|
364
|
-
else {
|
|
365
|
-
await view.navToLocString(loc, name);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
else if (!sessionParam && !defaultSession) {
|
|
369
|
-
console.warn('No loc specified');
|
|
370
|
-
}
|
|
371
|
-
for (const track of trackList) {
|
|
372
|
-
process(track, view, extra => path.basename(extra));
|
|
373
|
-
}
|
|
374
|
-
return renderToSvg(view, {
|
|
375
|
-
rasterizeLayers: !opts.noRasterize,
|
|
376
|
-
...opts,
|
|
377
|
-
});
|
|
378
|
-
}
|
package/esm/setupEnv.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function setupEnv(): void;
|
package/esm/setupEnv.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { TextDecoder, TextEncoder } from 'util';
|
|
2
|
-
import { Image, createCanvas } from 'canvas';
|
|
3
|
-
import { JSDOM } from 'jsdom';
|
|
4
|
-
import fetch, { Headers, Request, Response } from 'node-fetch';
|
|
5
|
-
export default function setupEnv() {
|
|
6
|
-
addGlobalCanvasUtils();
|
|
7
|
-
addGlobalTextUtils();
|
|
8
|
-
addGlobalDocument();
|
|
9
|
-
addFetchPolyfill();
|
|
10
|
-
}
|
|
11
|
-
function addGlobalCanvasUtils() {
|
|
12
|
-
global.nodeImage = Image;
|
|
13
|
-
global.nodeCreateCanvas = createCanvas;
|
|
14
|
-
}
|
|
15
|
-
function addGlobalTextUtils() {
|
|
16
|
-
global.TextEncoder = TextEncoder;
|
|
17
|
-
global.TextDecoder = TextDecoder;
|
|
18
|
-
}
|
|
19
|
-
function addGlobalDocument() {
|
|
20
|
-
const window = new JSDOM('...').window;
|
|
21
|
-
global.document = window.document;
|
|
22
|
-
global.window = window;
|
|
23
|
-
addFetchPolyfill();
|
|
24
|
-
}
|
|
25
|
-
function addFetchPolyfill() {
|
|
26
|
-
global.fetch = fetch;
|
|
27
|
-
global.Headers = Headers;
|
|
28
|
-
global.Response = Response;
|
|
29
|
-
global.Request = Request;
|
|
30
|
-
}
|
package/esm/util.d.ts
DELETED
package/esm/util.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import tmp from 'tmp';
|
|
4
|
-
export function booleanize(str) {
|
|
5
|
-
return str === 'false' ? false : !!str;
|
|
6
|
-
}
|
|
7
|
-
function createTmp() {
|
|
8
|
-
return tmp.fileSync({
|
|
9
|
-
mode: 0o644,
|
|
10
|
-
prefix: 'prefix-',
|
|
11
|
-
postfix: '.svg',
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
export function convert(result, args, spawnArgs = []) {
|
|
15
|
-
const { name } = createTmp();
|
|
16
|
-
const { pngwidth = '2048', out } = args;
|
|
17
|
-
fs.writeFileSync(name, result);
|
|
18
|
-
const a = ['-w', pngwidth, name, '-o', out, ...spawnArgs];
|
|
19
|
-
const ls = spawnSync('rsvg-convert', a);
|
|
20
|
-
console.error(`rsvg-convert stderr: ${ls.stderr.toString()}`);
|
|
21
|
-
console.log(`rsvg-convert stdout: ${ls.stdout.toString()}`);
|
|
22
|
-
fs.unlinkSync(name);
|
|
23
|
-
}
|