@@ -10,6 +10,8 @@ namespace MadsKristensen.EditorExtensions
10
10
{
11
11
public abstract class NodeExecutorBase
12
12
{
13
+ protected virtual bool Previewing { get { return false ; } }
14
+
13
15
///<summary>Indicates whether this compiler will emit a source map file. Will only return true if supported and enabled in user settings.</summary>
14
16
public abstract bool MinifyInPlace { get ; }
15
17
public abstract bool GenerateSourceMap { get ; }
@@ -18,20 +20,26 @@ public abstract class NodeExecutorBase
18
20
19
21
public async Task < CompilerResult > CompileAsync ( string sourceFileName , string targetFileName )
20
22
{
23
+ bool onlyPreview = false ;
24
+
21
25
if ( WEIgnore . TestWEIgnore ( sourceFileName , this is ILintCompiler ? "linter" : "compiler" , ServiceName . ToLowerInvariant ( ) ) )
22
26
{
23
27
Logger . Log ( String . Format ( CultureInfo . CurrentCulture , "{0}: The file {1} is ignored by .weignore. Skipping.." , ServiceName , Path . GetFileName ( sourceFileName ) ) ) ;
24
- return await CompilerResultFactory . GenerateResult ( sourceFileName , targetFileName , string . Empty , false , string . Empty , string . Empty , Enumerable . Empty < CompilerError > ( ) , true ) ;
28
+
29
+ if ( ! Previewing )
30
+ return await CompilerResultFactory . GenerateResult ( sourceFileName , targetFileName , string . Empty , false , string . Empty , string . Empty , Enumerable . Empty < CompilerError > ( ) , true ) ;
31
+
32
+ onlyPreview = true ;
25
33
}
26
34
27
35
CompilerResult response = await NodeServer . CallServiceAsync ( GetPath ( sourceFileName , targetFileName ) ) ;
28
36
29
- return await ProcessResult ( response , sourceFileName , targetFileName ) ;
37
+ return await ProcessResult ( response , onlyPreview , sourceFileName , targetFileName ) ;
30
38
}
31
39
32
40
// Don't try-catch this method: We need to "address" all the bugs,
33
41
// which may occur as the (node.js-based) service implement changes.
34
- private async Task < CompilerResult > ProcessResult ( CompilerResult result , string sourceFileName , string targetFileName )
42
+ private async Task < CompilerResult > ProcessResult ( CompilerResult result , bool onlyPreview , string sourceFileName , string targetFileName )
35
43
{
36
44
if ( result == null )
37
45
{
@@ -50,17 +58,23 @@ private async Task<CompilerResult> ProcessResult(CompilerResult result, string s
50
58
51
59
string resultString = PostProcessResult ( result ) ;
52
60
53
- if ( result . TargetFileName != null && ( MinifyInPlace || ! File . Exists ( result . TargetFileName ) ||
54
- resultString != await FileHelpers . ReadAllTextRetry ( result . TargetFileName ) ) )
61
+ if ( ! onlyPreview )
55
62
{
56
- ProjectHelpers . CheckOutFileFromSourceControl ( result . TargetFileName ) ;
57
- await FileHelpers . WriteAllTextRetry ( result . TargetFileName , resultString ) ;
58
- }
59
- if ( GenerateSourceMap && ( ! File . Exists ( result . MapFileName ) ||
60
- result . ResultMap != await FileHelpers . ReadAllTextRetry ( result . MapFileName ) ) )
61
- {
62
- ProjectHelpers . CheckOutFileFromSourceControl ( result . MapFileName ) ;
63
- await FileHelpers . WriteAllTextRetry ( result . MapFileName , result . ResultMap ) ;
63
+ // Write output file
64
+ if ( result . TargetFileName != null && ( MinifyInPlace || ! File . Exists ( result . TargetFileName ) ||
65
+ resultString != await FileHelpers . ReadAllTextRetry ( result . TargetFileName ) ) )
66
+ {
67
+ ProjectHelpers . CheckOutFileFromSourceControl ( result . TargetFileName ) ;
68
+ await FileHelpers . WriteAllTextRetry ( result . TargetFileName , resultString ) ;
69
+ }
70
+
71
+ // Write map file
72
+ if ( GenerateSourceMap && ( ! File . Exists ( result . MapFileName ) ||
73
+ result . ResultMap != await FileHelpers . ReadAllTextRetry ( result . MapFileName ) ) )
74
+ {
75
+ ProjectHelpers . CheckOutFileFromSourceControl ( result . MapFileName ) ;
76
+ await FileHelpers . WriteAllTextRetry ( result . MapFileName , result . ResultMap ) ;
77
+ }
64
78
}
65
79
66
80
return CompilerResult . UpdateResult ( result , resultString ) ;
0 commit comments