-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathcopy-overlays.js
More file actions
85 lines (69 loc) · 1.96 KB
/
copy-overlays.js
File metadata and controls
85 lines (69 loc) · 1.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
const DocsJson = require('@ionic/core/docs.json');
const fs = require('fs');
function generateOverlays() {
const components = [
{
tag: 'ion-action-sheet',
name: 'IonActionSheet'
},
{
tag: 'ion-alert',
name: 'IonAlert'
},
{
tag: 'ion-loading',
name: 'IonLoading'
},
{
tag: 'ion-picker-legacy',
name: 'IonPickerLegacy'
},
{
tag: 'ion-toast',
name: 'IonToast'
},
{
tag: 'ion-modal',
name: 'IonModal',
hasDelegateHost: true
},
{
tag: 'ion-popover',
name: 'IonPopover'
}
]
let componentImports = [];
let componentDefinitions = [];
components.forEach(component => {
const docsBlock = getDocsBlock(component.tag);
const props = getPropsFromDocsBlock(docsBlock);
const defineCustomElementFn = `define${component.name}CustomElement`;
componentImports.push(`import { defineCustomElement as ${defineCustomElementFn} } from '@ionic/core/components/${component.tag}.js'`);
const delegateHostString = component.hasDelegateHost ? ', true' : '';
componentDefinitions.push(`
export const ${component.name} = /*@__PURE__*/ defineOverlayContainer<JSX.${component.name}>('${component.tag}', ${defineCustomElementFn}, [${props.join(', ')}]${delegateHostString});
`);
});
const template = `/**
* This is an autogenerated file created by 'scripts/copy-overlays.js'.
* Changes made to this file will be overwritten on build.
*/
import {
JSX,
} from '@ionic/core/components';
${componentImports.join('\n')}
import { defineOverlayContainer } from '../vue-component-lib/overlays';
${componentDefinitions.join('')}
`;
fs.writeFileSync('./src/components/Overlays.ts', template);
}
function getDocsBlock(tag) {
return DocsJson.components.find(block => block.tag === tag);
}
function getPropsFromDocsBlock(docsBlock) {
return docsBlock.props.map(prop => `'${prop.name}'`);
}
function main() {
generateOverlays();
}
main();