Permalink
Browse files

add less support

  • Loading branch information...
Santas committed Jul 13, 2012
1 parent e2eb686 commit 5847fbb54add46f2094c67ee3a125572061ceab4
@@ -1,14 +1,15 @@
-{
- "name": "NodeAssets.Test",
- "description": "Test dependencies for MVCClient Side",
- "private": true,
- "author": { "name": "Felix Jorkowski (http://jorkowski.com)" },
- "version": "1.0.0",
- "dependencies": {
- "coffee-script": "*",
- "stylus": "*",
- "nib": "*",
- "uglify-js": "*",
- "csso": "*"
- }
+{
+ "name": "NodeAssets.Test",
+ "description": "Test dependencies for MVCClient Side",
+ "private": true,
+ "author": { "name": "Felix Jorkowski (http://jorkowski.com)" },
+ "version": "1.0.0",
+ "dependencies": {
+ "coffee-script": "*",
+ "stylus": "*",
+ "nib": "*",
+ "uglify-js": "*",
+ "csso": "*",
+ "less": "*"
+ }
}
@@ -1,50 +1,51 @@
-using NodeAssets.Core;
-using NodeAssets.Core.Commands;
-using NodeAssets.Core.Compilers;
-
-namespace NodeAssets
-{
- public static class CompilerConfigurationExtensions
- {
- /// <summary>
- /// Default configuration for compilers, using only .NET compilers
- /// Has Coffee, Sass/Scss, JsMinify and CssMinify
- /// </summary>
- public static ICompilerConfiguration WithDefaultConfiguration(this ICompilerConfiguration compilerConfig)
- {
- var passthrough = new PassthroughCompiler();
- var sassCompiler = new SassCompiler();
-
- return compilerConfig
- .CompilerFor(".coffee", new CoffeeSharpCompiler())
- .CompilerFor(".js", passthrough)
- .CompilerFor(".sass", sassCompiler)
- .CompilerFor(".scss", sassCompiler)
- .CompilerFor(".css", passthrough)
- .CompilerFor(".min.js.min", passthrough) // ignore .min.js files (they are already minified or want to ignore)
- .CompilerFor(".min.css.min", passthrough) // ignore .min.css files (they are already minified or want to ignore)
- .CompilerFor(".js.min", new JsMinifyCompiler())
- .CompilerFor(".css.min", new CssMinifyCompiler());
- }
-
- /// <summary>
- /// Default Node compiler configuration, uses nodejs libraries to compile
- /// </summary>
- /// <param name="nodeWorkspacePath">Path to directory where node_modules are installed</param>
- public static ICompilerConfiguration WithDefaultNodeConfiguration(this ICompilerConfiguration compilerConfig, string nodeWorkspacePath)
- {
- var passthrough = new PassthroughCompiler();
- var executor = new NodeExecutor(nodeWorkspacePath);
-
- return compilerConfig
- .CompilerFor(".coffee", new CoffeeCompiler(executor))
- .CompilerFor(".js", passthrough)
- .CompilerFor(".styl", new StylusCompiler(executor, true))
- .CompilerFor(".css", passthrough)
- .CompilerFor(".min.js.min", passthrough) // ignore .min.js files (they are already minified or want to ignore)
- .CompilerFor(".min.css.min", passthrough) // ignore .min.css files (they are already minified or want to ignore)
- .CompilerFor(".js.min", new UglifyJSCompiler(executor))
- .CompilerFor(".css.min", new CssoCompiler(executor));
- }
- }
-}
+using NodeAssets.Core;
+using NodeAssets.Core.Commands;
+using NodeAssets.Core.Compilers;
+
+namespace NodeAssets
+{
+ public static class CompilerConfigurationExtensions
+ {
+ /// <summary>
+ /// Default configuration for compilers, using only .NET compilers
+ /// Has Coffee, Sass/Scss, JsMinify and CssMinify
+ /// </summary>
+ public static ICompilerConfiguration WithDefaultConfiguration(this ICompilerConfiguration compilerConfig)
+ {
+ var passthrough = new PassthroughCompiler();
+ var sassCompiler = new SassCompiler();
+
+ return compilerConfig
+ .CompilerFor(".coffee", new CoffeeSharpCompiler())
+ .CompilerFor(".js", passthrough)
+ .CompilerFor(".sass", sassCompiler)
+ .CompilerFor(".scss", sassCompiler)
+ .CompilerFor(".css", passthrough)
+ .CompilerFor(".min.js.min", passthrough) // ignore .min.js files (they are already minified or want to ignore)
+ .CompilerFor(".min.css.min", passthrough) // ignore .min.css files (they are already minified or want to ignore)
+ .CompilerFor(".js.min", new JsMinifyCompiler())
+ .CompilerFor(".css.min", new CssMinifyCompiler());
+ }
+
+ /// <summary>
+ /// Default Node compiler configuration, uses nodejs libraries to compile
+ /// </summary>
+ /// <param name="nodeWorkspacePath">Path to directory where node_modules are installed</param>
+ public static ICompilerConfiguration WithDefaultNodeConfiguration(this ICompilerConfiguration compilerConfig, string nodeWorkspacePath)
+ {
+ var passthrough = new PassthroughCompiler();
+ var executor = new NodeExecutor(nodeWorkspacePath);
+
+ return compilerConfig
+ .CompilerFor(".coffee", new CoffeeCompiler(executor))
+ .CompilerFor(".js", passthrough)
+ .CompilerFor(".styl", new StylusCompiler(executor, true))
+ .CompilerFor(".less", new LessCompiler(executor))
+ .CompilerFor(".css", passthrough)
+ .CompilerFor(".min.js.min", passthrough) // ignore .min.js files (they are already minified or want to ignore)
+ .CompilerFor(".min.css.min", passthrough) // ignore .min.css files (they are already minified or want to ignore)
+ .CompilerFor(".js.min", new UglifyJSCompiler(executor))
+ .CompilerFor(".css.min", new CssoCompiler(executor));
+ }
+ }
+}
@@ -0,0 +1,35 @@
+using System;
+using System.IO;
+using System.Threading.Tasks;
+using NodeAssets.Core.Commands;
+
+namespace NodeAssets.Core.Compilers
+{
+ public sealed class LessCompiler : ICompiler
+ {
+ private const string ScriptLocation = "NodeAssets.Core.Compilers.Scripts.less.js";
+ private readonly INodeExecutor _executor;
+ private readonly string _executeScript;
+
+ public LessCompiler(INodeExecutor executor)
+ {
+ _executor = executor;
+ _executeScript = ScriptFinder.GetScript(ScriptLocation);
+ }
+
+ public Task<string> Compile(string initial, FileInfo originalFile)
+ {
+ initial = initial ?? string.Empty;
+
+ var script = _executeScript
+ .Replace("{0}", originalFile != null ? originalFile.FullName : string.Empty);
+
+ var command = _executor.ExecuteJsScript(script);
+ command.StdIn.Write(initial);
+ command.StdIn.Flush();
+ command.StdIn.Close();
+
+ return Task.Factory.StartNew(() => _executor.RunCommand(command));
+ }
+ }
+}
@@ -0,0 +1,24 @@
+var less = require('less');
+
+/*var workingDir = '{0}';
+
+var opt = {};
+if(workingDir != '')
+{
+ opt.filename = workingDir;
+}*/
+
+var stdin = process.openStdin();
+stdin.setEncoding('utf8');
+
+var styl = '';
+stdin.on('data', function (chunk) {
+ styl = styl + chunk;
+});
+
+stdin.on('end', function () {
+ less.render(styl, function (e, css) {
+ if (e) throw e;
+ console.log(css);
+ });
+});
Oops, something went wrong.

0 comments on commit 5847fbb

Please sign in to comment.