-
-
Save peccu/59f72a0220dc6e58c472a2f2f0da6db0 to your computer and use it in GitHub Desktop.
Generate a Hubot script (.js file) from the given Roswell script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#|-*- mode:lisp -*-|# | |
#| | |
exec ros -Q -- $0 "$@" | |
|# | |
#| | |
Generate a Hubot script (.js file) from the given Roswell script. | |
Usage: | |
$ hubotify <roswell script> | |
|# | |
(ql:quickload '(:parenscript) :silent t) | |
(import '(ps:ps ps:@ ps:lisp ps:create)) | |
(defun relative-path (path) | |
(make-pathname | |
:directory | |
(cons :relative | |
(nthcdr (length (pathname-directory *default-pathname-defaults*)) | |
(pathname-directory path))) | |
:defaults path)) | |
(defun main (&optional script &rest argv) | |
(declare (ignore argv)) | |
(let ((script (probe-file script))) | |
(unless script | |
(error "File does not exist: ~A" script)) | |
(let ((*error-output* (make-broadcast-stream))) | |
(load script)) | |
(when (fboundp (intern (string :js-main) :cl-user)) | |
(let ((js-file | |
(make-pathname :defaults script | |
;; Write .js file to ./scripts/. | |
:directory (append (pathname-directory *default-pathname-defaults*) | |
'("scripts")) | |
:type "js"))) | |
(with-open-file (*standard-output* js-file :direction :output :if-exists :supersede) | |
(princ | |
(ps | |
(defun run-main (callback &rest argv) | |
(setf (@ this exec-file) (@ (require "child_process") exec-file)) | |
((@ this exec-file) | |
(+ __dirname "/../" (lisp (namestring (relative-path script)))) | |
argv (create env (@ process env)) | |
(lambda (error stdout stderr) | |
(funcall callback error stdout stderr) | |
(values)))))) | |
(fresh-line) | |
(format t "module.exports = function(robot) {~%~A~%};" | |
(funcall (intern (string :js-main) :cl-user))) | |
(fresh-line)) | |
(format *error-output* "~&Wrote '~A'~%" js-file))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment