2018-10-21

(sph filesystem asset-compiler)

configuration format and helpers to process and concatenate files from multiple sources.

part of sph-lib

library description

for example to compile from many files in different preprocessor formats into one target format file.

features

  configuration for all processors

  process file always, only if source file is newer or only if destination file doesnt exist

  match files by suffix or custom procedure

  option to automatically create destination filenames

data structures

  config: hashtable:{symbol:output-format -> (config-output config-input ...)}

  config-output: #(symbol:id string:suffix false/procedure:processor-output)

  config-input: #(symbol:name source-match? false/procedure:processor-input)

  config-format: (config-output config-input ...)

  source-match? :: boolean/procedure:{any:source -> boolean}

  processor-input :: source-element port:output any:processor-options ->

  processor-output :: procedure:input->port port:output-port any:processor-options ->

  sources: (any:processor-dependent ...)

syntax

  ac-config :: (out-id suffix out-proc) (in-id matcher in-proc) ... -> hashtable

  ac-config-input :: id matcher processor -> vector

  ac-config-output :: id suffix processor -> vector

example config

  (define my-ac-config

    (ac-config

      ( (html ".htm" (l (process-input out-port options) (process-input out-port)))

        (html #t (l (source out-port options) (file->port source out-port)))

        (sxml #t s-template-sxml->html))

      ( (js #t js-output-processor)

        (js #t ac-input-copy)

        (sjs #t s-template-sescript->js))))

import name

(sph filesystem asset-compiler)

exports

procedure: ac-compile config output-format sources port [processor-options] ->
hashtable symbol list port [any] -> false/unspecified
"processor-options" is an optional value passed to input and output processors as the last argument
procedure: ac-compile->file config output-format sources dest-directory #:processor-options #:when #:dest-name ->
hashtable symbol list string _ ... -> string:path-destination
#:processor-options: any/alist #:when takes a symbol: new: update only if destination does not exist newer: update if destination does not exist or any source file is newer always: always compile, overwriting any existing destination file #:dest-name sets the destination file name to use instead of an automatically generated one
syntax: ac-config ((out-id suffix out-proc) (in-id matcher in-proc) ...) ...
syntax: ac-config-input id matcher processor
procedure: ac-config-input-p id matcher processor ->
symbol procedure/boolean procedure/false create a config-input object. if processor is false, a default processor that interprets source elements as filesystem paths and reads them is used. matcher procedure: match a source element #t: match the id as a filename extension separated with a dot for source elements which are strings else: never match
syntax: ac-config-output id suffix processor
procedure: ac-config-output-p id suffix processor ->
symbol string/procedure/boolean procedure -> vector
create a config-output object. if processor is false, a default processor that just copies is used. suffix #t: use the id as a filename extension separated with a dot else: no filename extension
procedure: ac-config-p config-source ->
list:((id config-output config-input ...) ...) -> hashtable
create an ac-config from a list with the following format
procedure: ac-destination path-directory format sources [name suffix] ->
string symbol string list -> string
create a string for an output path relative to "path-directory". format: * "{path-directory}/{format}/{name}" * "{path-directory}/{format}/_{basename-without-suffix-first-of-sources}-{base32-hash-of-sources}"
procedure: ac-input-id record ->
procedure: ac-input-matcher record ->
procedure: ac-input-processor record ->
variable: ac-input-record
procedure: ac-output-id record ->
procedure: ac-output-processor record ->
variable: ac-output-record
procedure: ac-output-suffix record ->
procedure: ac-source-files-updated? dest sources ->
string (string ...) -> boolean
true if any source is newer than destination
variable: sph-filesystem-asset-compiler-description