Initial Commit

This commit is contained in:
2020-11-10 21:44:20 +11:00
parent 43e9398507
commit 1aac34878e
44 changed files with 70899 additions and 73 deletions

View File

@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;
namespace Web.Controllers
{
[Route("Home")]
public class HomeController : Controller
{
[Route("Hello")]
public JsonResult Hello(Hello request)
{
return new JsonResult(new HelloResponse() {Result = $"hello, {request?.Name ?? "System.NullReferenceException"}"});
}
public IActionResult Index()
{
return View();
}
}
public class Hello
{
public string Name { get; set; }
}
public class HelloResponse
{
public string Result { get; set; }
}
}

19
Web/LICENSE Normal file
View File

@ -0,0 +1,19 @@
MIT License Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

41
Web/NLog.config Normal file
View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--
Write events to a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f"
<logger name="*" minlevel="Debug" writeTo="f" />
-->
</rules>
</nlog>

44
Web/Program.cs Normal file
View File

@ -0,0 +1,44 @@
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Web;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
namespace Web
{
public class Program
{
public static void Main(string[] args)
{
var logger = LogManager/*NLogBuilder/*.ConfigureNLog("nlog.config")*/.GetCurrentClassLogger();
try
{
logger.Debug("init main");
CreateHostBuilder(args).Build().Run();
}
catch (Exception exception)
{
//NLog: catch setup errors
logger.Fatal(exception, "Program stopped due to exception");
throw;
}
finally
{
NLog.LogManager.Shutdown();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })
.ConfigureLogging(logging =>
{
// prefer NLog for logging
//logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
})
.UseNLog();
}
}

View File

@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "https://localhost:5001/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyApp": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001/"
}
}
}

22
Web/README.md Normal file
View File

@ -0,0 +1,22 @@
# exsvelte
ProEX GUI in Svelte & ASP.NET Core MVC
### To setup dev:
Install Node.js, then, in a command prompt:
If you do not have yarn, install that first:
```
$ npm install --global yarn
```
Then, after clone, navigate to Web/ and run:
```
$ yarn install
```
###To dev:
Run in a command prompt:
```
$ rollup -c -w
```

119
Web/Startup.cs Normal file
View File

@ -0,0 +1,119 @@
using System.IO;
using Infrastructure.Data;
using Infrastructure.Data.OliVerse;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Rewrite;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Westwind.AspNetCore.LiveReload;
namespace Web
{
public class Startup
{
public Startup(IConfiguration configuration, IWebHostEnvironment hostEnvironment)
{
Configuration = configuration;
Env = hostEnvironment;
}
public IWebHostEnvironment Env { get; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddLiveReload(config =>
{
config.FolderToMonitor = Path.GetFullPath(Path.Combine(Env.ContentRootPath, ".."));
});
services.AddDbContext<ExDbContext>(opt =>
opt.UseSqlServer(Configuration.GetConnectionString("" /*TODO*/))
.AddInterceptors(new OutputCommandInterceptor()));
services.AddRazorPages(options => { });
services.AddControllersWithViews(options => { }); //(options => options.EnableEndpointRouting = false);
//.AddJsonOptions(options => { options.JsonSerializerOptions.; });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// dont redirect if in development
app.UseHttpsRedirection();
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseLiveReload();
app.UseStaticFiles(new StaticFileOptions() {ServeUnknownFileTypes = true, });
app.UseRouting();
// app.UseRewriter(new RewriteOptions().AddRedirect("", "/"));
// example of custom Endpoint-based routing examples:
// https://github.com/dotnet/aspnetcore/issues/4221#issuecomment-488596903
// https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/test/WebSites/RoutingWebSite/StartupForDynamic.cs
// old way of doing routing, requires options => options.EnableEndpointRouting = false
// app.UseMvc(routes =>
// {
// routes.MapRoute("default", "{controller=Home}");
// routes.MapSpaFallbackRoute("spa-fallback",
// new
// {
// controller = "Home",
// action = "Index"
// });
// });
//
//*/
app.UseEndpoints(endpoints =>
{
//endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}");
// try and match the URL to razor pages first
endpoints.MapRazorPages();
// then try and map the URL to Controllers (including the API)
//endpoints.MapControllerRoute("default", "/{controller}/");
endpoints.MapControllers();
// and if that doesnt work, send them the homepage, but leave their URI path intact as for handling by the SPA
endpoints.MapFallbackToController("Index", "Home");
// endpoints.MapFallbackToPage("/");
//endpoints.MapToSpaCliProxy("/");
// Note: only use spacliproxy in development.
// Production should use "UseSpaStaticFiles()"
}); //*/
// app.UseEndpoints(endpoints =>
// {
// endpoints.MapRazorPages();
// endpoints.MapControllers();
// });
}
}
}

