File tree Expand file tree Collapse file tree 19 files changed +358
-20
lines changed Expand file tree Collapse file tree 19 files changed +358
-20
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ src/SharedAssemblyVersionInfo.cs
4
4
src /** /* .nuspec
5
5
! src /template.nuspec
6
6
site /jekyll /_site
7
+ src /React.Sample.Cassette /cassette-cache
7
8
8
9
# # Ignore Visual Studio temporary files, build results, and
9
10
# # files generated by popular Visual Studio add-ons.
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ using React ;
11
+ using React . TinyIoC ;
12
+
13
+ namespace Cassette . React
14
+ {
15
+ /// <summary>
16
+ /// Handles registration of ReactJS.NET components that are only applicable
17
+ /// to Cassette when used in MSBuild.
18
+ /// </summary>
19
+ public class AssemblyRegistration : IAssemblyRegistration
20
+ {
21
+ /// <summary>
22
+ /// Registers components in the React IoC container
23
+ /// </summary>
24
+ /// <param name="container">Container to register components in</param>
25
+ public void Register ( TinyIoCContainer container )
26
+ {
27
+ if ( MSBuildUtils . IsInMSBuild ( ) )
28
+ {
29
+ RegisterForMSBuild ( container ) ;
30
+ }
31
+ }
32
+
33
+ /// <summary>
34
+ /// Registers components specific to the MSBuild environment in the React IoC container.
35
+ /// </summary>
36
+ /// <param name="container">Container to register components in</param>
37
+ private void RegisterForMSBuild ( TinyIoCContainer container )
38
+ {
39
+ container . Register < ICache , NullCache > ( ) ;
40
+ container . Register < IFileSystem , SimpleFileSystem > ( ) ;
41
+ }
42
+ }
43
+ }
Original file line number Diff line number Diff line change 56
56
<Compile Include =" ..\SharedAssemblyVersionInfo.cs" >
57
57
<Link >Properties\SharedAssemblyVersionInfo.cs</Link >
58
58
</Compile >
59
+ <Compile Include =" AssemblyRegistration.cs" />
60
+ <Compile Include =" CassetteMSBuildStartup.cs" />
59
61
<Compile Include =" InsertIntoPipelineJsxBundleProcessor.cs" />
60
62
<Compile Include =" JsxBundleProcessor.cs" />
61
63
<Compile Include =" JsxCompiler.cs" />
62
64
<Compile Include =" JsxFileSearchModifier.cs" />
65
+ <Compile Include =" MSBuildUtils.cs" />
63
66
<Compile Include =" Properties\AssemblyInfo.cs" />
67
+ <Compile Include =" ReactContainerConfiguration.cs" />
64
68
</ItemGroup >
65
69
<ItemGroup >
66
70
<None Include =" Cassette.React.nutrans" />
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ using System ;
11
+ using System . Diagnostics ;
12
+ using React ;
13
+
14
+ namespace Cassette . React
15
+ {
16
+ /// <summary>
17
+ /// Cassette has two modes of operating - Web (ASP.NET) and MSBuild. IoC registration for web
18
+ /// is already covered by React.Web. For the MSBuild mode, we need to initialise ReactJS.NET's
19
+ /// IoC container here.
20
+ /// </summary>
21
+ public class CassetteMSBuildStartup : IStartUpTask
22
+ {
23
+ /// <summary>
24
+ /// Handles initialisation of ReactJS.NET in Cassette. Only relevant when running in an
25
+ /// MSBuild context.
26
+ /// </summary>
27
+ public void Start ( )
28
+ {
29
+ if ( ! MSBuildUtils . IsInMSBuild ( ) )
30
+ {
31
+ return ;
32
+ }
33
+
34
+ // All "per-request" registrations should be singletons in MSBuild, since there's no
35
+ // such thing as a "request"
36
+ // TODO: Should these be per-task instead, once non-Cassette MSBuild support
37
+ // is introduced?
38
+ Initializer . Initialize ( requestLifetimeRegistration : registration => registration . AsSingleton ( ) ) ;
39
+ }
40
+ }
41
+ }
Original file line number Diff line number Diff line change 10
10
using System ;
11
11
using Cassette . BundleProcessing ;
12
12
using Cassette . Scripts ;
13
+ using React ;
13
14
14
15
namespace Cassette . React
15
16
{
@@ -20,14 +21,17 @@ namespace Cassette.React
20
21
public class JsxBundleProcessor : IBundleProcessor < ScriptBundle >
21
22
{
22
23
private readonly CassetteSettings _settings ;
24
+ private readonly IReactEnvironment _environment ;
23
25
24
26
/// <summary>
25
27
/// Initializes a new instance of the <see cref="JsxBundleProcessor"/> class.
26
28
/// </summary>
27
29
/// <param name="settings">Cassette settings.</param>
28
- public JsxBundleProcessor ( CassetteSettings settings )
30
+ /// <param name="environment">The ReactJS.NET environment</param>
31
+ public JsxBundleProcessor ( CassetteSettings settings , IReactEnvironment environment )
29
32
{
30
33
_settings = settings ;
34
+ _environment = environment ;
31
35
}
32
36
33
37
/// <summary>
@@ -41,7 +45,7 @@ public void Process(ScriptBundle bundle)
41
45
if ( asset . Path . EndsWith ( ".jsx" , StringComparison . InvariantCultureIgnoreCase ) )
42
46
{
43
47
asset . AddAssetTransformer (
44
- new CompileAsset ( new JsxCompiler ( ) , _settings . SourceDirectory )
48
+ new CompileAsset ( new JsxCompiler ( _environment ) , _settings . SourceDirectory )
45
49
) ;
46
50
}
47
51
}
Original file line number Diff line number Diff line change @@ -17,6 +17,17 @@ namespace Cassette.React
17
17
/// </summary>
18
18
public class JsxCompiler : ICompiler
19
19
{
20
+ private readonly IReactEnvironment _environment ;
21
+
22
+ /// <summary>
23
+ /// Initializes a new instance of the <see cref="JsxCompiler"/> class.
24
+ /// </summary>
25
+ /// <param name="environment">The ReactJS.NET environment</param>
26
+ public JsxCompiler ( IReactEnvironment environment )
27
+ {
28
+ _environment = environment ;
29
+ }
30
+
20
31
/// <summary>
21
32
/// Compiles the specified JSX file into JavaScript
22
33
/// </summary>
@@ -25,8 +36,7 @@ public class JsxCompiler : ICompiler
25
36
/// <returns>JavaScript</returns>
26
37
public CompileResult Compile ( string source , CompileContext context )
27
38
{
28
- var environment = AssemblyRegistration . Container . Resolve < IReactEnvironment > ( ) ;
29
- var output = environment . TransformJsx ( source ) ;
39
+ var output = _environment . TransformJsx ( source ) ;
30
40
return new CompileResult ( output , Enumerable . Empty < string > ( ) ) ;
31
41
}
32
42
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ using System ;
11
+ using System . Diagnostics ;
12
+
13
+ namespace Cassette . React
14
+ {
15
+ /// <summary>
16
+ /// Utility methods for interacting with Cassette in a MSBuild environment.
17
+ /// </summary>
18
+ public static class MSBuildUtils
19
+ {
20
+ /// <summary>
21
+ /// Determines if the current process is MSBuild
22
+ /// </summary>
23
+ /// <returns><c>true</c> if we are currently in MSBuild</returns>
24
+ public static bool IsInMSBuild ( )
25
+ {
26
+ try
27
+ {
28
+ return Process . GetCurrentProcess ( ) . ProcessName . StartsWith ( "MSBuild" ) ;
29
+ }
30
+ catch ( Exception )
31
+ {
32
+ return false ;
33
+ }
34
+ }
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2014, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
10
+ using CassetteTinyIoCContainer = Cassette . TinyIoC . TinyIoCContainer ;
11
+ using ReactTinyIoCContainer = React . TinyIoC . TinyIoCContainer ;
12
+ using React ;
13
+
14
+ namespace Cassette . React
15
+ {
16
+ /// <summary>
17
+ /// Cassette IoC configuration for ReactJS.NET
18
+ /// </summary>
19
+ public class ReactContainerConfiguration : IConfiguration < CassetteTinyIoCContainer >
20
+ {
21
+ /// <summary>
22
+ /// Configures the specified Cassette IoC container.
23
+ /// </summary>
24
+ /// <param name="container">The IoC container.</param>
25
+ public void Configure ( CassetteTinyIoCContainer container )
26
+ {
27
+ // Register ReactJS.NET's IoC container inside Cassette's.
28
+ container . Register < ReactTinyIoCContainer > ( global ::React . AssemblyRegistration . Container ) ;
29
+ RegisterPassthru < IReactEnvironment > ( container ) ;
30
+ }
31
+
32
+ /// <summary>
33
+ /// Registers a component in Cassette's IoC container that just delegates resolution to
34
+ /// ReactJS.NET's IoC container.
35
+ /// </summary>
36
+ /// <typeparam name="T">Type to register</typeparam>
37
+ /// <param name="container">Cassette's IoC container</param>
38
+ private void RegisterPassthru < T > ( CassetteTinyIoCContainer container ) where T : class
39
+ {
40
+ container . Register < T > ( ( c , overloads ) => global ::React . AssemblyRegistration . Container . Resolve < T > ( ) ) ;
41
+ }
42
+ }
43
+ }
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <!--
3
+ The web application csproj file has been modified to execute the Bundle target.
4
+ So after a build, the Cassette bundles will be saved into a cache directory.
5
+ -->
6
+ <Project xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
7
+ <UsingTask AssemblyFile =" $(OutputPath)\Cassette.MSBuild.dll" TaskName =" CreateBundles" />
8
+ <Target Name =" Bundle" >
9
+ <CreateBundles />
10
+ <!--
11
+ CreateBundles has the following optional properties:
12
+ Source: The root directory of the web application.
13
+ Bin: The directory containing the web application assemblies. Default is "bin".
14
+ Output: The directory to save the created bundles to. Default is "cassette-cache".
15
+ AppVirtualPath: The web application's virtual path. Default is "/".
16
+ IncludeOtherFiles: When true, non-bundled files such as images referenced by stylesheets are also copied to the output directory. Default is false.
17
+
18
+ The Web.config must also have the following section:
19
+ <cassette cacheDirectory="cassette-cache" />
20
+ -->
21
+ </Target >
22
+ </Project >
Original file line number Diff line number Diff line change 49
49
<Reference Include =" Cassette.Aspnet" >
50
50
<HintPath >..\packages\Cassette.Aspnet.2.4.1\lib\net40\Cassette.Aspnet.dll</HintPath >
51
51
</Reference >
52
+ <Reference Include =" Cassette.MSBuild" >
53
+ <HintPath >..\packages\Cassette.MSBuild.2.4.1\lib\net40\Cassette.MSBuild.dll</HintPath >
54
+ </Reference >
52
55
<Reference Include =" Cassette.Views" >
53
56
<HintPath >..\packages\Cassette.Views.2.4.1\lib\net40\Cassette.Views.dll</HintPath >
54
57
</Reference >
177
180
<ItemGroup >
178
181
<Content Include =" Content\Sample.jsx" />
179
182
</ItemGroup >
183
+ <ItemGroup >
184
+ <Content Include =" Cassette.targets" />
185
+ </ItemGroup >
180
186
<PropertyGroup >
181
187
<VisualStudioVersion Condition =" '$(VisualStudioVersion)' == ''" >10.0</VisualStudioVersion >
182
188
<VSToolsPath Condition =" '$(VSToolsPath)' == ''" >$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath >
205
211
</FlavorProperties >
206
212
</VisualStudio >
207
213
</ProjectExtensions >
214
+ <Target Name =" Bundle" AfterTargets =" Build" >
215
+ <Exec Command =" " $(msbuildtoolspath)\msbuild.exe" $(ProjectDirectory)cassette.targets /p:OutputPath=$(OutputPath) /t:Bundle /nr:false" />
216
+ </Target >
208
217
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
209
218
Other similar extension points exist, see Microsoft.Common.targets.
210
219
<Target Name="BeforeBuild">
You can’t perform that action at this time.
0 commit comments