dmmulroy / create-melange-app

The fastest, friendliest, and most delightful way to get started with OCaml, ReasonML, and Melange, geared towards JavaScript and TypeScript developers
121 stars 20 forks source link

fix project names with nested dirs #99

Closed mbpowers closed 4 months ago

mbpowers commented 7 months ago

when inputting a name in the cli that contains /, nested directories are created

fixes #98

JohnBakhmat commented 7 months ago

I would also consider adding "/" check then. So that some like me doesn't override his root directory with melange app

dmmulroy commented 7 months ago

Rather than this fix, and supporting nested directories, I would like to prohibit nested directories. Lets instead update this function in https://github.com/dmmulroy/create-melange-app/blob/develop/src/core/fs.ml to return a result and fail if there are invalid characters or slashes in the name here:

let parse_project_name_and_dir (str : string) =
  let trimmed = trim_trailing_slash str in
  if String.equal trimmed "." then
    let name = [| trimmed |] |> Nodejs.Path.resolve |> Nodejs.Path.basename in
    let directory = [| Nodejs.Process.cwd () |] |> Nodejs.Path.resolve in
    (name, directory)
  else
    let name = [| trimmed |] |> Nodejs.Path.resolve |> Nodejs.Path.basename in
    let directory =
      [| trimmed; name |] |> Nodejs.Path.resolve |> Nodejs.Path.dirname
    in
    (name, directory)
;;
mbpowers commented 7 months ago

okay I think this should be good