services: 'gc-root-service-type' now has a default value.
[guix.git] / guix / build / minify-build-system.scm
blob563def88e9f9e97c38c90acd59fc4721a993b027
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/>.
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))
30 ;; Commentary:
32 ;; Builder-side code of the standard minification procedure for JavaScript
33 ;; files.
35 ;; Code:
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))
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)))
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)
61 (define %standard-phases
62   (modify-phases gnu:%standard-phases
63     (delete 'bootstrap)
64     (delete 'configure)
65     (replace 'build build)
66     (delete 'check)
67     (replace 'install install)))
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))
74 ;;; minify-build-system.scm ends here