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