#!/usr/bin/guile !# (import (sph) (sph filesystem) (sph alist) (sph list) (sph cli)) (define path-project-example "/usr/share/sph/web/app/project-example") (define path-project-minimal "/usr/share/sph/web/app/project-minimal") (define (create-new-project path options) (let* ( (example? (alist-ref-q options example)) (source-path (if example? path-project-example path-project-minimal))) (if (file-exists? source-path) (begin (ensure-directory-structure path) (let (sed-file-paths (if example? (begin (system* "cp" "--dereference" "--recursive" "--preserve=mode" "--no-target-directory" source-path path) (map (l (a) (string-append path a)) (list "branch/main.scm" "exe/start" "main.scm" "exe/test" "test/module/main.scm" "lib/main.scm"))) (begin (system* "cp" "--dereference" "--preserve=mode" "--recursive" "--no-target-directory" source-path path) (map (l (a) (string-append path a)) (list "exe/start" "main.scm"))))) (apply system* "sed" "-i" (string-append "s/project-" (if example? "example" "minimal") "/" (remove-trailing-slash (basename path)) "/g") sed-file-paths))) (raise (pair (q source-path-not-found) source-path))))) (define (web-app options) (let (target-path (alist-ref options (q target))) (if target-path (let (target-path (path->full-path target-path)) (if (file-exists? target-path) (simple-format #t "failed: \"~A\" already exists\n" target-path) (begin (create-new-project (ensure-trailing-slash target-path) options) (simple-format #t "created ~A\n" target-path)))) (begin (display "please specify a target path or name\n") (exit 1))))) (define (web-app-cli) (let* ( (cli (cli-create #:description "creates new (web app) projects based on project templates that are immediately functional" #:options (q (((target)) (example #:description "creates an example project structure"))))) (options (cli))) (if (null? options) (cli (list "--help")) (web-app options)))) (web-app-cli)