-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
pr05 Typescript Migration #10: Setup Server TS Dependencies & migrate instance of server file #3636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
1b03597
97c4487
359c58c
85b9472
4a98bbb
cf33500
e12ad57
5210f5c
6b5ab98
9fb10e5
1757455
0663d24
38409a6
c69579d
914963a
a6adfec
b6a1f95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,6 @@ | |
| "lib": ["DOM", "ESNext"], | ||
| "jsx": "react", | ||
| }, | ||
| "include": ["./**/*"], | ||
| "exclude": ["../node_modules", "../server"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,5 +12,5 @@ | |
| "env": { | ||
| "NODE_ENV": "development" | ||
| }, | ||
| "ext": "js json" | ||
| "ext": "js ts json" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "extends": "../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "target": "ES2022", | ||
| "module": "commonjs", | ||
| "lib": ["ES2022"], | ||
| "types": ["node", "jest"], | ||
| }, | ||
| "include": ["./**/*"], | ||
| "exclude": ["../node_modules", "../client"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,10 @@ | |
| * @param {String} string | ||
| * @param {String} replacer (optional) character to replace invalid characters | ||
| */ | ||
| function generateFileSystemSafeName(string, replacer) { | ||
| export function generateFileSystemSafeName(string: string, replacer: string) { | ||
|
||
| // from here https://serverfault.com/a/242134 | ||
| const INVALID_CHARS_REGEX = /[*/?:\\<>|"\u0000-\u001F]/g; // eslint-disable-line | ||
| const slug = string.replace(INVALID_CHARS_REGEX, replacer || ''); | ||
|
|
||
| return slug; | ||
| } | ||
|
|
||
| export default generateFileSystemSafeName; | ||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,7 +1,9 @@ | ||||
| import { Request, Response } from 'express'; | ||||
| import get404Sketch from './404Page'; | ||||
|
|
||||
| export function renderIndex() { | ||||
| const assetsManifest = process.env.webpackAssets && JSON.parse(process.env.webpackAssets); | ||||
| const assetsManifest = | ||||
| process.env.webpackAssets && JSON.parse(process.env.webpackAssets); | ||||
| return ` | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
|
|
@@ -11,7 +13,11 @@ export function renderIndex() { | |||
| <meta name="keywords" content="p5.js, p5.js web editor, web editor, processing, code editor" /> | ||||
| <meta name="description" content="A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners." /> | ||||
| <title>p5.js Web Editor</title> | ||||
| ${process.env.NODE_ENV === 'production' ? `<link rel='stylesheet' href='${assetsManifest['/app.css']}' />` : ''} | ||||
| ${ | ||||
| process.env.NODE_ENV === 'production' | ||||
| ? `<link rel='stylesheet' href='${assetsManifest['/app.css']}' />` | ||||
| : '' | ||||
| } | ||||
| <link href='https://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'> | ||||
| <link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'> | ||||
| <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' / > | ||||
|
|
@@ -25,31 +31,54 @@ export function renderIndex() { | |||
| window.process.env.API_URL = '${process.env.API_URL}'; | ||||
| window.process.env.NODE_ENV = '${process.env.NODE_ENV}'; | ||||
| window.process.env.S3_BUCKET = '${process.env.S3_BUCKET}'; | ||||
| window.process.env.S3_BUCKET_URL_BASE = ${process.env.S3_BUCKET_URL_BASE ? `'${process.env.S3_BUCKET_URL_BASE}'` : undefined}; | ||||
| window.process.env.S3_BUCKET_URL_BASE = ${ | ||||
| process.env.S3_BUCKET_URL_BASE | ||||
| ? `'${process.env.S3_BUCKET_URL_BASE}'` | ||||
| : undefined | ||||
| }; | ||||
| window.process.env.AWS_REGION = '${process.env.AWS_REGION}'; | ||||
| window.process.env.FORCE_TO_HTTPS = ${process.env.FORCE_TO_HTTPS === 'false' ? false : undefined}; | ||||
| window.process.env.FORCE_TO_HTTPS = ${ | ||||
| process.env.FORCE_TO_HTTPS === 'false' ? false : undefined | ||||
| }; | ||||
| window.process.env.CLIENT = true; | ||||
| window.process.env.LOGIN_ENABLED = ${process.env.LOGIN_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.EXAMPLES_ENABLED = ${process.env.EXAMPLES_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.UI_ACCESS_TOKEN_ENABLED = ${process.env.UI_ACCESS_TOKEN_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.UI_COLLECTIONS_ENABLED = ${process.env.UI_COLLECTIONS_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.UPLOAD_LIMIT = ${process.env.UPLOAD_LIMIT ? `${process.env.UPLOAD_LIMIT}` : undefined}; | ||||
| window.process.env.TRANSLATIONS_ENABLED = ${process.env.TRANSLATIONS_ENABLED === 'true' ? true : false}; | ||||
| window.process.env.LOGIN_ENABLED = ${ | ||||
| process.env.LOGIN_ENABLED !== 'false' | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no big deal either way but would you want to use the helper utils you wrote for this case & the ones below?
the only thing is you'd have to move the utility file into common/ |
||||
| }; | ||||
| window.process.env.EXAMPLES_ENABLED = ${ | ||||
| process.env.EXAMPLES_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.UI_ACCESS_TOKEN_ENABLED = ${ | ||||
| process.env.UI_ACCESS_TOKEN_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.UI_COLLECTIONS_ENABLED = ${ | ||||
| process.env.UI_COLLECTIONS_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.UPLOAD_LIMIT = ${ | ||||
| process.env.UPLOAD_LIMIT ? `${process.env.UPLOAD_LIMIT}` : undefined | ||||
| }; | ||||
| window.process.env.TRANSLATIONS_ENABLED = ${ | ||||
| process.env.TRANSLATIONS_ENABLED === 'true' | ||||
| }; | ||||
| window.process.env.PREVIEW_URL = '${process.env.PREVIEW_URL}'; | ||||
| window.process.env.GA_MEASUREMENT_ID='${process.env.GA_MEASUREMENT_ID}'; | ||||
| </script> | ||||
| </head> | ||||
| <body> | ||||
| <div id="root" class="root-app"> | ||||
| </div> | ||||
| <script src='${process.env.NODE_ENV === 'production' ? `${assetsManifest['/app.js']}` : '/app.js'}'></script> | ||||
| <script src='${ | ||||
| process.env.NODE_ENV === 'production' | ||||
| ? `${assetsManifest['/app.js']}` | ||||
| : '/app.js' | ||||
| }'></script> | ||||
| </body> | ||||
| </html> | ||||
| `; | ||||
| } | ||||
|
|
||||
| export function renderProjectIndex(username, projectName) { | ||||
| const assetsManifest = process.env.webpackAssets && JSON.parse(process.env.webpackAssets); | ||||
| export function renderProjectIndex(username: string, projectName: string) { | ||||
| const assetsManifest = | ||||
| process.env.webpackAssets && JSON.parse(process.env.webpackAssets); | ||||
| return ` | ||||
| <!DOCTYPE html> | ||||
| <html lang="en"> | ||||
|
|
@@ -59,7 +88,11 @@ export function renderProjectIndex(username, projectName) { | |||
| <meta name="keywords" content="p5.js, p5.js web editor, web editor, processing, code editor" /> | ||||
| <meta name="description" content="A web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners." /> | ||||
| <title>${`${projectName} by ${username} -`}p5.js Web Editor</title> | ||||
| ${process.env.NODE_ENV === 'production' ? `<link rel='stylesheet' href='${assetsManifest['/app.css']}' />` : ''} | ||||
| ${ | ||||
| process.env.NODE_ENV === 'production' | ||||
| ? `<link rel='stylesheet' href='${assetsManifest['/app.css']}' />` | ||||
| : '' | ||||
| } | ||||
| <link href='https://fonts.googleapis.com/css?family=Inconsolata' rel='stylesheet' type='text/css'> | ||||
| <link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'> | ||||
| <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' / > | ||||
|
|
@@ -73,24 +106,46 @@ export function renderProjectIndex(username, projectName) { | |||
| window.process.env.API_URL = '${process.env.API_URL}'; | ||||
| window.process.env.NODE_ENV = '${process.env.NODE_ENV}'; | ||||
| window.process.env.S3_BUCKET = '${process.env.S3_BUCKET}'; | ||||
| window.process.env.S3_BUCKET_URL_BASE = ${process.env.S3_BUCKET_URL_BASE ? `'${process.env.S3_BUCKET_URL_BASE}'` : undefined}; | ||||
| window.process.env.S3_BUCKET_URL_BASE = ${ | ||||
| process.env.S3_BUCKET_URL_BASE | ||||
| ? `'${process.env.S3_BUCKET_URL_BASE}'` | ||||
| : undefined | ||||
| }; | ||||
| window.process.env.AWS_REGION = '${process.env.AWS_REGION}'; | ||||
| window.process.env.FORCE_TO_HTTPS = ${process.env.FORCE_TO_HTTPS === 'false' ? false : undefined}; | ||||
| window.process.env.FORCE_TO_HTTPS = ${ | ||||
| process.env.FORCE_TO_HTTPS === 'false' ? false : undefined | ||||
| }; | ||||
| window.process.env.CLIENT = true; | ||||
| window.process.env.LOGIN_ENABLED = ${process.env.LOGIN_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.EXAMPLES_ENABLED = ${process.env.EXAMPLES_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.UI_ACCESS_TOKEN_ENABLED = ${process.env.UI_ACCESS_TOKEN_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.UI_COLLECTIONS_ENABLED = ${process.env.UI_COLLECTIONS_ENABLED === 'false' ? false : true}; | ||||
| window.process.env.UPLOAD_LIMIT = ${process.env.UPLOAD_LIMIT ? `${process.env.UPLOAD_LIMIT}` : undefined}; | ||||
| window.process.env.TRANSLATIONS_ENABLED = ${process.env.TRANSLATIONS_ENABLED === 'true' ? true : false}; | ||||
| window.process.env.LOGIN_ENABLED = ${ | ||||
| process.env.LOGIN_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.EXAMPLES_ENABLED = ${ | ||||
| process.env.EXAMPLES_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.UI_ACCESS_TOKEN_ENABLED = ${ | ||||
| process.env.UI_ACCESS_TOKEN_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.UI_COLLECTIONS_ENABLED = ${ | ||||
| process.env.UI_COLLECTIONS_ENABLED !== 'false' | ||||
| }; | ||||
| window.process.env.UPLOAD_LIMIT = ${ | ||||
| process.env.UPLOAD_LIMIT ? `${process.env.UPLOAD_LIMIT}` : undefined | ||||
| }; | ||||
| window.process.env.TRANSLATIONS_ENABLED = ${ | ||||
| process.env.TRANSLATIONS_ENABLED === 'true' | ||||
| }; | ||||
| window.process.env.PREVIEW_URL = '${process.env.PREVIEW_URL}'; | ||||
| window.process.env.GA_MEASUREMENT_ID='${process.env.GA_MEASUREMENT_ID}'; | ||||
| </script> | ||||
| </head> | ||||
| <body> | ||||
| <div id="root" class="root-app"> | ||||
| </div> | ||||
| <script src='${process.env.NODE_ENV === 'production' ? `${assetsManifest['/app.js']}` : '/app.js'}'></script> | ||||
| <script src='${ | ||||
| process.env.NODE_ENV === 'production' | ||||
| ? `${assetsManifest['/app.js']}` | ||||
| : '/app.js' | ||||
| }'></script> | ||||
| </body> | ||||
| </html> | ||||
| `; | ||||
|
|
@@ -102,12 +157,12 @@ export function renderProjectIndex(username, projectName) { | |||
| * @param {import('express').e.Response} res | ||||
| * @param {boolean} [exists] | ||||
| */ | ||||
| export default async function sendHtml(req, res, exists = true) { | ||||
| export async function sendHtml(req: Request, res: Response, exists = true) { | ||||
| if (!exists) { | ||||
| res.status(404); | ||||
| const html = await get404Sketch(); | ||||
| res.send(html); | ||||
| } else { | ||||
| res.send(renderIndex()); | ||||
| } | ||||
| }; | ||||
| } | ||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "files": [], | ||
| "references": [ | ||
| { "path": "client" }, | ||
| // { "path": "server" } | ||
| { "path": "./client" }, | ||
| { "path": "./server" } | ||
| ], | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to be changed at all, but just wanted to add a super small style note that the repo’s convention is to skip trailing commas!