migrate to sveltekit and mdsvex
continuous-integration/drone the build failed
Details
@ -1,6 +1,5 @@
|
||||
.DS_Store
|
||||
/node_modules/
|
||||
/src/node_modules/@sapper/
|
||||
yarn-error.log
|
||||
/__sapper__/
|
||||
functions/render/build
|
||||
.yarn
|
||||
.svelte-kit
|
@ -1,7 +0,0 @@
|
||||
"use strict";
|
||||
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
||||
process.env.PORT = process.env.PORT || 3000;
|
||||
|
||||
const serverless = require("serverless-http");
|
||||
const server = require("./build/server/server");
|
||||
module.exports.handler = serverless(server);
|
@ -0,0 +1,12 @@
|
||||
const config = {
|
||||
"extensions": [".svelte.md", ".md", ".svx"],
|
||||
|
||||
"smartypants": {
|
||||
"dashes": "oldschool"
|
||||
},
|
||||
|
||||
"remarkPlugins": [],
|
||||
"rehypePlugins": []
|
||||
};
|
||||
|
||||
export default config;
|
@ -1,4 +1,4 @@
|
||||
[build]
|
||||
command = "yarn build-netlify"
|
||||
publish = "__sapper__/build"
|
||||
publish = "build"
|
||||
functions = "functions"
|
||||
|
@ -1,40 +1,23 @@
|
||||
{
|
||||
"name": "bigdumb-gq",
|
||||
"description": "AAGaming's website",
|
||||
"license": "MIT",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "sapper dev",
|
||||
"build": "sapper build --legacy",
|
||||
"build-netlify": "node scripts/buildNetlify",
|
||||
"export": "sapper export --legacy",
|
||||
"start": "node __sapper__/build"
|
||||
},
|
||||
"dependencies": {
|
||||
"compression": "^1.7.1",
|
||||
"encoding": "^0.1.13",
|
||||
"polka": "next",
|
||||
"serverless-http": "^2.7.0",
|
||||
"sirv": "^1.0.0",
|
||||
"svelte-media": "^0.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
|
||||
"@babel/plugin-transform-runtime": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"@babel/runtime": "^7.0.0",
|
||||
"@jackfranklin/rollup-plugin-markdown": "^0.3.0",
|
||||
"@rollup/plugin-babel": "^5.0.0",
|
||||
"@rollup/plugin-commonjs": "^14.0.0",
|
||||
"@rollup/plugin-node-resolve": "^8.0.0",
|
||||
"@rollup/plugin-replace": "^2.4.0",
|
||||
"@rollup/plugin-url": "^5.0.0",
|
||||
"rollup": "^2.3.4",
|
||||
"rollup-plugin-glob": "^1.0.2",
|
||||
"rollup-plugin-svelte": "^7.0.0",
|
||||
"rollup-plugin-terser": "^7.0.0",
|
||||
"sapper": "^0.28.0",
|
||||
"svelte": "^3.17.3"
|
||||
}
|
||||
}
|
||||
"name": "bigdumb-gq",
|
||||
"description": "AAGaming's website",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "svelte-kit dev",
|
||||
"build": "svelte-kit build",
|
||||
"build-netlify": "svelte-kit build",
|
||||
"start": "node build"
|
||||
},
|
||||
"dependencies": {
|
||||
"svelte-media": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-netlify": "next",
|
||||
"@sveltejs/kit": "next",
|
||||
"svelte": "^3.38.3",
|
||||
"svelte-preprocess": "^4.7.4",
|
||||
"mdsvex": "^0.9.7"
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
import path from 'path';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import replace from '@rollup/plugin-replace';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import url from '@rollup/plugin-url';
|
||||
import svelte from 'rollup-plugin-svelte';
|
||||
import babel from '@rollup/plugin-babel';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import markdown from '@jackfranklin/rollup-plugin-markdown';
|
||||
import glob from 'rollup-plugin-glob';
|
||||
import config from 'sapper/config/rollup.js';
|
||||
import pkg from './package.json';
|
||||
|
||||
const mode = process.env.NODE_ENV;
|
||||
const dev = mode === 'development';
|
||||
const legacy = !!process.env.SAPPER_LEGACY_BUILD;
|
||||
|
||||
const onwarn = (warning, onwarn) =>
|
||||
(warning.code === 'MISSING_EXPORT' && /'preload'/.test(warning.message)) ||
|
||||
(warning.code === 'CIRCULAR_DEPENDENCY' && /[/\\]@sapper[/\\]/.test(warning.message)) ||
|
||||
onwarn(warning);
|
||||
|
||||
export default {
|
||||
client: {
|
||||
input: config.client.input(),
|
||||
output: config.client.output(),
|
||||
plugins: [
|
||||
markdown(),
|
||||
glob(),
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
values:{
|
||||
'process.browser': true,
|
||||
'process.env.NODE_ENV': JSON.stringify(mode)
|
||||
},
|
||||
}),
|
||||
svelte({
|
||||
compilerOptions: {
|
||||
dev,
|
||||
hydratable: true
|
||||
}
|
||||
}),
|
||||
url({
|
||||
sourceDir: path.resolve(__dirname, 'src/node_modules/images'),
|
||||
publicPath: '/client/'
|
||||
}),
|
||||
resolve({
|
||||
browser: true,
|
||||
dedupe: ['svelte']
|
||||
}),
|
||||
commonjs(),
|
||||
|
||||
legacy && babel({
|
||||
extensions: ['.js', '.mjs', '.html', '.svelte'],
|
||||
babelHelpers: 'runtime',
|
||||
exclude: ['node_modules/@babel/**'],
|
||||
presets: [
|
||||
['@babel/preset-env', {
|
||||
targets: '> 0.25%, not dead'
|
||||
}]
|
||||
],
|
||||
plugins: [
|
||||
'@babel/plugin-syntax-dynamic-import',
|
||||
['@babel/plugin-transform-runtime', {
|
||||
useESModules: true
|
||||
}]
|
||||
]
|
||||
}),
|
||||
|
||||
!dev && terser({
|
||||
module: true
|
||||
})
|
||||
],
|
||||
|
||||
preserveEntrySignatures: false,
|
||||
onwarn,
|
||||
},
|
||||
|
||||
server: {
|
||||
input: config.server.input(),
|
||||
output: config.server.output(),
|
||||
plugins: [
|
||||
markdown(),
|
||||
glob(),
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
values:{
|
||||
'process.browser': false,
|
||||
'process.env.NODE_ENV': JSON.stringify(mode)
|
||||
},
|
||||
}),
|
||||
svelte({
|
||||
compilerOptions: {
|
||||
dev,
|
||||
generate: 'ssr',
|
||||
hydratable: true
|
||||
},
|
||||
emitCss: false
|
||||
}),
|
||||
url({
|
||||
sourceDir: path.resolve(__dirname, 'src/node_modules/images'),
|
||||
publicPath: '/client/',
|
||||
emitFiles: false // already emitted by client build
|
||||
}),
|
||||
resolve({
|
||||
dedupe: ['svelte']
|
||||
}),
|
||||
commonjs()
|
||||
],
|
||||
external: Object.keys(pkg.dependencies).concat(require('module').builtinModules),
|
||||
preserveEntrySignatures: 'strict',
|
||||
onwarn,
|
||||
},
|
||||
|
||||
serviceworker: {
|
||||
input: config.serviceworker.input(),
|
||||
output: config.serviceworker.output(),
|
||||
plugins: [
|
||||
resolve(),
|
||||
replace({
|
||||
preventAssignment: true,
|
||||
values:{
|
||||
'process.browser': true,
|
||||
'process.env.NODE_ENV': JSON.stringify(mode)
|
||||
},
|
||||
}),
|
||||
commonjs(),
|
||||
!dev && terser()
|
||||
],
|
||||
preserveEntrySignatures: false,
|
||||
onwarn,
|
||||
}
|
||||
};
|
@ -1,66 +0,0 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const child_process = require("child_process");
|
||||
|
||||
const buildPath = path.join(__dirname, "/../__sapper__/build");
|
||||
const functionsBuildPath = path.join(__dirname, "/../functions/render/build");
|
||||
const staticPath = path.join(__dirname, "/../static/");
|
||||
|
||||
run();
|
||||
|
||||
async function run() {
|
||||
// Delete previous function build
|
||||
await exec(`rm -rf ${functionsBuildPath}`);
|
||||
|
||||
// Build the sapper project
|
||||
await exec(`yarn build`);
|
||||
|
||||
// Copy build to function
|
||||
await exec(`rsync -av ${buildPath}/ ${functionsBuildPath} --exclude client`);
|
||||
|
||||
// Copy static files to project build
|
||||
await exec(`cp -a ${staticPath}/. ${buildPath}`);
|
||||
|
||||
// Add _redirects file to build folder (publish folder)
|
||||
addRedirectsFile();
|
||||
|
||||
// Fix the path in the function server.js file to work with the project structure
|
||||
fixBuildDirPathInServerFile();
|
||||
}
|
||||
|
||||
function addRedirectsFile() {
|
||||
const _redirectsPath = path.join(buildPath, "_redirects");
|
||||
fs.writeFileSync(_redirectsPath, "/* /.netlify/functions/render 200", {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
}
|
||||
|
||||
function fixBuildDirPathInServerFile() {
|
||||
const server = path.join(functionsBuildPath, "server/server.js");
|
||||
|
||||
fs.readFile(server, "utf8", function (err, data) {
|
||||
if (err) return console.log(err);
|
||||
|
||||
const result = data.replace(
|
||||
`"__sapper__/build"`,
|
||||
`path.join(__dirname + "/..")`
|
||||
).replace(/\${protocol}:\/\/127\.0\.0\.1:\${process\.env\.PORT}/g, `http://127.0.0.1:80`);
|
||||
|
||||
fs.writeFile(server, result, "utf8", function (err) {
|
||||
if (err) return console.log(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function exec(command) {
|
||||
return new Promise((fulfil, reject) => {
|
||||
child_process.exec(command, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
fulfil({ stdout, stderr });
|
||||
});
|
||||
});
|
||||
}
|
@ -1,304 +0,0 @@
|
||||
/**
|
||||
* Run this script to convert the project to TypeScript. This is only guaranteed to work
|
||||
* on the unmodified default template; if you have done code changes you are likely need
|
||||
* to touch up the generated project manually.
|
||||
*/
|
||||
|
||||
// @ts-check
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { argv } = require('process');
|
||||
|
||||
const projectRoot = argv[2] || path.join(__dirname, '..');
|
||||
|
||||
const isRollup = fs.existsSync(path.join(projectRoot, "rollup.config.js"));
|
||||
|
||||
function warn(message) {
|
||||
console.warn('Warning: ' + message);
|
||||
}
|
||||
|
||||
function replaceInFile(fileName, replacements) {
|
||||
if (fs.existsSync(fileName)) {
|
||||
let contents = fs.readFileSync(fileName, 'utf8');
|
||||
let hadUpdates = false;
|
||||
|
||||
replacements.forEach(([from, to]) => {
|
||||
const newContents = contents.replace(from, to);
|
||||
|
||||
const isAlreadyApplied = typeof to !== 'string' || contents.includes(to);
|
||||
|
||||
if (newContents !== contents) {
|
||||
contents = newContents;
|
||||
hadUpdates = true;
|
||||
} else if (!isAlreadyApplied) {
|
||||
warn(`Wanted to update "${from}" in ${fileName}, but did not find it.`);
|
||||
}
|
||||
});
|
||||
|
||||
if (hadUpdates) {
|
||||
fs.writeFileSync(fileName, contents);
|
||||
} else {
|
||||
console.log(`${fileName} had already been updated.`);
|
||||
}
|
||||
} else {
|
||||
warn(`Wanted to update ${fileName} but the file did not exist.`);
|
||||
}
|
||||
}
|
||||
|
||||
function createFile(fileName, contents) {
|
||||
if (fs.existsSync(fileName)) {
|
||||
warn(`Wanted to create ${fileName}, but it already existed. Leaving existing file.`);
|
||||
} else {
|
||||
fs.writeFileSync(fileName, contents);
|
||||
}
|
||||
}
|
||||
|
||||
function addDepsToPackageJson() {
|
||||
const pkgJSONPath = path.join(projectRoot, 'package.json');
|
||||
const packageJSON = JSON.parse(fs.readFileSync(pkgJSONPath, 'utf8'));
|
||||
packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, {
|
||||
...(isRollup ? { '@rollup/plugin-typescript': '^6.0.0' } : { 'ts-loader': '^8.0.4' }),
|
||||
'@tsconfig/svelte': '^1.0.10',
|
||||
'@types/compression': '^1.7.0',
|
||||
'@types/node': '^14.11.1',
|
||||
'@types/polka': '^0.5.1',
|
||||
'svelte-check': '^1.0.46',
|
||||
'svelte-preprocess': '^4.3.0',
|
||||
tslib: '^2.0.1',
|
||||
typescript: '^4.0.3'
|
||||
});
|
||||
|
||||
// Add script for checking
|
||||
packageJSON.scripts = Object.assign(packageJSON.scripts, {
|
||||
validate: 'svelte-check --ignore src/node_modules/@sapper'
|
||||
});
|
||||
|
||||
// Write the package JSON
|
||||
fs.writeFileSync(pkgJSONPath, JSON.stringify(packageJSON, null, ' '));
|
||||
}
|
||||
|
||||
function changeJsExtensionToTs(dir) {
|
||||
const elements = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
if (elements[i].isDirectory()) {
|
||||
changeJsExtensionToTs(path.join(dir, elements[i].name));
|
||||
} else if (elements[i].name.match(/^[^_]((?!json).)*js$/)) {
|
||||
fs.renameSync(path.join(dir, elements[i].name), path.join(dir, elements[i].name).replace('.js', '.ts'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateSingleSvelteFile({ view, vars, contextModule }) {
|
||||
replaceInFile(path.join(projectRoot, 'src', `${view}.svelte`), [
|
||||
[/(?:<script)(( .*?)*?)>/gm, (m, attrs) => `<script${attrs}${!attrs.includes('lang="ts"') ? ' lang="ts"' : ''}>`],
|
||||
...(vars ? vars.map(({ name, type }) => [`export let ${name};`, `export let ${name}: ${type};`]) : []),
|
||||
...(contextModule ? contextModule.map(({ js, ts }) => [js, ts]) : [])
|
||||
]);
|
||||
}
|
||||
|
||||
// Switch the *.svelte file to use TS
|
||||
function updateSvelteFiles() {
|
||||
[
|
||||
{
|
||||
view: 'components/Nav',
|
||||
vars: [{ name: 'segment', type: 'string' }]
|
||||
},
|
||||
{
|
||||
view: 'routes/_layout',
|
||||
vars: [{ name: 'segment', type: 'string' }]
|
||||
},
|
||||
{
|
||||
view: 'routes/_error',
|
||||
vars: [
|
||||
{ name: 'status', type: 'number' },
|
||||
{ name: 'error', type: 'Error' }
|
||||
]
|
||||
},
|
||||
{
|
||||
view: 'routes/blog/index',
|
||||
vars: [{ name: 'posts', type: '{ slug: string; title: string, html: any }[]' }],
|
||||
contextModule: [
|
||||
{
|
||||
js: '.then(r => r.json())',
|
||||
ts: '.then((r: { json: () => any; }) => r.json())'
|
||||
},
|
||||
{
|
||||
js: '.then(posts => {',
|
||||
ts: '.then((posts: { slug: string; title: string, html: any }[]) => {'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
view: 'routes/blog/[slug]',
|
||||
vars: [{ name: 'post', type: '{ slug: string; title: string, html: any }' }]
|
||||
}
|
||||
].forEach(updateSingleSvelteFile);
|
||||
}
|
||||
|
||||
function updateRollupConfig() {
|
||||
// Edit rollup config
|
||||
replaceInFile(path.join(projectRoot, 'rollup.config.js'), [
|
||||
// Edit imports
|
||||
[
|
||||
/'rollup-plugin-terser';\n(?!import sveltePreprocess)/,
|
||||
`'rollup-plugin-terser';
|
||||
import sveltePreprocess from 'svelte-preprocess';
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
`
|
||||
],
|
||||
// Edit inputs
|
||||
[
|
||||
/(?<!THIS_IS_UNDEFINED[^\n]*\n\s*)onwarn\(warning\);/,
|
||||
`(warning.code === 'THIS_IS_UNDEFINED') ||\n\tonwarn(warning);`
|
||||
],
|
||||
[/input: config.client.input\(\)(?!\.replace)/, `input: config.client.input().replace(/\\.js$/, '.ts')`],
|
||||
[
|
||||
/input: config.server.input\(\)(?!\.replace)/,
|
||||
`input: { server: config.server.input().server.replace(/\\.js$/, ".ts") }`
|
||||
],
|
||||
[
|
||||
/input: config.serviceworker.input\(\)(?!\.replace)/,
|
||||
`input: config.serviceworker.input().replace(/\\.js$/, '.ts')`
|
||||
],
|
||||
// Add preprocess
|
||||
[/compilerOptions/g, 'preprocess: sveltePreprocess({ sourceMap: dev }),\n\t\t\t\tcompilerOptions'],
|
||||
// Add TypeScript
|
||||
[/commonjs\(\)(?!,\n\s*typescript)/g, 'commonjs(),\n\t\t\ttypescript({ sourceMap: dev })']
|
||||
]);
|
||||
}
|
||||
|
||||
function updateWebpackConfig() {
|
||||
// Edit webpack config
|
||||
replaceInFile(path.join(projectRoot, 'webpack.config.js'), [
|
||||
// Edit imports
|
||||
[
|
||||
/require\('webpack-modules'\);\n(?!const sveltePreprocess)/,
|
||||
`require('webpack-modules');\nconst sveltePreprocess = require('svelte-preprocess');\n`
|
||||
],
|
||||
// Edit extensions
|
||||
[
|
||||
/\['\.mjs', '\.js', '\.json', '\.svelte', '\.html'\]/,
|
||||
`['.mjs', '.js', '.ts', '.json', '.svelte', '.html']`
|
||||
],
|
||||
// Edit entries
|
||||
[
|
||||
/entry: config\.client\.entry\(\)/,
|
||||
`entry: { main: config.client.entry().main.replace(/\\.js$/, '.ts') }`
|
||||
],
|
||||
[
|
||||
/entry: config\.server\.entry\(\)/,
|
||||
`entry: { server: config.server.entry().server.replace(/\\.js$/, '.ts') }`
|
||||
],
|
||||
[
|
||||
/entry: config\.serviceworker\.entry\(\)/,
|
||||
`entry: { 'service-worker': config.serviceworker.entry()['service-worker'].replace(/\\.js$/, '.ts') }`
|
||||
],
|
||||
[
|
||||
/loader: 'svelte-loader',\n\t\t\t\t\t\toptions: {/g,
|
||||
'loader: \'svelte-loader\',\n\t\t\t\t\t\toptions: {\n\t\t\t\t\t\t\tpreprocess: sveltePreprocess({ sourceMap: dev }),'
|
||||
],
|
||||
// Add TypeScript rules for client and server
|
||||
[
|
||||
/module: {\n\s*rules: \[\n\s*(?!{\n\s*test: \/\\\.ts\$\/)/g,
|
||||
`module: {\n\t\t\trules: [\n\t\t\t\t{\n\t\t\t\t\ttest: /\\.ts$/,\n\t\t\t\t\tloader: 'ts-loader'\n\t\t\t\t},\n\t\t\t\t`
|
||||
],
|
||||
// Add TypeScript rules for serviceworker
|
||||
[
|
||||
/output: config\.serviceworker\.output\(\),\n\s*(?!module)/,
|
||||
`output: config.serviceworker.output(),\n\t\tmodule: {\n\t\t\trules: [\n\t\t\t\t{\n\t\t\t\t\ttest: /\\.ts$/,\n\t\t\t\t\tloader: 'ts-loader'\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\t`
|
||||
],
|
||||
// Edit outputs
|
||||
[
|
||||
/output: config\.serviceworker\.output\(\),\n\s*(?!resolve)/,
|
||||
`output: config.serviceworker.output(),\n\t\tresolve: { extensions: ['.mjs', '.js', '.ts', '.json'] },\n\t\t`
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
function updateServiceWorker() {
|
||||
replaceInFile(path.join(projectRoot, 'src', 'service-worker.ts'), [
|
||||
[`shell.concat(files);`, `(shell as string[]).concat(files as string[]);`],
|
||||
[`self.skipWaiting();`, `((self as any) as ServiceWorkerGlobalScope).skipWaiting();`],
|
||||
[`self.clients.claim();`, `((self as any) as ServiceWorkerGlobalScope).clients.claim();`],
|
||||
[`fetchAndCache(request)`, `fetchAndCache(request: Request)`],
|
||||
[`self.addEventListener('activate', event =>`, `self.addEventListener('activate', (event: ExtendableEvent) =>`],
|
||||
[`self.addEventListener('install', event =>`, `self.addEventListener('install', (event: ExtendableEvent) =>`],
|
||||
[`addEventListener('fetch', event =>`, `addEventListener('fetch', (event: FetchEvent) =>`],
|
||||
]);
|
||||
}
|
||||
|
||||
function createTsConfig() {
|
||||
const tsconfig = `{
|
||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"lib": ["DOM", "ES2017", "WebWorker"]
|
||||
},
|
||||
"include": ["src/**/*", "src/node_modules/**/*"],
|
||||
"exclude": ["node_modules/*", "__sapper__/*", "static/*"]
|
||||
}`;
|
||||
|
||||
createFile(path.join(projectRoot, 'tsconfig.json'), tsconfig);
|
||||
}
|
||||
|
||||
// Adds the extension recommendation
|
||||
function configureVsCode() {
|
||||
const dir = path.join(projectRoot, '.vscode');
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
|
||||
createFile(path.join(projectRoot, '.vscode', 'extensions.json'), `{"recommendations": ["svelte.svelte-vscode"]}`);
|
||||
}
|
||||
|
||||
function deleteThisScript() {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Adding TypeScript with ${isRollup ? "Rollup" : "webpack" }...`);
|
||||
|
||||
addDepsToPackageJson();
|
||||
|
||||
changeJsExtensionToTs(path.join(projectRoot, 'src'));
|
||||
|
||||
updateSvelteFiles();
|
||||
|
||||
if (isRollup) {
|
||||
updateRollupConfig();
|
||||
} else {
|
||||
updateWebpackConfig();
|
||||
}
|
||||
|
||||
updateServiceWorker();
|
||||
|
||||
createTsConfig();
|
||||
|
||||
configureVsCode();
|
||||
|
||||
// Delete this script, but not during testing
|
||||
if (!argv[2]) {
|
||||
deleteThisScript();
|
||||
}
|
||||
|
||||
console.log('Converted to TypeScript.');
|
||||
|
||||
if (fs.existsSync(path.join(projectRoot, 'node_modules'))) {
|
||||
console.log(`
|
||||
Next:
|
||||
1. run 'npm install' again to install TypeScript dependencies
|
||||
2. run 'npm run build' for the @sapper imports in your project to work
|
||||
`);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
import {start} from '@sapper/app';
|
||||
|
||||
start({
|
||||
target: document.querySelector('#sapper')
|
||||
});
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 378 KiB After Width: | Height: | Size: 378 KiB |
After Width: | Height: | Size: 2.2 KiB |
Before Width: | Height: | Size: 839 B After Width: | Height: | Size: 839 B |
Before Width: | Height: | Size: 956 B After Width: | Height: | Size: 956 B |
Before Width: | Height: | Size: 814 B |
@ -1,3 +1,15 @@
|
||||
<script context="module">
|
||||
/**
|
||||
* @type {import('@sveltejs/kit').Load}
|
||||
*/
|
||||
export function load({ page: { path } }) {
|
||||
return {
|
||||
props: {
|
||||
segment: path
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
import Nav from '../components/Nav.svelte';
|
||||
import PageTransitions from '../components/PageTransitions.svelte';
|
@ -1,25 +1,29 @@
|
||||
import {findPost} from './_posts.js';
|
||||
|
||||
export function get(req, res, next) {
|
||||
export async function get({params}) {
|
||||
// the `permalink` parameter is available because
|
||||
// this file is called [permalink].json.js
|
||||
const { permalink } = req.params;
|
||||
const { permalink } = params;
|
||||
|
||||
const post = findPost(permalink);
|
||||
const post = await findPost(permalink);
|
||||
|
||||
if (post) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(post));
|
||||
return {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
status: 200,
|
||||
body: post
|
||||
}
|
||||
} else {
|
||||
res.writeHead(404, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify({
|
||||
message: `Not found`
|
||||
}));
|
||||
return {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
status: 404,
|
||||
body: {
|
||||
message: "Not Found"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,17 @@
|
||||
import posts from './_posts.js';
|
||||
import {getPosts} from './_posts.js';
|
||||
|
||||
const contents = JSON.stringify(posts.map(post => {
|
||||
export async function get() {
|
||||
const posts = (await getPosts()).map(post => {
|
||||
return {
|
||||
title: post.title,
|
||||
permalink: post.permalink
|
||||
};
|
||||
})
|
||||
return {
|
||||
title: post.title,
|
||||
permalink: post.permalink
|
||||
};
|
||||
}));
|
||||
|
||||
export function get(req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(contents);
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: posts
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import sirv from "sirv";
|
||||
import polka from "polka";
|
||||
import compression from "compression";
|
||||
import * as sapper from "@sapper/server";
|
||||
|
||||
const { PORT, NODE_ENV } = process.env;
|
||||
const dev = NODE_ENV === "development";
|
||||
|
||||
const server = polka(); // You can also use Express
|
||||
|
||||
server.use(compression({ threshold: 0 }));
|
||||
|
||||
if (dev) server.use(sirv("static", { dev }));
|
||||
|
||||
server.use(sapper.middleware());
|
||||
|
||||
if (dev)
|
||||
server.listen(PORT, (err) => {
|
||||
if (err) console.log("error", err);
|
||||
});
|
||||
|
||||
module.exports = server;
|
@ -0,0 +1,70 @@
|
||||
|
||||
import { mdsvex } from "mdsvex";
|
||||
import mdsvexConfig from "./mdsvex.config.js";
|
||||
// import preprocessor from 'svelte-preprocess';
|
||||
import netlify from '@sveltejs/adapter-netlify';
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
"extensions": [".svelte", ...mdsvexConfig.extensions],
|
||||
|
||||
// options passed to svelte.compile (https://svelte.dev/docs#svelte_compile)
|
||||
compilerOptions: null,
|
||||
|
||||
// an array of file extensions that should be treated as Svelte components
|
||||
extensions: ['.svelte', '.svx', '.md'],
|
||||
|
||||
kit: {
|
||||
adapter: netlify(),
|
||||
amp: false,
|
||||
appDir: '_app',
|
||||
files: {
|
||||
assets: 'static',
|
||||
hooks: 'src/hooks',
|
||||
lib: 'src/lib',
|
||||
routes: 'src/routes',
|
||||
serviceWorker: 'src/service-worker.js',
|
||||
template: 'src/template.html'
|
||||
},
|
||||
floc: false,
|
||||
//host: null,
|
||||
//hostHeader: null,
|
||||
hydrate: true,
|
||||
package: {
|
||||
dir: 'package',
|
||||
emitTypes: true,
|
||||
exports: {
|
||||
include: ['**'],
|
||||
exclude: ['_*', '**/_*']
|
||||
},
|
||||
files: {
|
||||
include: ['**'],
|
||||
exclude: []
|
||||
}
|
||||
},
|
||||
paths: {
|
||||
assets: '',
|
||||
base: ''
|
||||
},
|
||||
prerender: {
|
||||
crawl: true,
|
||||
enabled: true,
|
||||
force: false,
|
||||
pages: ['*']
|
||||
},
|
||||
router: true,
|
||||
serviceWorker: {
|
||||
exclude: []
|
||||
},
|
||||
ssr: true,
|
||||
target: "#svelte",
|
||||
trailingSlash: 'never',
|
||||
vite: () => ({polyfillDynamicImport: false})
|
||||
},
|
||||
|
||||
// options passed to svelte.preprocess (https://svelte.dev/docs#svelte_preprocess)
|
||||
// preprocessConfig: () => preprocessor(),
|
||||
|
||||
preprocess: mdsvex(mdsvexConfig)
|
||||
};
|
||||
|
||||
export default config;
|