25
Web/Views/Error.cshtml Normal file
View File

@ -0,0 +1,25 @@
@page
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@*
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
*@
<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

View File

@ -0,0 +1,3 @@
@{
ViewData["Title"] = "Home";
}

7
Web/Views/Privacy.cshtml Normal file
View File

@ -0,0 +1,7 @@
@page
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon"
type="image/png" href="favicon.png"/>
<title>@ViewData["Title"] - Web</title>
@* <link rel="stylesheet" href="/css/bootstrap.min.css"/> *@
@* <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> *@
<link rel="stylesheet" href="~/build/bundle.css" asp-append-version="true"/>
@* <link rel="stylesheet" href="~/site.css" asp-append-version="true"/> *@
<environment include="Development">
<script> basePath = ''</script>
</environment>
<environment exclude="Development">
<script> basePath = '@Url.Content("~")'; </script>
</environment>
</head>
<body>
@RenderBody()
<!-- Load the "module" version on browsers that can support it. -->
<script type="module" src="https://unpkg.com/dimport?module" data-main="/build/main.js"></script>
<!-- Load the "nomodule" version on older browsers acts as fallback! -->
<script type="nomodule" nomodule src="https://unpkg.com/dimport/nomodule" data-main="/build/main.js">
</script>
<!-- Old style JS library -->
<!--script type="text/javascript" src="~/dist/bundle.js" asp-append-version="true"></script-->
@RenderSection("scripts", required: false)
</body>
</html>

View File

@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

View File

@ -0,0 +1,3 @@
@namespace Web.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.SpaServices

View File

@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}

51
Web/Web.csproj Normal file
View File

@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<OutputType>Exe</OutputType>
<TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models" />
<Folder Include="src\components" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.Mvc" Version="5.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0" />
<PackageReference Include="NLog" Version="4.7.5" />
<PackageReference Include="NLog.Config" Version="4.7.5" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />
<PackageReference Include="NLog.Schema" Version="4.7.5" />
<PackageReference Include="NLog.Web" Version="4.9.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
<PackageReference Include="Westwind.AspNetCore.LiveReload" Version="0.2.14" />
</ItemGroup>
<ItemGroup>
<None Remove="node_modules\**" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="wwwroot\build\wwwroot\bundle.css" />
<_ContentIncludedByDefault Remove="wwwroot\build\wwwroot\bundle.css.map" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,20 @@
{
"DebugMode": true,
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"Console": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
}

15
Web/appsettings.json Normal file
View File

@ -0,0 +1,15 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}

25
Web/gulpfile.js Normal file
View File

@ -0,0 +1,25 @@
(function () {
var SCRIPTS = {
'dev': 'npm run dev',
'dtos': 'npm run dtos',
'build': 'npm run build',
'publish': 'npm run publish'
};
var gulp = require('gulp');
var exec = require('child_process').exec;
function runScript(script, done) {
process.env.FORCE_COLOR = 1;
var proc = exec(script + (script.startsWith("npm") ? " --silent" : ""));
proc.stdout.pipe(process.stdout);
proc.stderr.pipe(process.stderr);
proc.on('exit', () => done());
}
// Tasks
Object.keys(SCRIPTS).forEach(name => {
gulp.task(name, done => runScript(SCRIPTS[name], done));
});
})();

