Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const fileNames = Object.keys(files)
Object.keys(filters).forEach(glob => {
fileNames.forEach(file => {
if (minimatch(file, glob, { dot: true })) {
const condition = filters[glob]
if (!evaluate(condition, data)) {
delete files[file]
}
}
})
})
done()
}
const render = consolidate.handlebars.render
// register handlebars helper
Handlebars.registerHelper('if_eq', function (a, b, opts) {
return a === b
? opts.fn(this)
: opts.inverse(this)
})
Handlebars.registerHelper('unless_eq', function (a, b, opts) {
return a === b
? opts.inverse(this)
: opts.fn(this)
})
/**
* Generate a template given a `src` and `dest`.
/**
* Small utility module for compling HTML templates or pre-processed CSS.
*
* @author: [@jasonsims]('https://github.com/jasonsims')
*/
import {extname, dirname, basename} from 'path'
import cons from 'consolidate'
import P from 'bluebird'
var engineMap = {
// HTML Template engines
'html': renderDefault,
'hbs': cons.handlebars.render,
'njk': cons.nunjucks.render,
'emblem': renderEmblem,
// CSS pre-processors
'less': renderLess,
'stylus': renderStylus,
'styl': renderStyl,
'sass': renderSass,
'scss': renderSass,
// Handle plain CSS also
'css': renderDefault,
// Handle plain text
'txt': renderDefault,
// Handle missing extension
'': renderDefault
}
import express from 'express';
import httpProxy from 'http-proxy';
import errorHandler from 'errorhandler';
import path from 'path';
import consolidate from 'consolidate';
import { RouteErrors } from '../app/core/constants';
import { routeUrl, renderRouter } from './react-renderer';
const app = express();
let server;
app.engine('hbs', consolidate.handlebars);
app.set('views', __dirname + '/views');
app.set('view engine', 'hbs');
app.use(errorHandler({
dumpExceptions: true,
showStack: true
}));
app.get('/assets*', function (req, res) {
if (process.env.NODE_ENV == 'development') {
// When webpack is running
let proxy = httpProxy.createProxyServer();
proxy.web(req, res, {target: 'http://localhost:3001'});
} else {
res.sendFile(req.path.substr(7), { root: path.join(__dirname + '/../dist') });
}
const APP_ROOT = path.join(__dirname, '../../');
const IS_DEVELOPMENT = process.env.NODE_ENV === 'development';
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const app = express();
app.use(compression());
app.use(bodyParser.json());
/* ------------------------------------------ *
* Rendering configuration
* ------------------------------------------ */
// use handlebars as the html engine renderer
app.engine('hbs', consolidate.handlebars);
app.set('view engine', 'hbs');
/*
* Notice that the views is set within the 'build' directory. This
* was done to use the files that have been processed by Webpack
* (which occurs in both the development and production environments).
*/
app.set('views', path.join(APP_ROOT, 'build', 'views'));
// this is required to get babel (server side) to process css-modules
hook({
extensions: ['.scss', '.css'],
generateScopedName: config.webpack.localIdentName,
preprocessCss: (data, file) => sass.renderSync({ file }).css,
});
return Path.basename(file, Path.extname(file)) === 'footer';
});
if (header) {
viewModel.partials.header = getRelativePartial(header);
}
if (content) {
viewModel.partials.content = getRelativePartial(content);
}
if (footer) {
viewModel.partials.footer = getRelativePartial(footer);
}
Consolidate.handlebars(Path.join(hbTemplatePath, 'card.hbs'), viewModel, function (err, html) {
if (!err) {
callback && callback(html);
}
else {
console.error('TEMPLATES: Error generating view from Handlebars file card.hbs', err);
callback && callback();
}
});
}
return function documentation (req, res, next) {
Consolidate.handlebars(template, context, function renderCb (err, html) {
if (err) {
return next(err);
}
res.send(html);
});
};
}
module.exports = function (err, req, res, next) {
var tpl = path.resolve(__dirname, '../views/error.hbs');
var data = {
error: err,
route: req._fds.route,
method: req.method,
query: req.query,
match: req._fds.match,
config: req._fds.config
};
cons.handlebars(tpl, data, function (err, html) {
res.status(req._err || 500).send(html);
});
};
'fn': function (deferred) {
consolidate.handlebars(path.join(__dirname, 'views/includes/handlebars.html'), getData(), function (err, html) {
if (err) {
throw err;
}
deferred.resolve();
});
}
});