2017-12-14 21:41:57 +00:00
|
|
|
import * as fs from 'fs';
|
2018-01-07 16:47:56 +00:00
|
|
|
import * as util from 'util';
|
2017-12-14 21:41:57 +00:00
|
|
|
import * as glob from 'glob';
|
|
|
|
import * as yaml from 'js-yaml';
|
2018-01-07 16:47:56 +00:00
|
|
|
import * as licenseChecker from 'license-checker';
|
|
|
|
import * as tmp from 'tmp';
|
2017-12-17 05:35:30 +00:00
|
|
|
|
2018-03-29 11:32:18 +00:00
|
|
|
import { fa } from '../../build/fa';
|
2018-04-02 04:15:53 +00:00
|
|
|
import config from '../../config';
|
2018-03-29 11:32:18 +00:00
|
|
|
import { licenseHtml } from '../../build/license';
|
|
|
|
const constants = require('../../const.json');
|
2017-12-14 21:41:57 +00:00
|
|
|
|
2018-01-07 16:47:56 +00:00
|
|
|
export default async function(): Promise<{ [key: string]: any }> {
|
2017-12-16 19:02:30 +00:00
|
|
|
const vars = {} as { [key: string]: any };
|
2017-12-14 21:41:57 +00:00
|
|
|
|
2018-03-29 11:32:18 +00:00
|
|
|
const endpoints = glob.sync('./src/client/docs/api/endpoints/**/*.yaml');
|
2017-12-14 21:41:57 +00:00
|
|
|
vars['endpoints'] = endpoints.map(ep => {
|
|
|
|
const _ep = yaml.safeLoad(fs.readFileSync(ep, 'utf-8'));
|
|
|
|
return _ep.endpoint;
|
|
|
|
});
|
|
|
|
|
2018-03-29 11:32:18 +00:00
|
|
|
const entities = glob.sync('./src/client/docs/api/entities/**/*.yaml');
|
2017-12-14 21:41:57 +00:00
|
|
|
vars['entities'] = entities.map(x => {
|
|
|
|
const _x = yaml.safeLoad(fs.readFileSync(x, 'utf-8'));
|
|
|
|
return _x.name;
|
|
|
|
});
|
|
|
|
|
2018-03-29 11:32:18 +00:00
|
|
|
const docs = glob.sync('./src/client/docs/**/*.*.pug');
|
2017-12-14 21:41:57 +00:00
|
|
|
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 15:19:10 +00:00
|
|
|
vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1];
|
2017-12-14 21:41:57 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
vars['kebab'] = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
|
|
|
|
|
2017-12-15 16:06:28 +00:00
|
|
|
vars['config'] = config;
|
|
|
|
|
2017-12-16 19:31:24 +00:00
|
|
|
vars['copyright'] = constants.copyright;
|
|
|
|
|
2017-12-17 05:35:30 +00:00
|
|
|
vars['facss'] = fa.dom.css();
|
|
|
|
|
2017-12-31 17:08:41 +00:00
|
|
|
vars['license'] = licenseHtml;
|
|
|
|
|
2018-01-07 16:47:56 +00:00
|
|
|
const tmpObj = tmp.fileSync();
|
|
|
|
fs.writeFileSync(tmpObj.name, JSON.stringify({
|
|
|
|
licenseText: ''
|
|
|
|
}), 'utf-8');
|
|
|
|
const dependencies = await util.promisify(licenseChecker.init).bind(licenseChecker)({
|
2018-03-29 11:32:18 +00:00
|
|
|
start: __dirname + '/../../../',
|
2018-01-07 16:47:56 +00:00
|
|
|
customPath: tmpObj.name
|
|
|
|
});
|
|
|
|
tmpObj.removeCallback();
|
|
|
|
|
|
|
|
vars['dependencies'] = dependencies;
|
|
|
|
|
2017-12-14 21:41:57 +00:00
|
|
|
return vars;
|
|
|
|
}
|