71
Web/package.json Normal file
View File

@ -0,0 +1,71 @@
{
"name": "exsvelte",
"version": "0.1.0",
"repository": "https://quartznet.info/git/MiniJack/exsvelte",
"author": "Ben Parsons <9parsonsb@gmail.com>",
"license": "MIT",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv wwwroot"
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.8.3",
"@beyonk/svelte-toggle": "^0.1.2",
"@rollup/plugin-commonjs": "^11.0.1",
"@rollup/plugin-json": "^4.0.1",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-typescript": "^2.1.0",
"@types/node": "^13.1.8",
"aspnet-webpack": "^3.0.0",
"autoprefixer": "^10.0.1",
"babel-cli": "^6.23.0",
"css-loader": "^3.4.2",
"eslint-plugin-svelte3": "^2.7.3",
"event-source-polyfill": "^1.0.12",
"file-loader": "^5.0.2",
"gulp": "^4.0.2",
"install": "^0.13.0",
"isomorphic-fetch": "^2.2.1",
"jquery": "^3.5.1",
"node-sass": "^5.0.0",
"rollup": "^2.33.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-sass": "^1.2.2",
"rollup-plugin-scss": "^2.6.1",
"rollup-plugin-svelte": "^6.0.0",
"rollup-plugin-terser": "^7.0.0",
"sass": "^1.29.0",
"sirv": "^1.0.7",
"sirv-cli": "^1.0.0",
"svelte": "^3.29.4",
"svelte-loader": "^2.13.6",
"svelte-navaid": "^0.1.1",
"svelte-preprocess": "^4.5.2",
"ts-loader": "^6.2.1",
"tslib": "^1.10.0",
"typescript": "^3.7.5",
"uglifyjs-webpack-plugin": "^2.2.0",
"url-loader": "^3.0.0",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"webpack-dev-middleware": "^3.7.2",
"webpack-hot-middleware": "^2.25.0",
"webpack-virtual-modules": "^0.2.1"
},
"dependencies": {
"@beyonk/svelte-carousel": "^2.8.0",
"bootstrap": "^4.5.3",
"jquery": "^3.5.1",
"popper.js": "^1.16.1",
"postcss": "^8.1.6",
"scss": "^0.2.4",
"siema": "^1.5.1",
"svelte-feather-icons": "^3.3.0",
"svelte-swipe": "^1.7.1"
}
}

122
Web/rollup.config.js Normal file
View File

@ -0,0 +1,122 @@
import babel from 'rollup-plugin-babel';
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';
import json from "@rollup/plugin-json";
import scss from 'rollup-plugin-scss'
import { nodeResolve } from '@rollup/plugin-node-resolve';
const production = !process.env.ROLLUP_WATCH;
const port = process.env.PORT;
const buildDir = 'wwwroot/build';
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
server = require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
process.on('SIGTERM', toExit);
process.on('exit', toExit);
}
};
}
export default {
input: 'src/main.ts',
output: {
sourcemap: true,
format: 'esm',
name: 'app',
//file: 'wwwroot/bundle.js'
dir: buildDir,
},
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
// // we'll extract any component CSS out into
// // a separate file - better for performance
// css: css => {
// css.write('bundle.css');
// },
preprocess: sveltePreprocess({
scss: {
includePaths: ['src'],
excludePaths: ['wwwroot', 'node_modules'],
minify: !production
},
postcss: {
plugins: [require('autoprefixer')],
},
}),
emitCss: true
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs({
extensions: ['.js'],
namedExports: {
'node_modules/bootstrap/dist/js/bootstrap.min.js' : ['bootstrap'],
jquery : 'jQuery',
'popper.js': 'Popper'
},
exclude: "node_modules/**"
}),
json(),
globals(),
builtins(),
babel({exclude: "node_modules/**"}),
nodeResolve(),
typescript({ sourceMap: !production }),
scss({
exclude: ['node_modules'],
sass: require('sass'),
minify: !production,
output: 'wwwroot/build/bundle.css',
sourcemap: true
}),
// In dev mode, call `npm run start` once
// the bundle has been generated
//!production && serve(),
// Watch the `wwwroot` directory and refresh the
// browser on changes when not in production
// note that livereload will not work when running under aspnetcore. use the livereload nuget package when running under aspnetcore
!production && livereload({
watch: './wwwroot',
port,
}),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
};

