summaryrefslogtreecommitdiff
path: root/src/web/docs/gulpfile.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-02-05 03:59:29 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-02-05 03:59:29 +0900
commitdbd3cdb308d2edf600b20a8b632045c6163ae326 (patch)
treede3630065fcddeb1916668ef3b0b43a219340e2e /src/web/docs/gulpfile.ts
parentFix (diff)
parentMerge pull request #1097 from syuilo/refactor (diff)
downloadmisskey-dbd3cdb308d2edf600b20a8b632045c6163ae326.tar.gz
misskey-dbd3cdb308d2edf600b20a8b632045c6163ae326.tar.bz2
misskey-dbd3cdb308d2edf600b20a8b632045c6163ae326.zip
Merge remote-tracking branch 'refs/remotes/origin/master' into vue-#972
Diffstat (limited to 'src/web/docs/gulpfile.ts')
-rw-r--r--src/web/docs/gulpfile.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/web/docs/gulpfile.ts b/src/web/docs/gulpfile.ts
new file mode 100644
index 0000000000..d5ddda108d
--- /dev/null
+++ b/src/web/docs/gulpfile.ts
@@ -0,0 +1,77 @@
+/**
+ * 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');
+
+import I18nReplacer from '../../common/build/i18n';
+import fa from '../../common/build/fa';
+import generateVars from './vars';
+
+require('./api/gulpfile.ts');
+
+gulp.task('doc', [
+ 'doc:docs',
+ 'doc:api',
+ 'doc:styles'
+]);
+
+gulp.task('doc:docs', async () => {
+ const commonVars = await generateVars();
+
+ 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,
+ lang: lang,
+ 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`,
+ };
+ pug.renderFile(file, vars, (renderErr, content) => {
+ if (renderErr) {
+ console.error(renderErr);
+ return;
+ }
+
+ pug.renderFile('./src/web/docs/layout.pug', Object.assign({}, vars, {
+ content
+ }), (renderErr2, html) => {
+ if (renderErr2) {
+ console.error(renderErr2);
+ return;
+ }
+ const i18n = new I18nReplacer(lang);
+ html = html.replace(i18n.pattern, i18n.replacement);
+ html = fa(html);
+ 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');
+ });
+ });
+ });
+ });
+ });
+});
+
+gulp.task('doc:styles', () =>
+ gulp.src('./src/web/docs/**/*.styl')
+ .pipe(stylus())
+ .pipe((cssnano as any)())
+ .pipe(gulp.dest('./built/web/docs/assets/'))
+);