Skip to content
Snippets Groups Projects
Commit 78c1c09c authored by Zandor Smith's avatar Zandor Smith :computer:
Browse files

Support Typescript files.

parent 6e6d039c
No related branches found
No related tags found
No related merge requests found
Pipeline #343520 passed
......@@ -8,13 +8,13 @@ async function step02RenameEntryExtension() {
if(!packageMain) {
throw new Error("package.json does not contain a main property.");
}
if(packageMain.endsWith(".jsx")) {
console.log("package.json main property already ends with .jsx. Skipping step 02.");
if(packageMain.endsWith(".jsx") || packageMain.endsWith(".tsx")) {
console.log("package.json main property already ends with .jsx / .tsx. Skipping step 02.");
return;
}
const currentPath = packageMain;
const newPath = "./src/index.jsx";
const newPath = packageMain.endsWith(".ts") ? "./src/index.tsx" : "./src/index.jsx";
if(fs.existsSync(newPath)) {
console.log(`${newPath} already exists. Skipping step 02.`);
......
......@@ -31,7 +31,7 @@ async function processFilesInDirectory(directory) {
madeChanges = true;
}
if((filePath.endsWith(".js") || filePath.endsWith(".jsx")) && fileContent.includes("process.env")) {
if((filePath.endsWith(".js") || filePath.endsWith(".jsx") || filePath.endsWith(".ts") || filePath.endsWith(".tsx")) && fileContent.includes("process.env")) {
console.log("Replace 'process.env' with 'import.meta.env' in", filePath);
fileContent = fileContent.replaceAll("process.env", "import.meta.env");
madeChanges = true;
......
......@@ -21,7 +21,7 @@ async function processFilesInDirectory(directory) {
if (!file.isFile()) {
continue;
}
if(!file.name.endsWith(".js")) {
if(!file.name.endsWith(".js") && !file.name.endsWith(".ts")) {
continue;
}
......@@ -33,10 +33,11 @@ async function processFilesInDirectory(directory) {
continue;
}
const newPath = oldPath.replace(".js", ".jsx");
let newPath = oldPath.replace(".js", ".jsx");
newPath = newPath.replace(".ts", ".tsx");
fs.renameSync(oldPath, newPath);
console.log(`${file.name} renamed to ${file.name.replace(".js", ".jsx")}`);
console.log(`${file.name} renamed to ${newPath}`);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment