capybara/init.rkt

76 lines
2.4 KiB
Racket

#lang racket/base
(require racket/file racket/path racket/pretty racket/runtime-path
"compiler.rkt" "render.rkt" "util.rkt")
(provide init-project)
(define-runtime-path *nginx.conf* "support/nginx-dev.conf")
(define (init-project name [dir (build-path (current-directory) name)])
(when (directory-exists? dir)
(error "directory already exists!" (path->string dir)))
(define src (simple-form-path (build-path dir "src")))
(define target (simple-form-path (build-path dir "target")))
(make-directory* src)
(make-directory* target)
(with-output-to-file
(build-path src "index.md")
(λ ()
(pretty-write
(list (list 'title name)
(list 'summary "a cool site")
(apply list 'date (get-date-ymd))
(list 'tags "tag1" "tag2")
(list 'lang "en")
(list 'authors "you")))
(write-string "\n# welcome to capybara\n\nthis is a blank site. you should put stuff here")))
(with-output-to-file
(build-path src "index.scss")
(λ () (write-string "/* your cool SCSS goes here */")))
(with-output-to-file
(build-path src "favicon.png.rkt")
(λ ()
(write-string "#lang capybara/pict\n\n")
(write-string "; this is an example pict which will become the site favicon\n")
(write-string "(standard-cat 128 128)")))
(with-output-to-file
(build-path src "config.rktd")
(λ () (pretty-write (list (list 'base "http://localhost:8080")))))
(with-output-to-file
(build-path src "40x.md")
(λ ()
(pretty-write
'((title "error page")
(lang "en")))
(write-string "\n# error\n\nno such page; or you are not authorized to view it")))
(with-output-to-file
(build-path src "50x.md")
(λ ()
(pretty-write
'((title "error page")
(lang "en")))
(write-string "\n# error\n\nthe server ran into an error :(")))
(with-output-to-file
(build-path dir "nginx.conf")
(λ ()
(define conf (file->string *nginx.conf*))
(write-string (regexp-replace #rx"@PWD" conf (path->string target)))))
(parameterize ([current-directory dir])
(generate/execute (scan-for-rules)))
(void))
(module+ main
(require racket/cmdline)
(command-line
#:program "capybara-init"
#:args (name)
(with-handlers ([exn? (λ (e) (printf "error: ~a\n" (exn-message e)))])
(init-project name)
(printf "created project ~a\n" name))))