forked from cappuccino/cappuccino
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.j
119 lines (87 loc) · 4.44 KB
/
main.j
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
importClass(java.io.File);
importClass(java.io.FileOutputStream);
importClass(java.io.BufferedWriter);
importClass(java.io.OutputStreamWriter);
function main()
{
if (arguments.length < 1)
return printUsage();
var index = 0,
count = arguments.length,
shouldSymbolicallyLink = false,
justFrameworks = false,
template = "Application",
destination = "";
for (; index < count; ++index)
{
var argument = arguments[index];
switch (arguments[index])
{
case "-l": shouldSymbolicallyLink = true;
break;
case "-h":
case "--help": printUsage();
return;
case "-t":
case "--template": template = arguments[++index];
break;
case "-f":
case "--frameworks": justFrameworks = true;
break;
default: destination = argument;
}
}
var sourceTemplate = new File(OBJJ_HOME + "/lib/steam/Templates/" + template),
destinationProject = new File(destination);
if (!destinationProject.exists())
{
exec(["cp", "-vR", sourceTemplate.getCanonicalPath(), destinationProject.getCanonicalPath()], true);
var files = getFiles(destinationProject, ['j', "plist", "html"]),
index = 0,
count = files.length;
for (; index < count; ++index)
{
var file = files[index],
contents = readFile(file);
contents = contents.replace(/__Product__/g, destinationProject.getName());
writeContentsToFile(contents, file);
}
createFrameworksInFile(destinationProject, shouldSymbolicallyLink);
}
else
System.out.println("Directory already exists");
}
function createFrameworksInFile(/*File*/ aFile, /*Boolean*/ shouldSymbolicallyLink)
{
var destinationFrameworks = new File(aFile.getCanonicalPath()+ "/Frameworks"),
destinationDebugFrameworks = new File(aFile.getCanonicalPath() + "/Frameworks/Debug");
if (!shouldSymbolicallyLink)
{
var sourceFrameworks = new File(OBJJ_HOME + "/lib/Frameworks"),
sourceDebugFrameworks = new File(OBJJ_HOME + "/lib/Frameworks-Debug");
exec(["cp", "-vR", sourceFrameworks.getCanonicalPath(), destinationFrameworks.getCanonicalPath()], true);
exec(["cp", "-vR", sourceDebugFrameworks.getCanonicalPath(), destinationDebugFrameworks.getCanonicalPath()], true);
return true;
}
var STEAM_BUILD = System.getenv("STEAM_BUILD");
// Release Frameworks
new File(destinationFrameworks).mkdir();
exec(["ln", "-s", new File(STEAM_BUILD + "/Release/Objective-J").getCanonicalPath(),
new File(aFile.getCanonicalPath() + "/Frameworks/Objective-J").getCanonicalPath()], true);
exec(["ln", "-s", new File(STEAM_BUILD + "/Release/Foundation").getCanonicalPath(),
new File(aFile.getCanonicalPath() + "/Frameworks/Foundation").getCanonicalPath()], true);
exec(["ln", "-s", new File(STEAM_BUILD + "/Release/AppKit").getCanonicalPath(),
new File(aFile.getCanonicalPath() + "/Frameworks/AppKit").getCanonicalPath()], true);
// Debug Frameworks
new File(destinationDebugFrameworks).mkdir();
exec(["ln", "-s", new File(STEAM_BUILD + "/Debug/Objective-J").getCanonicalPath(),
new File(aFile.getCanonicalPath() + "/Frameworks/Debug/Objective-J").getCanonicalPath()], true);
exec(["ln", "-s", new File(STEAM_BUILD + "/Debug/Foundation").getCanonicalPath(),
new File(aFile.getCanonicalPath() + "/Frameworks/Debug/Foundation").getCanonicalPath()], true);
exec(["ln", "-s", new File(STEAM_BUILD + "/Debug/AppKit").getCanonicalPath(),
new File(aFile.getCanonicalPath() + "/Frameworks/Debug/AppKit").getCanonicalPath()], true);
}
function printUsage()
{
print("capp /path/to/your/app [options]");
}