View File

@ -0,0 +1,128 @@
// @ts-check
/** This script modifies the project to support TS code in .svelte files like:
<script lang="ts">
export let name: string;
</script>
As well as validating the code for CI.
*/
/** To work on this script:
rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template
*/
const fs = require("fs")
const path = require("path")
const { argv } = require("process")
const projectRoot = argv[2] || path.join(__dirname, "..")
// Add deps to pkg.json
const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"))
packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, {
"svelte-check": "^1.0.0",
"svelte-preprocess": "^4.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"typescript": "^3.9.3",
"tslib": "^2.0.0",
"@tsconfig/svelte": "^1.0.0"
})
// Add script for checking
packageJSON.scripts = Object.assign(packageJSON.scripts, {
"validate": "svelte-check"
})
// Write the package JSON
fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " "))
// mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too
const beforeMainJSPath = path.join(projectRoot, "src", "main.js")
const afterMainTSPath = path.join(projectRoot, "src", "main.ts")
fs.renameSync(beforeMainJSPath, afterMainTSPath)
// Switch the app.svelte file to use TS
const appSveltePath = path.join(projectRoot, "src", "App.svelte")
let appFile = fs.readFileSync(appSveltePath, "utf8")
appFile = appFile.replace("<script>", '<script lang="ts">')
appFile = appFile.replace("export let name;", 'export let name: string;')
fs.writeFileSync(appSveltePath, appFile)
// Edit rollup config
const rollupConfigPath = path.join(projectRoot, "rollup.config.js")
let rollupConfig = fs.readFileSync(rollupConfigPath, "utf8")
// Edit imports
rollupConfig = rollupConfig.replace(`'rollup-plugin-terser';`, `'rollup-plugin-terser';
import sveltePreprocess from 'svelte-preprocess';
import typescript from '@rollup/plugin-typescript';`)
// Replace name of entry point
rollupConfig = rollupConfig.replace(`'src/main.js'`, `'src/main.ts'`)
// Add preprocess to the svelte config, this is tricky because there's no easy signifier.
// Instead we look for `css:` then the next `}` and add the preprocessor to that
let foundCSS = false
let match
// https://regex101.com/r/OtNjwo/1
const configEditor = new RegExp(/css:.|\n*}/gmi)
while (( match = configEditor.exec(rollupConfig)) != null) {
if (foundCSS) {
const endOfCSSIndex = match.index + 1
rollupConfig = rollupConfig.slice(0, endOfCSSIndex) + ",\n preprocess: sveltePreprocess()," + rollupConfig.slice(endOfCSSIndex);
break
}
if (match[0].includes("css:")) foundCSS = true
}
// Add TypeScript
rollupConfig = rollupConfig.replace(
'commonjs(),',
'commonjs(),\n\t\ttypescript({\n\t\t\tsourceMap: !production,\n\t\t\tinlineSources: !production\n\t\t}),'
);
fs.writeFileSync(rollupConfigPath, rollupConfig)
// Add TSConfig
const tsconfig = `{
"extends": "@tsconfig/svelte/tsconfig.json",
"include": ["src/**/*"],
"exclude": ["node_modules/*", "__sapper__/*", "public/*"]
}`
const tsconfigPath = path.join(projectRoot, "tsconfig.json")
fs.writeFileSync(tsconfigPath, tsconfig)
// Delete this script, but not during testing
if (!argv[2]) {
// Remove the script
fs.unlinkSync(path.join(__filename))
// Check for Mac's DS_store file, and if it's the only one left remove it
const remainingFiles = fs.readdirSync(path.join(__dirname))
if (remainingFiles.length === 1 && remainingFiles[0] === '.DS_store') {
fs.unlinkSync(path.join(__dirname, '.DS_store'))
}
// Check if the scripts folder is empty
if (fs.readdirSync(path.join(__dirname)).length === 0) {
// Remove the scripts folder
fs.rmdirSync(path.join(__dirname))
}
}
// Adds the extension recommendation
fs.mkdirSync(path.join(projectRoot, ".vscode"))
fs.writeFileSync(path.join(projectRoot, ".vscode", "extensions.json"), `{
"recommendations": ["svelte.svelte-vscode"]
}
`)
console.log("Converted to TypeScript.")
if (fs.existsSync(path.join(projectRoot, "node_modules"))) {
console.log("\nYou will need to re-run your dependency manager to get started.")
}

