-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
58 lines (49 loc) · 1.6 KB
/
gulpfile.mjs
File metadata and controls
58 lines (49 loc) · 1.6 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
import gulp from 'gulp'
import flatten from 'gulp-flatten'
import fs from 'fs'
import path from 'path'
export function dist(cb) {
gulp.src(['packages/(**)/dist/(**)']).pipe(flatten()).pipe(gulp.dest('dist/'))
cb()
}
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
function scanPackages(dir) {
const result = []
const folders = fs
.readdirSync(dir, { withFileTypes: true })
.filter((d) => d.isDirectory())
for (const folder of folders) {
const folderName = folder.name
const packageJsonPath = path.join(dir, folderName, 'package.json')
if (fs.existsSync(packageJsonPath)) {
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
result.push({
name: capitalize(folderName),
id: pkg.name || '',
description: pkg.description || '',
author: pkg.author || '',
version: pkg.version || '',
url: `${folderName}/index.html`
})
}
}
return result
}
export function demos(cb) {
gulp
.src(['packages/(**)/demo/(**)'])
.pipe(flatten({ includeParents: 1 }))
.pipe(gulp.dest('demos/public/out/'))
gulp.src(['dist/(**).min.js']).pipe(gulp.dest('demos/public/out/dist/'))
const packagesDir = path.join(import.meta.dirname, './packages')
const outputFile = path.join(import.meta.dirname, './demos/packages.json')
const data = scanPackages(packagesDir).sort((a, b) =>
a.name.localCompare(b.name)
)
fs.mkdirSync(path.dirname(outputFile), { recursive: true })
fs.writeFileSync(outputFile, JSON.stringify(data, null, 2))
console.log(`Generated ${outputFile}`)
cb()
}