<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="FinalHTML" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<Import Project="devTools\FC.targets" />
	<PropertyGroup>
		<OutputDirectory>.\bin\</OutputDirectory>
		<JSMoudleFileName>fc.js</JSMoudleFileName>
	</PropertyGroup>

	<PropertyGroup Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)' == 'X64' ">
		<ArchitectureSuffix>64</ArchitectureSuffix>
	</PropertyGroup>
	<PropertyGroup Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)' == 'X86' ">
		<ArchitectureSuffix>86</ArchitectureSuffix>
	</PropertyGroup>

	<PropertyGroup Condition=" '$([MSBuild]::IsOsPlatform(Windows))' ">
		<TweeGoExe>tweego_win$(ArchitectureSuffix).exe</TweeGoExe>
	</PropertyGroup>
	<PropertyGroup Condition=" '$([MSBuild]::IsOsPlatform(Linux))' ">
		<TweeGoExe>tweego_nix$(ArchitectureSuffix)</TweeGoExe>
	</PropertyGroup>
	<PropertyGroup Condition=" '$([MSBuild]::IsOsPlatform(OSX))' ">
		<TweeGoExe>tweego_osx$(ArchitectureSuffix)</TweeGoExe>
	</PropertyGroup>

	<Target Name="CollectGitInfo" DependsOnTargets="FindGit">
		<Exec Command="$(GitExe) rev-parse --short HEAD" ConsoleToMsBuild="true" EchoOff="true">
			<Output TaskParameter="ConsoleOutput" PropertyName="GitHash" />
		</Exec>
	</Target>

	<Target Name="DisplayMessages" DependsOnTargets="CollectGitInfo">
		<Message Text="MSBuildProjectDirectory: $(MSBuildProjectDirectory)" />
		<Message Text="ArchitectureSuffix: $(ArchitectureSuffix)" Importance="high" />
		<Message Text="TweeGoExe: $(TweeGoExe)" Importance="high" />
		<Message Text="PA: $([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)" />
		<Message Text="Git found: $(GitExeFound)" Importance="high" />
		<Message Text="Git executable: $(GitExe)" Importance="high" />
		<Message Text="HEAD commit hash: $(GitHash)" Importance="high" />
    </Target>

	<Target Name="createDirs">
		<MakeDir Directories="$(OutputDirectory)\resources"/>
	</Target>

	<Target Name="JSModule" DependsOnTargets="createDirs;DisplayMessages">
		<ItemGroup>
			<jsScripts Include=".\js\**\*.js" /> <!-- will be sorted aphabetically -->
		</ItemGroup>
		<ConcatFiles Inputs="@(jsSCripts)" BaseDir="$(MSBuildProjectDirectory)" Output="$(OutputDirectory)\$(JSMoudleFileName)"/>
	</Target>

	<Target Name="AlphaDisclaimer" DependsOnTargets="CollectGitInfo" Condition=" '$(GitExeFound)'" >
		<ReplaceFileText
			InputFilename="$(MSBuildProjectDirectory)\src\gui\mainMenu\AlphaDisclaimer.tw"
			OutputFilename="$(MSBuildProjectDirectory)\src\gui\mainMenu\AlphaDisclaimer.tw"
			MatchExpression="(build: \$releaseID)"
			ReplacementText="$1, git commit: $(GitHash)"
		/>
	</Target>

	<Target Name="ResetAlphaDisclaimer" DependsOnTargets="FindGit" Condition=" '$(GitExeFound)'" >
		<Exec Command="$(GitExe) checkout -- src/gui/mainMenu/AlphaDisclaimer.tw" />
	</Target>

	<Target Name="tmpOutput" DependsOnTargets="JSModule;AlphaDisclaimer">
		<Exec Command="devTools\tweeGo\$(TweeGoExe) --module=$(OutputDirectory)\$(JSMoudleFileName) --head devTools\head.html -o $(OutputDirectory)\tmp.html src\" />
	</Target>

	<Target Name="FinalHTML" DependsOnTargets="tmpOutput;ResetAlphaDisclaimer">
		<Delete Files="$(OutputDirectory)\$(JSMoudleFileName)" />
		<Move SourceFiles="$(OutputDirectory)\tmp.html" DestinationFiles="$(OutputDirectory)\FC_pregmod.html" />
	</Target>

	<Target Name="JavaSanityCheck">
		<Exec Command="java -jar .\devTools\javaSanityCheck\SanityCheck.jar" />
	</Target>

	<!-- Twine targets -->

	<Target Name="TwineCSS">
		<ItemGroup>
			<cssFiles Include=".\src\**\*.css" /> <!-- will be sorted aphabetically -->
		</ItemGroup>
		<ConcatFiles Inputs="@(cssFiles)" BaseDir="$(MSBuildProjectDirectory)" Output="$(MSBuildProjectDirectory)\devNotes\twine CSS.txt"/>
	</Target>

	<Target Name="TwineJS">
		<ItemGroup>
			<jsFiles Include=".\js\**\*.js;.\src\**\*.js" Exclude=".\src\art\assistantArt.js"/> <!-- will be sorted aphabetically -->
		</ItemGroup>
		<ConcatFiles Inputs="@(jsFiles)" BaseDir="$(MSBuildProjectDirectory)" Output="$(MSBuildProjectDirectory)\devNotes\twine JS.raw"/>
		<StripComments
			InputFilename="$(MSBuildProjectDirectory)\devNotes\twine JS.raw"
			OutputFilename="$(MSBuildProjectDirectory)\devNotes\twine JS.txt"
		/>
	</Target>

	<Target Name="Twine" DependsOnTargets="TwineCSS;TwineJS"/>

</Project>

fc-pregmod.proj