Commit | Line | Data |
---|---|---|
88c8f247 RW |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (guix build minify-build-system) | |
20 | #:use-module ((guix build gnu-build-system) #:prefix gnu:) | |
21 | #:use-module ((guix build minify-build-system) #:prefix minify:) | |
22 | #:use-module (guix build utils) | |
23 | #:use-module (srfi srfi-1) | |
24 | #:use-module (srfi srfi-26) | |
25 | #:use-module (ice-9 popen) | |
26 | #:export (%standard-phases | |
27 | minify-build | |
28 | minify)) | |
29 | ||
30 | ;; Commentary: | |
31 | ;; | |
32 | ;; Builder-side code of the standard minification procedure for JavaScript | |
33 | ;; files. | |
34 | ;; | |
35 | ;; Code: | |
36 | ||
37 | (define* (minify file #:key target (directory "")) | |
38 | (format #t "minifying ~a\n" file) | |
39 | (let* ((base (basename file ".js")) | |
40 | (installed (or target (string-append directory base ".min.js"))) | |
41 | (minified (open-pipe* OPEN_READ "uglify-js" file))) | |
42 | (call-with-output-file installed | |
43 | (cut dump-port minified <>)) | |
44 | #t)) | |
45 | ||
46 | (define* (build #:key javascript-files | |
47 | #:allow-other-keys) | |
48 | (let ((files (or javascript-files | |
49 | (find-files "src" "\\.js$")))) | |
50 | (mkdir-p "guix/build") | |
51 | (every (cut minify <> #:directory "guix/build/") files))) | |
52 | ||
53 | (define* (install #:key outputs #:allow-other-keys) | |
54 | (let* ((out (assoc-ref outputs "out")) | |
55 | (js (string-append out "/share/javascript/"))) | |
56 | (mkdir-p js) | |
57 | (for-each (cut install-file <> js) | |
58 | (find-files "guix/build" "\\.min\\.js$"))) | |
59 | #t) | |
60 | ||
61 | (define %standard-phases | |
62 | (modify-phases gnu:%standard-phases | |
189be331 | 63 | (delete 'bootstrap) |
88c8f247 RW |
64 | (delete 'configure) |
65 | (replace 'build build) | |
66 | (delete 'check) | |
67 | (replace 'install install))) | |
68 | ||
69 | (define* (minify-build #:key inputs (phases %standard-phases) | |
70 | #:allow-other-keys #:rest args) | |
71 | "Build the given JavaScript package, applying all of PHASES in order." | |
72 | (apply gnu:gnu-build #:inputs inputs #:phases phases args)) | |
73 | ||
74 | ;;; minify-build-system.scm ends here |