-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
playground-generator.ts
51 lines (44 loc) · 1.73 KB
/
playground-generator.ts
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
import { writeFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { globbySync } from 'globby'
const components = globbySync('./packages/components/**/src/stories/*Demo.vue', {
ignore: ['**/node_modules/**', '**/dist/**', '**/node_modules/@oku-ui/**'],
deep: 4,
})
const componentsJson = components.map((component) => {
return {
name: component.split('/').pop()!.replace('.vue', ''),
// AlertDialogDemo -> alert-dialog -> /alert-dialog
path: `/${component.split('/').pop()!.replace('.vue', '').replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '').replace(/-demo$/, '')}`,
}
})
const core = globbySync('./packages/core/**/src/stories/*Demo.vue', {
ignore: ['**/node_modules/**', '**/dist/**', '**/node_modules/@oku-ui/**'],
deep: 4,
})
const coreJson = core.map((component) => {
return {
name: component.split('/').pop()!.replace('.vue', ''),
// AlertDialogDemo -> alert-dialog -> /alert-dialog
path: `/${component.split('/').pop()!.replace('.vue', '').replace(/([A-Z])/g, '-$1').toLowerCase().replace(/^-/, '').replace(/-demo$/, '')}`,
}
})
const mergedJson = [...componentsJson, ...coreJson]
writeFileSync(resolve('./playground/vue3/src/components.json'), JSON.stringify(mergedJson, null, 2), {
encoding: 'utf-8',
mode: 0o666,
})
writeFileSync(resolve('./playground/nuxt3/components.json'), JSON.stringify(mergedJson, null, 2), {
encoding: 'utf-8',
mode: 0o666,
})
for (const component of mergedJson) {
writeFileSync(resolve(`./playground/vue3/src/pages${component.path}.vue`), `<template>
<div><${component.name} allshow /></div>
</template>
`)
writeFileSync(resolve(`./playground/nuxt3/pages${component.path}.vue`), `<template>
<div><${component.name} allshow /></div>
</template>
`)
}