Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Bug fix - Server.ts now doesn't have type issues #315

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions scripts/setupTypeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,31 @@ function addDepsToPackageJson() {
fs.writeFileSync(pkgJSONPath, JSON.stringify(packageJSON, null, ' '));
}

function updateServerFile(fileName) {
let contents = fs.readFileSync(fileName, "utf8");
const newContents = contents
.replace(
/import\s+polka.+from\s'polka';/,
`import polka, { Middleware } from 'polka'`
)
.replace(
/compression\({.+\),/,
"compression({ threshold: 0 }) as unknown as Middleware,"
)
.replace(/.listen\(.+(\t|\n).+(\t|\n).+}\)/, ".listen(PORT)");
fs.writeFileSync(fileName, newContents);
}

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$/)) {
if (elements[i].name === "server.js") {
updateServerFile(path.join(dir, elements[i].name));
}
fs.renameSync(path.join(dir, elements[i].name), path.join(dir, elements[i].name).replace('.js', '.ts'));
}
}
Expand Down