Skip to content

Commit

Permalink
Address janet-lang#74 - add new-exe-project subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
sogaiu committed Jun 1, 2023
1 parent af002e6 commit bcf0331
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions jpm/commands.janet
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
new-c-project name
Create a new C+Janet project in a directory `name`.
new-exe-project name
Create a new project for an executable in a directory `name`.
Privileged global subcommands:
install (repo or name)...
Expand Down Expand Up @@ -349,6 +352,11 @@
[name]
(scaffold-project name {:c true}))

(defn new-exe-project
"Create a new executable project"
[name]
(scaffold-project name {:c false :exe true}))

(def subcommands
{"build" build
"clean" clean
Expand Down Expand Up @@ -378,5 +386,6 @@
"exec" shell
"new-project" new-project
"new-c-project" new-c-project
"new-exe-project" new-exe-project
"janet" (fn [& args] (shell (dyn :executable) ;args))
"save-config" save-config})
19 changes: 18 additions & 1 deletion jpm/scaffold.janet
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@
}
```)

(deftemplate exe-project-template
````
(declare-project
:name "$name"
:description ```$description ```
:version "0.0.0")
(declare-executable
:name "$name"
:entry "$name/init.janet")
````)

(deftemplate readme-template
```
# ${name}
Expand Down Expand Up @@ -176,6 +188,7 @@
(def description (opt-ask :description options))
(def date (format-date))
(def scaffold-native (get options :c))
(def scaffold-exe (get options :exe))
(def template-opts (merge-into @{:name name :year year :author author :date date :description description} options))
(print "creating project directory for " name)
(os/mkdir name)
Expand All @@ -187,11 +200,15 @@
(spit (string name "/README.md") (readme-template template-opts))
(spit (string name "/LICENSE") (license-template template-opts))
(spit (string name "/CHANGELOG.md") (changelog-template template-opts))
(if scaffold-native
(cond
scaffold-native
(do
(os/mkdir (string name "/c"))
(spit (string name "/c/module.c") (module-c-template template-opts))
(spit (string name "/test/native.janet") (native-test-template template-opts))
(spit (string name "/project.janet") (native-project-template template-opts)))
scaffold-exe
(do
(spit (string name "/project.janet") (exe-project-template template-opts)))
(do
(spit (string name "/project.janet") (project-template template-opts)))))

0 comments on commit bcf0331

Please sign in to comment.