-
Notifications
You must be signed in to change notification settings - Fork 20
/
rm-build.js
33 lines (30 loc) · 993 Bytes
/
rm-build.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
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const readdir = promisify(fs.readdir)
const rmdir = promisify(fs.rmdir)
const unlink = promisify(fs.unlink)
const rmdirs = async (dir) => {
let entries = await readdir(dir, { withFileTypes: true })
for (const entry of entries) {
let fullPath = path.join(dir, entry.name)
if (entry.isDirectory()) {
await rmdirs(fullPath)
} else {
await unlink(fullPath)
}
}
return rmdir(dir)
}
(async () => {
const buildItems = await readdir(process.cwd(), { withFileTypes: true })
for (const buildItem of buildItems) {
const fullPath = path.join(process.cwd(), buildItem.name)
if (buildItem.name.startsWith('index.')) {
await unlink(fullPath)
} else if (buildItem.name.match(/^v([0-9]+)+(\.[0-9]+)+(-[a-zA-Z0-9-_]+)?/g)) {
// Matches 'v' followed by digits separated by dots followed by an optional '-tag'
await rmdirs(fullPath)
}
}
})()