Skip to content

Commit 67faa7e

Browse files
Source map support for Iced CoffeeScript
1 parent 586abae commit 67faa7e

File tree

8 files changed

+33
-35
lines changed

8 files changed

+33
-35
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [x] LESS: Added StrictUnits and RootPath compiler support
55
- [x] LESS: Added relative URL compiler support (#63)
66
- [x] Use the official CoffeeScript compiler (#68)
7+
- [x] Enable source maps for Iced CoffeeScript
78
- [ ] Generate gulpfile.js from compilerconfig.json (#34)
89
- [ ] Preview window (#6)
910
- [ ] File globbing pattern support (#49)

src/WebCompiler/Compile/CoffeeScriptCompiler.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ internal class CoffeeScriptCompiler : ICompiler
1010
{
1111
private static Regex _errorRx = new Regex(":(?<line>[0-9]+):(?<column>[0-9]+).*error: (?<message>.+)", RegexOptions.Compiled);
1212
private string _path;
13-
private string _output = string.Empty;
1413
private string _error = string.Empty;
1514
private string _temp = Path.Combine(Path.GetTempPath(), ".coffee-script");
1615

@@ -99,20 +98,16 @@ private void RunCompilerProcess(Config config, FileInfo info)
9998
CreateNoWindow = true,
10099
FileName = "cmd.exe",
101100
Arguments = $"/c \"\"{Path.Combine(_path, "node_modules\\.bin\\coffee.cmd")}\" {arguments} \"{info.FullName}\"\"",
102-
StandardOutputEncoding = Encoding.UTF8,
103101
StandardErrorEncoding = Encoding.UTF8,
104-
RedirectStandardOutput = true,
105102
RedirectStandardError = true,
106103
};
107104

108105
start.EnvironmentVariables["PATH"] = _path + ";" + start.EnvironmentVariables["PATH"];
109106

110107
Process p = Process.Start(start);
111-
var stdout = p.StandardOutput.ReadToEndAsync();
112108
var stderr = p.StandardError.ReadToEndAsync();
113109
p.WaitForExit();
114110

115-
_output = stdout.Result;
116111
_error = stderr.Result;
117112
}
118113

@@ -128,9 +123,6 @@ private string ConstructArguments(Config config)
128123
if (options.Bare)
129124
arguments += " --bare";
130125

131-
//if (options.Globals)
132-
// arguments += " --globals";
133-
134126
return arguments;
135127
}
136128
}

src/WebCompiler/Compile/IcedCoffeeScriptCompiler.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ internal class IcedCoffeeScriptCompiler : ICompiler
1010
{
1111
private static Regex _errorRx = new Regex(":(?<line>[0-9]+):(?<column>[0-9]+).*error: (?<message>.+)", RegexOptions.Compiled);
1212
private string _path;
13-
private string _output = string.Empty;
1413
private string _error = string.Empty;
14+
private string _temp = Path.Combine(Path.GetTempPath(), ".iced-coffee-script");
1515

1616
public IcedCoffeeScriptCompiler(string path)
1717
{
@@ -36,7 +36,19 @@ public CompilerResult Compile(Config config)
3636
{
3737
RunCompilerProcess(config, info);
3838

39-
result.CompiledContent = _output;
39+
string tempFile = Path.ChangeExtension(Path.Combine(_temp, info.Name), ".js");
40+
41+
if (File.Exists(tempFile))
42+
{
43+
result.CompiledContent = File.ReadAllText(tempFile);
44+
45+
if (config.SourceMap)
46+
{
47+
string mapFile = tempFile + ".map";
48+
if (File.Exists(mapFile))
49+
result.SourceMap = File.ReadAllText(mapFile);
50+
}
51+
}
4052

4153
if (_error.Length > 0)
4254
{
@@ -86,29 +98,25 @@ private void RunCompilerProcess(Config config, FileInfo info)
8698
CreateNoWindow = true,
8799
FileName = "cmd.exe",
88100
Arguments = $"/c \"\"{Path.Combine(_path, "node_modules\\.bin\\iced.cmd")}\" {arguments} \"{info.FullName}\"\"",
89-
StandardOutputEncoding = Encoding.UTF8,
90101
StandardErrorEncoding = Encoding.UTF8,
91-
RedirectStandardOutput = true,
92102
RedirectStandardError = true,
93103
};
94104

95105
start.EnvironmentVariables["PATH"] = _path + ";" + start.EnvironmentVariables["PATH"];
96106

97107
Process p = Process.Start(start);
98-
var stdout = p.StandardOutput.ReadToEndAsync();
99108
var stderr = p.StandardError.ReadToEndAsync();
100109
p.WaitForExit();
101110

102-
_output = stdout.Result;
103111
_error = stderr.Result;
104112
}
105113

106-
private static string ConstructArguments(Config config)
114+
private string ConstructArguments(Config config)
107115
{
108-
string arguments = " --print";
116+
string arguments = $" --compile --output \"{_temp}\"";
109117

110-
//if (config.SourceMap)
111-
// arguments += " --source-map-map-inline";
118+
if (config.SourceMap)
119+
arguments += " --map";
112120

113121
IcedCoffeeScriptOptions options = new IcedCoffeeScriptOptions(config);
114122

src/WebCompilerTest/Compile/IcedCoffeeScriptTest.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ public void Cleanup()
2121
{
2222
File.Delete("../../artifacts/iced/test.js");
2323
File.Delete("../../artifacts/iced/test.min.js");
24+
File.Delete("../../artifacts/iced/test.js.map");
2425
}
2526

2627
[TestMethod, TestCategory("Iced CoffeeScript")]
27-
public void CompileCoffeeScript()
28+
public void CompileIcedCoffeeScript()
2829
{
2930
var result = _processor.Process("../../artifacts/icedcoffeeconfig.json");
30-
FileInfo info = new FileInfo("../../artifacts/iced/test.js");
31-
Assert.IsTrue(info.Exists);
32-
Assert.IsTrue(info.Length > 5);
31+
FileInfo js = new FileInfo("../../artifacts/iced/test.js");
32+
FileInfo map = new FileInfo("../../artifacts/iced/test.js.map");
33+
Assert.IsTrue(js.Exists);
34+
Assert.IsTrue(map.Exists);
35+
Assert.IsTrue(js.Length > 5);
36+
Assert.IsTrue(map.Length > 5);
3337
}
3438

3539
[TestMethod, TestCategory("Iced CoffeeScript")]
36-
public void CompileCoffeeScriptWithError()
40+
public void CompileIcedCoffeeScriptWithError()
3741
{
3842
var result = _processor.Process("../../artifacts/icedcoffeeconfigerror.json");
3943
var error = result.First().Errors[0];

src/WebCompilerTest/artifacts/icedcoffeeconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"outputFile": "iced/test.js",
44
"inputFile": "iced/test.iced",
55
"minify": { },
6-
"includeInProject": true
6+
"includeInProject": true,
7+
"sourceMap": true
78
}
89
]

src/WebCompilerVsix/JSON/compilerconfig-schema.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@
6969
},
7070
"minify": {
7171
"$ref": "#/definitions/cssOptions"
72-
},
73-
"sourceMap": {
74-
"description": "Set to true to automatically create inline source map files.",
75-
"type": "boolean"
7672
}
7773
}
7874
},
@@ -198,7 +194,7 @@
198194
"minLength": 1
199195
},
200196
"sourceMap": {
201-
"description": "Set to true to automatically create inline source map files.",
197+
"description": "Set to true to automatically create either inline source maps or a .map file.",
202198
"type": "boolean"
203199
}
204200
},

src/WebCompilerVsix/JSON/compilerconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"minify": {
66
"enabled": true
77
},
8-
"includeInProject": true
8+
"includeInProject": true,
99
},
1010
{
1111
"outputFile": "foo.css",

src/WebCompilerVsix/WebCompilerVsix.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,7 @@
222222
<ItemGroup />
223223
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
224224
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
225-
<ProjectExtensions>
226-
<VisualStudio>
227-
<UserProperties JSON_4compilerconfig_1json__JSONSchema="compilerconfig-schema.json" />
228-
</VisualStudio>
229-
</ProjectExtensions>
225+
<ProjectExtensions />
230226
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
231227
Other similar extension points exist, see Microsoft.Common.targets.
232228
<Target Name="BeforeBuild">

0 commit comments

Comments
 (0)