|
@@
-1,158
+1,157
b''
|
|
1
|
|
|
1
|
|
|
2
|
(in-package txt2web)
|
|
2
|
(in-package txt2web)
|
|
3
|
|
|
3
|
|
|
4
|
(defvar *app-name* "")
|
|
4
|
(defvar *app-name* "txt2web")
|
|
5
|
|
|
5
|
|
|
6
|
(defun entry-point-no-args ()
|
|
6
|
(defun entry-point-no-args ()
|
|
7
|
(setf *delivered* t)
|
|
7
|
(setf *delivered* t)
|
|
8
|
(entry-point uiop:*command-line-arguments*))
|
|
8
|
(entry-point uiop:*command-line-arguments*))
|
|
9
|
|
|
9
|
|
|
10
|
(defun entry-point (args)
|
|
10
|
(defun entry-point (args)
|
|
11
|
(setf *app-name* (uiop:argv0))
|
|
|
|
|
12
|
(let ((*package* (find-package :txt2web)))
|
|
11
|
(let ((*package* (find-package :txt2web)))
|
|
13
|
(catch :terminate
|
|
12
|
(catch :terminate
|
|
14
|
(let ((compiler (apply #'make-instance 'compiler (parse-opts args))))
|
|
13
|
(let ((compiler (apply #'make-instance 'compiler (parse-opts args))))
|
|
15
|
(write-compiled-file compiler))))
|
|
14
|
(write-compiled-file compiler))))
|
|
16
|
(values))
|
|
15
|
(values))
|
|
17
|
|
|
16
|
|
|
18
|
(defun parse-opts (args)
|
|
17
|
(defun parse-opts (args)
|
|
19
|
(let ((mode :sources)
|
|
18
|
(let ((mode :sources)
|
|
20
|
(data (list :sources nil :target nil :js nil :css nil :body nil :compile nil :beautify nil)))
|
|
19
|
(data (list :sources nil :target nil :js nil :css nil :body nil :compile nil :beautify nil)))
|
|
21
|
(loop :for arg :in args
|
|
20
|
(loop :for arg :in args
|
|
22
|
:do (alexandria:switch (arg :test #'string=)
|
|
21
|
:do (alexandria:switch (arg :test #'string=)
|
|
23
|
("-o" (setf mode :target))
|
|
22
|
("-o" (setf mode :target))
|
|
24
|
("--js" (setf mode :js))
|
|
23
|
("--js" (setf mode :js))
|
|
25
|
("--css" (setf mode :css))
|
|
24
|
("--css" (setf mode :css))
|
|
26
|
("--body" (setf mode :body))
|
|
25
|
("--body" (setf mode :body))
|
|
27
|
("-c" (setf (getf data :compile) t))
|
|
26
|
("-c" (setf (getf data :compile) t))
|
|
28
|
("--beautify" (setf (getf data :beautify) t))
|
|
27
|
("--beautify" (setf (getf data :beautify) t))
|
|
29
|
(t (push arg (getf data mode)))))
|
|
28
|
(t (push arg (getf data mode)))))
|
|
30
|
(unless (< 0 (length (getf data :sources)))
|
|
29
|
(unless (< 0 (length (getf data :sources)))
|
|
31
|
(report-error "There should be at least one source"))
|
|
30
|
(report-error "There should be at least one source"))
|
|
32
|
(unless (> 1 (length (getf data :target)))
|
|
31
|
(unless (> 1 (length (getf data :target)))
|
|
33
|
(report-error "There should be no more than one target"))
|
|
32
|
(report-error "There should be no more than one target"))
|
|
34
|
(unless (> 1 (length (getf data :body)))
|
|
33
|
(unless (> 1 (length (getf data :body)))
|
|
35
|
(report-error "There should be no more than one body"))
|
|
34
|
(report-error "There should be no more than one body"))
|
|
36
|
(unless (getf data :target)
|
|
35
|
(unless (getf data :target)
|
|
37
|
(setf (getf data :target)
|
|
36
|
(setf (getf data :target)
|
|
38
|
(let* ((sources (first (getf data :sources)))
|
|
37
|
(let* ((sources (first (getf data :sources)))
|
|
39
|
(tokens (uiop:split-string sources :separator "."))
|
|
38
|
(tokens (uiop:split-string sources :separator "."))
|
|
40
|
(target (format nil "~{~A~^.~}.html"
|
|
39
|
(target (format nil "~{~A~^.~}.html"
|
|
41
|
(butlast tokens))))
|
|
40
|
(butlast tokens))))
|
|
42
|
(list target))))
|
|
41
|
(list target))))
|
|
43
|
(list :sources (getf data :sources)
|
|
42
|
(list :sources (getf data :sources)
|
|
44
|
:target (first (getf data :target))
|
|
43
|
:target (first (getf data :target))
|
|
45
|
:js (getf data :js)
|
|
44
|
:js (getf data :js)
|
|
46
|
:css (getf data :css)
|
|
45
|
:css (getf data :css)
|
|
47
|
:body (first (getf data :body))
|
|
46
|
:body (first (getf data :body))
|
|
48
|
:compile (getf data :compile)
|
|
47
|
:compile (getf data :compile)
|
|
49
|
:beautify (getf data :beautify))))
|
|
48
|
:beautify (getf data :beautify))))
|
|
50
|
|
|
49
|
|
|
51
|
(defun print-usage ()
|
|
50
|
(defun print-usage ()
|
|
52
|
(lformat t :usage *app-name*))
|
|
51
|
(lformat t :usage *app-name*))
|
|
53
|
|
|
52
|
|
|
54
|
(defun parse-file (filename)
|
|
53
|
(defun parse-file (filename)
|
|
55
|
(handler-case
|
|
54
|
(handler-case
|
|
56
|
(p:parse 'txt2web-grammar
|
|
55
|
(p:parse 'txt2web-grammar
|
|
57
|
(alexandria:read-file-into-string filename))
|
|
56
|
(alexandria:read-file-into-string filename))
|
|
58
|
(p:esrap-parse-error (e)
|
|
57
|
(p:esrap-parse-error (e)
|
|
59
|
(format t "~A~%" e)
|
|
58
|
(format t "~A~%" e)
|
|
60
|
(uiop:quit 1))))
|
|
59
|
(uiop:quit 1))))
|
|
61
|
|
|
60
|
|
|
62
|
(defun report-error (fmt &rest args)
|
|
61
|
(defun report-error (fmt &rest args)
|
|
63
|
(format t "ERROR: ~A~%" (apply #'format nil fmt args))
|
|
62
|
(format t "ERROR: ~A~%" (apply #'format nil fmt args))
|
|
64
|
(print-usage)
|
|
63
|
(print-usage)
|
|
65
|
(throw :terminate nil))
|
|
64
|
(throw :terminate nil))
|
|
66
|
|
|
65
|
|
|
67
|
;;; JS
|
|
66
|
;;; JS
|
|
68
|
|
|
67
|
|
|
69
|
(defun minify-package (package-designator minify prefix)
|
|
68
|
(defun minify-package (package-designator minify prefix)
|
|
70
|
(setf (ps:ps-package-prefix package-designator) prefix)
|
|
69
|
(setf (ps:ps-package-prefix package-designator) prefix)
|
|
71
|
(if minify
|
|
70
|
(if minify
|
|
72
|
(ps:obfuscate-package package-designator)
|
|
71
|
(ps:obfuscate-package package-designator)
|
|
73
|
(ps:unobfuscate-package package-designator)))
|
|
72
|
(ps:unobfuscate-package package-designator)))
|
|
74
|
|
|
73
|
|
|
75
|
(defmethod js-sources ((compiler compiler))
|
|
74
|
(defmethod js-sources ((compiler compiler))
|
|
76
|
(let ((ps:*ps-print-pretty* (beautify compiler)))
|
|
75
|
(let ((ps:*ps-print-pretty* (beautify compiler)))
|
|
77
|
(cond ((beautify compiler)
|
|
76
|
(cond ((beautify compiler)
|
|
78
|
(minify-package "TXT2WEB.MAIN" nil "qsp_")
|
|
77
|
(minify-package "TXT2WEB.MAIN" nil "qsp_")
|
|
79
|
(minify-package "TXT2WEB.API" nil "qsp_api_")
|
|
78
|
(minify-package "TXT2WEB.API" nil "qsp_api_")
|
|
80
|
(minify-package "TXT2WEB.LIB" nil "qsp_lib_"))
|
|
79
|
(minify-package "TXT2WEB.LIB" nil "qsp_lib_"))
|
|
81
|
(t
|
|
80
|
(t
|
|
82
|
(minify-package "TXT2WEB.MAIN" t "_")
|
|
81
|
(minify-package "TXT2WEB.MAIN" t "_")
|
|
83
|
(minify-package "TXT2WEB.API" t "a_")
|
|
82
|
(minify-package "TXT2WEB.API" t "a_")
|
|
84
|
(minify-package "TXT2WEB.LIB" t "l_")))
|
|
83
|
(minify-package "TXT2WEB.LIB" t "l_")))
|
|
85
|
(format nil "~{~A~^~%~%~}" (mapcar #'ps:ps* (reverse (js compiler))))))
|
|
84
|
(format nil "~{~A~^~%~%~}" (mapcar #'ps:ps* (reverse (js compiler))))))
|
|
86
|
|
|
85
|
|
|
87
|
;;; CSS
|
|
86
|
;;; CSS
|
|
88
|
|
|
87
|
|
|
89
|
(defmethod css-sources ((compiler compiler))
|
|
88
|
(defmethod css-sources ((compiler compiler))
|
|
90
|
(format nil "~{~A~^~%~%~}" (css compiler)))
|
|
89
|
(format nil "~{~A~^~%~%~}" (css compiler)))
|
|
91
|
|
|
90
|
|
|
92
|
;;; HTML
|
|
91
|
;;; HTML
|
|
93
|
|
|
92
|
|
|
94
|
(defmethod html-sources ((compiler compiler))
|
|
93
|
(defmethod html-sources ((compiler compiler))
|
|
95
|
(let ((flute:*escape-html* nil)
|
|
94
|
(let ((flute:*escape-html* nil)
|
|
96
|
(body-template (body compiler))
|
|
95
|
(body-template (body compiler))
|
|
97
|
(js (js-sources compiler))
|
|
96
|
(js (js-sources compiler))
|
|
98
|
(css (css-sources compiler)))
|
|
97
|
(css (css-sources compiler)))
|
|
99
|
(with-output-to-string (out)
|
|
98
|
(with-output-to-string (out)
|
|
100
|
(write
|
|
99
|
(write
|
|
101
|
(flute:h
|
|
100
|
(flute:h
|
|
102
|
(html
|
|
101
|
(html
|
|
103
|
(head
|
|
102
|
(head
|
|
104
|
(title "txt2web"))
|
|
103
|
(title "txt2web"))
|
|
105
|
(body
|
|
104
|
(body
|
|
106
|
body-template
|
|
105
|
body-template
|
|
107
|
(style css)
|
|
106
|
(style css)
|
|
108
|
(script js))))
|
|
107
|
(script js))))
|
|
109
|
:stream out
|
|
108
|
:stream out
|
|
110
|
:pretty nil))))
|
|
109
|
:pretty nil))))
|
|
111
|
|
|
110
|
|
|
112
|
(defun filename-game (filename)
|
|
111
|
(defun filename-game (filename)
|
|
113
|
(let ((filename (alexandria:lastcar (uiop:split-string filename :separator "/"))))
|
|
112
|
(let ((filename (alexandria:lastcar (uiop:split-string filename :separator "/"))))
|
|
114
|
(format nil "~{~A~^.~}" (butlast (uiop:split-string filename :separator ".")))))
|
|
113
|
(format nil "~{~A~^.~}" (butlast (uiop:split-string filename :separator ".")))))
|
|
115
|
|
|
114
|
|
|
116
|
(defmethod initialize-instance ((compiler compiler) &key sources ((:js js-files)) ((:css css-files)) ((:body body-file)) compile &allow-other-keys)
|
|
115
|
(defmethod initialize-instance ((compiler compiler) &key sources ((:js js-files)) ((:css css-files)) ((:body body-file)) compile &allow-other-keys)
|
|
117
|
(call-next-method)
|
|
116
|
(call-next-method)
|
|
118
|
(with-slots (body css js)
|
|
117
|
(with-slots (body css js)
|
|
119
|
compiler
|
|
118
|
compiler
|
|
120
|
;; Compile the game's JS
|
|
119
|
;; Compile the game's JS
|
|
121
|
(dolist (source sources)
|
|
120
|
(dolist (source sources)
|
|
122
|
(let ((ps (parse-file source))
|
|
121
|
(let ((ps (parse-file source))
|
|
123
|
(game-name (filename-game source)))
|
|
122
|
(game-name (filename-game source)))
|
|
124
|
(destructuring-bind (kw &rest locations)
|
|
123
|
(destructuring-bind (kw &rest locations)
|
|
125
|
ps
|
|
124
|
ps
|
|
126
|
(unless (eq kw 'lib:game)
|
|
125
|
(unless (eq kw 'lib:game)
|
|
127
|
(report-error "Internal error!"))
|
|
126
|
(report-error "Internal error!"))
|
|
128
|
(push
|
|
127
|
(push
|
|
129
|
`(lib:game (,game-name) ,@locations)
|
|
128
|
`(lib:game (,game-name) ,@locations)
|
|
130
|
js))))
|
|
129
|
js))))
|
|
131
|
;; Does the user need us to do anything else
|
|
130
|
;; Does the user need us to do anything else
|
|
132
|
(unless compile
|
|
131
|
(unless compile
|
|
133
|
;; Read in body
|
|
132
|
;; Read in body
|
|
134
|
(when body-file
|
|
133
|
(when body-file
|
|
135
|
(setf body
|
|
134
|
(setf body
|
|
136
|
(alexandria:read-file-into-string body-file)))
|
|
135
|
(alexandria:read-file-into-string body-file)))
|
|
137
|
;; Include js files
|
|
136
|
;; Include js files
|
|
138
|
(dolist (js-file js-files)
|
|
137
|
(dolist (js-file js-files)
|
|
139
|
(push (format nil "////// Included file ~A~%~A" js-file
|
|
138
|
(push (format nil "////// Included file ~A~%~A" js-file
|
|
140
|
(alexandria:read-file-into-string js-file))
|
|
139
|
(alexandria:read-file-into-string js-file))
|
|
141
|
js))
|
|
140
|
js))
|
|
142
|
;; Include css files
|
|
141
|
;; Include css files
|
|
143
|
(when css-files
|
|
142
|
(when css-files
|
|
144
|
;; User option overrides the default css
|
|
143
|
;; User option overrides the default css
|
|
145
|
(setf css nil)
|
|
144
|
(setf css nil)
|
|
146
|
(dolist (css-file css-files)
|
|
145
|
(dolist (css-file css-files)
|
|
147
|
(push (format nil "////// Included file ~A~%~A" css-file
|
|
146
|
(push (format nil "////// Included file ~A~%~A" css-file
|
|
148
|
(alexandria:read-file-into-string css-file))
|
|
147
|
(alexandria:read-file-into-string css-file))
|
|
149
|
css))))))
|
|
148
|
css))))))
|
|
150
|
|
|
149
|
|
|
151
|
(defmethod write-compiled-file ((compiler compiler))
|
|
150
|
(defmethod write-compiled-file ((compiler compiler))
|
|
152
|
(alexandria:write-string-into-file
|
|
151
|
(alexandria:write-string-into-file
|
|
153
|
(if (compile-only compiler)
|
|
152
|
(if (compile-only compiler)
|
|
154
|
;; Just the JS
|
|
153
|
;; Just the JS
|
|
155
|
(js-sources compiler)
|
|
154
|
(js-sources compiler)
|
|
156
|
;; All of it
|
|
155
|
;; All of it
|
|
157
|
(html-sources compiler))
|
|
156
|
(html-sources compiler))
|
|
158
|
(target compiler) :if-exists :supersede))
|
|
157
|
(target compiler) :if-exists :supersede))
|