Skip to content

Commit

Permalink
fix: Sanitize project name for WSL compatibility while running start-…
Browse files Browse the repository at this point in the history
…database.sh (#1991)
  • Loading branch information
aryanp-86 authored Oct 7, 2024
1 parent e08dbe3 commit 43f77ad
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cli/src/installers/dbContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ import { PKG_ROOT } from "~/consts.js";
import { type Installer } from "~/installers/index.js";
import { parseNameAndPath } from "~/utils/parseNameAndPath.js";

// Sanitizes a project name to ensure it adheres to Docker container naming conventions.
const sanitizeName = (name: string): string => {
return name
.replace(/[^a-zA-Z0-9_.-]/g, "_") // Replace invalid characters with underscores
.toLowerCase(); // Convert to lowercase for consistency
};

export const dbContainerInstaller: Installer = ({
projectDir,
databaseProvider,
Expand All @@ -18,11 +25,14 @@ export const dbContainerInstaller: Installer = ({
const scriptDest = path.join(projectDir, "start-database.sh");
// for configuration with postgresql and mysql when project is created with '.' project name
const [projectNameParsed] =
projectName == "." ? parseNameAndPath(projectDir) : [projectName];
projectName === "." ? parseNameAndPath(projectDir) : [projectName];

// Sanitize the project name for Docker container usage
const sanitizedProjectName = sanitizeName(projectNameParsed);

fs.writeFileSync(
scriptDest,
scriptText.replaceAll("project1", projectNameParsed)
scriptText.replaceAll("project1", sanitizedProjectName)
);
fs.chmodSync(scriptDest, "755");
};

0 comments on commit 43f77ad

Please sign in to comment.