/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/plugins/console/render.ts
52 строки
1 KB
D-Sketon
refactor: refactor types & support warehouse6 (#5483)
22 янв 2025, 10:05
Не верифицирован
22 янв 2025, 10:05
70efca7
Код
Авторство
О чём код?
import { resolve } from 'path'; import tildify from 'tildify'; import prettyHrtime from 'pretty-hrtime'; import { writeFile } from 'hexo-fs'; import { cyan, magenta } from 'picocolors'; import type Hexo from '../../hexo'; import type Promise from 'bluebird'; interface RenderArgs { _: string[] o?: string output?: string pretty?: boolean engine?: string [key: string]: any } function renderConsole(this: Hexo, args: RenderArgs): Promise<void> { // Display help message if user didn't input any arguments if (!args._.length) { return this.call('help', {_: 'render'}); } const baseDir = this.base_dir; const src = resolve(baseDir, args._[0]); const output = args.o || args.output; const start = process.hrtime(); const { log } = this; return this.render.render({ path: src, engine: args.engine }).then(result => { if (typeof result === 'object') { if (args.pretty) { result = JSON.stringify(result, null, ' '); } else { result = JSON.stringify(result); } } if (!output) return console.log(result); const dest = resolve(baseDir, output); const interval = prettyHrtime(process.hrtime(start)); log.info('Rendered in %s: %s -> %s', cyan(interval), magenta(tildify(src)), magenta(tildify(dest))); return writeFile(dest, result); }); } export = renderConsole;