-
-
Notifications
You must be signed in to change notification settings - Fork 940
Expand file tree
/
Copy pathdumpExamplesJson.ts
More file actions
115 lines (101 loc) · 2.96 KB
/
Copy pathdumpExamplesJson.ts
File metadata and controls
115 lines (101 loc) · 2.96 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Dumps examples.json to docs/examples.json from metadata in the examples in the example directory
*/
import path from 'path';
import fs from 'fs';
import * as CacheManagement from '../src/examples/CacheManagement';
import * as SymbolCircleLayer from '../src/examples/SymbolCircleLayer';
import * as UserLocation from '../src/examples/UserLocation';
import * as Map from '../src/examples/Map';
import * as V10 from '../src/examples/V10';
import * as Annotations from '../src/examples/Annotations';
import * as FillRasterLayer from '../src/examples/FillRasterLayer';
import * as LineLayer from '../src/examples/LineLayer';
import * as Camera from '../src/examples/Camera';
import type {
Examples,
Example,
} from '../../scripts/autogenHelpers/examplesJsonSchema';
import {
examplesJSONPath,
mapsRootPath,
} from '../../scripts/autogenHelpers/docconfig.js';
jest.mock('../src/assets/scale-test-icon4.png', () => null, {
virtual: true,
});
jest.mock('../src/assets/sportcar.glb', () => null, {
virtual: true,
});
const allTests = {
CacheManagement,
SymbolCircleLayer,
UserLocation,
Map,
V10,
Annotations,
FillRasterLayer,
LineLayer,
Camera,
} as const;
const relExamplesPath = path.join('example', 'src', 'examples');
const examplesPath = path.join(mapsRootPath, relExamplesPath);
function getExampleFullPath(
groupName: string,
testName: string,
): { fullPath: string; relPath: string } {
const extensions = ['js', 'jsx', 'ts', 'tsx'];
const relPathBase = path.join(groupName, testName);
const existingExamplePaths = extensions
.map(ext => ({
relPath: `${relPathBase}.${ext}`,
fullPath: path.join(relExamplesPath, `${relPathBase}.${ext}`),
}))
.filter(({ relPath: _relPath, fullPath }) =>
fs.existsSync(path.join(mapsRootPath, fullPath)),
);
if (existingExamplePaths.length === 0) {
throw new Error(
`Could not find example file for ${groupName}/${testName} - ${path.join(
examplesPath,
relPathBase,
)}.*`,
);
}
return existingExamplePaths[0];
}
describe('dump-examples-json', () => {
it('examples are dumped outside the test', () => {
expect(true).toBe(true);
});
});
const exampleGroups: Examples = [];
type AllTestKeys = keyof typeof allTests;
const allTestKeys = Object.keys(allTests) as AllTestKeys[];
allTestKeys.forEach(groupName => {
const { metadata, ...tests } = allTests[groupName];
const examples: Example[] = [];
Object.entries(tests).forEach(([testName, test]) => {
const { metadata: testMetadata } = test as unknown as {
metadata?: Example['metadata'];
};
const { fullPath, relPath } = getExampleFullPath(groupName, testName);
if (testMetadata) {
examples.push({
metadata: testMetadata,
fullPath,
relPath,
name: testName,
});
}
});
exampleGroups.push({
groupName,
metadata,
examples,
});
});
fs.writeFileSync(
examplesJSONPath,
JSON.stringify(exampleGroups, null, 2),
'utf8',
);