forked from vuejs/vue-router-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.js
33 lines (32 loc) · 1.02 KB
/
generate.js
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
#!/bin/bash node
const glob = require('glob')
const path = require('path')
const fs = require('fs')
const prettier = require("prettier");
Promise.resolve(glob.sync(`${__dirname}/examples/*`))
.then(
files => files.filter(dir => fs.lstatSync(dir).isDirectory())
)
.then(
dirs => dirs.map(dir => ({path: dir, name: dir.replace(`${__dirname}/examples/`, '')}))
)
.then(
dirs => dirs.map(dir => (
`{
name: ${JSON.stringify(dir.name)},
files: ${JSON.stringify(
glob.sync(`${dir.path}/**/*`)
.filter(filename => /\.(vue|js|jsx)$/.test(filename))
.map(filename => filename.replace(`${dir.path}/`, '')),
null, 2)},
bundle: () => import('./${dir.name}')
}`))
)
.then(
examples => fs.writeFile(
path.join(__dirname, 'examples/index.js'),
prettier.format('// NOTE: THIS IS AN AUTOGENERATED FILE.\nexport default [\n' + examples.join(',\n') + '\n]\n', {semi: false}),
(error) => {
if (error) console.log(error)
})
)