├── .gitattributes ├── .gitignore ├── raven.bat ├── package.sc ├── test └── test.sc ├── LICENSE ├── README.md ├── install.sc └── raven.sc /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sc linguist-language=Scheme -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.ss 3 | package.json 4 | lib/ 5 | *.tar 6 | *.tar.gz -------------------------------------------------------------------------------- /raven.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | @set CHEZSCHEMELIBDIRS=.;lib;%UserProfile%\raven 3 | @set CHEZSCHEMELIBEXTS=.chezscheme.sls;;.chezscheme.so;.ss;;.so;.sls;;.so;.scm;;.so;.sch;;.so;.sc;;.so 4 | @set "EXE=%UserProfile%\raven\raven\raven.sc" 5 | scheme --script %EXE% %* -------------------------------------------------------------------------------- /package.sc: -------------------------------------------------------------------------------- 1 | (("name" . "Raven") 2 | ("version" . "0.3.8") 3 | ("description" . "a package manager for Chez Scheme") 4 | ("keywords" 5 | ("tool" "package manager" "chez-scheme")) 6 | ("author" 7 | ("guenchi" "chclock")) 8 | ("license" . "MIT") 9 | ("homepage" . "http://ravensc.com") 10 | ("bugs" 11 | ("url" . "https://github.com/guenchi/raven/issues")) 12 | ("private" . #f) 13 | ("scripts" 14 | ("run" . "scheme --script")) 15 | ("dependencies") 16 | ("devDependencies")) 17 | -------------------------------------------------------------------------------- /test/test.sc: -------------------------------------------------------------------------------- 1 | ":"; exec scheme --script $0 "$@"; 2 | 3 | (define (test cmd) 4 | (printf "~a\n" (make-string 90 #\#)) 5 | (printf "run: ~a\n" cmd) 6 | (printf "~a\n" (make-string 90 #\-)) 7 | (system cmd) 8 | (printf "\n~a\n" (make-string 90 #\#))) 9 | 10 | ;; start 11 | (test "raven") 12 | (test "raven -v") 13 | (test "raven -h") 14 | 15 | (test "raven init -h") 16 | 17 | (test "raven install") 18 | (test "raven install -h") 19 | (test "raven install irregex") 20 | (test "raven install -dev json@0.5.1") 21 | 22 | (test "raven uninstall") 23 | (test "raven uninstall -h") 24 | (test "raven uninstall irregex") 25 | (test "raven uninstall json -dev") 26 | 27 | (test "raven run -h") 28 | (test "sudo raven install -g raven") -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright guenchi, chclock (c) 2017-2018 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raven 2 | Raven is a Package Manager for Chez Scheme 3 | 4 | ***[Web Site](http://ravensc.com)*** 5 | 6 | ***[Manual](https://guenchi.gitbooks.io/raven/content/)*** 7 | 8 | ***[Packages List](http://ravensc.com/list)*** 9 | 10 | package | description | only for Chez | r6rs common | pure Scheme | C lib depenced 11 | ---------|-------------|----------------|-------------|-------------|---------------- 12 | ***library*** 13 | darkart|foreign library call|X|||X 14 | srfi | srfi || X | X | 15 | sufage | srfi || X | X | 16 | core | small procedures || X | X | 17 | slib ||| X | X | 18 | scheme-lib || X ||| X 19 | ***web*** 20 | igropyr | http server | X ||| X 21 | ballista | web framwork | X || X | X 22 | catapult | web framwork | X || X | X 23 | libra | web framwork || X | X | 24 | json | Json parser || X | X | 25 | chez-json | Json parser || X | X | 26 | anb-json | Json parser || X | X | 27 | jwt | Json Web Token | X || X | X 28 | liber | HTML parser || X | X | 29 | ***system*** 30 | socket || X ||| X 31 | libc || X ||| X 32 | ***database*** 33 | mysql|| X ||| X 34 | ***hash*** 35 | base64 | BASE64 || X | X | 36 | csha256 | SHA256 hash | X |||X 37 | ***crypo*** 38 | chs256 | HMAC-SHA256 | X |||X 39 | ***compiler*** 40 | nanopass|compiler framwork||X|X| 41 | lalr | LALR(1) parser || X | X | 42 | ***statistics*** 43 | chez-stats|statistics||X|X| 44 | 45 | `the Raven libraries generally work fine on the R6RS implementation, except for some built on the c library which dependent on Chez Scheme's FFI.` 46 | 47 | 48 | Running project: 49 | 50 | ``` 51 | $ raven run example.sc 52 | ``` 53 | 54 | if you will run a project compiled: 55 | 56 | ``` 57 | $ export CHEZSCHEMELIBDIRS=.:lib:/usr/local/lib 58 | $ export CHEZSCHEMELIBEXTS=.chezscheme.sls::.chezscheme.so:.ss::.so:.sls::.so:.scm::.so:.sch::.so:.sc::.so 59 | $ scheme exemple.so 60 | ``` 61 | 62 | 63 | 64 | The project Raven is supported by [theschemer.org](http://theschemer.org) 65 | 66 | The principal developers are: [guenchi](https://github.com/guenchi), [chclock](https://github.com/chclock) 67 | 68 | Nota Bene: We recommend that the libraries for Raven files use .sc for distinguishing the libraries of r5rs / r7rs small. 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /install.sc: -------------------------------------------------------------------------------- 1 | ;;; Info Begin 2 | 3 | (define install-version "0.3.8") 4 | 5 | (define windows? 6 | (case (machine-type) 7 | ((a6nt i3nt ta6nt ti3nt) #t) 8 | (else #f))) 9 | 10 | (define target-linux-path "/usr/local/lib/raven") 11 | 12 | (define target-window-path (string-append (or (getenv "UserProfile") "c:") "\\raven")) 13 | 14 | (define target-path (if windows? target-window-path target-linux-path)) 15 | 16 | (define raven-url "http://ravensc.com/raven") 17 | 18 | ;;; Info End 19 | 20 | ;;; Helper Begin 21 | 22 | (define (read-file file-name) 23 | (let ((p (open-input-file file-name))) 24 | (let loop ((lst '()) (c (read-char p))) 25 | (if (eof-object? c) 26 | (begin 27 | (close-input-port p) 28 | (list->string (reverse lst))) 29 | (loop (cons c lst) (read-char p)))))) 30 | 31 | (define (system-return cmd) 32 | (define tmp "./##tmp##") 33 | (define rst "") 34 | (and (zero? (system (string-append cmd " > " tmp))) 35 | (file-exists? tmp) 36 | (begin (set! rst (read-file tmp)))) 37 | (delete-file tmp) 38 | rst 39 | ) 40 | 41 | (define (newest-version) 42 | (define ver (system-return (string-append "curl -s " raven-url))) 43 | (if (or (string-ci=? ver "#f") (string-ci=? ver "")) 44 | #f 45 | ver)) 46 | 47 | (define (clear-directory path) 48 | (when (file-directory? path) 49 | (for-each 50 | (lambda (p) 51 | (let ([p2 (string-append path "/" p)]) 52 | (if (file-directory? p2) 53 | (clear-directory p2) 54 | (delete-file p2) 55 | ))) 56 | (directory-list path)) 57 | (delete-directory path))) 58 | 59 | (define (install) 60 | (define ver (newest-version)) 61 | (if ver 62 | (begin 63 | (unless (file-directory? target-path) 64 | (mkdir target-path)) 65 | (clear-directory (format "~a/raven" target-path)) 66 | (printf "loading raven ~a ......\n" ver) 67 | (if windows? 68 | (if (and 69 | (system (format "cd /d ~a && curl -# -o raven.tar.gz ~a/~a && 7z x raven.tar.gz -y -aoa >> install.log && 7z x raven.tar -o~a/raven -y -aoa >> install.log" 70 | target-path raven-url ver target-path)) 71 | (delete-file (format "~a/raven.tar.gz" target-path)) 72 | (delete-file (format "~a/raven.tar" target-path)) 73 | (delete-file (format "~a/install.log" target-path))) 74 | (begin 75 | (printf "The script has been downloaded in ~a\\raven\nYou should add this path to the system variables PATH before you enjoy the raven\n" target-path) 76 | (printf "install raven ~a success\n" ver)) 77 | (printf "install raven ~a fail\n" ver) 78 | ) 79 | (if (and 80 | (mkdir (format "~a/raven" target-path)) 81 | (system (format "cd ~a && curl -# -o raven.tar.gz ~a/~a && tar -xzf raven.tar.gz -C ~a/raven" 82 | target-path raven-url ver target-path)) 83 | (delete-file (format "~a/raven.tar.gz" target-path))) 84 | (begin 85 | (delete-file "/usr/local/bin/raven") 86 | (system "ln -s /usr/local/lib/raven/raven/raven.sc /usr/local/bin/raven") 87 | (system "chmod +x /usr/local/bin/raven") 88 | (printf "install raven ~a success\n" ver)) 89 | (printf "install raven ~a fail\n" ver) 90 | ) 91 | ) 92 | ) 93 | (printf "dont't exist raven\n") 94 | ) 95 | ) 96 | 97 | ;;; Helper End 98 | 99 | (install) 100 | 101 | (exit) 102 | -------------------------------------------------------------------------------- /raven.sc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ":"; export CHEZSCHEMELIBDIRS=.:lib:/usr/local/lib && export CHEZSCHEMELIBEXTS=.chezscheme.sls::.chezscheme.so:.ss::.so:.sls::.so:.scm::.so:.sch::.so:.sc::.so && exec scheme --script $0 "$@"; 3 | 4 | 5 | ;;; Association List Begin 6 | 7 | (define package-sc->scm 8 | (case-lambda 9 | ([] (package-sc->scm raven-pkg-path)) 10 | ([path] (call-with-input-file path read)))) 11 | 12 | (define asl-ref 13 | (case-lambda 14 | ([asl key] (asl-ref asl key #f)) 15 | ([asl key default] (let ([rst (assoc key asl)]) 16 | (if rst (cdr rst) default))))) 17 | 18 | (define asl-set! 19 | (case-lambda 20 | ([asl key x y] 21 | (if (null? (asl-ref asl key)) 22 | (set-cdr! (assoc key asl) (cons (cons x y) '())) 23 | (asl-set! (asl-ref asl key) x y))) 24 | ([asl x y] 25 | (if (equal? x (caar asl)) 26 | (set-cdr! (car asl) y) 27 | (if (null? (cdr asl)) 28 | (set-cdr! asl (cons (cons x y) '())) 29 | (asl-set! (cdr asl) x y)))))) 30 | 31 | (define asl-delete! 32 | (case-lambda 33 | ([asl key x] 34 | (unless (null? (asl-ref asl key)) 35 | (if (equal? x (caar (asl-ref asl key))) 36 | (set-cdr! (assoc key asl) (cdr (asl-ref asl key))) 37 | (asl-delete! (asl-ref asl key) x)))) 38 | ([asl x] 39 | (unless (null? (cdr asl)) 40 | (if (equal? x (caadr asl)) 41 | (set-cdr! asl (cddr asl)) 42 | (asl-delete! (cdr asl) x)))))) 43 | 44 | (define (write-asl-format p asl level) 45 | (let loop ([ls asl] [space (make-string (* level 4) #\space)]) 46 | (unless (null? ls) 47 | (display space p) 48 | (if (and (pair? (cdar ls)) (list? (cdar ls)) (pair? (cadar ls))) 49 | (begin 50 | (display #\( p) 51 | (write (caar ls) p) 52 | (display " \n" p) 53 | (write-asl-format p (cdar ls) (1+ level)) 54 | (display #\) p)) 55 | (write (car ls) p)) 56 | (unless (null? (cdr ls)) 57 | (newline p) 58 | (loop (cdr ls) space))))) 59 | 60 | (define (write-package-file path asl) 61 | (delete-file path) 62 | (call-with-output-file path 63 | (lambda (p) 64 | (display #\( p) 65 | (write-asl-format p asl 0) 66 | (display #\) p)))) 67 | 68 | ;;; Association List End 69 | 70 | ;;; Helper Begin 71 | 72 | (define (read-file file-name) 73 | ;; 读取文件 74 | (let ((p (open-input-file file-name))) 75 | (let loop ((lst '()) (c (read-char p))) 76 | (if (eof-object? c) 77 | (begin 78 | (close-input-port p) 79 | (list->string (reverse lst))) 80 | (loop (cons c lst) (read-char p)))))) 81 | 82 | (define (write-file file-name content) 83 | ;; 写文件 84 | (delete-file file-name) 85 | (let ([p (open-output-file file-name)] [len (string-length content)]) 86 | (let loop ([idx 0]) 87 | (when (< idx len) 88 | (write-char (string-ref content idx) p) 89 | (loop (add1 idx)))) 90 | (close-output-port p) 91 | ) 92 | ) 93 | 94 | (define (make-package-asl name version description author private) 95 | ;; 默认package内容 96 | (list 97 | (cons "name" name) 98 | (cons "version" version) 99 | (cons "description" description) 100 | (cons "keywords" '()) 101 | (cons "author" `((,author))) 102 | (cons "private" private) 103 | (cons "scripts" '(("repl" . "scheme") ("run" . "scheme --script"))) 104 | (cons "dependencies" '()) 105 | (cons "devDependencies" '()) 106 | )) 107 | 108 | (define console-readline 109 | ;; 获取控制台输入 110 | (case-lambda 111 | ([] (console-readline #f #f)) 112 | ([prompt] (console-readline prompt #f)) 113 | ([prompt default] (begin 114 | (when prompt (printf prompt)) 115 | (let loop ([c (read-char)] [lst '()]) 116 | (if (char=? c #\newline) 117 | (if (or (null? lst) (and (char=? (car lst) #\return) (= 1 (length lst)))) 118 | (or default "") 119 | (if (char=? (car lst) #\return) 120 | (apply string (reverse (cdr lst))) 121 | (apply string (reverse lst)))) 122 | (loop (read-char) (cons c lst)))))))) 123 | 124 | (define (create-pkg-file) 125 | (define name (console-readline "project name: ")) 126 | (define version (console-readline "version(0.1.0): " "0.1.0")) 127 | (define description (console-readline "description: ")) 128 | (define author (console-readline (format "author(~a): " raven-user) raven-user)) 129 | (define private (console-readline "private?(Y/n): " "y")) 130 | (set! private (not (string-ci=? private "n"))) 131 | (let ([asl (make-package-asl name version description author private)]) 132 | (when (file-exists? raven-pkg-path) 133 | (let ([old-asl (package-sc->scm)]) 134 | (asl-set! asl raven-depend-key (asl-ref old-asl raven-depend-key '())) 135 | (asl-set! asl raven-dev-depend-key (asl-ref old-asl raven-dev-depend-key '()))) 136 | (delete-file raven-pkg-path)) 137 | (write-package-file raven-pkg-path asl)) 138 | ) 139 | 140 | (define load-lib 141 | (case-lambda 142 | ([lib ver] (load-lib lib ver raven-library-path)) 143 | ([lib ver lib-path] (load-lib lib ver lib-path #f)) 144 | ([lib ver lib-path check?] (load-lib lib ver lib-path check? #t)) 145 | ([lib ver lib-path check? printf?] 146 | (begin 147 | (unless ver 148 | (set! ver (newest-version lib))) 149 | (unless (file-directory? lib-path) 150 | (mkdir lib-path)) 151 | (unless check? 152 | (clear-directory (format "~a/~a" lib-path lib))) 153 | (when printf? 154 | (printf (format "loading ~a ~a ......\n" lib ver))) 155 | (if (and check? 156 | (file-exists? (format "~a/~a/~a" lib-path lib raven-pkg-file)) 157 | (string-ci>=? (asl-ref (package-sc->scm (format "~a/~a/~a" lib-path lib raven-pkg-file)) "version" "0.0.0") ver)) 158 | (printf "a high version ~a ~a exists\nstop loading ~a ~a\n" 159 | lib (asl-ref (package-sc->scm (format "~a/~a/~a" lib-path lib raven-pkg-file)) "version") lib ver) 160 | (if 161 | (if raven-windows? 162 | (and 163 | (system (format "cd /d ~a && curl -# -o ~a.tar.gz ~a/~a/~a && 7z x ~a.tar.gz -y -aoa >> install.log && 7z x ~a.tar -o~a/~a -y -aoa >> install.log" 164 | lib-path lib raven-url lib ver lib lib lib-path lib)) 165 | (delete-file (format "~a/~a.tar.gz" lib-path lib) #t) 166 | (delete-file (format "~a/~a.tar" lib-path lib) #t) 167 | (delete-file (format "~a/install.log" lib-path) #t)) 168 | (and 169 | (if (file-exists? (format "~a/~a" lib-path lib)) 170 | #t 171 | (mkdir (format "~a/~a" lib-path lib))) 172 | (system (format "cd ~a && curl -# -o ~a.tar.gz ~a/~a/~a && tar -xzf ~a.tar.gz -C ~a/~a" 173 | lib-path lib raven-url lib ver lib lib-path lib)) 174 | (delete-file (format "~a/~a.tar.gz" lib-path lib) #t))) 175 | (begin 176 | (when (file-exists? (format "~a/~a/~a" lib-path lib raven-pkg-file)) 177 | (let* ([asl (package-sc->scm (format "~a/~a/~a" lib-path lib raven-pkg-file))] 178 | [libs-asl (asl-ref asl raven-depend-key '())] 179 | [scripts (asl-ref asl "scripts" '())] 180 | [build (asl-ref scripts "build")]) 181 | (for-each 182 | (lambda (lib/ver) 183 | (load-lib (car lib/ver) (cdr lib/ver) lib-path #t #t)) 184 | libs-asl) 185 | (when build (system build)))) 186 | (when printf? (printf (format "load ~a ~a success\n" lib ver))) 187 | #t) 188 | (begin 189 | (when printf? (printf (format "load ~a ~a fail\n" lib ver))) 190 | #f) 191 | ) 192 | ) 193 | ) 194 | ) 195 | ) 196 | ) 197 | 198 | (define (opt-string? str) 199 | ;; 是否为选项 200 | (and (> (string-length str) 1) 201 | (string-ci=? (substring str 0 1) "-"))) 202 | 203 | (define (string->opt str) 204 | ;; 获取选项 205 | (string->symbol (substring str 1 (string-length str)))) 206 | 207 | (define (clear-directory path) 208 | ;; 清空并删除文件夹 209 | (when (file-directory? path) 210 | (for-each 211 | (lambda (p) 212 | (let ([p2 (string-append path "/" p)]) 213 | (if (file-directory? p2) 214 | (clear-directory p2) 215 | (delete-file p2 #t) 216 | ))) 217 | (directory-list path)) 218 | (delete-directory path #t) 219 | ) 220 | ) 221 | 222 | (define (delete-file/directory path) 223 | (if (file-directory? path) 224 | (clear-directory path) 225 | (delete-file path #t)) 226 | ) 227 | 228 | (define (system-return cmd) 229 | ;; 读取命令行返回内容 230 | (define tmp "./._##tmp##") 231 | (define rst "") 232 | (and (zero? (system (string-append cmd " > " tmp))) 233 | (file-exists? tmp) 234 | (begin (set! rst (read-file tmp)))) 235 | (delete-file tmp) 236 | rst 237 | ) 238 | 239 | (define (newest-lib/version lib) 240 | ;; get lib's version from server 241 | (define splite-index (string-index lib #\@)) 242 | (if splite-index 243 | (let ([name (substring lib 0 splite-index)] 244 | [ver (substring lib (1+ splite-index) (string-length lib))]) 245 | (if (string=? ver "") 246 | (cons name (newest-version name)) 247 | (cons name ver))) 248 | (cons lib (newest-version lib)) 249 | ) 250 | ) 251 | 252 | (define (newest-version lib) 253 | ;; 获取最新库版本 254 | (define ver (system-return (format "curl -s ~a/~a" raven-url lib))) 255 | (if (or (string-ci=? ver "#f") (string-ci=? ver "")) 256 | #f 257 | ver) 258 | ) 259 | 260 | (define (ask-Y/n? tip) 261 | ;; Input request Y/n 262 | (printf (format "~a(Y/n)" tip)) 263 | (not (string-ci=? (console-readline) "n")) 264 | ) 265 | 266 | (define (string-index str chr) 267 | (define len (string-length str)) 268 | (do ((pos 0 (+ 1 pos))) 269 | ((or (>= pos len) (char=? chr (string-ref str pos))) 270 | (and (< pos len) pos)))) 271 | 272 | (define (string-join string-list sep) 273 | (let loop ([new-s '()] [old-s string-list]) 274 | (if (null? old-s) 275 | (if (null? new-s) 276 | "" 277 | (apply string-append (reverse (cdr new-s)))) 278 | (loop (cons* sep (car old-s) new-s) (cdr old-s))) 279 | ) 280 | ) 281 | 282 | ;;; Helper End 283 | 284 | ;;; Command Begin 285 | 286 | (define (init opts args) 287 | ;; Initial 288 | (cond 289 | ((member "-h" opts) (raven-printf-help "init-h")) 290 | (else (begin 291 | (create-pkg-file) 292 | (unless (file-directory? raven-library-path) 293 | (mkdir raven-library-path)) 294 | (let ([libs (asl-ref (package-sc->scm) raven-current-key '())]) 295 | (for-each (lambda (l/v) (load-lib (car l/v) (cdr l/v))) libs)) 296 | (printf "raven init over\n"))) 297 | ) 298 | ) 299 | 300 | (define (install opts libs) 301 | ;; Installation 302 | (cond 303 | ((member "-h" opts) (raven-printf-help "install-h")) 304 | (else (begin 305 | (unless (or raven-global? (file-exists? raven-pkg-path)) 306 | (write-package-file raven-pkg-path (make-package-asl "" "" "" raven-user #f))) 307 | (unless (file-directory? raven-library-path) 308 | (mkdir raven-library-path)) 309 | (if (null? libs) 310 | (if raven-global? 311 | (printf "please add library name\n") 312 | (let* ([asl (package-sc->scm)] 313 | [libs-asl (asl-ref asl raven-current-key '())]) 314 | (for-each (lambda (l/v) (load-lib (car l/v) (cdr l/v))) libs-asl) 315 | (printf "install all libraries over\n"))) 316 | (if raven-global? 317 | (for-each 318 | (lambda (name) 319 | (let ([lib/ver (newest-lib/version name)]) 320 | (if (cdr lib/ver) 321 | (let* ([lib (car lib/ver)] 322 | [ver (cdr lib/ver)] 323 | [rst (load-lib lib ver)]) 324 | (when rst 325 | (if raven-windows? 326 | (printf "~a has been downloaded in ~a\\~a\n" lib raven-library-path lib) 327 | (begin 328 | (delete-file (format "/usr/local/bin/~a" lib) #t) 329 | (system (format "ln -s ~a/~a/~a.sc /usr/local/bin/~a" raven-library-path lib lib lib)) 330 | (system (format "chmod +x /usr/local/bin/~a" lib)) 331 | (printf "install ~a ~a success\n" lib ver))))) 332 | (printf (format "wrong library name: ~a\n" (car lib/ver)))))) 333 | libs) 334 | (let ([asl (package-sc->scm)]) 335 | (for-each 336 | (lambda (name) 337 | (let ([lib/ver (newest-lib/version name)]) 338 | (if (cdr lib/ver) 339 | (let* ([lib (car lib/ver)] 340 | [ver (cdr lib/ver)] 341 | [rst (load-lib lib ver)]) 342 | (when rst 343 | (unless (asl-ref asl raven-current-key) 344 | (asl-set! asl raven-current-key '())) 345 | (asl-set! asl raven-current-key lib ver))) 346 | (printf (format "wrong library name: ~a\n" (car lib/ver)))))) 347 | libs) 348 | (write-package-file raven-pkg-path asl) 349 | (printf "raven install over\n")))))) 350 | ) 351 | ) 352 | 353 | (define (uninstall opts libs) 354 | ;; Uninstallation 355 | (cond 356 | ((member "-h" opts) (raven-printf-help "uninstall-h")) 357 | (else (if (null? libs) 358 | (printf "please add library name\n") 359 | ;; uninstall libs 360 | (if raven-global? 361 | (for-each 362 | (lambda (name) 363 | (printf "deleting ~a/~a ......\n" raven-library-path name) 364 | (delete-file/directory (format "~a/~a" raven-library-path name)) 365 | (unless raven-windows? 366 | (delete-file (format "/usr/local/bin/~a" name))) 367 | (printf "uninstall ~a success\n" name)) 368 | libs) 369 | (if (and (file-directory? raven-library-path) (file-exists? raven-pkg-path)) 370 | (let* ([asl (package-sc->scm)] 371 | [libs-asl (asl-ref asl raven-current-key '())]) 372 | (for-each 373 | (lambda (name) 374 | (printf "deleting ~a/~a ......\n" raven-library-path name) 375 | (clear-directory (format "~a/~a" raven-library-path name)) 376 | (asl-delete! asl raven-current-key name) 377 | (printf "uninstall ~a success\n" name)) 378 | libs) 379 | (write-package-file raven-pkg-path asl) 380 | (printf "raven uninstall over\n")) 381 | (printf "please raven init first\n") 382 | )) 383 | )) 384 | ) 385 | ) 386 | 387 | (define (pack opts args) 388 | (cond 389 | ((member "-h" opts) (raven-printf-help "pack-h")) 390 | (else (let* ([asl (package-sc->scm)] 391 | [ver (asl-ref asl "version" "")] 392 | [lib (string-downcase (asl-ref asl "name" ""))] 393 | [dir (if (null? args) "" (format "cd ~a &&" (car args)))]) 394 | (unless (null? args) 395 | (write-file (format "~a/~a/~a" raven-current-path (car args) raven-pkg-file) (read-file raven-pkg-path))) 396 | (if raven-windows? 397 | (and (system 398 | (format "~a 7z a ~a.tar ./ && 7z d ~a.tar lib -r && 7z d ~a.tar .* -r && 7z d ~a.tar .tar -r && 7z d ~a.tar .tar.gz -r && 7z a ~a-~a.tar.gz ~a.tar" 399 | dir ver ver ver ver ver lib ver ver)) 400 | (delete-file (format "~a/~a.tar" (if (null? args) "." (format"./~a" (car args))) ver))) 401 | (system (format "~a tar -zcf ~a-~a.tar.gz --exclude lib --exclude \"*.tar.gz\" --exclude \".*\" *" dir lib ver))) 402 | (unless (null? args) 403 | (if raven-windows? 404 | (system (format "move ~a\\~a-~a.tar.gz ~a-~a.tar.gz" (car args) lib ver lib ver)) 405 | (system (format "mv ~a/~a-~a.tar.gz ~a-~a.tar.gz" (car args) lib ver lib ver))) 406 | (delete-file (format "~a/~a/~a" raven-current-path (car args) raven-pkg-file))) 407 | (printf "raven library : ~a-~a.tar.gz is ready\n" lib ver))) 408 | ) 409 | ) 410 | 411 | (define (self-command opts cmds) 412 | ;; 自定义命令 413 | (cond 414 | ((and (string-ci=? (car cmds) "run") (member "-h" opts)) (raven-printf-help "run-h")) 415 | (else (if (file-exists? raven-pkg-path) 416 | (let* ([scripts (asl-ref (package-sc->scm) "scripts")] 417 | [cmd (if scripts (asl-ref scripts (car cmds)) #f)] 418 | [args (append (cdr cmds) opts)]) 419 | (if cmd 420 | (system (format "~a ~a" cmd (string-join args " "))) 421 | (if (string-ci=? (car cmds) "run") 422 | (system (format "scheme --script ~a" (string-join args " "))) 423 | (printf "invaild command\n")))) 424 | (printf "please run raven init first\n"))) 425 | ) 426 | ) 427 | 428 | ;;; Command End 429 | 430 | ;;; Info Begin 431 | 432 | (define raven-url "http://ravensc.com") 433 | 434 | (define raven-windows? 435 | (case (machine-type) 436 | ((a6nt i3nt ta6nt ti3nt) #t) 437 | (else #f))) 438 | 439 | (define raven-user (if raven-windows? (or (getenv "USERNAME") "") (or (getenv "USER")""))) 440 | 441 | (define raven-current-path (current-directory)) 442 | 443 | (define raven-library-dir "lib") 444 | 445 | (define raven-library-path (format "~a/~a" raven-current-path raven-library-dir)) 446 | 447 | (define raven-pkg-file "package.sc") 448 | 449 | (define raven-pkg-path (format "~a/~a" raven-current-path raven-pkg-file)) 450 | 451 | (define raven-depend-key "dependencies") 452 | 453 | (define raven-dev-depend-key "devDependencies") 454 | 455 | (define raven-current-key raven-depend-key) 456 | 457 | (define raven-global-path (if raven-windows? (string-append (or (getenv "UserProfile") "C:") "\\raven") "/usr/local/lib/raven")) 458 | 459 | (define raven-global-dir "raven") 460 | 461 | (define raven-global? #f) 462 | 463 | (define raven-version (asl-ref (package-sc->scm (format "~a/raven/~a" raven-global-path raven-pkg-file)) "version" "")) 464 | 465 | ;;; Info End 466 | 467 | ;;; Main Begin 468 | 469 | (define (raven-init) 470 | ;; 初始化环境 471 | #f 472 | ) 473 | 474 | (define (init-opts opts) 475 | ;; 检测环境 476 | (when (member "-g" opts) 477 | (set! raven-library-dir raven-global-dir) 478 | (set! raven-library-path raven-global-path) 479 | (set! raven-global? #t)) 480 | (when (member "-dev" opts) 481 | (set! raven-current-key raven-dev-depend-key)) 482 | ) 483 | 484 | (define (check-version) 485 | ;; 运行前检查版本 486 | (printf (format "Raven version: ~a\n" raven-version)) 487 | ) 488 | 489 | (define raven-help 490 | '( 491 | ("raven-h" 492 | . "\nUsage: raven [option]\n\nwhere is one of:\n\tinit, install, uninstall, run, pack\n\nraven -h\tquick help on \n\n") 493 | ("init-h" 494 | . "\nUsage:\n\nraven init\n\tcreat a file package.sc for a new project\n\n") 495 | ("install-h" 496 | . "\nUsage:\n\nraven install [option]\n\tinstall the \"dependencies\" of the package.sc\n\nraven install [option] \n\tinstall the package of current version and update package.sc\n\nraven install [option] @\n\tinstall the package of specified version and update package.sc\n\n[option]:\n\t-clean: clean the C source files after complie\n\t-dev: work with \"devDependencies\" instead of \"dependencies\"\n\t-g: install package as a CLI tool. need root permissions.\n\n") 497 | ("uninstall-h" 498 | . "\nUsage:\n\nraven install [option] \n\tremove the package and update package.sc\n\n[option]:\n\t-dev: work with \"devDependencies\" instead of \"dependencies\"\n\t-g: remove a CLI tool. need root permissions.\n\n") 499 | ("pack-h" 500 | . "\nUsage:\n\nraven pack\n\tpacking the current project in file tar.gz\n\n") 501 | ("run-h" 502 | . "\nUsage:\n\nraven run\n\truning the current project\n\n") 503 | ) 504 | ) 505 | 506 | (define raven-printf-help 507 | (case-lambda 508 | ([key] (raven-printf-help key "")) 509 | ([key default] (printf (asl-ref raven-help key default)))) 510 | ) 511 | 512 | (define (global-opts opts) 513 | (case (car opts) 514 | [("-v" "--version") (check-version)] 515 | [("-h" "--help") (raven-printf-help "raven-h")] 516 | [("--clean") (printf "todo\n")] 517 | [else (raven-printf-help "raven-h")] 518 | ) 519 | ) 520 | 521 | (define (raven) 522 | ;; raven 启动方法 523 | (define args (command-line-arguments)) 524 | (raven-init) 525 | (if (null? args) 526 | (raven-printf-help "raven-h") 527 | (let-values 528 | ([(opts cmds) (partition opt-string? args)]) 529 | (init-opts opts) 530 | (if (null? cmds) 531 | (global-opts opts) 532 | (case (car cmds) 533 | [("init") (init opts (cdr cmds))] 534 | [("install") (install opts (cdr cmds))] 535 | [("uninstall") (uninstall opts (cdr cmds))] 536 | [("pack") (pack opts (cdr cmds))] 537 | [else (self-command opts cmds)])) 538 | ) 539 | ) 540 | ) 541 | 542 | ;;; Main End 543 | 544 | ;; start 545 | (raven) 546 | --------------------------------------------------------------------------------