-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-story-args.js
More file actions
74 lines (64 loc) · 1.91 KB
/
generate-story-args.js
File metadata and controls
74 lines (64 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* This script generates a json file with config and lookup values from the data
* currently put in the public folder. It assumes specific file names to be present,
* and containing data of a specific shape.
*
* We do this as a workaround as Storybook does not support async args or argstypes.
*/
import fs from 'node:fs'
export function createStoryArgs() {
const config = JSON.parse(
fs.readFileSync('public/data/config.json')
)
const wellboreHeadersData = JSON.parse(
fs.readFileSync('public/data/wellbore-headers.json')
)
const surfaceMetaData = JSON.parse(
fs.readFileSync('public/data/surface-meta.json')
)
const stratColumns = JSON.parse(
fs.readFileSync('public/data/strat-columns.json')
)
const wellboreOptions = Object.values(wellboreHeadersData)
.filter(d => d.drilled)
.sort((a, b) => a.name.localeCompare(b.name))
.reduce(
(prev, wellbore) => ({
...prev,
[wellbore.id]: wellbore.name,
}),
{}
)
const surfaceOptions = Object.values(surfaceMetaData)
.sort((a, b) => a.max - b.max)
.reduce(
(prev, surface) => ({
...prev,
[surface.id]: surface.name
}), {})
const stratUnitTypes = new Set()
const stratUnits = new Set()
Object.values(stratColumns).forEach(stratColumn => {
stratColumn.units.forEach(unit => {
stratUnitTypes.add(unit.unitType)
stratUnits.add(unit.name)
})
})
const output = {
utmZone: config.utmZone || '31N',
origin: config.origin,
defaultWellbore: config.wellbore,
defaultWell: config.well,
defaultStratColumn: config.stratColumn,
wellboreOptions,
surfaceOptions,
stratUnitOptions: Array.from(stratUnits),
stratUnitTypeOptions: Array.from(stratUnitTypes),
}
fs.writeFile('src/storybook/story-args.json', JSON.stringify(output), (err) => {
if (err) {
console.error(err)
}
})
}
createStoryArgs()