2017-12-14 22:41:57 +01:00
|
|
|
/**
|
|
|
|
* 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 mkdirp from 'mkdirp';
|
|
|
|
import stylus = require('gulp-stylus');
|
|
|
|
import cssnano = require('gulp-cssnano');
|
|
|
|
|
2018-03-29 13:32:18 +02:00
|
|
|
import I18nReplacer from '../../build/i18n';
|
|
|
|
import fa from '../../build/fa';
|
2017-12-14 22:41:57 +01:00
|
|
|
import generateVars from './vars';
|
|
|
|
|
|
|
|
require('./api/gulpfile.ts');
|
|
|
|
|
|
|
|
gulp.task('doc', [
|
|
|
|
'doc:docs',
|
|
|
|
'doc:api',
|
|
|
|
'doc:styles'
|
|
|
|
]);
|
|
|
|
|
2018-01-07 17:47:56 +01:00
|
|
|
gulp.task('doc:docs', async () => {
|
|
|
|
const commonVars = await generateVars();
|
2017-12-14 22:41:57 +01:00
|
|
|
|
2018-03-29 13:32:18 +02:00
|
|
|
glob('./src/client/docs/**/*.*.pug', (globErr, files) => {
|
2017-12-14 22:41:57 +01:00
|
|
|
if (globErr) {
|
|
|
|
console.error(globErr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
files.forEach(file => {
|
|
|
|
const [, name, lang] = file.match(/docs\/(.+?)\.(.+?)\.pug$/);
|
|
|
|
const vars = {
|
|
|
|
common: commonVars,
|
2017-12-15 16:19:10 +01:00
|
|
|
lang: lang,
|
2017-12-16 20:02:30 +01:00
|
|
|
title: fs.readFileSync(file, 'utf-8').match(/^h1 (.+?)\r?\n/)[1],
|
2018-03-29 13:32:18 +02:00
|
|
|
src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/${name}.${lang}.pug`,
|
2017-12-14 22:41:57 +01:00
|
|
|
};
|
2017-12-15 16:19:10 +01:00
|
|
|
pug.renderFile(file, vars, (renderErr, content) => {
|
2017-12-14 22:41:57 +01:00
|
|
|
if (renderErr) {
|
|
|
|
console.error(renderErr);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-15 16:19:10 +01:00
|
|
|
|
2018-03-29 13:32:18 +02:00
|
|
|
pug.renderFile('./src/client/docs/layout.pug', Object.assign({}, vars, {
|
2017-12-15 16:19:10 +01:00
|
|
|
content
|
|
|
|
}), (renderErr2, html) => {
|
|
|
|
if (renderErr2) {
|
|
|
|
console.error(renderErr2);
|
2017-12-14 22:41:57 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-12-17 06:35:30 +01:00
|
|
|
const i18n = new I18nReplacer(lang);
|
2018-05-18 03:34:48 +02:00
|
|
|
html = html.replace(i18n.pattern, i18n.replacement);
|
2017-12-17 06:35:30 +01:00
|
|
|
html = fa(html);
|
2018-03-29 13:32:18 +02:00
|
|
|
const htmlPath = `./built/client/docs/${lang}/${name}.html`;
|
2017-12-15 16:19:10 +01:00
|
|
|
mkdirp(path.dirname(htmlPath), (mkdirErr) => {
|
|
|
|
if (mkdirErr) {
|
|
|
|
console.error(mkdirErr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fs.writeFileSync(htmlPath, html, 'utf-8');
|
|
|
|
});
|
2017-12-14 22:41:57 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('doc:styles', () =>
|
2018-03-29 13:32:18 +02:00
|
|
|
gulp.src('./src/client/docs/**/*.styl')
|
2017-12-14 22:41:57 +01:00
|
|
|
.pipe(stylus())
|
|
|
|
.pipe((cssnano as any)())
|
2018-03-29 13:32:18 +02:00
|
|
|
.pipe(gulp.dest('./built/client/docs/assets/'))
|
2017-12-14 22:41:57 +01:00
|
|
|
);
|