David Catuhe 10 anni fa
parent
commit
c676937ff8

+ 6 - 0
Tools/JSKompactor/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+    </startup>
+</configuration>

+ 102 - 0
Tools/JSKompactor/JSKompactor.csproj

@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>JSKompactor</RootNamespace>
+    <AssemblyName>JSKompactor</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <SccProjectName>SAK</SccProjectName>
+    <SccLocalPath>SAK</SccLocalPath>
+    <SccAuxPath>SAK</SccAuxPath>
+    <SccProvider>SAK</SccProvider>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x64\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+    <OutputPath>bin\x64\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>bin\x86\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
+    <OutputPath>bin\x86\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 44 - 0
Tools/JSKompactor/JSKompactor.sln

@@ -0,0 +1,44 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.21005.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JSKompactor", "JSKompactor.csproj", "{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}"
+EndProject
+Global
+	GlobalSection(TeamFoundationVersionControl) = preSolution
+		SccNumberOfProjects = 1
+		SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
+		SccTeamFoundationServer = https://deltakosh.visualstudio.com/defaultcollection
+		SccProjectUniqueName0 = JSKompactor.csproj
+		SccProjectName0 = .
+		SccAuxPath0 = https://deltakosh.visualstudio.com/defaultcollection
+		SccLocalPath0 = .
+		SccProvider0 = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
+	EndGlobalSection
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Debug|x64 = Debug|x64
+		Debug|x86 = Debug|x86
+		Release|Any CPU = Release|Any CPU
+		Release|x64 = Release|x64
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Debug|x64.ActiveCfg = Debug|x64
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Debug|x64.Build.0 = Debug|x64
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Debug|x86.ActiveCfg = Debug|x86
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Debug|x86.Build.0 = Debug|x86
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Release|x64.ActiveCfg = Release|x64
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Release|x64.Build.0 = Release|x64
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Release|x86.ActiveCfg = Release|x86
+		{E5AA2DCD-51FB-465B-9EF5-45BDA4DF7A63}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 190 - 0
Tools/JSKompactor/Program.cs

@@ -0,0 +1,190 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace JSKompactor
+{
+    class Program
+    {
+        static string Extends = "var __extends = this.__extends || function (d, b) {\r\n" +
+                        "    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\r\n" +
+                        "    function __() { this.constructor = d; }\r\n" +
+                        "    __.prototype = b.prototype;\r\n" +
+                        "    d.prototype = new __();\r\n" +
+                        "};";
+
+        static void Main(string[] args)
+        {
+            if (args.Length != 4)
+            {
+                DisplayUsage();
+                return;
+            }
+
+            // Parsing arguments
+            string output = "";
+            string inputFilenames = "";
+            string workingFolder = "";
+            string shadersFolder = "";
+
+            foreach (var arg in args)
+            {
+                var order = arg.Substring(0, 3);
+
+                switch (order)
+                {
+                    case "/i:":
+                        inputFilenames = arg.Substring(3);
+                        break;
+                    case "/o:":
+                        output = arg.Substring(3);
+                        break;
+                    case "/w:":
+                        workingFolder = arg.Substring(3);
+                        break;
+                    case "/s:":
+                        shadersFolder = arg.Substring(3);
+                        break;
+                    default:
+                        DisplayUsage();
+                        return;
+                }
+            }
+
+            if (string.IsNullOrEmpty(workingFolder) || string.IsNullOrEmpty(output) || string.IsNullOrEmpty(inputFilenames))
+            {
+                DisplayUsage();
+                return;
+            }
+
+
+            // Merges files            
+            var inputs = inputFilenames.Split(',');
+
+            var builder = new StringBuilder();
+            foreach (var input in inputs)
+            {
+                try
+                {
+                    builder.Append(File.ReadAllText(Path.Combine(workingFolder, input)));
+                    Console.ForegroundColor = ConsoleColor.Green;
+                    Console.WriteLine("Merging " + input);
+                    Console.ResetColor();
+                }
+                catch (Exception ex)
+                {
+                    Console.ForegroundColor = ConsoleColor.Red;
+                    Console.WriteLine("Unable to load " + input);
+                    Console.WriteLine(ex.Message);
+                    Console.ResetColor();
+                }
+            }
+
+            var result = builder.ToString();
+
+            // Remove all extends
+            result = result.Replace(Extends, "");
+
+            // Add only one __extends
+            result = Extends + result;
+
+            // Compress
+            result = RemoveUseStrict(result);
+            //result = RemoveComments(result);
+            //result = RemoveNewLines(result);
+            //result = RemoveWhiteSpaces(result);
+
+            // Integrate shaders
+            if (!string.IsNullOrEmpty(shadersFolder))
+            {
+                var shaders = Directory.GetFiles(Path.Combine(workingFolder, shadersFolder), "*.fx");
+                var shadersString = "";
+                foreach (var shader in shaders)
+                {
+                    shadersString += Path.GetFileName(shader).Replace(".fragment.fx", "PixelShader").Replace(".vertex.fx", "VertexShader") + ":";
+                    var lines = File.ReadAllLines(shader);
+                    var selectedLines = new List<string>();
+
+                    for (var index = 0; index < lines.Length; index++)
+                    {
+                        var val = lines[index].Trim();
+
+                        if (!val.StartsWith("//"))
+                        {
+                            selectedLines.Add(val);
+                        }
+                    }
+
+                    shadersString += "\"" + string.Join("\\n", selectedLines.ToArray()) + "\",\n";
+                }
+
+
+                result = result.Replace("Effect.ShadersStore = {};", "Effect.ShadersStore={" + shadersString + "};");
+            }
+
+            // Output file
+            File.WriteAllText(output, result);
+        }
+
+        static string RemoveUseStrict(string source)
+        {
+            return source.Replace("\"use strict\";", "");
+        }
+
+        static string RemoveComments(string source)
+        {
+            var regExp = new Regex(@"\s*?//.+?$", RegexOptions.Multiline);
+
+            return regExp.Replace(source, "");
+        }
+
+        static string RemoveNewLines(string source)
+        {
+            var regExp = new Regex("(\r|\n|\t)", RegexOptions.Multiline);
+
+            return regExp.Replace(source, "");
+        }
+
+        static bool IsValidChar(char c)
+        {
+            return Char.IsLetterOrDigit(c) || c == '_';
+        }
+
+        static string RemoveWhiteSpaces(string source)
+        {
+            var builder = new StringBuilder(source.Length);
+
+            var isInString = false;
+
+            for (var index = 0; index < source.Length; index++)
+            {
+                var previous = source[Math.Max(0, index - 1)];
+                var current = source[index];
+                var next = source[Math.Min(source.Length - 1, index + 1)];
+
+                if (current == '"' && previous != '\\')
+                {
+                    isInString = !isInString;
+                }
+                else if (current == ' ' && !isInString)
+                {
+                    if (!IsValidChar(previous) || !IsValidChar(next))
+                    {
+                        continue;
+                    }
+                }
+
+                builder.Append(current);
+            }
+
+            return builder.ToString();
+        }
+
+        static void DisplayUsage()
+        {
+            Console.WriteLine("JSKompactor usage: JSKompactor.exe /w:\"Working folder\" /i:\"Comma separated list of files to merge\" /s:\"Shaders folder\" /o:\"output file\"");
+        }
+    }
+}

+ 36 - 0
Tools/JSKompactor/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("JSKompactor")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("JSKompactor")]
+[assembly: AssemblyCopyright("Copyright ©  2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("a2671fa7-6051-4193-9257-d36e7c6a4ef9")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]