|
| 1 | +import { fileURLToPath } from 'node:url' |
| 2 | +import { readFileSync } from 'node:fs' |
| 3 | +import { dirname, resolve } from 'node:path' |
| 4 | + |
| 5 | +const resolver = (path) => { |
| 6 | + const __dirname = dirname(fileURLToPath(import.meta.url)) |
| 7 | + return resolve(__dirname, path) |
| 8 | +} |
| 9 | + |
| 10 | +const readJson = (path) => { |
| 11 | + try { |
| 12 | + return JSON.parse(readFileSync(resolver(path))) |
| 13 | + } catch (error) { |
| 14 | + console.error(error) |
| 15 | + } |
| 16 | +} |
| 17 | + |
1 | 18 | /**
|
2 |
| - * Export all figure JSON |
| 19 | + * Export all figures fixture data |
3 | 20 | */
|
4 | 21 | export default {
|
5 | 22 | annotationsCheckbox: {
|
6 | 23 | dimensions: { height: 1455, width: 1200 },
|
7 |
| - figure: require('./annotations-checkbox/figure.json'), |
8 |
| - manifest: require('./annotations-checkbox/manifest.json') |
| 24 | + figure: readJson('./annotations-checkbox/figure.json'), |
| 25 | + manifest: readJson('./annotations-checkbox/manifest.json') |
9 | 26 | },
|
10 | 27 | annotationsRadio: {
|
11 | 28 | dimensions: { height: 2868, width: 2082 },
|
12 |
| - figure: require('./annotations-radio/figure.json'), |
13 |
| - manifest: require('./annotations-radio/manifest.json') |
| 29 | + figure: readJson('./annotations-radio/figure.json'), |
| 30 | + manifest: readJson('./annotations-radio/manifest.json') |
14 | 31 | },
|
15 | 32 | sequence: {
|
16 | 33 | dimensions: { height: 2160, width: 1827 },
|
17 |
| - figure: require('./sequence/figure.json'), |
18 |
| - files: require('./sequence/files.json'), |
19 |
| - manifest: require('./sequence/manifest.json') |
| 34 | + figure: readJson('./sequence/figure.json'), |
| 35 | + files: readJson('./sequence/files.json'), |
| 36 | + manifest: readJson('./sequence/manifest.json') |
20 | 37 | },
|
21 | 38 | sequenceWithAnnotations: {
|
22 | 39 | dimensions: { height: 2048, width: 1536 },
|
23 |
| - figure: require('./sequence-with-annotations/figure.json'), |
24 |
| - files: require('./sequence-with-annotations/files.json'), |
25 |
| - manifest: require('./sequence-with-annotations/manifest.json') |
| 40 | + figure: readJson('./sequence-with-annotations/figure.json'), |
| 41 | + files: readJson('./sequence-with-annotations/files.json'), |
| 42 | + manifest: readJson('./sequence-with-annotations/manifest.json') |
26 | 43 | },
|
27 | 44 | zoomable: {
|
28 | 45 | dimensions: { height: 3221, width: 4096 },
|
29 |
| - figure: require('./zoomable/figure.json'), |
30 |
| - manifest: require('./zoomable/manifest.json') |
| 46 | + figure: readJson('./zoomable/figure.json'), |
| 47 | + manifest: readJson('./zoomable/manifest.json') |
31 | 48 | },
|
32 | 49 | zoomableSequence: {
|
33 | 50 | dimensions: { height: 2160, width: 1827 },
|
34 |
| - figure: require('./zoomable-sequence/figure.json'), |
35 |
| - files: require('./zoomable-sequence/files.json'), |
36 |
| - manifest: require('./zoomable-sequence/manifest.json') |
| 51 | + figure: readJson('./zoomable-sequence/figure.json'), |
| 52 | + files: readJson('./zoomable-sequence/files.json'), |
| 53 | + manifest: readJson('./zoomable-sequence/manifest.json') |
37 | 54 | }
|
38 | 55 | }
|
0 commit comments