|
1 | | -module Spdx |
2 | | - |
3 | | -open FSharp.Data |
4 | | -open System.IO |
5 | | - |
6 | | -[<Literal>] |
7 | | -let private URL = "https://spdx.org/licenses/licenses.json" |
8 | | - |
9 | | -type Spdx = JsonProvider<"""{ "licenses": [{ |
10 | | - "reference": "./MIT.html", |
11 | | - "isDeprecatedLicenseId": false, |
12 | | - "isFsfLibre": true, |
13 | | - "detailsUrl": "http://spdx.org/licenses/MIT.json", |
14 | | - "referenceNumber": "201", |
15 | | - "name": "MIT License", |
16 | | - "licenseId": "MIT", |
17 | | - "seeAlso": [ |
18 | | - "https://opensource.org/licenses/MIT" |
19 | | - ], |
20 | | - "isOsiApproved": true |
21 | | - }] }"""> |
22 | | - |
23 | | -let private download() = Spdx.AsyncLoad URL |
24 | | -let private getFileLocation() = Path.Combine(System.Environment.CurrentDirectory, "licenses.json") |
25 | | - |
26 | | -let getSpdx refreshFile = |
27 | | - async { |
28 | | - if refreshFile then |
29 | | - if File.Exists(getFileLocation()) then File.Delete <| getFileLocation() |
30 | | - let! contents = download() |
31 | | - File.WriteAllText(getFileLocation(), contents.ToString()) |
32 | | - return contents |
33 | | - else if not (File.Exists(getFileLocation())) then |
34 | | - let! contents = download() |
35 | | - File.WriteAllText(getFileLocation(), contents.ToString()) |
36 | | - return contents |
37 | | - else |
38 | | - let contents = File.ReadAllText <| getFileLocation() |
39 | | - return Spdx.Parse contents |
40 | | - } |
| 1 | +module Spdx |
| 2 | + |
| 3 | +open FSharp.Data |
| 4 | +open System.IO |
| 5 | + |
| 6 | +[<Literal>] |
| 7 | +let private URL = |
| 8 | + "https://spdx.org/licenses/licenses.json" |
| 9 | + |
| 10 | +type Spdx = |
| 11 | + JsonProvider<"""{ "licenses": [{ |
| 12 | + "reference": "./MIT.html", |
| 13 | + "isDeprecatedLicenseId": false, |
| 14 | + "isFsfLibre": true, |
| 15 | + "detailsUrl": "http://spdx.org/licenses/MIT.json", |
| 16 | + "referenceNumber": "201", |
| 17 | + "name": "MIT License", |
| 18 | + "licenseId": "MIT", |
| 19 | + "seeAlso": [ |
| 20 | + "https://opensource.org/licenses/MIT" |
| 21 | + ], |
| 22 | + "isOsiApproved": true |
| 23 | + }, |
| 24 | + { |
| 25 | + "reference": "./MIT.html", |
| 26 | + "isDeprecatedLicenseId": false, |
| 27 | + "detailsUrl": "http://spdx.org/licenses/MIT.json", |
| 28 | + "referenceNumber": "201", |
| 29 | + "name": "MIT License", |
| 30 | + "licenseId": "MIT", |
| 31 | + "seeAlso": [ |
| 32 | + "https://opensource.org/licenses/MIT" |
| 33 | + ], |
| 34 | + "isOsiApproved": true |
| 35 | + }] }"""> |
| 36 | + |
| 37 | +let private download () = Spdx.AsyncLoad URL |
| 38 | + |
| 39 | +let private getFileLocation () = |
| 40 | + Path.Combine(System.Environment.CurrentDirectory, "licenses.json") |
| 41 | + |
| 42 | +let getSpdx refreshFile = |
| 43 | + async { |
| 44 | + if refreshFile then |
| 45 | + if File.Exists(getFileLocation ()) then File.Delete <| getFileLocation () |
| 46 | + let! contents = download () |
| 47 | + File.WriteAllText(getFileLocation (), contents.ToString()) |
| 48 | + return contents |
| 49 | + else if not (File.Exists(getFileLocation ())) then |
| 50 | + let! contents = download () |
| 51 | + File.WriteAllText(getFileLocation (), contents.ToString()) |
| 52 | + return contents |
| 53 | + else |
| 54 | + let contents = File.ReadAllText <| getFileLocation () |
| 55 | + return Spdx.Parse contents |
| 56 | + } |
0 commit comments