Skip to content

Commit

Permalink
Add TypeScriptServicesOutDir and UseKnockout options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidoine committed Dec 6, 2017
1 parent 815f927 commit 028cd2d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
16 changes: 10 additions & 6 deletions src/Folke.Core/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ public static class ApplicationBuilderExtensions
app.UseMvc();
app.UseRequestLocalization();

var options = new FolkeCoreApplicationOptions();
optionsAction(options);

using (var transaction = connection.BeginTransaction())
{
connection.UpdateIdentityUserSchema<int, User>();
connection.UpdateIdentityRoleSchema<int, User>();
connection.UpdateSchema(typeof(User).GetTypeInfo().Assembly);

var options = new FolkeCoreApplicationOptions();
optionsAction(options);
CreateAdministrator(roleManager, userManager, options).GetAwaiter().GetResult();
transaction.Commit();
}

if (env.IsDevelopment())
{
CreateTypeScriptServices(applicationPartManager);
CreateTypeScriptServices(applicationPartManager, options.UseKnockout, options.TypeScriptServicesOutDir ?? "src/services");
}

return app;
Expand All @@ -72,7 +73,7 @@ private static async Task CreateAdministrator(RoleManager<Role> roleManager, Use
}
}

private static void CreateTypeScriptServices(ApplicationPartManager applicationPartManager)
private static void CreateTypeScriptServices(ApplicationPartManager applicationPartManager, bool useKnockout, string outputDir)
{
ControllerFeature feature = new ControllerFeature();
applicationPartManager.PopulateFeature(feature);
Expand All @@ -81,9 +82,12 @@ private static void CreateTypeScriptServices(ApplicationPartManager applicationP
var assembly = converter.ReadControllers(controllerTypes);
var typeScript = new TypeScriptWriter();
// Call WriteAssembly twice ; once for TypeScript objects and once for Knockout mappings
typeScript.WriteAssembly(assembly, true);
if (useKnockout)
{
typeScript.WriteAssembly(assembly, true);
}
typeScript.WriteAssembly(assembly, false);
typeScript.WriteToFiles("src/services");
typeScript.WriteToFiles(outputDir);
}
}
}
8 changes: 4 additions & 4 deletions src/Folke.Core/Folke.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Folke.CsTsService" Version="3.*" />
<PackageReference Include="Folke.Identity.Elm" Version="3.*" />
<PackageReference Include="Folke.Identity.Server" Version="3.*" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.*" />
<PackageReference Include="Folke.CsTsService" Version="4.0.0" />
<PackageReference Include="Folke.Identity.Elm" Version="3.0.0.1" />
<PackageReference Include="Folke.Identity.Server" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/Folke.Core/FolkeCoreApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public class FolkeCoreApplicationOptions
{
public string AdministratorEmail { get; set; }
public string AdministratorPassword { get; set; }
public string TypeScriptServicesOutDir { get; set; }
public bool UseKnockout { get; set; }
}
}
10 changes: 5 additions & 5 deletions test/Folke.Core.Tests/Folke.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Folke.Elm.Sqlite" Version="2.*" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.*" />
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*" />
<PackageReference Include="Folke.Elm.Sqlite" Version="2.3.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 028cd2d

Please sign in to comment.