Skip to content

Commit

Permalink
chore: check if any of the server/client entries exist
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 3362623 commit 0f2b3f5
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,17 @@ export async function generateEntry(remixRoot: string, entry: string) {
let config = await readConfig(remixRoot);

// 1. validate requested entry file
let entries = new Set([
"entry.server.tsx",
"entry.server.js",
"entry.server.jsx",
let clientEntries = new Set([
"entry.client.tsx",
"entry.client.js",
"entry.client.jsx",
]);
let serverEntries = new Set([
"entry.server.tsx",
"entry.server.js",
"entry.server.jsx",
]);
let entries = new Set([...clientEntries, ...serverEntries]);
if (!entries.has(entry)) {
console.log(
colors.error(
Expand Down Expand Up @@ -392,15 +395,23 @@ export async function generateEntry(remixRoot: string, entry: string) {
}
}

// 2.2. check if the entry file exists
let inputFile = entry.startsWith("entry.client.")
? defaultEntryClient
: defaultEntryServer;
let outputFile = path.resolve(path.join(remixRoot, "app", entry));
let entryExists = await fse.pathExists(outputFile);
if (entryExists) {
console.log(colors.gray(`Entry file ${outputFile} already exists.`));
return;
// 2.2. check if any of the requested entry file exists
let entryType = entry.startsWith("entry.client.") ? "client" : "server";
let inputFile =
entryType === "client" ? defaultEntryClient : defaultEntryServer;
let outputFile: string = "";
let entriesToCheck = entryType === "client" ? clientEntries : serverEntries;
for (let entryToCheck of entriesToCheck) {
outputFile = path.resolve(remixRoot, "app", entryToCheck);
let entryExists = await fse.pathExists(outputFile);
if (entryExists) {
console.log(
colors.gray(
`Entry file ${path.relative(remixRoot, entryToCheck)} already exists.`
)
);
return;
}
}

// 3. if entry is jsx?, convert to js
Expand Down

0 comments on commit 0f2b3f5

Please sign in to comment.