-
Notifications
You must be signed in to change notification settings - Fork 32
/
FindUnusedAssets.fsx
48 lines (39 loc) · 1.39 KB
/
FindUnusedAssets.fsx
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
open System
open System.IO
let WhiteList: string list = [ ]
let ImagesPath = "./src/assets/images"
let ContentPath = "./src/content"
let ComponentsPath = "./src/components"
// let PagesPath = "./src/pages"
let getAllFilesInPath = fun path -> Directory.GetFiles(path, "*", SearchOption.AllDirectories)
let assets = getAllFilesInPath ImagesPath
let imageMap = assets |> Array.map (fun x -> Path.GetFileName x, x) |> Map.ofArray
let getAllContent() =
let contentArr = ResizeArray()
let content = getAllFilesInPath ContentPath
let components = getAllFilesInPath ComponentsPath
// let pages = getAllFilesInPath PagesPath
let readLinesAsync (file: string) =
task {
let! file = File.ReadAllLinesAsync(file)
contentArr.AddRange file
}
for file in content do
(readLinesAsync file).Wait()
for file in components do
(readLinesAsync file).Wait()
// for file in pages do
// (readLinesAsync file).Wait()
contentArr
|> String.concat "\n"
let displayUnusedImages() =
let content: string = getAllContent()
let imagesNames = imageMap.Keys
let unusedImages =
imagesNames
|> Seq.filter (fun x -> not (content.Contains x))
|> Seq.filter (fun x -> not (WhiteList |> List.contains x))
printfn "--------- Unused images: %i ---------" (unusedImages |> Seq.length)
unusedImages
|> Seq.iter (fun x -> printfn "Unused image: %s" imageMap.[x])
displayUnusedImages()