summaryrefslogtreecommitdiff
path: root/src/web/docs/api/endpoints/gulpfile.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-12-14 16:24:41 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-12-14 16:24:41 +0900
commit5166fc92b64af25946b9c5a55ee05cebca0d24fa (patch)
tree76f81e15699273bf2baa2dc3e237adc95a097183 /src/web/docs/api/endpoints/gulpfile.ts
parentMerge branch 'master' of https://github.com/syuilo/misskey (diff)
downloadsharkey-5166fc92b64af25946b9c5a55ee05cebca0d24fa.tar.gz
sharkey-5166fc92b64af25946b9c5a55ee05cebca0d24fa.tar.bz2
sharkey-5166fc92b64af25946b9c5a55ee05cebca0d24fa.zip
:pizza:
Diffstat (limited to 'src/web/docs/api/endpoints/gulpfile.ts')
-rw-r--r--src/web/docs/api/endpoints/gulpfile.ts75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/web/docs/api/endpoints/gulpfile.ts b/src/web/docs/api/endpoints/gulpfile.ts
new file mode 100644
index 0000000000..a2c3944709
--- /dev/null
+++ b/src/web/docs/api/endpoints/gulpfile.ts
@@ -0,0 +1,75 @@
+/**
+ * Gulp tasks
+ */
+
+import * as fs from 'fs';
+import * as path from 'path';
+import * as glob from 'glob';
+import * as gulp from 'gulp';
+import * as pug from 'pug';
+import * as yaml from 'js-yaml';
+import * as mkdirp from 'mkdirp';
+
+import config from './../../../../conf';
+
+const parseParam = param => {
+ const id = param.type.match(/^id\((.+?)\)/);
+ const object = param.type.match(/^object\((.+?)\)/);
+ const isArray = /\[\]$/.test(param.type);
+ if (id) {
+ param.kind = 'id';
+ param.type = 'string';
+ param.entity = id[1];
+ if (isArray) {
+ param.type += '[]';
+ }
+ }
+ if (object) {
+ param.kind = 'object';
+ param.type = 'object';
+ param.def = object[1];
+ if (isArray) {
+ param.type += '[]';
+ }
+ }
+
+ return param;
+};
+
+gulp.task('doc:endpoints', () => {
+ glob('./src/web/docs/api/endpoints/**/*.yaml', (globErr, files) => {
+ if (globErr) {
+ console.error(globErr);
+ return;
+ }
+ //console.log(files);
+ files.forEach(file => {
+ const ep = yaml.safeLoad(fs.readFileSync(file, 'utf-8'));
+ const vars = {
+ endpoint: ep.endpoint,
+ url: `${config.api_url}/${ep.endpoint}`,
+ desc: ep.desc,
+ params: ep.params.map(p => parseParam(p)),
+ paramDefs: Object.keys(ep.paramDefs).map(key => ({
+ name: key,
+ params: ep.paramDefs[key].map(p => parseParam(p))
+ })),
+ res: ep.res.map(p => parseParam(p))
+ };
+ pug.renderFile('./src/web/docs/api/endpoints/view.pug', vars, (renderErr, html) => {
+ if (renderErr) {
+ console.error(renderErr);
+ return;
+ }
+ const htmlPath = `./built/web/docs/api/endpoints/${ep.endpoint}.html`;
+ mkdirp(path.dirname(htmlPath), (mkdirErr) => {
+ if (mkdirErr) {
+ console.error(mkdirErr);
+ return;
+ }
+ fs.writeFileSync(htmlPath, html, 'utf-8');
+ });
+ });
+ });
+ });
+});