-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilesGen.sml
56 lines (52 loc) · 1.76 KB
/
FilesGen.sml
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
structure FilesGen =
struct
fun isWhitespace ch = ch = #" " orelse ch = #"\n"
val trim =
Substring.string o Substring.dropr isWhitespace
o Substring.dropl isWhitespace o Substring.full
exception Skip
fun genFiles (FilesData.Data file) =
let
val () = List.app genFiles (#depends file)
fun checkFileName (fileName: string) : string =
if OS.FileSys.access (fileName, []) then
( print
(fileName
^
" already exists. Enter a new filename (or press enter to skip): \n")
; case Option.map trim (TextIO.inputLine TextIO.stdIn) of
NONE => raise Skip
| SOME "" => raise Skip
| SOME fileName => checkFileName fileName
)
else
fileName
val fileName = checkFileName (#fileName file)
val os = TextIO.openOut fileName
in
TextIO.output (os, #data file);
TextIO.closeOut os
end
handle Skip => ()
fun genProjectFiles projectName =
let
fun replaceCaret s =
let
val (l, r) = Substring.splitl (fn ch => ch <> #"^") (Substring.full s)
in
Substring.concat [l, Substring.full projectName, Substring.triml 1 r]
end
val cmFile = FilesData.mapFileName (fn s => projectName ^ s) CMFile.t
val mlbFile = FilesData.mapFileName (fn s => projectName ^ s) MLBFile.t
val milletFile = FilesData.mapData replaceCaret MilletFile.t
val buildPolyFile = FilesData.mapData replaceCaret BuildPolyMLFile.t
in
List.app genFiles
[cmFile, mlbFile, milletFile, buildPolyFile, BuildMLkitFile.t]
end
fun genProject projectName =
( OS.FileSys.mkDir projectName
; OS.FileSys.chDir projectName
; genProjectFiles projectName
)
end