diff --git a/WebCompiler.sln b/WebCompiler.sln
index c3380f98..1743ad1b 100644
--- a/WebCompiler.sln
+++ b/WebCompiler.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.24720.0
+# Visual Studio Version 18
+VisualStudioVersion = 18.5.11716.220 stable
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebCompilerVsix", "src\WebCompilerVsix\WebCompilerVsix.csproj", "{49C270BE-9645-40D5-BE08-91ADE243D394}"
EndProject
diff --git a/src/WebCompiler/Compile/BabelCompiler.cs b/src/WebCompiler/Compile/BabelCompiler.cs
index bb6984bc..462921a3 100644
--- a/src/WebCompiler/Compile/BabelCompiler.cs
+++ b/src/WebCompiler/Compile/BabelCompiler.cs
@@ -18,7 +18,7 @@ public BabelCompiler(string path)
_path = path;
}
- public CompilerResult Compile(Config config)
+ public CompilerResult Compile(ConfigEntry config)
{
string baseFolder = Path.GetDirectoryName(config.FileName);
string inputFile = Path.Combine(baseFolder, config.InputFile);
@@ -75,7 +75,7 @@ public CompilerResult Compile(Config config)
return result;
}
- private void RunCompilerProcess(Config config, FileInfo info)
+ private void RunCompilerProcess(ConfigEntry config, FileInfo info)
{
string arguments = ConstructArguments(config);
@@ -106,7 +106,7 @@ private void RunCompilerProcess(Config config, FileInfo info)
}
}
- private static string ConstructArguments(Config config)
+ private static string ConstructArguments(ConfigEntry config)
{
//string relative = FileHelpers.MakeRelative(config.GetAbsoluteOutputFile().FullName, config.GetAbsoluteInputFile().FullName);
string arguments = $"--presets react --out-file \"\"";
@@ -115,8 +115,8 @@ private static string ConstructArguments(Config config)
if (options.SourceMap || config.SourceMap)
arguments += " --source-maps inline";
- if (options.Compact.HasValue && !options.Compact.Value)
- arguments += " --compact false";
+ if (options.Compact.HasValue)
+ arguments += " --compact " + (options.Compact.Value ? "true" : "false");
return arguments;
}
diff --git a/src/WebCompiler/Compile/BabelOptions.cs b/src/WebCompiler/Compile/BabelOptions.cs
index da02320e..ba5a8f40 100644
--- a/src/WebCompiler/Compile/BabelOptions.cs
+++ b/src/WebCompiler/Compile/BabelOptions.cs
@@ -14,7 +14,7 @@ public BabelOptions()
///
/// Load the settings from the config object
///
- protected override void LoadSettings(Config config)
+ protected override void LoadSettings(ConfigEntry config)
{
base.LoadSettings(config);
}
diff --git a/src/WebCompiler/Compile/BaseOptions.cs b/src/WebCompiler/Compile/BaseOptions.cs
index 1d0496d0..028adafc 100644
--- a/src/WebCompiler/Compile/BaseOptions.cs
+++ b/src/WebCompiler/Compile/BaseOptions.cs
@@ -1,7 +1,9 @@
using System;
+using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using WebCompiler.Config;
namespace WebCompiler
{
@@ -13,10 +15,34 @@ namespace WebCompiler
///
/// Loads the options based on the config object
///
- public static T FromConfig(Config config)
+ public static T FromConfig(ConfigEntry config)
{
+ ConfigMsBuild msBuildConfig = config as ConfigMsBuild;
string defaultFile = config.FileName + ".defaults";
+ if (msBuildConfig != null)
+ {
+ List configsToTry = new List {
+ defaultFile.Replace(".defaults", $".{msBuildConfig.Configuration}"),
+ defaultFile,
+ };
+ if (!string.IsNullOrEmpty(msBuildConfig.StartupDirectory))
+ {
+ configsToTry.Add($"{msBuildConfig.StartupDirectory}\\" +
+ defaultFile.Replace(".defaults", $".{msBuildConfig.Configuration}"));
+ configsToTry.Add($"{msBuildConfig.StartupDirectory}\\{defaultFile}");
+ }
+
+ foreach(string fileToTry in configsToTry)
+ {
+ if (File.Exists(fileToTry))
+ {
+ defaultFile = fileToTry;
+ break;
+ }
+ }
+ }
+
T options = new T();
if (File.Exists(defaultFile))
@@ -48,7 +74,7 @@ public static T FromConfig(Config config)
///
/// Load the settings from the config object
///
- protected virtual void LoadSettings(Config config)
+ protected virtual void LoadSettings(ConfigEntry config)
{
var sourceMap = GetValue(config, "sourceMap");
if (sourceMap != null)
@@ -64,7 +90,7 @@ protected virtual void LoadSettings(Config config)
///
/// Gets a value from a string keyed dictionary
///
- protected string GetValue(Config config, string key)
+ protected string GetValue(ConfigEntry config, string key)
{
if (config.Options.ContainsKey(key))
return config.Options[key].ToString();
diff --git a/src/WebCompiler/Compile/CompilerService.cs b/src/WebCompiler/Compile/CompilerService.cs
index 87c93d42..d8cf1525 100644
--- a/src/WebCompiler/Compile/CompilerService.cs
+++ b/src/WebCompiler/Compile/CompilerService.cs
@@ -10,7 +10,7 @@ namespace WebCompiler
///
public static class CompilerService
{
- internal const string Version = "1.14.15";
+ internal const string Version = "1.14.17";
private static readonly string _path = Path.Combine(Path.GetTempPath(), "WebCompiler" + Version);
private static object _syncRoot = new object(); // Used to lock on the initialize step
@@ -29,7 +29,7 @@ public static bool IsSupported(string inputFile)
return AllowedExtensions.Contains(ext);
}
- internal static ICompiler GetCompiler(Config config)
+ internal static ICompiler GetCompiler(ConfigEntry config)
{
string ext = Path.GetExtension(config.InputFile).ToUpperInvariant();
ICompiler compiler = null;
diff --git a/src/WebCompiler/Compile/CssRelativePathAdjuster.cs b/src/WebCompiler/Compile/CssRelativePathAdjuster.cs
index a16bd8cd..c6d86479 100644
--- a/src/WebCompiler/Compile/CssRelativePathAdjuster.cs
+++ b/src/WebCompiler/Compile/CssRelativePathAdjuster.cs
@@ -8,7 +8,7 @@ static class CssRelativePath
{
private static readonly Regex _rxUrl = new Regex(@"url\s*\(\s*([""']?)([^:)]+)\1\s*\)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
- public static string Adjust(string content, Config config)
+ public static string Adjust(string content, ConfigEntry config)
{
string cssFileContents = content;
string absoluteOutputPath = config.GetAbsoluteOutputFile().FullName;
diff --git a/src/WebCompiler/Compile/HandlebarsCompiler.cs b/src/WebCompiler/Compile/HandlebarsCompiler.cs
index 7a0070ef..2b62afd6 100644
--- a/src/WebCompiler/Compile/HandlebarsCompiler.cs
+++ b/src/WebCompiler/Compile/HandlebarsCompiler.cs
@@ -22,7 +22,7 @@ public HandlebarsCompiler(string path)
_path = path;
}
- public CompilerResult Compile(Config config)
+ public CompilerResult Compile(ConfigEntry config)
{
string baseFolder = Path.GetDirectoryName(config.FileName);
string inputFile = Path.Combine(baseFolder, config.InputFile);
@@ -121,7 +121,7 @@ public CompilerResult Compile(Config config)
return result;
}
- private void RunCompilerProcess(Config config, FileInfo info)
+ private void RunCompilerProcess(ConfigEntry config, FileInfo info)
{
string arguments = ConstructArguments(config);
@@ -152,7 +152,7 @@ private void RunCompilerProcess(Config config, FileInfo info)
}
}
- private string ConstructArguments(Config config)
+ private string ConstructArguments(ConfigEntry config)
{
string arguments = "";
diff --git a/src/WebCompiler/Compile/HandlebarsOptions.cs b/src/WebCompiler/Compile/HandlebarsOptions.cs
index e678fe01..58db2e38 100644
--- a/src/WebCompiler/Compile/HandlebarsOptions.cs
+++ b/src/WebCompiler/Compile/HandlebarsOptions.cs
@@ -17,7 +17,7 @@ public HandlebarsOptions()
///
/// Load the settings from the config object
///
- protected override void LoadSettings(Config config)
+ protected override void LoadSettings(ConfigEntry config)
{
base.LoadSettings(config);
diff --git a/src/WebCompiler/Compile/ICompiler.cs b/src/WebCompiler/Compile/ICompiler.cs
index f87db101..3140d48c 100644
--- a/src/WebCompiler/Compile/ICompiler.cs
+++ b/src/WebCompiler/Compile/ICompiler.cs
@@ -2,6 +2,6 @@
{
internal interface ICompiler
{
- CompilerResult Compile(Config config);
+ CompilerResult Compile(ConfigEntry config);
}
}
\ No newline at end of file
diff --git a/src/WebCompiler/Compile/IcedCoffeeScriptCompiler.cs b/src/WebCompiler/Compile/IcedCoffeeScriptCompiler.cs
index 65b1aecb..96f632a3 100644
--- a/src/WebCompiler/Compile/IcedCoffeeScriptCompiler.cs
+++ b/src/WebCompiler/Compile/IcedCoffeeScriptCompiler.cs
@@ -18,7 +18,7 @@ public IcedCoffeeScriptCompiler(string path)
_path = path;
}
- public CompilerResult Compile(Config config)
+ public CompilerResult Compile(ConfigEntry config)
{
string baseFolder = Path.GetDirectoryName(config.FileName);
string inputFile = Path.Combine(baseFolder, config.InputFile);
@@ -93,7 +93,7 @@ public CompilerResult Compile(Config config)
return result;
}
- private void RunCompilerProcess(Config config, FileInfo info)
+ private void RunCompilerProcess(ConfigEntry config, FileInfo info)
{
string arguments = ConstructArguments(config);
@@ -120,7 +120,7 @@ private void RunCompilerProcess(Config config, FileInfo info)
}
}
- private string ConstructArguments(Config config)
+ private string ConstructArguments(ConfigEntry config)
{
string arguments = $" --compile --output \"{_temp}\"";
diff --git a/src/WebCompiler/Compile/IcedCoffeeScriptOptions.cs b/src/WebCompiler/Compile/IcedCoffeeScriptOptions.cs
index 1e61c5bb..67c0be57 100644
--- a/src/WebCompiler/Compile/IcedCoffeeScriptOptions.cs
+++ b/src/WebCompiler/Compile/IcedCoffeeScriptOptions.cs
@@ -16,7 +16,7 @@ public IcedCoffeeScriptOptions()
///
/// Loads the settings based on the config
///
- protected override void LoadSettings(Config config)
+ protected override void LoadSettings(ConfigEntry config)
{
base.LoadSettings(config);
diff --git a/src/WebCompiler/Compile/LessCompiler.cs b/src/WebCompiler/Compile/LessCompiler.cs
index e0c63405..fd4a4857 100644
--- a/src/WebCompiler/Compile/LessCompiler.cs
+++ b/src/WebCompiler/Compile/LessCompiler.cs
@@ -18,7 +18,7 @@ public LessCompiler(string path)
_path = path;
}
- public CompilerResult Compile(Config config)
+ public CompilerResult Compile(ConfigEntry config)
{
string baseFolder = Path.GetDirectoryName(config.FileName);
string inputFile = Path.Combine(baseFolder, config.InputFile);
@@ -75,7 +75,7 @@ public CompilerResult Compile(Config config)
return result;
}
- private void RunCompilerProcess(Config config, FileInfo info)
+ private void RunCompilerProcess(ConfigEntry config, FileInfo info)
{
string arguments = ConstructArguments(config);
@@ -106,7 +106,7 @@ private void RunCompilerProcess(Config config, FileInfo info)
}
}
- private static string ConstructArguments(Config config)
+ private static string ConstructArguments(ConfigEntry config)
{
string arguments = " --no-color --js";
diff --git a/src/WebCompiler/Compile/LessOptions.cs b/src/WebCompiler/Compile/LessOptions.cs
index 7f7ce263..552690f2 100644
--- a/src/WebCompiler/Compile/LessOptions.cs
+++ b/src/WebCompiler/Compile/LessOptions.cs
@@ -16,7 +16,7 @@ public LessOptions()
///
/// Load the settings from the config object
///
- protected override void LoadSettings(Config config)
+ protected override void LoadSettings(ConfigEntry config)
{
base.LoadSettings(config);
diff --git a/src/WebCompiler/Compile/SassCompiler.cs b/src/WebCompiler/Compile/SassCompiler.cs
index ee2fa65f..091ac50e 100644
--- a/src/WebCompiler/Compile/SassCompiler.cs
+++ b/src/WebCompiler/Compile/SassCompiler.cs
@@ -20,7 +20,7 @@ public SassCompiler(string path)
_path = path;
}
- public CompilerResult Compile(Config config)
+ public CompilerResult Compile(ConfigEntry config)
{
string baseFolder = Path.GetDirectoryName(config.FileName);
string inputFile = Path.Combine(baseFolder, config.InputFile);
@@ -78,7 +78,7 @@ public CompilerResult Compile(Config config)
return result;
}
- private void RunCompilerProcess(Config config, FileInfo info)
+ private void RunCompilerProcess(ConfigEntry config, FileInfo info)
{
string arguments = ConstructArguments(config);
@@ -127,7 +127,7 @@ private void RunCompilerProcess(Config config, FileInfo info)
}
}
- private static string ConstructArguments(Config config)
+ private static string ConstructArguments(ConfigEntry config)
{
var arguments = new StringBuilder();
diff --git a/src/WebCompiler/Compile/SassOptions.cs b/src/WebCompiler/Compile/SassOptions.cs
index f2cd2c41..acf40653 100644
--- a/src/WebCompiler/Compile/SassOptions.cs
+++ b/src/WebCompiler/Compile/SassOptions.cs
@@ -15,7 +15,7 @@ public SassOptions()
///
/// Loads the settings based on the config
///
- protected override void LoadSettings(Config config)
+ protected override void LoadSettings(ConfigEntry config)
{
base.LoadSettings(config);
diff --git a/src/WebCompiler/Compile/StylusCompiler.cs b/src/WebCompiler/Compile/StylusCompiler.cs
index cd3ccd07..3848649d 100644
--- a/src/WebCompiler/Compile/StylusCompiler.cs
+++ b/src/WebCompiler/Compile/StylusCompiler.cs
@@ -19,7 +19,7 @@ public StylusCompiler(string path)
_path = path;
}
- public CompilerResult Compile(Config config)
+ public CompilerResult Compile(ConfigEntry config)
{
string baseFolder = Path.GetDirectoryName(config.FileName);
string inputFile = Path.Combine(baseFolder, config.InputFile);
@@ -76,7 +76,7 @@ public CompilerResult Compile(Config config)
return result;
}
- private void RunCompilerProcess(Config config, FileInfo info)
+ private void RunCompilerProcess(ConfigEntry config, FileInfo info)
{
string arguments = ConstructArguments(config);
@@ -107,7 +107,7 @@ private void RunCompilerProcess(Config config, FileInfo info)
}
}
- private static string ConstructArguments(Config config)
+ private static string ConstructArguments(ConfigEntry config)
{
string arguments = " --print";
diff --git a/src/WebCompiler/Compile/StylusOptions.cs b/src/WebCompiler/Compile/StylusOptions.cs
index 27ceaf74..1a41f7c6 100644
--- a/src/WebCompiler/Compile/StylusOptions.cs
+++ b/src/WebCompiler/Compile/StylusOptions.cs
@@ -14,7 +14,7 @@ public StylusOptions()
///
/// Load the settings from the config object
///
- protected override void LoadSettings(Config config)
+ protected override void LoadSettings(ConfigEntry config)
{
base.LoadSettings(config);
}
diff --git a/src/WebCompiler/Config/CompileFileEventArgs.cs b/src/WebCompiler/Config/CompileFileEventArgs.cs
index 9b8c6714..b9ef12ce 100644
--- a/src/WebCompiler/Config/CompileFileEventArgs.cs
+++ b/src/WebCompiler/Config/CompileFileEventArgs.cs
@@ -13,7 +13,7 @@ public class CompileFileEventArgs : EventArgs
/// The configuration object being processed.
/// The base folder of the config file.
/// True if there were any changes.
- public CompileFileEventArgs(Config config, string baseFolder, bool containsChanges)
+ public CompileFileEventArgs(ConfigEntry config, string baseFolder, bool containsChanges)
{
ContainsChanges = containsChanges;
Config = config;
@@ -28,7 +28,7 @@ public CompileFileEventArgs(Config config, string baseFolder, bool containsChang
///
/// The Config object used by the compiler.
///
- public Config Config { get; set; }
+ public ConfigEntry Config { get; set; }
///
/// The base folder of the current execution.
diff --git a/src/WebCompiler/Config/Config.cs b/src/WebCompiler/Config/ConfigEntry.cs
similarity index 89%
rename from src/WebCompiler/Config/Config.cs
rename to src/WebCompiler/Config/ConfigEntry.cs
index c905f02c..bcf4dfbe 100644
--- a/src/WebCompiler/Config/Config.cs
+++ b/src/WebCompiler/Config/ConfigEntry.cs
@@ -9,8 +9,23 @@ namespace WebCompiler
///
/// Represents a configuration object used by the compilers.
///
- public class Config
+ public class ConfigEntry
{
+ public ConfigEntry() { }
+
+ internal ConfigEntry(ConfigEntry c)
+ {
+ FileName = c.FileName;
+ OutputFile = c.OutputFile;
+ InputFile = c.InputFile;
+ Minify = c.Minify != null ? new Dictionary(c.Minify) : null;
+ IncludeInProject = c.IncludeInProject;
+ SourceMap = c.SourceMap;
+ OutputUTF8Identifier = c.OutputUTF8Identifier;
+ Options = c.Options != null ? new Dictionary(c.Options) : null;
+ Output = c.Output;
+ }
+
///
/// The file path to the configuration file.
///
@@ -151,7 +166,7 @@ public override bool Equals(object obj)
if (obj.GetType() != GetType()) return false;
if (obj == this) return true;
- Config other = (Config)obj;
+ ConfigEntry other = (ConfigEntry)obj;
return GetHashCode() == other.GetHashCode();
}
@@ -167,21 +182,21 @@ public override int GetHashCode()
/// For the JSON.NET serializer
public bool ShouldSerializeIncludeInProject()
{
- Config config = new Config();
+ ConfigEntry config = new ConfigEntry();
return IncludeInProject != config.IncludeInProject;
}
/// For the JSON.NET serializer
public bool ShouldSerializeMinify()
{
- Config config = new Config();
+ ConfigEntry config = new ConfigEntry();
return !DictionaryEqual(Minify, config.Minify, null);
}
/// For the JSON.NET serializer
public bool ShouldSerializeOptions()
{
- Config config = new Config();
+ ConfigEntry config = new ConfigEntry();
return !DictionaryEqual(Options, config.Options, null);
}
diff --git a/src/WebCompiler/Config/ConfigFileProcessor.cs b/src/WebCompiler/Config/ConfigFileProcessor.cs
index 8afbf9fa..c0d7c007 100644
--- a/src/WebCompiler/Config/ConfigFileProcessor.cs
+++ b/src/WebCompiler/Config/ConfigFileProcessor.cs
@@ -20,8 +20,9 @@ public class ConfigFileProcessor
/// The absolute or relative file path to compilerconfig.json
/// Optional configuration items in the config file
/// Forces compilation of all config items.
+ /// Indicates if the process is being run from MSBuild.
/// A list of compiler results.
- public IEnumerable Process(string configFile, IEnumerable configs = null, bool force = false)
+ public IEnumerable Process(string configFile, IEnumerable configs = null, bool force = false, ICompilerBuildTaskSettings buildSettings = null)
{
if (_processing.Contains(configFile))
return Enumerable.Empty();
@@ -32,12 +33,12 @@ public IEnumerable Process(string configFile, IEnumerable SourceFileChanged(string configFile,
var configs = ConfigHandler.GetConfigs(configFile);
// Compile if the file if it's referenced directly in compilerconfig.json
- foreach (Config config in configs)
+ foreach (ConfigEntry config in configs)
{
string input = Path.Combine(folder, config.InputFile.Replace("/", "\\"));
@@ -144,7 +145,7 @@ private IEnumerable SourceFileChanged(string configFile,
{
string sourceExtension = Path.GetExtension(sourceFile);
- foreach (Config config in configs)
+ foreach (ConfigEntry config in configs)
{
string inputExtension = Path.GetExtension(config.InputFile);
@@ -161,15 +162,15 @@ private IEnumerable SourceFileChanged(string configFile,
///
/// Returns a collection of config objects that all contain the specified sourceFile
///
- public static IEnumerable IsFileConfigured(string configFile, string sourceFile)
+ public static IEnumerable IsFileConfigured(string configFile, string sourceFile)
{
try
{
var configs = ConfigHandler.GetConfigs(configFile);
string folder = Path.GetDirectoryName(configFile);
- List list = new List();
+ List list = new List();
- foreach (Config config in configs)
+ foreach (ConfigEntry config in configs)
{
string input = Path.Combine(folder, config.InputFile.Replace("/", "\\"));
@@ -185,7 +186,7 @@ public static IEnumerable IsFileConfigured(string configFile, string sou
}
}
- private CompilerResult ProcessConfig(string baseFolder, Config config)
+ private CompilerResult ProcessConfig(string baseFolder, ConfigEntry config)
{
ICompiler compiler = CompilerService.GetCompiler(config);
@@ -242,7 +243,7 @@ private CompilerResult ProcessConfig(string baseFolder, Config config)
return result;
}
- private static bool AdjustRelativePaths(Config config)
+ private static bool AdjustRelativePaths(ConfigEntry config)
{
if (!config.Options.ContainsKey("relativeUrls"))
return true;
@@ -250,7 +251,7 @@ private static bool AdjustRelativePaths(Config config)
return config.Options["relativeUrls"].ToString() == "True";
}
- private void OnBeforeProcess(Config config, string baseFolder, bool containsChanges)
+ private void OnBeforeProcess(ConfigEntry config, string baseFolder, bool containsChanges)
{
if (BeforeProcess != null)
{
@@ -258,7 +259,7 @@ private void OnBeforeProcess(Config config, string baseFolder, bool containsChan
}
}
- private void OnConfigProcessed(Config config, int amountProcessed, int total)
+ private void OnConfigProcessed(ConfigEntry config, int amountProcessed, int total)
{
if (ConfigProcessed != null)
{
@@ -266,7 +267,7 @@ private void OnConfigProcessed(Config config, int amountProcessed, int total)
}
}
- private void OnAfterProcess(Config config, string baseFolder, bool containsChanges)
+ private void OnAfterProcess(ConfigEntry config, string baseFolder, bool containsChanges)
{
if (AfterProcess != null)
{
diff --git a/src/WebCompiler/Config/ConfigHandler.cs b/src/WebCompiler/Config/ConfigHandler.cs
index 5b827bde..676935be 100644
--- a/src/WebCompiler/Config/ConfigHandler.cs
+++ b/src/WebCompiler/Config/ConfigHandler.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using Newtonsoft.Json;
+using WebCompiler.Config;
namespace WebCompiler
{
@@ -16,10 +17,10 @@ public class ConfigHandler
///
/// The file path of the configuration file.
/// The compiler config object to add to the configration file.
- public void AddConfig(string fileName, Config config)
+ public void AddConfig(string fileName, ConfigEntry config)
{
- IEnumerable existing = GetConfigs(fileName);
- List configs = new List();
+ IEnumerable existing = GetConfigs(fileName);
+ List configs = new List();
configs.AddRange(existing);
configs.Add(config);
config.FileName = fileName;
@@ -37,10 +38,10 @@ public void AddConfig(string fileName, Config config)
///
/// Removes the specified config from the file.
///
- public void RemoveConfig(Config configToRemove)
+ public void RemoveConfig(ConfigEntry configToRemove)
{
- IEnumerable configs = GetConfigs(configToRemove.FileName);
- List newConfigs = new List();
+ IEnumerable configs = GetConfigs(configToRemove.FileName);
+ List newConfigs = new List();
if (configs.Contains(configToRemove))
{
@@ -95,21 +96,27 @@ public void CreateDefaultsFile(string fileName)
///
/// A relative or absolute file path to the configuration file.
/// A list of Config objects.
- public static IEnumerable GetConfigs(string fileName)
+ public static IEnumerable GetConfigs(string fileName, ICompilerBuildTaskSettings buildSettings = null)
{
FileInfo file = new FileInfo(fileName);
if (!file.Exists)
- return Enumerable.Empty();
+ return Enumerable.Empty() ;
string content = File.ReadAllText(fileName);
- var configs = JsonConvert.DeserializeObject>(content);
+ var configs = JsonConvert.DeserializeObject>(content);
string folder = Path.GetDirectoryName(file.FullName);
- foreach (Config config in configs)
+ // Convert to build configs
+ if (buildSettings != null)
{
- config.FileName = fileName;
+ configs = configs.Select(c => new ConfigMsBuild(buildSettings, c, fileName));
}
+ else
+ foreach (ConfigEntry config in configs)
+ {
+ config.FileName = fileName;
+ }
return configs;
}
diff --git a/src/WebCompiler/Config/ConfigMsBuild.cs b/src/WebCompiler/Config/ConfigMsBuild.cs
new file mode 100644
index 00000000..863feeec
--- /dev/null
+++ b/src/WebCompiler/Config/ConfigMsBuild.cs
@@ -0,0 +1,24 @@
+namespace WebCompiler.Config
+{
+ class ConfigMsBuild: ConfigEntry
+ {
+ public ConfigMsBuild(ICompilerBuildTaskSettings buildSettings, ConfigEntry c, string fileName)
+ : base(c)
+ {
+ Configuration = buildSettings.Configuration;
+ StartupDirectory = buildSettings.StartupDirectory;
+ FileName = fileName;
+ }
+
+ ///
+ /// Usually the build flavor , such as "Debug" or "Release". This is used to determine which config file to use
+ /// when multiple config files exist for the same project.
+ ///
+ public string Configuration { get; set; }
+
+ ///
+ /// The directory in which the compiler was started. This is used to resolve relative paths in the config file.
+ ///
+ public string StartupDirectory { get; set; }
+ }
+}
diff --git a/src/WebCompiler/Config/ConfigProcessedEventArgs.cs b/src/WebCompiler/Config/ConfigProcessedEventArgs.cs
index 1ddb2b8a..8c8c6a3b 100644
--- a/src/WebCompiler/Config/ConfigProcessedEventArgs.cs
+++ b/src/WebCompiler/Config/ConfigProcessedEventArgs.cs
@@ -13,7 +13,7 @@ public class ConfigProcessedEventArgs : EventArgs
/// The configuration object being processed.
/// The amount of completed configs in the .json file.
/// Total number of configs in the .json file
- public ConfigProcessedEventArgs(Config config, int amountProcessed, int total)
+ public ConfigProcessedEventArgs(ConfigEntry config, int amountProcessed, int total)
{
Config = config;
AmountProcessed = amountProcessed;
@@ -23,7 +23,7 @@ public ConfigProcessedEventArgs(Config config, int amountProcessed, int total)
///
/// The Config object used by the compiler.
///
- public Config Config { get; set; }
+ public ConfigEntry Config { get; set; }
///
/// The amount of completed configs in the .json file.
diff --git a/src/WebCompiler/MSBuild/BuildWebCompiler2022.targets b/src/WebCompiler/MSBuild/BuildWebCompiler2022.targets
index d95a5c74..4b206f75 100644
--- a/src/WebCompiler/MSBuild/BuildWebCompiler2022.targets
+++ b/src/WebCompiler/MSBuild/BuildWebCompiler2022.targets
@@ -2,14 +2,17 @@
<_WebCompilerTaskAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">..\tools\netstandard2.1\WebCompiler.dll
- <_WebCompilerTaskAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">..\tools\net4.8\WebCompiler.exe
+ <_WebCompilerTaskAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">..\tools\net48\WebCompiler.exe
-
+
diff --git a/src/WebCompiler/MSBuild/CompilerBuildTask.cs b/src/WebCompiler/MSBuild/CompilerBuildTask.cs
index a1677d9c..15c0301c 100644
--- a/src/WebCompiler/MSBuild/CompilerBuildTask.cs
+++ b/src/WebCompiler/MSBuild/CompilerBuildTask.cs
@@ -5,22 +5,43 @@
namespace WebCompiler
{
+
///
/// An MSBuild task for running web compilers on a given config file.
///
- public class CompilerBuildTask : Task
+ public class CompilerBuildTask : Task, ICompilerBuildTaskSettings
{
+ ///
+ /// The build configuration (e.g., Debug or Release)
+ ///
+ public string Configuration { get; set; }
+
///
/// The file path of the compilerconfig.json file
///
public string FileName { get; set; }
+ ///
+ /// The initial directory in the build process. This is used to resolve relative paths in the config file.
+ ///
+ public string StartupDirectory { get; set; }
+
///
/// Execute the Task
///
public override bool Execute()
{
- FileInfo configFile = new FileInfo(FileName);
+ string[] configFilesToTry = new string[] {
+ FileName.Replace(".json", $".{(Configuration ?? "")}.json"),
+ FileName
+ };
+ FileInfo configFile = null;
+
+ foreach (var fn in configFilesToTry)
+ {
+ configFile = new FileInfo(fn);
+ if (configFile.Exists) break;
+ }
if (!configFile.Exists)
{
@@ -45,7 +66,7 @@ public override bool Execute()
try
{
- var results = processor.Process(configFile.FullName);
+ var results = processor.Process(configFile.FullName, buildSettings: this);
bool isSuccessful = true;
foreach (CompilerResult result in results)
diff --git a/src/WebCompiler/MSBuild/ICompilerBuildTaskSettings.cs b/src/WebCompiler/MSBuild/ICompilerBuildTaskSettings.cs
new file mode 100644
index 00000000..b9965047
--- /dev/null
+++ b/src/WebCompiler/MSBuild/ICompilerBuildTaskSettings.cs
@@ -0,0 +1,17 @@
+namespace WebCompiler
+{
+ public interface ICompilerBuildTaskSettings
+ {
+ public string Configuration { get; }
+
+ ///
+ /// The file path of the compilerconfig.json file
+ ///
+ public string FileName { get; }
+
+ ///
+ /// The initial directory in the build process. This is used to resolve relative paths in the config file.
+ ///
+ public string StartupDirectory { get; }
+ }
+}
diff --git a/src/WebCompiler/Minify/BaseMinifyOptions.cs b/src/WebCompiler/Minify/BaseMinifyOptions.cs
index e6b1cd7e..d411856b 100644
--- a/src/WebCompiler/Minify/BaseMinifyOptions.cs
+++ b/src/WebCompiler/Minify/BaseMinifyOptions.cs
@@ -13,7 +13,7 @@ public abstract class BaseMinifyOptions
///
/// Loads the options based on the config object
///
- protected static void LoadDefaultSettings(Config config, string minifierType)
+ protected static void LoadDefaultSettings(ConfigEntry config, string minifierType)
{
string defaultFile = config.FileName + ".defaults";
@@ -41,7 +41,7 @@ protected static void LoadDefaultSettings(Config config, string minifierType)
///
/// Gets the string value of the minification settings.
///
- protected static string GetValue(Config config, string key, object defaultValue = null)
+ protected static string GetValue(ConfigEntry config, string key, object defaultValue = null)
{
if (config.Minify.ContainsKey(key))
return config.Minify[key].ToString();
diff --git a/src/WebCompiler/Minify/CssOptions.cs b/src/WebCompiler/Minify/CssOptions.cs
index c76fbe45..a0151997 100644
--- a/src/WebCompiler/Minify/CssOptions.cs
+++ b/src/WebCompiler/Minify/CssOptions.cs
@@ -13,7 +13,7 @@ public class CssOptions : BaseMinifyOptions
///
///
/// CssSettings based on the config file.
- public static CssSettings GetSettings(Config config)
+ public static CssSettings GetSettings(ConfigEntry config)
{
LoadDefaultSettings(config, "css");
diff --git a/src/WebCompiler/Minify/FileMinifier.cs b/src/WebCompiler/Minify/FileMinifier.cs
index 3e9db90f..01c2cb91 100644
--- a/src/WebCompiler/Minify/FileMinifier.cs
+++ b/src/WebCompiler/Minify/FileMinifier.cs
@@ -12,7 +12,7 @@ namespace WebCompiler
///
public class FileMinifier
{
- internal static MinificationResult MinifyFile(Config config)
+ internal static MinificationResult MinifyFile(ConfigEntry config)
{
FileInfo file = config.GetAbsoluteOutputFile();
string extension = file.Extension.ToUpperInvariant();
@@ -29,7 +29,7 @@ internal static MinificationResult MinifyFile(Config config)
return null;
}
- private static MinificationResult MinifyJavaScript(Config config, string file)
+ private static MinificationResult MinifyJavaScript(ConfigEntry config, string file)
{
string content = File.ReadAllText(file);
var settings = JavaScriptOptions.GetSettings(config);
@@ -62,7 +62,7 @@ private static MinificationResult MinifyJavaScript(Config config, string file)
return new MinificationResult(result, null);
}
- private static MinificationResult MinifyCss(Config config, string file)
+ private static MinificationResult MinifyCss(ConfigEntry config, string file)
{
string content = File.ReadAllText(file);
var settings = CssOptions.GetSettings(config);
@@ -106,7 +106,7 @@ private static string GetMinFileName(string file)
return fileName + ext;
}
- private static void GzipFile(Config config, string sourceFile, bool containsChanges)
+ private static void GzipFile(ConfigEntry config, string sourceFile, bool containsChanges)
{
if (!config.Minify.ContainsKey("gzip") || !config.Minify["gzip"].ToString().Equals("true", StringComparison.OrdinalIgnoreCase))
return;
diff --git a/src/WebCompiler/Minify/JavaScriptOptions.cs b/src/WebCompiler/Minify/JavaScriptOptions.cs
index ea8ebf6e..bcfe1bc0 100644
--- a/src/WebCompiler/Minify/JavaScriptOptions.cs
+++ b/src/WebCompiler/Minify/JavaScriptOptions.cs
@@ -14,7 +14,7 @@ public class JavaScriptOptions : BaseMinifyOptions
///
///
/// CodeSettings based on the config file.
- public static CodeSettings GetSettings(Config config)
+ public static CodeSettings GetSettings(ConfigEntry config)
{
LoadDefaultSettings(config, "javascript");
diff --git a/src/WebCompiler/Node/package.json b/src/WebCompiler/Node/package.json
index 3889c5a4..f07e9da3 100644
--- a/src/WebCompiler/Node/package.json
+++ b/src/WebCompiler/Node/package.json
@@ -1,15 +1,15 @@
{
"dependencies": {
- "autoprefixer": "^10.4.21",
+ "autoprefixer": "^10.5.5",
"babel": "^5.8.34",
- "handlebars": "^4.7.8",
+ "handlebars": "^4.7.9",
"iced-coffee-script": "^108.0.14",
- "less": "^4.2.2",
+ "less": "^4.9.1",
"less-plugin-autoprefix": "^2.0.0",
"less-plugin-csscomb": "^0.0.2",
- "postcss": "^8.5.3",
- "postcss-cli": "^11.0.1",
- "sass": "^1.86.0",
+ "postcss": "^8.5.28",
+ "postcss-cli": "^12.0.0",
+ "sass": "^1.104.0",
"stylus": "^0.64.0"
}
}
diff --git a/src/WebCompiler/Program.cs b/src/WebCompiler/Program.cs
index 068d49db..33a8314b 100644
--- a/src/WebCompiler/Program.cs
+++ b/src/WebCompiler/Program.cs
@@ -5,6 +5,15 @@
namespace WebCompiler
{
+ class DummySettings : ICompilerBuildTaskSettings
+ {
+ public string Configuration { get; set; }
+
+ public string FileName { get; set; }
+
+ public string StartupDirectory { get; set; }
+ }
+
class Program
{
static int Main(params string[] args)
@@ -50,8 +59,21 @@ private static void EventHookups(ConfigFileProcessor processor, string configPat
FileMinifier.AfterWritingGzipFile += (s, e) => { Console.WriteLine($" \x1B[32mGZipped"); };
}
- private static IEnumerable GetConfigs(string configPath, string file)
+ private static IEnumerable GetConfigs(string configPath, string file)
{
+ //string configName = Environment.GetEnvironmentVariable("Configuration");
+ //string startupDir = Environment.GetEnvironmentVariable("MSBuildStartupDirectory");
+ //ICompilerBuildTaskSettings settings = null;
+
+ //if (!string.IsNullOrWhiteSpace(configName) || !string.IsNullOrWhiteSpace(startupDir))
+ //{
+ // settings = new DummySettings
+ // {
+ // Configuration = configName,
+ // StartupDirectory = startupDir
+ // };
+ //}
+
var configs = ConfigHandler.GetConfigs(configPath);
if (configs == null || !configs.Any())
diff --git a/src/WebCompiler/Properties/launchSettings.json b/src/WebCompiler/Properties/launchSettings.json
new file mode 100644
index 00000000..361332c6
--- /dev/null
+++ b/src/WebCompiler/Properties/launchSettings.json
@@ -0,0 +1,13 @@
+{
+ "profiles": {
+ "WebCompiler": {
+ "commandName": "Project",
+ "commandLineArgs": "compilerconfig.json",
+ "workingDirectory": "C:\\SourceCode\\Ratings\\Website\\Ratings.Web.Data",
+ "environmentVariables": {
+ "Configuration": "Debug",
+ "MSBuildStartupDirectory": "C:\\SourceCode\\Ratings"
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WebCompiler/WebCompiler.csproj b/src/WebCompiler/WebCompiler.csproj
index baaa7f19..9f0587d5 100644
--- a/src/WebCompiler/WebCompiler.csproj
+++ b/src/WebCompiler/WebCompiler.csproj
@@ -12,9 +12,9 @@
true
true
- Mads Kristensen, Jason Moore
+ Mads Kristensen, Jason Moore, Kristian Oye
https://github.com/failwyn/WebCompiler
- 1.14.15
+ 1.14.17
True
AnyCPU
diff --git a/src/WebCompiler/packages.config b/src/WebCompiler/packages.config
index 1f381648..15bb5110 100644
--- a/src/WebCompiler/packages.config
+++ b/src/WebCompiler/packages.config
@@ -1,6 +1,6 @@
-
-
-
+
+
+
\ No newline at end of file
diff --git a/src/WebCompilerTest/Config/ConfigHandlerTest.cs b/src/WebCompilerTest/Config/ConfigHandlerTest.cs
index eb809266..d744bba2 100644
--- a/src/WebCompilerTest/Config/ConfigHandlerTest.cs
+++ b/src/WebCompilerTest/Config/ConfigHandlerTest.cs
@@ -31,7 +31,7 @@ public void Cleanup()
[TestMethod, TestCategory("Config")]
public void AddConfig()
{
- var newConfig = new WebCompiler.Config();
+ var newConfig = new WebCompiler.ConfigEntry();
const string newInputFileName = "newInputFile";
newConfig.InputFile = newInputFileName;
@@ -45,7 +45,7 @@ public void AddConfig()
[TestMethod, TestCategory("Config")]
public void NonExistingConfigFileShouldReturnEmptyList()
{
- var expectedResult = Enumerable.Empty();
+ var expectedResult = Enumerable.Empty();
var result = ConfigHandler.GetConfigs("../NonExistingFile.config");
diff --git a/src/WebCompilerTest/Config/ConfigTest.cs b/src/WebCompilerTest/Config/ConfigTest.cs
index a291400e..ff6324af 100644
--- a/src/WebCompilerTest/Config/ConfigTest.cs
+++ b/src/WebCompilerTest/Config/ConfigTest.cs
@@ -8,7 +8,7 @@ namespace WebCompilerTest.Config
[TestClass]
public class ConfigTest
{
- private WebCompiler.Config _config;
+ private WebCompiler.ConfigEntry _config;
private const string dummyConfigFile = "../../artifacts/config/dummy.json";
private const string inputFile = "../../artifacts/config/compilationrequired.scss";
@@ -31,7 +31,7 @@ public void Setup()
{
var configFileInfo = new FileInfo(dummyConfigFile);
- _config = new WebCompiler.Config
+ _config = new WebCompiler.ConfigEntry
{
FileName = configFileInfo.FullName,
InputFile = _inputFileInfo.FullName,
diff --git a/src/WebCompilerTest/packages.config b/src/WebCompilerTest/packages.config
index b8b73697..520836c4 100644
--- a/src/WebCompilerTest/packages.config
+++ b/src/WebCompilerTest/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file