forked from Justin-Credible/Ionic-TypeScript-MDHA-Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJustinCredible.Build.Targets
116 lines (103 loc) · 4.1 KB
/
JustinCredible.Build.Targets
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
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Used to get the version number string from a Cordova configuration XML file. -->
<UsingTask
TaskName="GetVersionNumbers"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll" >
<ParameterGroup>
<ConfigFile ParameterType="System.String" Required="true" />
<MajorVersion ParameterType="System.String" Required="false" Output="true" />
<MinorVersion ParameterType="System.String" Required="false" Output="true" />
<BuildVersion ParameterType="System.String" Required="false" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"/>
<Using Namespace="System"/>
<Using Namespace="System.Linq"/>
<Using Namespace="System.Xml.Linq"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var configXml = XDocument.Load(this.ConfigFile);
var versionString = configXml.Root.Attribute("version").Value.ToString();
var versionParts = versionString.Split('.');
this.MajorVersion = versionParts[0];
this.MinorVersion = versionParts[1];
this.BuildVersion = versionParts[2];
return true;
]]>
</Code>
</Task>
</UsingTask>
<!-- Used to get an arbitrary preference value from a Cordova configuration XML file. -->
<UsingTask
TaskName="GetPreferenceFromConfigXml"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll" >
<ParameterGroup>
<ConfigFile ParameterType="System.String" Required="true" Output="false" />
<PreferenceName ParameterType="System.String" Required="true" Output="false" />
<PreferenceValue ParameterType="System.String" Required="false" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq"/>
<Using Namespace="System"/>
<Using Namespace="System.Linq"/>
<Using Namespace="System.Xml.Linq"/>
<Using Namespace="System.Xml.XPath"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var document = new XPathDocument(this.ConfigFile);
var query = String.Format("/*[local-name() = 'widget']/*[local-name() = 'preference'][@name='{0}']/@value", this.PreferenceName);
var node = document.CreateNavigator().SelectSingleNode(query);
this.PreferenceValue = node.Value;
return true;
]]>
</Code>
</Task>
</UsingTask>
<!--
Used to create a JavaScript file which declares global variables for
use in the application during runtime.
-->
<UsingTask
TaskName="CreateBuildVarsJs"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll" >
<ParameterGroup>
<FilePath ParameterType="System.String" Required="true" />
<IsDebug ParameterType="System.String" Required="true" />
<MajorVersion ParameterType="System.String" Required="true" />
<MinorVersion ParameterType="System.String" Required="true" />
<BuildVersion ParameterType="System.String" Required="true" />
<ApiUrl ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.Text"/>
<Using Namespace="System.IO"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
StringBuilder jsSource = new StringBuilder();
jsSource.Append("window.buildVars = {");
jsSource.AppendFormat("debug: {0}", IsDebug.ToString().ToLower());
jsSource.AppendFormat(",");
jsSource.AppendFormat("buildTimestamp: '{0}'", DateTime.Now.ToString());
jsSource.AppendFormat(",");
jsSource.AppendFormat("majorVersion: {0}", MajorVersion);
jsSource.AppendFormat(",");
jsSource.AppendFormat("minorVersion: {0}", MinorVersion);
jsSource.AppendFormat(",");
jsSource.AppendFormat("buildVersion: {0}", BuildVersion);
jsSource.AppendFormat(",");
jsSource.AppendFormat("apiUrl: '{0}'", ApiUrl);
jsSource.Append("};");
File.WriteAllText(FilePath, jsSource.ToString());
return true;
]]>
</Code>
</Task>
</UsingTask>
</Project>