运行 来自 Common Lisp 的 `create-react-app`
Run `create-react-app` from within Common Lisp
假设本地系统安装了 create-react-app
(npm i -g create-react-app
),我想 运行 它带有 Common Lisp 文件中的参数。执行此操作的最佳方法是什么?
据我所知,可行的解决方案是 uiop:run-program,因为您的 cl 发行版可能包含 asdf
。
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}>
这个报告错误,因为 create-react-app
本身没有参数。
(uiop:run-program "create-react-app my-new-shiny-app" :output t :error-output t)
成功,并在您的 cwd 中创建应用程序。
你可以把它包装成这样的函数,例如:
(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)
还没有彻底测试过,但应该可以。
假设本地系统安装了 create-react-app
(npm i -g create-react-app
),我想 运行 它带有 Common Lisp 文件中的参数。执行此操作的最佳方法是什么?
据我所知,可行的解决方案是 uiop:run-program,因为您的 cl 发行版可能包含 asdf
。
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}>
这个报告错误,因为 create-react-app
本身没有参数。
(uiop:run-program "create-react-app my-new-shiny-app" :output t :error-output t)
成功,并在您的 cwd 中创建应用程序。
你可以把它包装成这样的函数,例如:
(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)
还没有彻底测试过,但应该可以。