#!/usr/bin/env sitefile
#
# Sitefile for node-sitefile document server
# A note of caution: this example config does shameless things like executing any shell
# script if you want to, like call http://localhost/clean.sh. Ymmv.
#
# Id: node-sitefile/0.0.5-dev+20161010
sitefile: 0.0.5

showStackError: true

paths:
  routers_replace: false
  routers:
  - 'sitefile:example/routers'

#autoExport:
#  - rjs: /app/rjs

routes:

  media/script/dhtml.js: coffee:lib/sitefile/client/dhtml.coffee
  media/script/sitefile-client.js: static:build/client/sf-v0.js
  media/style: static:build/style

  doc/literate: static:build/docs/docco/

  example: static:example
  # FIXME: example/: redir:example/main

  example/bookshelf/knex.sqlite/_/v1: bookshelfapi:example/bookshelf/knex.json
  example/bookshelf/knex: knex:example/bookshelf/knex.json
  # Example, get data from another endpoint, the one above?
  # XXX: example/bookshelf/knex/query-1: knex.sql:example/bookshelf/sql.coffee?knex=..

  _pug: pug:example/pug-*.pug
  _stylus: stylus:example/**/*.styl
  _sass: sass:example/**/*.sass
  _coffee: coffee:example/**/*.coffee
  _markdown: markdown:*.md
  _markdown_1: markdown:example/**/*.md
  _sh: sh:example/*.sh
  _gv: gv:example/*.gv
  # FIXME: aliases _pu: pu:example/*.pu
  _pu: plantuml:example/*.plantuml
  _pu_dev_doc: plantuml:doc/dev/*.plantuml
  _json: data.json:example/*.json

  mocha/client/*: mocha.client:#
  mocha/server/*: mocha.test:#

  # Some defaults for root
  '': redir:ReadMe
  index: redir:ReadMe

  # Example routes for ReadMe
  #ReadMe: du:ReadMe.rst # Du defaults to HTML
  #ReadMe: redir:ReadMe.html
  #ReadMe.html: du:ReadMe.rst
  #ReadMe.xml: du:ReadMe.rst

  # Dynamic rules using glob spec
  _du: du:**/*.rst

  #_rst2html: rst2html:**/*.rst
  gitflow: du:.gitflow.rst

  Sitefile: redir:Sitefile.yaml
  Sitefile.yaml: static:Sitefile.yaml
  Sitefile.json: sitefile:?resolve=sitefile
  Sitefile/debug: sitefile:#
  Sitefile/resource: sitefile.resource:#
  Sitefile/handler: sitefile.handler:#
  Sitefile/global: sitefile.global:#

  Sitefile/core/auto: core.autocomplete:#
  Sitefile/core: core:#

  # Proxy JSON metadata, settings in options.local.npm/...
  npm/npm/latest.json: http:#
  npm/node-sitefile/latest.json: http:#

  # Look for installed package in PWD and Sitefile dir
  npm/packages/: 'static:{,sitefile:}node_modules/'

  # FIXME: display current PM2 procs and/or preconfigured apps status
  proc/pm2: pm2:pm2-apps.json

  # Some HTTP redirect handlers configured on JSON mappings
  vendor/:package.:format: http.vendor:cdn.json
  r:ref/(.*): http.ref:#
  r:res/(.*): http.res:#
  site/:site/:path: http.site:sites.json

  # Three seperate resources, layered for the RequireJS client.
  # The JSON is a path object extracted from cdn.json, and a shim and map and
  # other RequireJS option objects.
  app/rjs-sf-v0.json: rjs.config:paths=$ref:cdn.json#/js/http/packages;baseUrl=/app;main=cs!sf-v0
  # The JSON is wrapped in a script to initialize RequireJS
  app/rjs-sf-v0.js: rjs.main:app/rjs-sf-v0.json
  # Finally a specific router is wired to display a pug template with all of the
  # above.
  app/v0: pug:sitefile-client:sf-v0.pug#
  # Serve coffee script for RequireJS client
  app: static:lib/sitefile/client

  # FIXME: fonts? want to build CSS+font loading into RequireJS client
  fonts: static:node_modules/bootstrap/fonts

  # Just an instance of the example router in example/routers
  sf-example/default: sf-example:#
  sf-example/data1: sf-example.data1:#
  sf-example/data2: sf-example.data2:#

  local: static:public/local


  # TODO: imagemacking processing?
  #/shadows/:path: convert.filter:**/*.png

  tools: static:tools


  _pug_server: pug:example/server-*.pug
  _pug_prism: pug:example/prism*.pug
  _pug_polymer: pug:example/polymer*.pug


options:
  global:
    du:
      link_stylesheets: true
      scripts:
        $ref: '#/defs/scripts/default'
      stylesheets:
        $ref: '#/defs/stylesheets/default'
    rst2html:
      link_stylesheets: true
      flags:
      - "--no-toc-backlinks"
      scripts:
        $ref: '#/defs/scripts/default'
      stylesheets:
        $ref: '#/defs/stylesheets/default'
    #pug:
    #  merge:
    #    scripts:
    #      $ref: '#/defs/scripts/default'
    #    stylesheets:
    #      $ref: '#/defs/stylesheets/default'

  local:
    npm/node-sitefile/latest.json:
      spec:
        hostname: 'registry.npmjs.org'
        path: '/node-sitefile/latest'

    npm/npm/latest.json:
      spec:
        hostname: 'registry.npmjs.org'
        path: '/npm/latest'

    Sitefile/debug:
      local_var: 'fooooo'

    app/v0:
      merge:
        stylesheets:
          - /vendor/bootstrap.css
          - /vendor/jquery-ui.css
        scripts:
          - /vendor/jquery.js
        clients:
          $ref: '#/defs/app/v0/clients'

    example/server-generated-page:
      merge:
        stylesheets:
          - /vendor/bootstrap.css
          - /vendor/bootstrap-theme.css
          - /media/style/default.css
          - /example/server-generated-stylesheet
        scripts:
          - /vendor/jquery.js
          #- /vendor/require.js
          #- /vendor/source-map-support.js
          - /vendor/coffee-script.js
          - /example/server-generated-javascript
        links:
          - type: text/coffescript
            href: /example/script.coffee

defs:
  scripts:
    default:
      - /vendor/jquery.js
      #- /vendor/require.js
      #- /vendor/source-map-support.js
      - /vendor/coffee-script.js
      #- src: /media/script/sitefile-client.js
      #  path: build/client/default.js
  stylesheets:
    default:
      - url: /vendor/bootstrap.css
      - url: /vendor/bootstrap-theme.css
      - url: /media/style/default.css
        path: build/style/default.css

  app:
    v0:
      clients:
        - type: require-js
          id: require-js-sitefile-v0-app
          href: /vendor/require.js
          main: /app/rjs-sf-v0.js


