Skip to content

Commit

Permalink
chore: check if entry is js, convert ts to js
Browse files Browse the repository at this point in the history
Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh committed Dec 21, 2022
1 parent 11bcfad commit e98cd05
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { log } from "../logging";
import { createApp } from "./create";
import { getPreferredPackageManager } from "./getPreferredPackageManager";
import { setupRemix, isSetupPlatform, SetupPlatform } from "./setup";
import { convertTSFileToJS } from "./migrate/migrations/convert-to-javascript/convertTSFilesToJS/convertTSFileToJS";

export * as migrate from "./migrate";

Expand Down Expand Up @@ -398,12 +399,24 @@ export async function generateEntry(remixRoot: string, entry: string) {
return;
}

// 3. copy the entry file from the template
let inputFile = entry.startsWith("entry.client.")
? defaultEntryClient
: defaultEntryServer;
let outputFile = path.resolve(remixRoot, entry);
await fse.copyFile(
entry.startsWith("entry.client.") ? defaultEntryClient : defaultEntryServer,
outputFile
);

// 3. if entry is jsx?, convert to js
// otherwise, copy the entry file from the defaults
if (/\.jsx?$/.test(entry)) {
let contents = await fse.readFile(inputFile, "utf-8");
let javascript = convertTSFileToJS({
filename: entry,
projectDir: remixRoot,
source: contents,
});
await fse.writeFile(outputFile, javascript);
} else {
await fse.copyFile(inputFile, outputFile);
}

console.log(colors.blue(`Entry file ${entry} created at ${outputFile}.`));
}

0 comments on commit e98cd05

Please sign in to comment.