Skip to content
Snippets Groups Projects
Commit f40ba2cb authored by ezsh's avatar ezsh
Browse files

Strip JS comments for Twine JS generation by MSBuild

parent 3e7ee270
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,40 @@
</Task>
</UsingTask>
<!-- https://stackoverflow.com/questions/3524317/regex-to-strip-line-comments-from-c-sharp/3524689#3524689 -->
<UsingTask TaskName="StripComments" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var blockComments = @"/\*(.*?)\*/";
var lineComments = @"//(.*?)\r?\n";
var strings = @"""((\\[^\n]|[^""\n])*)""";
var verbatimStrings = @"@(""[^""]*"")+";
File.WriteAllText(
OutputFilename,
Regex.Replace(File.ReadAllText(InputFilename),
blockComments + "|" + lineComments + "|" + strings + "|" + verbatimStrings,
me => {
if (me.Value.StartsWith("/*") || me.Value.StartsWith("//"))
return me.Value.StartsWith("//") ? "\n" : "";
// Keep the literal strings
return me.Value;
},
RegexOptions.Singleline
)
);
]]>
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="GetToolPath" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<ToolName Required="true" />
......
......@@ -89,7 +89,11 @@
<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.txt"/>
<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"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment