pages
Version:
AngularJS / Node.js sidekick.
64 lines (36 loc) • 1.88 kB
text/coffeescript
async = require 'async'
utils = require '../../lib/utils'
sources = require './sources'
notifications = require './notifications'
Pass jSON to the Jade view, allowing mixins to render the appropriate HTML for resources related to the current environment's needs.
buildCmd = (view) ->
config = require "#{process.cwd()}/pages"
pageJson =
Inject an assumed `NODE_ENV` of `production` or `development`.
NODE_ENV: process.env.NODE_ENV
Asset references were added in `./js.litcoffee` and `./css.litcoffee` based on environment.
assets:
js: global.pages.assets.js
css: global.pages.assets.css
IF we have _constants_ set in `pages.litcoffee`, pass them to `appConstants`.
pageJson.constants = JSON.stringify(config.constants) if config.constants
cmd = "#{global.pkgBasePath}/node_modules/jade/bin/jade --obj '#{JSON.stringify(pageJson)}' #{view.from} --out #{view.to}"
cmd = "#{cmd} --pretty" if process.env.NODE_ENV is 'development'
cmd
compileJadeView = (view, cb) -> utils.runWithOutputAndCb buildCmd(view), notifications.jade, cb
getJadeViews = (cb) ->
utils.listFiles "#{process.cwd()}/views", '.jade', (files) ->
files = files.map (file) ->
viewDir = "#{process.cwd()}/views"
fileName = file.split('/')[file.split('/').length - 1]
filePath = file.replace viewDir, ''
filePath = filePath.replace fileName, ''
fileName = fileName.replace '.jade', '.html'
from: file, to: "#{process.cwd()}/_app/views#{filePath}"
files.push from: "#{process.cwd()}/index.jade", to: "#{process.cwd()}/_app/"
cb files
build = (cb) -> getJadeViews (views) -> async.each views, compileJadeView, cb
## Public API ##
publicFns =
build: build
module.exports = publicFns