46
Web/src/App.svelte Normal file
View File

@ -0,0 +1,46 @@
<script>
import Router from 'svelte-navaid/Router.svelte';
import Route from 'svelte-navaid/Route.svelte';
import {onDestroy} from 'svelte';
import Nav from './components/Nav.svelte';
import Home from './routes/Home.svelte'
import Button from './routes/Button.svelte'
import tmp from './routes/temp.svelte'
import Joe from './routes/Joe.svelte'
let navigate;
const routes = [
{path: "/", component: Home},
{path: "Button", component: Button},
{path: "tmp", component: tmp},
{path: 'joe', component: Joe}
];
</script>
<Router bind:navigate >
<Nav {navigate}/>
<main>
{#each routes as route}
<Route path={route.path} component={route.component}/>
{/each}
<Route>
<h1 style="text-align: center; margin: 0 auto; font-size: 10em">404</h1>
</Route>
</main>
</Router>
<style>
main {
position: relative;
max-width: 80em;
background-color: white;
padding: 2em;
margin: 0 auto;
box-sizing: border-box;
}
</style>

View File

@ -0,0 +1,36 @@
<script>
import { getContext } from 'svelte';
import { writable } from 'svelte/store';
const navigate = getContext('navigate');
const navaid = getContext('navaid');
const base = navaid && navaid.base || writable('/');
const library = navaid && navaid.library || writable(null);
let props;
let href;
export let append;
$: {
props = { ...$$props };
href = props.href;
delete props.href;
href = ($library && $library.prefix ? $library.prefix : '') + (!append ? $base : '') + href.replace(/^\//, '');
}
const click = () => {
navigate(href);
}
</script>
<style>
span {
text-decoration: none;
padding: 1rem 0.5rem;
display: block;
color: #005de6;
}
</style>
<span {...props} on:click={click}><slot></slot></span>

View File

@ -0,0 +1,72 @@
<script>
import Link from './Link.svelte';
import {getContext} from 'svelte';
const {routes, active, params} = getContext('navaid');
export let navigate;
let current;
$: isActive = str => {
active.subscribe(v=>current=v);
if (str === "/" && $active.path === "")
return "selected";
return $active.path === str ? 'selected' : '';
};
</script>
{#if $active}
<nav>
<ul>
<li><Link class="{ isActive('') }" href="/">Home</Link></li>
<li><Link class="{ isActive('Button') }" href="Button">Button</Link></li>
<li><Link class="{ isActive('tmp') }" href="tmp">tmp</Link></li>
<li><Link class="{ isActive('joe') }" href="joe">joe</Link></li>
</ul>
</nav>
{/if}
<style>
nav {
border-bottom: 1px solid rgba(170, 30, 30, 0.1);
font-weight: 300;
padding: 0 1em;
}
ul {
margin: 0;
padding: 0;
}
/* clearfix */
ul::after {
content: '';
display: block;
clear: both;
}
li {
display: block;
float: left;
}
:global(.selected) {
position: relative;
display: inline-block;
}
:global(.selected::after) {
position: absolute;
content: '';
width: calc(100% - 1em);
height: 2px;
background-color: rgb(170, 30, 30);
display: block;
bottom: -1px;
}
</style>

17
Web/src/main.ts Normal file
View File

@ -0,0 +1,17 @@
import 'bootstrap/dist/css/bootstrap.css';
import 'jquery'
import 'bootstrap'
import '../wwwroot/site.scss'
// @ts-ignore
import App from './App.svelte';
const app = new App({
target: document.body,
props: {
name: 'world'
}
});
export default app;

View File

@ -0,0 +1,13 @@
<svelte:head>
<title>Test Page!</title>
</svelte:head>
<script>
let number = 0;
</script>
<h3>Number: {number}</h3>
<br/>
<button class="btn-primary btn btn-lg" on:click="{()=>number+=1}">INCREMENT!</button>
<button class="btn-primary btn btn-lg" on:click="{()=>number-=1}">DECREMENT!</button>

View File

@ -0,0 +1,65 @@
<svelte:head>
<title>Test!</title>
</svelte:head>
<h1>Great success!</h1>
<figure>
<img alt="Borat" src="https://raw.githubusercontent.com/Kiho/aspcore-spa-cli/master/samples/SvelteCliSample/wwwroot/great-success.png">
<figcaption>HIGH FIVE!</figcaption>
</figure>
<ul>
<li><p><strong> Live reloading.</strong></p>
<p>Try editing this file (routes/index.html) to test</p>
<li>
<p>
<strong>sass/scss</strong>
</p>
<p>
Add `lang="sass/scss"` to a &lt;style&gt; tag to use SASS/SCSS (i.e "&lt;style lang='scss'&gt;")
</p>
</li>
</ul>
<style>
h1, figure, p, h3 {
text-align: center;
vertical-align: middle;
margin: 0 auto;
}
ul {
list-style: none;
}
h1 {
font-size: 2.8em;
text-transform: uppercase;
font-weight: 700;
margin: 0 0 0.5em 0;
}
figure {
margin: 0 0 1em 0;
}
img {
width: 100%;
max-width: 400px;
margin: 0 0 1em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>

View File

@ -0,0 +1,48 @@
<script>
import {Swipe, SwipeItem} from 'svelte-swipe'
import {ChevronLeftIcon, ChevronRightIcon} from 'svelte-feather-icons'
const swipeConfig = {
autoplay: false,
delay: 2000,
showIndicators: true,
transitionDuration: 1000,
defaultIndex: 0,
};
</script>
<div class="swipe-holder">
<Swipe>
<SwipeItem>
<div class="swipe-content">Slide 1</div>
</SwipeItem>
<SwipeItem>
<div class="swipe-content">Slide 2</div>
</SwipeItem>
<SwipeItem>
<div class="swipe-content">Slide 3</div>
</SwipeItem>
</Swipe>
</div>
<style>
.swipe-holder
{
max-width: max-content;
left:0;
display: block;
position: absolute;
height:100%;
width:100%;
background: blue;
}
.swipe-content
{
top:0;
bottom:0;
right:0;
background: red;
height:100%;
width:100%;
}
</style>

6
Web/tsconfig.json Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "@tsconfig/svelte/tsconfig.json",
"include": ["src/**/*"],
"exclude": ["node_modules/*", "__sapper__/*", "public/*", "bin/*", "wwwroot/*"],
}

21087
Web/wwwroot/build/bundle.css Normal file

File diff suppressed because one or more lines are too long

19814
Web/wwwroot/build/main.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

20991
Web/wwwroot/bundle.css Normal file

File diff suppressed because it is too large Load Diff

BIN
Web/wwwroot/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

2
Web/wwwroot/site.scss Normal file
View File

@ -0,0 +1,2 @@
@import "../node_modules/bootstrap/scss/bootstrap";

7348
Web/yarn.lock Normal file

File diff suppressed because it is too large Load Diff