Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Generate a Hubot script (.js file) from the given Roswell script.
#|-*- 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))
(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 (new -object)
(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