Skip to content

Commit

Permalink
set up to support TypeScript, convert one file, see #311
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Dec 16, 2024
1 parent 863507b commit 492b208
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
"scripts"
],
"scripts": {
"lint": "grunt --gruntfile Gruntfile.cjs lint",
"start-node": "bash ../perennial/bin/sage run src/server/app.js",
"dev-node": "nodemon --exec \"bash ../perennial/bin/sage run src/server/app.js",
"debug": "npm run make-public-config && npm run build --workspace=client && bash ../perennial/bin/sage run --inspect src/server/app.js",
"lint": "grunt lint",
"type-check": "grunt type-check",
"start-node": "bash ../perennial/bin/sage run src/server/app.ts",
"dev-node": "nodemon --exec \"bash ../perennial/bin/sage run src/server/app.ts",
"debug": "npm run make-public-config && npm run build --workspace=client && bash ../perennial/bin/sage run --inspect src/server/app.ts",
"make-public-config": "bash ../perennial/bin/sage run ./scripts/js/make-public-config-file.mjs",
"dev": "npm run make-public-config && npm run lint && concurrently \"npm run dev --workspace=client\" \"npm run dev-node\"",
"start": "npm run make-public-config && npm run lint && npm run build --workspace=client && npm run start-node",
"dev": "npm run make-public-config && npm run lint && npm run type-check && concurrently \"npm run dev --workspace=client\" \"npm run dev-node\"",
"start": "npm run make-public-config && npm run lint && npm run type-check && npm run build --workspace=client && npm run start-node",
"prod": "npm run make-public-config && npm run build --workspace=client && npm run start-node"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"concurrently": "^8.0.1",
"grunt": "^1.4.1",
"winston": "^3.8.2"
"@babel/core": "~7.20.12",
"concurrently": "~8.0.1",
"grunt": "~1.5.3",
"winston": "~3.8.2"
}
}
6 changes: 4 additions & 2 deletions src/server/app.js → src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* This file is the entry point for Rosetta's server-side code. It sets up the Express app, which has two components:
* (1) the built react app server, and
* (1) the built React app server, and
* (2) the translation API.
*
* (1) is responsible for serving the static files generated when we build the React front end. (2) is responsible for
Expand Down Expand Up @@ -82,13 +82,15 @@ if ( publicConfig.ENVIRONMENT === 'development' ) {
app.get( '/services/logout', mockSignOut );
}

// @ts-expect-error - privateConfig is not yet in TS. TODO: - remedy - see https://github.com/phetsims/rosetta/issues/311
app.listen( privateConfig.ROSETTA_PORT, () => {
logger.info( 'rosetta started' );
// @ts-expect-error - privateConfig is not yet in TS. TODO: - remedy - see https://github.com/phetsims/rosetta/issues/311
logger.info( `http://localhost:${privateConfig.ROSETTA_PORT}/translate` );

// Log private config keys except for secret ones.
const unsafeKeys = [ 'BUILD_SERVER_AUTH', 'GITHUB_PAT', 'SERVER_TOKEN' ];
const privateKeysToLog = Object.keys( privateConfig ).filter( key => !unsafeKeys.includes( key ) );
const privateKeysToLog = ( Object.keys( privateConfig ) as ( keyof typeof privateConfig )[] ).filter( key => !unsafeKeys.includes( key ) );
logger.info( `config (from ${pathToConfig}):` );
for ( const key of privateKeysToLog ) {
logger.info( ` ${key}: ${privateConfig[ key ]}` );
Expand Down
20 changes: 11 additions & 9 deletions src/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
"private": true,
"type": "module",
"dependencies": {
"@octokit/rest": "^19.0.7",
"axios": "^0.24.0",
"body-parser": "^1.20.1",
"cors": "^2.8.5",
"dotenv": "^10.0.0",
"express": "^4.17.1",
"mongodb": "^4.2.0",
"nodemon": "^2.0.22",
"winston": "^3.3.3"
"@types/express": "~5.0.0",
"@types/cors": "~2.8.12",
"@octokit/rest": "~19.0.7",
"axios": "~0.24.0",
"body-parser": "~1.20.1",
"cors": "~2.8.5",
"dotenv": "~10.0.0",
"express": "~4.17.1",
"mongodb": "~4.2.0",
"nodemon": "~2.0.22",
"winston": "~3.3.3"
}
}
4 changes: 2 additions & 2 deletions src/server/translationApi/getRepoNameToStringKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import getStringKeyFromStringKeyWithRepoName from './getStringKeyFromStringKeyWi
* @param {String[]} stringKeysWithRepoName - stringKey/REPO_NAME we get from a sim's HTML
* @param {String[]} commonRepos - list of common repos
* @param {String[]} commonStringKeys - list of common string keys
* @returns {{[]}} - an object of objects where the keys are common repo names and their values are
* lists of string keys that belong to those repos
* @returns {Object} - an object of objects where the keys are common repo names and their values are
* lists of string keys that belong to those repos
*/
const getRepoNameToStringKeys = ( stringKeysWithRepoName, commonRepos, commonStringKeys ) => {
const repoNameToStringKeys = {};
Expand Down
16 changes: 16 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../perennial-alias/tsconfig/tsconfig-node.json",
"include": [
"src/common/**/*",
"src/server/**/*",
"../perennial/js/common/simPhetioMetadata.js"
],
"exclude": [
"**/node_modules/**/*",
],
"references": [
{
"path": "../perennial/js/browser-and-node/tsconfig.json"
}
]
}

0 comments on commit 492b208

Please sign in to comment.