2017-12-14 14:41:57 -07:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as glob from 'glob';
|
|
|
|
import * as yaml from 'js-yaml';
|
2017-12-16 22:35:30 -07:00
|
|
|
|
|
|
|
import { fa } from '../../common/build/fa';
|
2017-12-15 09:06:28 -07:00
|
|
|
import config from '../../conf';
|
2017-12-31 10:08:41 -07:00
|
|
|
import { licenseHtml } from '../../common/build/license';
|
2017-12-16 12:31:24 -07:00
|
|
|
const constants = require('../../const.json');
|
2017-12-14 14:41:57 -07:00
|
|
|
|
2017-12-16 12:02:30 -07:00
|
|
|
export default function(): { [key: string]: any } {
|
|
|
|
const vars = {} as { [key: string]: any };
|
2017-12-14 14:41:57 -07:00
|
|
|
|
|
|
|
const endpoints = glob.sync('./src/web/docs/api/endpoints/**/*.yaml');
|
|
|
|
vars['endpoints'] = endpoints.map(ep => {
|
|
|
|
const _ep = yaml.safeLoad(fs.readFileSync(ep, 'utf-8'));
|
|
|
|
return _ep.endpoint;
|
|
|
|
});
|
|
|
|
|
|
|
|
const entities = glob.sync('./src/web/docs/api/entities/**/*.yaml');
|
|
|
|
vars['entities'] = entities.map(x => {
|
|
|
|
const _x = yaml.safeLoad(fs.readFileSync(x, 'utf-8'));
|
|
|
|
return _x.name;
|
|
|
|
});
|
|
|
|
|
|
|
|
const docs = glob.sync('./src/web/docs/**/*.*.pug');
|
|
|
|
vars['docs'] = {};
|
|
|
|
docs.forEach(x => {
|
|
|
|
const [, name, lang] = x.match(/docs\/(.+?)\.(.+?)\.pug$/);
|
|
|
|
if (vars['docs'][name] == null) {
|
|
|
|
vars['docs'][name] = {
|
|
|
|
name,
|
|
|
|
title: {}
|
|
|
|
};
|
|
|
|
}
|
2017-12-15 08:19:10 -07:00
|
|
|
vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1];
|
2017-12-14 14:41:57 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
vars['kebab'] = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
|
|
|
|
|
2017-12-15 09:06:28 -07:00
|
|
|
vars['config'] = config;
|
|
|
|
|
2017-12-16 12:31:24 -07:00
|
|
|
vars['copyright'] = constants.copyright;
|
|
|
|
|
2017-12-16 22:35:30 -07:00
|
|
|
vars['facss'] = fa.dom.css();
|
|
|
|
|
2017-12-31 10:08:41 -07:00
|
|
|
vars['license'] = licenseHtml;
|
|
|
|
|
2017-12-14 14:41:57 -07:00
|
|
|
return vars;
|
|
|
|
}
|