summaryrefslogtreecommitdiff
path: root/src/web/docs/api/gulpfile.ts
diff options
context:
space:
mode:
authorAkihiko Odaki <nekomanma@pixiv.co.jp>2018-03-29 01:20:40 +0900
committerAkihiko Odaki <nekomanma@pixiv.co.jp>2018-03-29 01:54:41 +0900
commit90f8fe7e538bb7e52d2558152a0390e693f39b11 (patch)
tree0f830887053c8f352b1cd0c13ca715fd14c1f030 /src/web/docs/api/gulpfile.ts
parentImplement remote account resolution (diff)
downloadsharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.gz
sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.bz2
sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.zip
Introduce processor
Diffstat (limited to 'src/web/docs/api/gulpfile.ts')
-rw-r--r--src/web/docs/api/gulpfile.ts188
1 files changed, 0 insertions, 188 deletions
diff --git a/src/web/docs/api/gulpfile.ts b/src/web/docs/api/gulpfile.ts
deleted file mode 100644
index cd1bf15307..0000000000
--- a/src/web/docs/api/gulpfile.ts
+++ /dev/null
@@ -1,188 +0,0 @@
-/**
- * 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 locales from '../../../../locales';
-import I18nReplacer from '../../../common/build/i18n';
-import fa from '../../../common/build/fa';
-import config from './../../../conf';
-
-import generateVars from '../vars';
-
-const langs = Object.keys(locales);
-
-const kebab = string => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
-
-const parseParam = param => {
- const id = param.type.match(/^id\((.+?)\)|^id/);
- const entity = param.type.match(/^entity\((.+?)\)/);
- const isObject = /^object/.test(param.type);
- const isDate = /^date/.test(param.type);
- const isArray = /\[\]$/.test(param.type);
- if (id) {
- param.kind = 'id';
- param.type = 'string';
- param.entity = id[1];
- if (isArray) {
- param.type += '[]';
- }
- }
- if (entity) {
- param.kind = 'entity';
- param.type = 'object';
- param.entity = entity[1];
- if (isArray) {
- param.type += '[]';
- }
- }
- if (isObject) {
- param.kind = 'object';
- }
- if (isDate) {
- param.kind = 'date';
- param.type = 'string';
- if (isArray) {
- param.type += '[]';
- }
- }
-
- return param;
-};
-
-const sortParams = params => {
- params.sort((a, b) => {
- if (a.name < b.name)
- return -1;
- if (a.name > b.name)
- return 1;
- return 0;
- });
- return params;
-};
-
-const extractDefs = params => {
- let defs = [];
-
- params.forEach(param => {
- if (param.def) {
- defs.push({
- name: param.defName,
- params: sortParams(param.def.map(p => parseParam(p)))
- });
-
- const childDefs = extractDefs(param.def);
-
- defs = defs.concat(childDefs);
- }
- });
-
- return sortParams(defs);
-};
-
-gulp.task('doc:api', [
- 'doc:api:endpoints',
- 'doc:api:entities'
-]);
-
-gulp.task('doc:api:endpoints', async () => {
- const commonVars = await generateVars();
- 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: {
- host: config.api_url,
- path: ep.endpoint
- },
- desc: ep.desc,
- params: sortParams(ep.params.map(p => parseParam(p))),
- paramDefs: extractDefs(ep.params),
- res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null,
- resDefs: ep.res ? extractDefs(ep.res) : null,
- };
- langs.forEach(lang => {
- pug.renderFile('./src/web/docs/api/endpoints/view.pug', Object.assign({}, vars, {
- lang,
- title: ep.endpoint,
- src: `https://github.com/syuilo/misskey/tree/master/src/web/docs/api/endpoints/${ep.endpoint}.yaml`,
- kebab,
- common: commonVars
- }), (renderErr, html) => {
- if (renderErr) {
- console.error(renderErr);
- return;
- }
- const i18n = new I18nReplacer(lang);
- html = html.replace(i18n.pattern, i18n.replacement);
- html = fa(html);
- const htmlPath = `./built/web/docs/${lang}/api/endpoints/${ep.endpoint}.html`;
- mkdirp(path.dirname(htmlPath), (mkdirErr) => {
- if (mkdirErr) {
- console.error(mkdirErr);
- return;
- }
- fs.writeFileSync(htmlPath, html, 'utf-8');
- });
- });
- });
- });
- });
-});
-
-gulp.task('doc:api:entities', async () => {
- const commonVars = await generateVars();
- glob('./src/web/docs/api/entities/**/*.yaml', (globErr, files) => {
- if (globErr) {
- console.error(globErr);
- return;
- }
- files.forEach(file => {
- const entity = yaml.safeLoad(fs.readFileSync(file, 'utf-8'));
- const vars = {
- name: entity.name,
- desc: entity.desc,
- props: sortParams(entity.props.map(p => parseParam(p))),
- propDefs: extractDefs(entity.props),
- };
- langs.forEach(lang => {
- pug.renderFile('./src/web/docs/api/entities/view.pug', Object.assign({}, vars, {
- lang,
- title: entity.name,
- src: `https://github.com/syuilo/misskey/tree/master/src/web/docs/api/entities/${kebab(entity.name)}.yaml`,
- kebab,
- common: commonVars
- }), (renderErr, html) => {
- if (renderErr) {
- console.error(renderErr);
- return;
- }
- const i18n = new I18nReplacer(lang);
- html = html.replace(i18n.pattern, i18n.replacement);
- html = fa(html);
- const htmlPath = `./built/web/docs/${lang}/api/entities/${kebab(entity.name)}.html`;
- mkdirp(path.dirname(htmlPath), (mkdirErr) => {
- if (mkdirErr) {
- console.error(mkdirErr);
- return;
- }
- fs.writeFileSync(htmlPath, html, 'utf-8');
- });
- });
- });
- });
- });
-});