1 module install;
2 
3 import std.stdio;
4 import std.algorithm;
5 import std.range;
6 import std.array : array;
7 import getopt = std.getopt;
8 
9 import mage;
10 
11 debug {
12   bool progress(in Path src, in Path dest) {
13     writefln("  %s => %s", src, dest);
14     return true;
15   }
16 }
17 else {
18   bool progress(A...)(A a) { return true; }  
19 }
20 
21 int main(string[] args) {
22 
23   string srcStr;
24   string destStr;
25 
26   auto getoptResult = getopt.getopt(args,
27                                     getopt.config.required,
28                                     "src|s",  "The root of the repo.", &srcStr,
29                                     "dest|d", "The dir to install to.", &destStr
30                                     );
31 
32   if(getoptResult.helpWanted) {
33     getopt.defaultGetoptPrinter("Install mage to a specified dir.", getoptResult.options);
34     return 1;
35   }
36 
37   auto root = Path(srcStr).asNormalizedPath;
38   assert(root.exists, "Source dir does not exist!");
39   debug writefln("Source:      %s", root.resolved());
40   
41   auto install = Path(destStr).asNormalizedPath;
42   if(!install.exists) {
43     install.mkdir(true);
44   }
45   else {
46     assert(install.isDir, "Install target must either not exist or be a directory!");
47   }
48   debug writefln("Destination: %s", install.resolved());
49 
50   auto thirdParty = root ~ "thirdParty";
51   auto output = root ~ "output";
52   auto srcCode = root ~ "code";
53   auto destImport = install ~ "import";
54   if(!destImport.exists) {
55     destImport.mkdir(true);
56   }
57   auto destCode = install ~ "code";
58   if(!destCode.exists) {
59     destCode.mkdir(true);
60   }
61   auto destLib = install ~ "lib";
62   if(!destLib.exists) {
63     destLib.mkdir(true);
64   }
65 
66   // Code
67   (srcCode ~ "lib").copyTo!progress(destImport);
68   (srcCode ~ "app").copyTo!progress(destImport);
69   (srcCode ~ "install" ~ "wand.d").copyTo!progress(destCode);
70   //(srcCode ~ "install" ~ "MageSource.d.template").copyTo!progress(destCode);
71 
72   // Binaries/Output
73   (output ~ "libmage.lib").copyTo!progress(destLib);
74   (output ~ "mage.exe").copyTo!progress(install);
75 
76   // Third-party Code
77   (thirdParty ~ "pathlib" ~ "code").copyTo!progress(destImport);
78 
79   // Third-Party Binaries/Output
80   (thirdParty ~ "pathlib" ~ "output").copyTo!progress(destLib);
81 
82   return 0;
83 }