Created
December 5, 2024 01:12
-
-
Save jonsagara/8219a5c469bc6126be3c5392729d44c3 to your computer and use it in GitHub Desktop.
bundleconfig.json checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// For users of Bundler & Minifier 2022+ | |
// https://marketplace.visualstudio.com/items?itemName=Failwyn.BundlerMinifier64 | |
// | |
// Check to see if output and input files in bundleconfig.json exist. | |
// | |
open System | |
open System.IO | |
open System.Text | |
open System.Text.Json | |
open System.Text.Json.Serialization | |
type Bundle = { | |
[<JsonPropertyName("outputFileName")>] OutputFileName : string | |
[<JsonPropertyName("inputFiles")>] InputFiles : string[] | |
} | |
type BundleMissingFiles = { | |
OutputFilePath : string option | |
InputFilePaths : string[] | |
} | |
[<Literal>] | |
let webProjectPath = @"C:\Path\To\Dir\Containing\AspNetCoreProjectFileAndBundleConfigJson\" | |
let bundleconfigFilePath = Path.Combine(webProjectPath, "bundleconfig.json") | |
if not(File.Exists(bundleconfigFilePath)) then | |
printfn $"bundleconfig.json not found at %s{bundleconfigFilePath}" | |
else | |
let bundleconfigJson = File.ReadAllText(bundleconfigFilePath, Encoding.UTF8) | |
let bundleconfig = JsonSerializer.Deserialize<Bundle[]>(bundleconfigJson) | |
let bundleMissingFiles = | |
bundleconfig | |
|> Array.map (fun bundle -> | |
let outputFilePath = Path.Combine(webProjectPath, bundle.OutputFileName) | |
let missingOutputFile = | |
match File.Exists(outputFilePath) with | |
| true -> None | |
| false -> Some outputFilePath | |
let missingInputFiles = | |
bundle.InputFiles | |
|> Array.filter (fun inputFile -> | |
not <| File.Exists(Path.Combine(webProjectPath, inputFile)) | |
) | |
{ OutputFilePath = missingOutputFile; InputFilePaths = missingInputFiles }) | |
|> Array.filter (fun bundle -> | |
// Only keep bundles where there are files missing. | |
(bundle.OutputFilePath |> Option.isSome) || (bundle.InputFilePaths.Length > 0) | |
) | |
if bundleMissingFiles.Length = 0 then | |
printfn $"There are no missing files in %s{bundleconfigFilePath}" | |
else | |
bundleMissingFiles | |
|> Array.iter (fun bundle -> | |
let missingOutputFilePath = | |
match bundle.OutputFilePath with | |
| Some p -> p | |
| None -> null | |
if not(String.IsNullOrWhiteSpace(missingOutputFilePath)) then do | |
printfn $"- Output file '%s{missingOutputFilePath}' does not exist" | |
bundle.InputFilePaths | |
|> Array.iter (fun inputFile -> | |
printfn $"-- Input file '%s{inputFile}' does not exist" | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment