; This dune file segment configures the build process for the project, 
; focusing on web bundling.

; This stanza excludes the 'node_modules' directory from being 
; considered by dune, which is a standard practice to prevent Dune from scanning 
; dependency files.
(dirs :standard \ node_modules)

; The 'alias' block named 'all' defines a high-level alias for building the 
; entire project. It specifies that the 'all' alias depends on another alias, 
; typically named after the bundler being used (e.g., 'vite', 'webpack'). This 
; setup allows for easy switching between different bundlers without changing 
; the overall build process.
{{#each aliases}}
(alias 
  (name {{this.name}})
  (deps
     {{#each this.deps}}
     ({{this}}){{#unless @last}} {{/unless}}{{#if @last}}){{/if}})
     {{/each}}

{{/each}}

; The 'rule' block associated with the bundler alias (e.g., 'vite', 'webpack') 
; defines the specific steps to build and bundle the web application. 
;
; - 'targets (dir dist)' indicates the output directory for the bundled files.
;
; - The 'deps' section lists dependencies like the project alias, bundler config 
;   files, and entry HTML file. 
;
; - The 'action' specifies the system command to run the bundler, in this case a
;   script from 'node_modules' to run a bundler.
;
; - 'promote (until-clean)' in 'mode' is used for artifact promotion, managing built files.
{{#each rules}}
(rule
  (alias {{this.alias}})
   (targets {{#each this.targets}}({{this}}){{#unless @last}} {{/unless}}{{/each}})
   (deps
     {{#each this.deps}}
     ({{this}}){{#unless @last}} {{/unless}}{{#if @last}}){{/if}}
     {{/each}}
   (action
    ({{{this.action}}}))
   (mode
     (promote (until-clean))))

{{/each}}

; The 'melange.emit' block is used to compile ReasonML/OCaml code to JavaScript.
; - 'target output' specifies where the compiled JS files will be placed.
; - It relies on the 'app' library and compiles using specified module systems 
;   (here, es6 and mjs).
{{#each melange_emits}}
  (melange.emit
   (target {{this.target}})
   (alias {{this.alias}})
   (libraries {{#each this.libraries}}{{this}}{{#unless @last}} {{/unless}}{{#if @last}}){{/if}}{{/each}}
   (module_systems ({{this.module_system}})))
{{/each}}


