Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / build-scripts / render-embedded-chat.js
bloba3beca82da9ed7026ee57e80d4541fe102b39ec9
1 #!/usr/bin/env node
2 'use strict';
4 const Promise = require('bluebird');
5 const express = require('express');
6 const fs = require('fs-extra');
7 const outputFile = Promise.promisify(fs.outputFile);
8 const expressHbs = require('express-hbs');
9 const resolveStatic = require('../server/web/resolve-static');
10 require('../server/web/register-helpers')(expressHbs);
11 const shutdown = require('shutdown');
13 var opts = require('yargs')
14 .option('output', {
15 alias: 'o',
16 required: true,
17 description: 'Output'
19 .option('android', {
20 type: 'boolean',
21 default: false,
22 description: 'Output'
24 .help('help')
25 .alias('help', 'h').argv;
27 function die(err) {
28 console.error('Unable to render', err);
29 process.exit(1);
32 const app = express();
34 app.engine(
35 'hbs',
36 expressHbs.express3({
37 partialsDir: resolveStatic('/templates/partials'),
38 onCompile: function(exhbs, source) {
39 return exhbs.handlebars.compile(source, { preventIndent: true });
41 layoutsDir: resolveStatic('/layouts'),
42 contentHelperName: 'content'
46 app.set('view engine', 'hbs');
47 app.set('views', resolveStatic('/templates'));
49 app.render(
50 'mobile/native-embedded-chat-app',
52 isAndroidBuild: opts.android
54 function(err, html) {
55 if (err) {
56 die(err);
59 outputFile(opts.output, html, { encoding: 'utf8' })
60 .catch(die)
61 .then(() => {
62 shutdown.shutdownGracefully();
63 });