Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run `create-react-app` from within Common Lisp

Assuming that a local system has create-react-app installed (npm i -g create-react-app), I want to run it with parameters from within a Common Lisp file. What's the best way to do this?

like image 318
lispquestions Avatar asked May 05 '26 07:05

lispquestions


1 Answers

as far as i know, the potrable solution is uiop:run-program, since your cl distribution probably has the asdf included.

CL-USER> (uiop:run-program "create-react-app" :output t :error-output t)
;;Please specify the project directory:
;;  create-react-app <project-directory>

;;For example:
;;  create-react-app my-react-app

;;Run create-react-app --help to see all options.
;;; Debugger entered on #<UIOP/RUN-PROGRAM:SUBPROCESS-ERROR {10018B83A3}>

this one reports error, as the create-react-app itself does for no args.

(uiop:run-program "create-react-app my-new-shiny-app" :output t :error-output t)

succeeds, and creates app in your cwd.

you can wrap it into a function like this, for example:

(defun create-react-app (app-path &key verbose info scripts-version template use-npm use-pnp typescript)
  (let ((cmd (format nil "create-react-app ~a ~
                            ~@[--verbose~*~] ~
                            ~@[--info~*~] ~
                            ~@[--scripts-version ~a~] ~
                            ~@[--template ~a~] ~
                            ~@[--use-npm~*~] ~
                            ~@[--use-pnp~*~] ~
                            ~@[--typescript~*~]"
                     app-path verbose info scripts-version template use-npm use-pnp typescript)))
    (format t "executing shell command: ~a~%" cmd)
    (uiop:run-program cmd :output t :error-output t)))

(create-react-app "my-new-shiny-app" :template "cra-template-quickstart-redux" :use-npm t)

havent thoroughly tested it, but it should work.

like image 166
leetwinski Avatar answered May 10 '26 23:05

leetwinski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!