jacobobryant / biff

A Clojure web framework for solo developers.
https://biffweb.com
MIT License
878 stars 43 forks source link

Hyphenated project name creates hyphenated root src directory #108

Closed jeffp42ker closed 2 years ago

jeffp42ker commented 2 years ago

When defining a hypenated project name at the new_project prompts, I use "the_example" as the project directory name and "the-example.core" as the main namespace. The script creates file structure under /src/the-example/ and /dev/the-example/

➜  bash <(curl -s https://raw.githubusercontent.com/jacobobryant/biff/master/new-project.sh)

Creating a new Biff project.
Fetching latest Biff version...
Enter name for project directory: the_example
Enter main namespace (e.g. example.core): the-example.core

Your project is ready. Run the following commands to get started:

  cd the_example
  git init
  ./task dev

➜  cd the_example
➜  the_example tree
.
├── config
│   ├── dev.env
│   ├── prod.env
│   └── task.env
├── deps.edn
├── dev
│   └── the-example
│       ├── core_test.clj
│       ├── dev
│       │   └── css.clj
│       └── dev.clj
├── infra
│   ├── post-receive
│   └── setup.sh
├── resources
│   └── public
│       ├── css
│       │   └── custom.css
│       └── js
│           ├── ensure-signed-in.js
│           └── ensure-signed-out.js
├── shadow-cljs.edn
├── src
│   └── the-example
│       ├── admin.clj
│       ├── client
│       │   ├── app
│       │   │   ├── components.cljs
│       │   │   ├── db.cljs
│       │   │   ├── handlers.cljs
│       │   │   ├── mutations.cljs
│       │   │   ├── routes.cljc
│       │   │   └── system.cljs
│       │   └── app.cljs
│       ├── core.clj
│       ├── env.clj
│       ├── handlers.clj
│       ├── routes
│       │   └── auth.clj
│       ├── routes.clj
│       ├── rules.clj
│       ├── templates.clj
│       ├── views
│       │   └── shared.cljc
│       └── views.clj
└── task

15 directories, 31 files
➜  the_example 

The issue appears to be in the add-derived tasks function. Helper function could be:

(defn ns->path [s]
  (-> s
      (str/replace "." "/")
      (str/replace "-" "_")))

(defn add-derived [{:keys [main-ns] :as opts}]
  (let [parent-ns (str/replace (str main-ns) #"(\.core)$" "")
        parent-path (ns->path parent-ns)
        main-ns-path (ns->path (str main-ns))]
    (assoc opts
      :parent-ns parent-ns
      :parent-path parent-path
      :main-ns-path main-ns-path)))
jacobobryant commented 2 years ago

Closed via #109