-
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathstudio-clean.ts
More file actions
64 lines (53 loc) · 1.92 KB
/
Copy pathstudio-clean.ts
File metadata and controls
64 lines (53 loc) · 1.92 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
/**
* Removes all generated Studio build output (src/CoreShop/Bundle/<X>Bundle/Resources/public/studio/*).
*
* The GitHub Action rebuilds and commits these artifacts, so deleting them locally keeps the
* git diff/history reviewable. Run `npm run build` afterwards to get a working local Studio again.
*
* Usage:
* npm run clean:builds # delete
* npm run clean:builds -- --dry # list what would be deleted
*/
import fs from 'fs'
import path from 'path'
const bundlesRoot = path.resolve(__dirname, 'src/CoreShop/Bundle')
const dryRun = process.argv.slice(2).includes('--dry')
function studioDirs(): string[] {
if (!fs.existsSync(bundlesRoot)) {
return []
}
return fs.readdirSync(bundlesRoot, { withFileTypes: true })
.filter(entry => entry.isDirectory() && entry.name.endsWith('Bundle'))
.map(entry => path.join(bundlesRoot, entry.name, 'Resources/public/studio'))
.filter(dir => fs.existsSync(dir))
}
function countFiles(dir: string): number {
return fs.readdirSync(dir, { withFileTypes: true, recursive: true })
.filter(entry => entry.isFile())
.length
}
let removedBuilds = 0
let removedFiles = 0
for (const studioDir of studioDirs()) {
for (const build of fs.readdirSync(studioDir, { withFileTypes: true })) {
if (!build.isDirectory()) {
continue
}
const buildDir = path.join(studioDir, build.name)
const files = countFiles(buildDir)
const relative = path.relative(__dirname, buildDir)
if (dryRun) {
console.log(`would remove ${relative} (${files} files)`)
} else {
fs.rmSync(buildDir, { recursive: true, force: true })
console.log(`removed ${relative} (${files} files)`)
}
removedBuilds++
removedFiles += files
}
}
console.log(
removedBuilds === 0
? 'No studio build output found.'
: `${dryRun ? 'Would remove' : 'Removed'} ${removedBuilds} build director${removedBuilds === 1 ? 'y' : 'ies'} (${removedFiles} files).`
)