From 8bf2b692397fd91b290c12322fb6b3a567fbdc01 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 00:37:38 +0800 Subject: [PATCH 01/45] refactor: esm --- lib/box/file.js | 4 +- lib/box/index.js | 18 +++--- lib/extend/console.js | 6 +- lib/extend/deployer.js | 4 +- lib/extend/filter.js | 4 +- lib/extend/generator.js | 4 +- lib/extend/helper.js | 2 +- lib/extend/index.js | 24 +++---- lib/extend/injector.js | 4 +- lib/extend/migrator.js | 4 +- lib/extend/processor.js | 6 +- lib/extend/renderer.js | 6 +- lib/extend/tag.js | 10 +-- lib/hexo/default_config.js | 2 +- lib/hexo/index.js | 64 +++++++++++-------- lib/hexo/load_config.js | 20 +++--- lib/hexo/load_database.js | 6 +- lib/hexo/load_plugins.js | 10 +-- lib/hexo/load_theme_config.js | 12 ++-- lib/hexo/locals.js | 4 +- lib/hexo/multi_config_path.js | 12 ++-- lib/hexo/post.js | 20 +++--- lib/hexo/register_models.js | 4 +- lib/hexo/render.js | 8 +-- lib/hexo/router.js | 8 +-- lib/hexo/scaffold.js | 6 +- lib/hexo/source.js | 4 +- lib/hexo/update_package.js | 6 +- lib/models/asset.js | 6 +- lib/models/cache.js | 6 +- lib/models/category.js | 6 +- lib/models/data.js | 4 +- lib/models/index.js | 22 +++---- lib/models/page.js | 12 ++-- lib/models/post.js | 14 ++-- lib/models/post_asset.js | 6 +- lib/models/post_category.js | 4 +- lib/models/post_tag.js | 4 +- lib/models/tag.js | 6 +- lib/models/types/moment.js | 6 +- lib/plugins/console/clean.js | 6 +- lib/plugins/console/config.js | 10 +-- lib/plugins/console/deploy.js | 6 +- lib/plugins/console/generate.js | 18 +++--- lib/plugins/console/index.js | 2 +- lib/plugins/console/list/category.js | 8 +-- lib/plugins/console/list/common.js | 6 +- lib/plugins/console/list/index.js | 14 ++-- lib/plugins/console/list/page.js | 8 +-- lib/plugins/console/list/post.js | 8 +-- lib/plugins/console/list/route.js | 4 +- lib/plugins/console/list/tag.js | 8 +-- lib/plugins/console/migrate.js | 4 +- lib/plugins/console/new.js | 8 +-- lib/plugins/console/publish.js | 6 +- lib/plugins/console/render.js | 12 ++-- .../filter/after_post_render/excerpt.js | 2 +- .../filter/after_post_render/external_link.js | 4 +- lib/plugins/filter/after_post_render/index.js | 2 +- .../filter/after_render/external_link.js | 4 +- lib/plugins/filter/after_render/index.js | 2 +- .../filter/after_render/meta_generator.js | 2 +- lib/plugins/filter/before_exit/index.js | 2 +- .../filter/before_exit/save_database.js | 2 +- lib/plugins/filter/before_generate/index.js | 2 +- .../filter/before_generate/render_post.js | 4 +- .../before_post_render/backtick_code_block.js | 2 +- .../filter/before_post_render/index.js | 2 +- .../filter/before_post_render/titlecase.js | 2 +- lib/plugins/filter/index.js | 2 +- lib/plugins/filter/new_post_path.js | 12 ++-- lib/plugins/filter/post_permalink.js | 6 +- lib/plugins/filter/template_locals/i18n.js | 4 +- lib/plugins/filter/template_locals/index.js | 2 +- lib/plugins/generator/asset.js | 10 +-- lib/plugins/generator/index.js | 2 +- lib/plugins/generator/page.js | 2 +- lib/plugins/generator/post.js | 2 +- lib/plugins/helper/css.js | 6 +- lib/plugins/helper/date.js | 20 +++--- lib/plugins/helper/debug.js | 6 +- lib/plugins/helper/favicon_tag.js | 4 +- lib/plugins/helper/feed_tag.js | 6 +- lib/plugins/helper/format.js | 28 ++++---- lib/plugins/helper/fragment_cache.js | 4 +- lib/plugins/helper/full_url_for.js | 4 +- lib/plugins/helper/gravatar.js | 5 +- lib/plugins/helper/image_tag.js | 4 +- lib/plugins/helper/index.js | 2 +- lib/plugins/helper/is.js | 20 +++--- lib/plugins/helper/js.js | 6 +- lib/plugins/helper/link_to.js | 4 +- lib/plugins/helper/list_archives.js | 6 +- lib/plugins/helper/list_categories.js | 4 +- lib/plugins/helper/list_posts.js | 4 +- lib/plugins/helper/list_tags.js | 6 +- lib/plugins/helper/mail_to.js | 6 +- lib/plugins/helper/markdown.js | 2 +- lib/plugins/helper/meta_generator.js | 2 +- lib/plugins/helper/number_format.js | 2 +- lib/plugins/helper/open_graph.js | 8 +-- lib/plugins/helper/paginator.js | 4 +- lib/plugins/helper/partial.js | 6 +- lib/plugins/helper/relative_url.js | 4 +- lib/plugins/helper/render.js | 4 +- lib/plugins/helper/search_form.js | 4 +- lib/plugins/helper/tagcloud.js | 6 +- lib/plugins/helper/toc.js | 4 +- lib/plugins/helper/url_for.js | 4 +- lib/plugins/injector/index.js | 2 +- lib/plugins/processor/asset.js | 16 ++--- lib/plugins/processor/common.js | 24 +++---- lib/plugins/processor/data.js | 6 +- lib/plugins/processor/index.js | 2 +- lib/plugins/processor/post.js | 16 ++--- lib/plugins/renderer/index.js | 2 +- lib/plugins/renderer/json.js | 2 +- lib/plugins/renderer/nunjucks.js | 8 +-- lib/plugins/renderer/plain.js | 2 +- lib/plugins/renderer/yaml.js | 8 +-- lib/plugins/tag/asset_img.js | 6 +- lib/plugins/tag/asset_link.js | 4 +- lib/plugins/tag/asset_path.js | 4 +- lib/plugins/tag/blockquote.js | 6 +- lib/plugins/tag/code.js | 6 +- lib/plugins/tag/iframe.js | 4 +- lib/plugins/tag/img.js | 4 +- lib/plugins/tag/include_code.js | 8 +-- lib/plugins/tag/index.js | 8 +-- lib/plugins/tag/link.js | 4 +- lib/plugins/tag/post_link.js | 6 +- lib/plugins/tag/post_path.js | 6 +- lib/plugins/tag/pullquote.js | 4 +- lib/theme/index.js | 10 +-- lib/theme/processors/config.js | 8 +-- lib/theme/processors/i18n.js | 10 +-- lib/theme/processors/source.js | 10 +-- lib/theme/processors/view.js | 8 +-- lib/theme/view.js | 8 +-- 139 files changed, 499 insertions(+), 488 deletions(-) diff --git a/lib/box/file.js b/lib/box/file.js index 87ae2ba5f2..d1f6192166 100644 --- a/lib/box/file.js +++ b/lib/box/file.js @@ -1,6 +1,6 @@ 'use strict'; -const { readFile, readFileSync, stat, statSync } = require('hexo-fs'); +import {readFile, readFileSync, stat, statSync} from 'hexo-fs'; class File { constructor({ source, path, params, type }) { @@ -32,4 +32,4 @@ File.TYPE_UPDATE = 'update'; File.TYPE_SKIP = 'skip'; File.TYPE_DELETE = 'delete'; -module.exports = File; +export default File; diff --git a/lib/box/index.js b/lib/box/index.js index 2975570b8c..e4ee6fc90c 100644 --- a/lib/box/index.js +++ b/lib/box/index.js @@ -1,13 +1,13 @@ 'use strict'; -const { join, sep } = require('path'); -const Promise = require('bluebird'); -const File = require('./file'); -const { Pattern, createSha1Hash } = require('hexo-util'); -const { createReadStream, readdir, stat, watch } = require('hexo-fs'); -const { magenta } = require('picocolors'); -const { EventEmitter } = require('events'); -const { isMatch, makeRe } = require('micromatch'); +import {join, sep} from 'path'; +import Promise from 'bluebird'; +import File from './file'; +import {Pattern, createSha1Hash} from 'hexo-util'; +import {createReadStream, readdir, stat, watch} from 'hexo-fs'; +import {magenta} from 'picocolors'; +import {EventEmitter} from 'events'; +import {isMatch, makeRe} from 'micromatch'; const defaultPattern = new Pattern(() => ({})); @@ -272,4 +272,4 @@ function readDirWalker(ctx, base, results, ignore, prefix) { }); } -module.exports = Box; +export default Box; diff --git a/lib/extend/console.js b/lib/extend/console.js index 3c2765ddac..371bb61f04 100644 --- a/lib/extend/console.js +++ b/lib/extend/console.js @@ -1,7 +1,7 @@ 'use strict'; -const Promise = require('bluebird'); -const abbrev = require('abbrev'); +import Promise from 'bluebird'; +import abbrev from 'abbrev'; /** * Console plugin option @@ -82,4 +82,4 @@ class Console { } } -module.exports = Console; +export default Console; diff --git a/lib/extend/deployer.js b/lib/extend/deployer.js index 4653662f08..60615b6ad0 100644 --- a/lib/extend/deployer.js +++ b/lib/extend/deployer.js @@ -1,6 +1,6 @@ 'use strict'; -const Promise = require('bluebird'); +import Promise from 'bluebird'; class Deployer { constructor() { @@ -29,4 +29,4 @@ class Deployer { } } -module.exports = Deployer; +export default Deployer; diff --git a/lib/extend/filter.js b/lib/extend/filter.js index 520b22668e..1354233812 100644 --- a/lib/extend/filter.js +++ b/lib/extend/filter.js @@ -1,6 +1,6 @@ 'use strict'; -const Promise = require('bluebird'); +import Promise from 'bluebird'; const typeAlias = { pre: 'before_post_render', @@ -89,4 +89,4 @@ class Filter { } } -module.exports = Filter; +export default Filter; diff --git a/lib/extend/generator.js b/lib/extend/generator.js index 6a0c087703..903e6735ab 100644 --- a/lib/extend/generator.js +++ b/lib/extend/generator.js @@ -1,6 +1,6 @@ 'use strict'; -const Promise = require('bluebird'); +import Promise from 'bluebird'; class Generator { constructor() { @@ -31,4 +31,4 @@ class Generator { } } -module.exports = Generator; +export default Generator; diff --git a/lib/extend/helper.js b/lib/extend/helper.js index d8c6156d4c..60ebd5d050 100644 --- a/lib/extend/helper.js +++ b/lib/extend/helper.js @@ -34,4 +34,4 @@ class Helper { } } -module.exports = Helper; +export default Helper; diff --git a/lib/extend/index.js b/lib/extend/index.js index f4ddd1a2e5..e5fcd71b32 100644 --- a/lib/extend/index.js +++ b/lib/extend/index.js @@ -1,17 +1,17 @@ 'use strict'; -const Console = require('./console'); -const Deployer = require('./deployer'); -const Filter = require('./filter'); -const Generator = require('./generator'); -const Helper = require('./helper'); -const Highlight = require('./syntax_highlight'); -const Injector = require('./injector'); -const Migrator = require('./migrator'); -const Processor = require('./processor'); -const Renderer = require('./renderer'); -const Tag = require('./tag'); +import Console from './console'; +import Deployer from './deployer'; +import Filter from './filter'; +import Generator from './generator'; +import Helper from './helper'; +import Highlight from './syntax_highlight'; +import Injector from './injector'; +import Migrator from './migrator'; +import Processor from './processor'; +import Renderer from './renderer'; +import Tag from './tag'; -module.exports = { +export default { Console, Deployer, Filter, Generator, Helper, Highlight, Injector, Migrator, Processor, Renderer, Tag }; diff --git a/lib/extend/injector.js b/lib/extend/injector.js index 74689d3202..dfdfaa65ef 100644 --- a/lib/extend/injector.js +++ b/lib/extend/injector.js @@ -1,6 +1,6 @@ 'use strict'; -const { Cache } = require('hexo-util'); +import {Cache} from 'hexo-util'; class Injector { constructor() { @@ -99,4 +99,4 @@ class Injector { } } -module.exports = Injector; +export default Injector; diff --git a/lib/extend/migrator.js b/lib/extend/migrator.js index 12a25bc5a6..a418c6de55 100644 --- a/lib/extend/migrator.js +++ b/lib/extend/migrator.js @@ -1,6 +1,6 @@ 'use strict'; -const Promise = require('bluebird'); +import Promise from 'bluebird'; class Migrator { constructor() { @@ -29,4 +29,4 @@ class Migrator { } } -module.exports = Migrator; +export default Migrator; diff --git a/lib/extend/processor.js b/lib/extend/processor.js index da2efbd7e6..cfbea335a5 100644 --- a/lib/extend/processor.js +++ b/lib/extend/processor.js @@ -1,7 +1,7 @@ 'use strict'; -const Promise = require('bluebird'); -const { Pattern } = require('hexo-util'); +import Promise from 'bluebird'; +import {Pattern} from 'hexo-util'; class Processor { constructor() { @@ -35,4 +35,4 @@ class Processor { } } -module.exports = Processor; +export default Processor; diff --git a/lib/extend/renderer.js b/lib/extend/renderer.js index 994b1270f9..5b12c0f4f1 100644 --- a/lib/extend/renderer.js +++ b/lib/extend/renderer.js @@ -1,7 +1,7 @@ 'use strict'; -const { extname } = require('path'); -const Promise = require('bluebird'); +import {extname} from 'path'; +import Promise from 'bluebird'; const getExtname = str => { if (typeof str !== 'string') return ''; @@ -63,4 +63,4 @@ class Renderer { } } -module.exports = Renderer; +export default Renderer; diff --git a/lib/extend/tag.js b/lib/extend/tag.js index f633781513..fd8ad76726 100644 --- a/lib/extend/tag.js +++ b/lib/extend/tag.js @@ -1,9 +1,9 @@ 'use strict'; -const { stripIndent } = require('hexo-util'); -const { cyan, magenta, red, bold } = require('picocolors'); -const { Environment } = require('nunjucks'); -const Promise = require('bluebird'); +import {stripIndent} from 'hexo-util'; +import {cyan, magenta, red, bold} from 'picocolors'; +import {Environment} from 'nunjucks'; +import Promise from 'bluebird'; const rSwigRawFullBlock = /{% *raw *%}/; const rCodeTag = /]*>[\s\S]+?<\/code>/g; const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); @@ -252,4 +252,4 @@ class Tag { } } -module.exports = Tag; +export default Tag; diff --git a/lib/hexo/default_config.js b/lib/hexo/default_config.js index 3c887a2400..4982d7813a 100644 --- a/lib/hexo/default_config.js +++ b/lib/hexo/default_config.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = { +export default { // Site title: 'Hexo', subtitle: '', diff --git a/lib/hexo/index.js b/lib/hexo/index.js index 8f6fe53344..6fbb9d1f0c 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.js @@ -1,29 +1,43 @@ 'use strict'; -const Promise = require('bluebird'); -const { sep, join, dirname } = require('path'); -const tildify = require('tildify'); -const Database = require('warehouse').default; -const { magenta, underline } = require('picocolors'); -const { EventEmitter } = require('events'); -const { readFile } = require('hexo-fs'); -const Module = require('module'); -const { runInThisContext } = require('vm'); -const { version } = require('../../package.json'); -const { logger } = require('hexo-log'); -const { Console, Deployer, Filter, Generator, Helper, Highlight, Injector, Migrator, Processor, Renderer, Tag } = require('../extend'); -const Render = require('./render'); -const registerModels = require('./register_models'); -const Post = require('./post'); -const Scaffold = require('./scaffold'); -const Source = require('./source'); -const Router = require('./router'); -const Theme = require('../theme'); -const Locals = require('./locals'); -const defaultConfig = require('./default_config'); -const loadDatabase = require('./load_database'); -const multiConfigPath = require('./multi_config_path'); -const { deepMerge, full_url_for } = require('hexo-util'); +import Promise from 'bluebird'; +import {sep, join, dirname} from 'path'; +import tildify from 'tildify'; +import Database from 'warehouse'; +import {magenta, underline} from 'picocolors'; +import {EventEmitter} from 'events'; +import {readFile} from 'hexo-fs'; +import Module from 'module'; +import {runInThisContext} from 'vm'; +import {version} from '../../package.json'; +import logger from 'hexo-log'; + +import { + Console, + Deployer, + Filter, + Generator, + Helper, + Highlight, + Injector, + Migrator, + Processor, + Renderer, + Tag, +} from '../extend'; + +import Render from './render'; +import registerModels from './register_models'; +import Post from './post'; +import Scaffold from './scaffold'; +import Source from './source'; +import Router from './router'; +import Theme from '../theme'; +import Locals from './locals'; +import defaultConfig from './default_config'; +import loadDatabase from './load_database'; +import multiConfigPath from './multi_config_path'; +import {deepMerge, full_url_for} from 'hexo-util'; let resolveSync; // = require('resolve'); const libDir = dirname(__dirname); @@ -492,4 +506,4 @@ Hexo.prototype.core_dir = Hexo.core_dir; Hexo.version = version; Hexo.prototype.version = Hexo.version; -module.exports = Hexo; +export default Hexo; diff --git a/lib/hexo/load_config.js b/lib/hexo/load_config.js index 81528e765c..6e87bdb43c 100644 --- a/lib/hexo/load_config.js +++ b/lib/hexo/load_config.js @@ -1,15 +1,15 @@ 'use strict'; -const { sep, resolve, join, parse } = require('path'); -const tildify = require('tildify'); -const Theme = require('../theme'); -const Source = require('./source'); -const { exists, readdir } = require('hexo-fs'); -const { magenta } = require('picocolors'); -const { deepMerge } = require('hexo-util'); -const validateConfig = require('./validate_config'); - -module.exports = async ctx => { +import {sep, resolve, join, parse} from 'path'; +import tildify from 'tildify'; +import Theme from '../theme'; +import Source from './source'; +import {exists, readdir} from 'hexo-fs'; +import {magenta} from 'picocolors'; +import {deepMerge} from 'hexo-util'; +import validateConfig from './validate_config'; + +export default async ctx => { if (!ctx.env.init) return; const baseDir = ctx.base_dir; diff --git a/lib/hexo/load_database.js b/lib/hexo/load_database.js index b3d59a036e..29c9d32175 100644 --- a/lib/hexo/load_database.js +++ b/lib/hexo/load_database.js @@ -1,9 +1,9 @@ 'use strict'; -const fs = require('hexo-fs'); -const Promise = require('bluebird'); +import fs from 'hexo-fs'; +import Promise from 'bluebird'; -module.exports = ctx => { +export default ctx => { if (ctx._dbLoaded) return Promise.resolve(); const db = ctx.database; diff --git a/lib/hexo/load_plugins.js b/lib/hexo/load_plugins.js index 010127c74e..4668233416 100644 --- a/lib/hexo/load_plugins.js +++ b/lib/hexo/load_plugins.js @@ -1,11 +1,11 @@ 'use strict'; -const { join } = require('path'); -const { exists, readFile, listDir } = require('hexo-fs'); -const Promise = require('bluebird'); -const { magenta } = require('picocolors'); +import {join} from 'path'; +import {exists, readFile, listDir} from 'hexo-fs'; +import Promise from 'bluebird'; +import {magenta} from 'picocolors'; -module.exports = ctx => { +export default ctx => { if (!ctx.env.init || ctx.env.safe) return; return loadModules(ctx).then(() => loadScripts(ctx)); diff --git a/lib/hexo/load_theme_config.js b/lib/hexo/load_theme_config.js index 1abb35d842..5856e89d72 100644 --- a/lib/hexo/load_theme_config.js +++ b/lib/hexo/load_theme_config.js @@ -1,12 +1,12 @@ 'use strict'; -const { join, parse } = require('path'); -const tildify = require('tildify'); -const { exists, readdir } = require('hexo-fs'); -const { magenta } = require('picocolors'); -const { deepMerge } = require('hexo-util'); +import {join, parse} from 'path'; +import tildify from 'tildify'; +import {exists, readdir} from 'hexo-fs'; +import {magenta} from 'picocolors'; +import {deepMerge} from 'hexo-util'; -module.exports = ctx => { +export default ctx => { if (!ctx.env.init) return; if (!ctx.config.theme) return; diff --git a/lib/hexo/locals.js b/lib/hexo/locals.js index dfdc9a772c..751852cd4d 100644 --- a/lib/hexo/locals.js +++ b/lib/hexo/locals.js @@ -1,6 +1,6 @@ 'use strict'; -const { Cache } = require('hexo-util'); +import {Cache} from 'hexo-util'; class Locals { constructor() { @@ -61,4 +61,4 @@ class Locals { } } -module.exports = Locals; +export default Locals; diff --git a/lib/hexo/multi_config_path.js b/lib/hexo/multi_config_path.js index 7d81d67643..26667bf2bd 100644 --- a/lib/hexo/multi_config_path.js +++ b/lib/hexo/multi_config_path.js @@ -1,11 +1,11 @@ 'use strict'; -const { isAbsolute, resolve, join, extname } = require('path'); -const fs = require('hexo-fs'); -const yml = require('js-yaml'); -const { deepMerge } = require('hexo-util'); +import {isAbsolute, resolve, join, extname} from 'path'; +import fs from 'hexo-fs'; +import yml from 'js-yaml'; +import {deepMerge} from 'hexo-util'; -module.exports = ctx => function multiConfigPath(base, configPaths, outputDir) { +export default ctx => (function multiConfigPath(base, configPaths, outputDir) { const { log } = ctx; const defaultPath = join(base, '_config.yml'); @@ -74,4 +74,4 @@ module.exports = ctx => function multiConfigPath(base, configPaths, outputDir) { // write file and return path return outputPath; -}; +}); diff --git a/lib/hexo/post.js b/lib/hexo/post.js index 2df362d2fa..4b74896b42 100644 --- a/lib/hexo/post.js +++ b/lib/hexo/post.js @@ -1,14 +1,14 @@ 'use strict'; -const assert = require('assert'); -const moment = require('moment'); -const Promise = require('bluebird'); -const { join, extname, basename } = require('path'); -const { magenta } = require('picocolors'); -const { load } = require('js-yaml'); -const { slugize, escapeRegExp } = require('hexo-util'); -const { copyDir, exists, listDir, mkdirs, readFile, rmdir, unlink, writeFile } = require('hexo-fs'); -const { parse: yfmParse, split: yfmSplit, stringify: yfmStringify } = require('hexo-front-matter'); +import assert from 'assert'; +import moment from 'moment'; +import Promise from 'bluebird'; +import {join, extname, basename} from 'path'; +import {magenta} from 'picocolors'; +import {load} from 'js-yaml'; +import {slugize, escapeRegExp} from 'hexo-util'; +import {copyDir, exists, listDir, mkdirs, readFile, rmdir, unlink, writeFile} from 'hexo-fs'; +import {parse as yfmParse, split as yfmSplit, stringify as yfmStringify} from 'hexo-front-matter'; const preservedKeys = ['title', 'slug', 'path', 'layout', 'date', 'content']; const rHexoPostRenderEscape = /([\s\S]+?)<\/hexoPostRenderCodeBlock>/g; @@ -448,4 +448,4 @@ class Post { } } -module.exports = Post; +export default Post; diff --git a/lib/hexo/register_models.js b/lib/hexo/register_models.js index 6245e122a1..6cd8ab63c5 100644 --- a/lib/hexo/register_models.js +++ b/lib/hexo/register_models.js @@ -1,8 +1,8 @@ 'use strict'; -const models = require('../models'); +import models from '../models'; -module.exports = ctx => { +export default ctx => { const db = ctx.database; const keys = Object.keys(models); diff --git a/lib/hexo/render.js b/lib/hexo/render.js index 802d1b38f0..7810f8bdc3 100644 --- a/lib/hexo/render.js +++ b/lib/hexo/render.js @@ -1,8 +1,8 @@ 'use strict'; -const { extname } = require('path'); -const Promise = require('bluebird'); -const { readFile, readFileSync } = require('hexo-fs'); +import {extname} from 'path'; +import Promise from 'bluebird'; +import {readFile, readFileSync} from 'hexo-fs'; const getExtname = str => { if (typeof str !== 'string') return ''; @@ -131,4 +131,4 @@ class Render { } } -module.exports = Render; +export default Render; diff --git a/lib/hexo/router.js b/lib/hexo/router.js index a1f3a32c8b..fed1d5cd4b 100644 --- a/lib/hexo/router.js +++ b/lib/hexo/router.js @@ -1,8 +1,8 @@ 'use strict'; -const { EventEmitter } = require('events'); -const Promise = require('bluebird'); -const Stream = require('stream'); +import {EventEmitter} from 'events'; +import Promise from 'bluebird'; +import Stream from 'stream'; const { Readable } = Stream; class RouteStream extends Readable { @@ -166,4 +166,4 @@ class Router extends EventEmitter { } } -module.exports = Router; +export default Router; diff --git a/lib/hexo/scaffold.js b/lib/hexo/scaffold.js index c1d59f2aa2..0706eac78a 100644 --- a/lib/hexo/scaffold.js +++ b/lib/hexo/scaffold.js @@ -1,7 +1,7 @@ 'use strict'; -const { extname, join } = require('path'); -const { exists, listDir, readFile, unlink, writeFile } = require('hexo-fs'); +import {extname, join} from 'path'; +import {exists, listDir, readFile, unlink, writeFile} from 'hexo-fs'; class Scaffold { constructor(context) { @@ -68,4 +68,4 @@ class Scaffold { } } -module.exports = Scaffold; +export default Scaffold; diff --git a/lib/hexo/source.js b/lib/hexo/source.js index 00830b348f..7a186db2c4 100644 --- a/lib/hexo/source.js +++ b/lib/hexo/source.js @@ -1,6 +1,6 @@ 'use strict'; -const Box = require('../box'); +import Box from '../box'; class Source extends Box { constructor(ctx) { @@ -10,4 +10,4 @@ class Source extends Box { } } -module.exports = Source; +export default Source; diff --git a/lib/hexo/update_package.js b/lib/hexo/update_package.js index b0c16fa5ef..7247dbd952 100644 --- a/lib/hexo/update_package.js +++ b/lib/hexo/update_package.js @@ -1,9 +1,9 @@ 'use strict'; -const { join } = require('path'); -const fs = require('hexo-fs'); +import {join} from 'path'; +import fs from 'hexo-fs'; -module.exports = ctx => { +export default ctx => { const pkgPath = join(ctx.base_dir, 'package.json'); return readPkg(pkgPath).then(pkg => { diff --git a/lib/models/asset.js b/lib/models/asset.js index d821ead83f..ae100fae03 100644 --- a/lib/models/asset.js +++ b/lib/models/asset.js @@ -1,9 +1,9 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const { join } = require('path'); +import {Schema} from 'warehouse'; +import {join} from 'path'; -module.exports = ctx => { +export default ctx => { const Asset = new Schema({ _id: {type: String, required: true}, path: {type: String, required: true}, diff --git a/lib/models/cache.js b/lib/models/cache.js index 89ef7286a5..9b0f570d63 100644 --- a/lib/models/cache.js +++ b/lib/models/cache.js @@ -1,9 +1,9 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const Promise = require('bluebird'); +import {Schema} from 'warehouse'; +import Promise from 'bluebird'; -module.exports = ctx => { +export default ctx => { const Cache = new Schema({ _id: {type: String, required: true}, hash: {type: String, default: ''}, diff --git a/lib/models/category.js b/lib/models/category.js index 5c535799a6..a9b0165c74 100644 --- a/lib/models/category.js +++ b/lib/models/category.js @@ -1,9 +1,9 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const { slugize, full_url_for } = require('hexo-util'); +import {Schema} from 'warehouse'; +import {slugize, full_url_for} from 'hexo-util'; -module.exports = ctx => { +export default ctx => { const Category = new Schema({ name: {type: String, required: true}, parent: {type: Schema.Types.CUID, ref: 'Category'} diff --git a/lib/models/data.js b/lib/models/data.js index 3b3f25487f..138aac85fb 100644 --- a/lib/models/data.js +++ b/lib/models/data.js @@ -1,8 +1,8 @@ 'use strict'; -const { Schema } = require('warehouse').default; +import {Schema} from 'warehouse'; -module.exports = ctx => { +export default ctx => { const Data = new Schema({ _id: {type: String, required: true}, data: Object diff --git a/lib/models/index.js b/lib/models/index.js index 18ae185867..a8639fec6d 100644 --- a/lib/models/index.js +++ b/lib/models/index.js @@ -1,16 +1,16 @@ 'use strict'; -const Asset = require('./asset'); -const Cache = require('./cache'); -const Category = require('./category'); -const Data = require('./data'); -const Page = require('./page'); -const Post = require('./post'); -const PostAsset = require('./post_asset'); -const PostCategory = require('./post_category'); -const PostTag = require('./post_tag'); -const Tag = require('./tag'); +import Asset from './asset'; +import Cache from './cache'; +import Category from './category'; +import Data from './data'; +import Page from './page'; +import Post from './post'; +import PostAsset from './post_asset'; +import PostCategory from './post_category'; +import PostTag from './post_tag'; +import Tag from './tag'; -module.exports = { +export default { Asset, Cache, Category, Data, Page, Post, PostAsset, PostCategory, PostTag, Tag }; diff --git a/lib/models/page.js b/lib/models/page.js index 0216ffede5..0a38670002 100644 --- a/lib/models/page.js +++ b/lib/models/page.js @@ -1,12 +1,12 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const { join } = require('path'); -const Moment = require('./types/moment'); -const moment = require('moment'); -const { full_url_for } = require('hexo-util'); +import {Schema} from 'warehouse'; +import {join} from 'path'; +import Moment from './types/moment'; +import moment from 'moment'; +import {full_url_for} from 'hexo-util'; -module.exports = ctx => { +export default ctx => { const Page = new Schema({ title: {type: String, default: ''}, date: { diff --git a/lib/models/post.js b/lib/models/post.js index 4cb28421e3..2e4d19b010 100644 --- a/lib/models/post.js +++ b/lib/models/post.js @@ -1,11 +1,11 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const moment = require('moment'); -const { extname, join, sep } = require('path'); -const Promise = require('bluebird'); -const Moment = require('./types/moment'); -const { full_url_for } = require('hexo-util'); +import {Schema} from 'warehouse'; +import moment from 'moment'; +import {extname, join, sep} from 'path'; +import Promise from 'bluebird'; +import Moment from './types/moment'; +import {full_url_for} from 'hexo-util'; function pickID(data) { return data._id; @@ -15,7 +15,7 @@ function removeEmptyTag(tags) { return tags.filter(tag => tag != null && tag !== '').map(tag => `${tag}`); } -module.exports = ctx => { +export default ctx => { const Post = new Schema({ id: String, title: {type: String, default: ''}, diff --git a/lib/models/post_asset.js b/lib/models/post_asset.js index 9c3c3778f8..18250e09a2 100644 --- a/lib/models/post_asset.js +++ b/lib/models/post_asset.js @@ -1,9 +1,9 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const { join } = require('path'); +import {Schema} from 'warehouse'; +import {join} from 'path'; -module.exports = ctx => { +export default ctx => { const PostAsset = new Schema({ _id: {type: String, required: true}, slug: {type: String, required: true}, diff --git a/lib/models/post_category.js b/lib/models/post_category.js index f7169d0f0d..e34c427205 100644 --- a/lib/models/post_category.js +++ b/lib/models/post_category.js @@ -1,8 +1,8 @@ 'use strict'; -const { Schema } = require('warehouse').default; +import {Schema} from 'warehouse'; -module.exports = ctx => { +export default ctx => { const PostCategory = new Schema({ post_id: {type: Schema.Types.CUID, ref: 'Post'}, category_id: {type: Schema.Types.CUID, ref: 'Category'} diff --git a/lib/models/post_tag.js b/lib/models/post_tag.js index 21ce51f287..ddc3f193df 100644 --- a/lib/models/post_tag.js +++ b/lib/models/post_tag.js @@ -1,8 +1,8 @@ 'use strict'; -const { Schema } = require('warehouse').default; +import {Schema} from 'warehouse'; -module.exports = ctx => { +export default ctx => { const PostTag = new Schema({ post_id: {type: Schema.Types.CUID, ref: 'Post'}, tag_id: {type: Schema.Types.CUID, ref: 'Tag'} diff --git a/lib/models/tag.js b/lib/models/tag.js index 7f6245c861..4b0a2b22a9 100644 --- a/lib/models/tag.js +++ b/lib/models/tag.js @@ -1,10 +1,10 @@ 'use strict'; -const { Schema } = require('warehouse').default; -const { slugize, full_url_for } = require('hexo-util'); +import {Schema} from 'warehouse'; +import {slugize, full_url_for} from 'hexo-util'; const { hasOwnProperty: hasOwn } = Object.prototype; -module.exports = ctx => { +export default ctx => { const Tag = new Schema({ name: {type: String, required: true} }); diff --git a/lib/models/types/moment.js b/lib/models/types/moment.js index 95dca78b65..1347d8b558 100644 --- a/lib/models/types/moment.js +++ b/lib/models/types/moment.js @@ -1,7 +1,7 @@ 'use strict'; -const { SchemaType } = require('warehouse').default; -const { moment, toMomentLocale } = require('../../plugins/helper/date'); +import {SchemaType} from 'warehouse'; +import {moment, toMomentLocale} from '../../plugins/helper/date'; class SchemaTypeMoment extends SchemaType { constructor(name, options = {}) { @@ -87,4 +87,4 @@ function toMoment(value) { return moment(value); } -module.exports = SchemaTypeMoment; +export default SchemaTypeMoment; diff --git a/lib/plugins/console/clean.js b/lib/plugins/console/clean.js index ab6895f165..588d5350da 100644 --- a/lib/plugins/console/clean.js +++ b/lib/plugins/console/clean.js @@ -1,7 +1,7 @@ 'use strict'; -const Promise = require('bluebird'); -const fs = require('hexo-fs'); +import Promise from 'bluebird'; +import fs from 'hexo-fs'; function cleanConsole(args) { return Promise.all([ @@ -35,4 +35,4 @@ function deletePublicDir(ctx) { }); } -module.exports = cleanConsole; +export default cleanConsole; diff --git a/lib/plugins/console/config.js b/lib/plugins/console/config.js index 3811746475..0d57d80d88 100644 --- a/lib/plugins/console/config.js +++ b/lib/plugins/console/config.js @@ -1,9 +1,9 @@ 'use strict'; -const yaml = require('js-yaml'); -const fs = require('hexo-fs'); -const { extname } = require('path'); -const Promise = require('bluebird'); +import yaml from 'js-yaml'; +import fs from 'hexo-fs'; +import {extname} from 'path'; +import Promise from 'bluebird'; function configConsole(args) { const key = args._[0]; @@ -83,4 +83,4 @@ function castValue(value) { return value; } -module.exports = configConsole; +export default configConsole; diff --git a/lib/plugins/console/deploy.js b/lib/plugins/console/deploy.js index bd35db8a23..485e24be79 100644 --- a/lib/plugins/console/deploy.js +++ b/lib/plugins/console/deploy.js @@ -1,7 +1,7 @@ 'use strict'; -const { exists } = require('hexo-fs'); -const { underline, magenta } = require('picocolors'); +import {exists} from 'hexo-fs'; +import {underline, magenta} from 'picocolors'; function deployConsole(args) { let config = this.config.deploy; @@ -58,4 +58,4 @@ function deployConsole(args) { }); } -module.exports = deployConsole; +export default deployConsole; diff --git a/lib/plugins/console/generate.js b/lib/plugins/console/generate.js index 261ba40132..cc69f52a6c 100644 --- a/lib/plugins/console/generate.js +++ b/lib/plugins/console/generate.js @@ -1,13 +1,13 @@ 'use strict'; -const { exists, writeFile, unlink, stat, mkdirs } = require('hexo-fs'); -const { join } = require('path'); -const Promise = require('bluebird'); -const prettyHrtime = require('pretty-hrtime'); -const { cyan, magenta } = require('picocolors'); -const tildify = require('tildify'); -const { PassThrough } = require('stream'); -const { createSha1Hash } = require('hexo-util'); +import {exists, writeFile, unlink, stat, mkdirs} from 'hexo-fs'; +import {join} from 'path'; +import Promise from 'bluebird'; +import prettyHrtime from 'pretty-hrtime'; +import {cyan, magenta} from 'picocolors'; +import tildify from 'tildify'; +import {PassThrough} from 'stream'; +import {createSha1Hash} from 'hexo-util'; class Generater { constructor(ctx, args) { @@ -196,4 +196,4 @@ function generateConsole(args = {}) { }); } -module.exports = generateConsole; +export default generateConsole; diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.js index 3a34b7b0fb..12db73f207 100644 --- a/lib/plugins/console/index.js +++ b/lib/plugins/console/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = function(ctx) { +export default function(ctx) { const { console } = ctx.extend; console.register('clean', 'Remove generated files and cache.', require('./clean')); diff --git a/lib/plugins/console/list/category.js b/lib/plugins/console/list/category.js index 8550ec6c1d..c53fceea42 100644 --- a/lib/plugins/console/list/category.js +++ b/lib/plugins/console/list/category.js @@ -1,8 +1,8 @@ 'use strict'; -const { underline } = require('picocolors'); -const table = require('text-table'); -const { stringLength } = require('./common'); +import {underline} from 'picocolors'; +import table from 'text-table'; +import {stringLength} from './common'; function listCategory() { const categories = this.model('Category'); @@ -23,4 +23,4 @@ function listCategory() { if (data.length === 1) console.log('No categories.'); } -module.exports = listCategory; +export default listCategory; diff --git a/lib/plugins/console/list/common.js b/lib/plugins/console/list/common.js index ee0b12d039..963e4135e7 100644 --- a/lib/plugins/console/list/common.js +++ b/lib/plugins/console/list/common.js @@ -1,8 +1,8 @@ 'use strict'; -const strip = require('strip-ansi'); +import strip from 'strip-ansi'; -exports.stringLength = str => { +export function stringLength(str) { str = strip(str); const len = str.length; @@ -16,4 +16,4 @@ exports.stringLength = str => { } return result; -}; +} diff --git a/lib/plugins/console/list/index.js b/lib/plugins/console/list/index.js index debab88983..de85552bdb 100644 --- a/lib/plugins/console/list/index.js +++ b/lib/plugins/console/list/index.js @@ -1,11 +1,11 @@ 'use strict'; -const abbrev = require('abbrev'); -const page = require('./page'); -const post = require('./post'); -const route = require('./route'); -const tag = require('./tag'); -const category = require('./category'); +import abbrev from 'abbrev'; +import page from './page'; +import post from './post'; +import route from './route'; +import tag from './tag'; +import category from './category'; const store = { page, post, route, tag, category @@ -24,4 +24,4 @@ function listConsole(args) { return this.load().then(() => Reflect.apply(store[alias[type]], this, [args])); } -module.exports = listConsole; +export default listConsole; diff --git a/lib/plugins/console/list/page.js b/lib/plugins/console/list/page.js index 7ea880ed54..443bbc383c 100644 --- a/lib/plugins/console/list/page.js +++ b/lib/plugins/console/list/page.js @@ -1,8 +1,8 @@ 'use strict'; -const { magenta, underline, gray } = require('picocolors'); -const table = require('text-table'); -const { stringLength } = require('./common'); +import {magenta, underline, gray} from 'picocolors'; +import table from 'text-table'; +import {stringLength} from './common'; function listPage() { const Page = this.model('Page'); @@ -25,4 +25,4 @@ function listPage() { if (data.length === 1) console.log('No pages.'); } -module.exports = listPage; +export default listPage; diff --git a/lib/plugins/console/list/post.js b/lib/plugins/console/list/post.js index e09a975b5e..58ecf673df 100644 --- a/lib/plugins/console/list/post.js +++ b/lib/plugins/console/list/post.js @@ -1,8 +1,8 @@ 'use strict'; -const { gray, magenta, underline } = require('picocolors'); -const table = require('text-table'); -const { stringLength } = require('./common'); +import {gray, magenta, underline} from 'picocolors'; +import table from 'text-table'; +import {stringLength} from './common'; function mapName(item) { return item.name; @@ -38,4 +38,4 @@ function listPost() { if (data.length === 1) console.log('No posts.'); } -module.exports = listPost; +export default listPost; diff --git a/lib/plugins/console/list/route.js b/lib/plugins/console/list/route.js index d6a3cdbb8e..29ab342e9e 100644 --- a/lib/plugins/console/list/route.js +++ b/lib/plugins/console/list/route.js @@ -1,6 +1,6 @@ 'use strict'; -const archy = require('archy'); +import archy from 'archy'; function listRoute() { const routes = this.route.list().sort(); @@ -50,4 +50,4 @@ function buildNodes(tree) { return nodes; } -module.exports = listRoute; +export default listRoute; diff --git a/lib/plugins/console/list/tag.js b/lib/plugins/console/list/tag.js index 6f5dab7c69..69710978a8 100644 --- a/lib/plugins/console/list/tag.js +++ b/lib/plugins/console/list/tag.js @@ -1,8 +1,8 @@ 'use strict'; -const { magenta, underline } = require('picocolors'); -const table = require('text-table'); -const { stringLength } = require('./common'); +import {magenta, underline} from 'picocolors'; +import table from 'text-table'; +import {stringLength} from './common'; function listTag() { const Tag = this.model('Tag'); @@ -23,4 +23,4 @@ function listTag() { if (data.length === 1) console.log('No tags.'); } -module.exports = listTag; +export default listTag; diff --git a/lib/plugins/console/migrate.js b/lib/plugins/console/migrate.js index 707b14ba55..fff1d3e811 100644 --- a/lib/plugins/console/migrate.js +++ b/lib/plugins/console/migrate.js @@ -1,6 +1,6 @@ 'use strict'; -const { underline, magenta } = require('picocolors'); +import {underline, magenta} from 'picocolors'; function migrateConsole(args) { // Display help message if user didn't input any arguments @@ -26,4 +26,4 @@ function migrateConsole(args) { return Reflect.apply(migrators[type], this, [args]); } -module.exports = migrateConsole; +export default migrateConsole; diff --git a/lib/plugins/console/new.js b/lib/plugins/console/new.js index a73663e27f..4b44177965 100644 --- a/lib/plugins/console/new.js +++ b/lib/plugins/console/new.js @@ -1,8 +1,8 @@ 'use strict'; -const tildify = require('tildify'); -const { magenta } = require('picocolors'); -const { basename } = require('path'); +import tildify from 'tildify'; +import {magenta} from 'picocolors'; +import { basename } from 'path'; const reservedKeys = { _: true, @@ -53,4 +53,4 @@ function newConsole(args) { }); } -module.exports = newConsole; +export default newConsole; diff --git a/lib/plugins/console/publish.js b/lib/plugins/console/publish.js index 2192e196a1..420d03c6bc 100644 --- a/lib/plugins/console/publish.js +++ b/lib/plugins/console/publish.js @@ -1,7 +1,7 @@ 'use strict'; -const tildify = require('tildify'); -const { magenta } = require('picocolors'); +import tildify from 'tildify'; +import {magenta} from 'picocolors'; function publishConsole(args) { // Display help message if user didn't input any arguments @@ -17,4 +17,4 @@ function publishConsole(args) { }); } -module.exports = publishConsole; +export default publishConsole; diff --git a/lib/plugins/console/render.js b/lib/plugins/console/render.js index 57028ba0d1..768426e054 100644 --- a/lib/plugins/console/render.js +++ b/lib/plugins/console/render.js @@ -1,10 +1,10 @@ 'use strict'; -const { resolve } = require('path'); -const tildify = require('tildify'); -const prettyHrtime = require('pretty-hrtime'); -const fs = require('hexo-fs'); -const { cyan, magenta } = require('picocolors'); +import {resolve} from 'path'; +import tildify from 'tildify'; +import prettyHrtime from 'pretty-hrtime'; +import fs from 'hexo-fs'; +import {cyan, magenta} from 'picocolors'; function renderConsole(args) { // Display help message if user didn't input any arguments @@ -40,4 +40,4 @@ function renderConsole(args) { }); } -module.exports = renderConsole; +export default renderConsole; diff --git a/lib/plugins/filter/after_post_render/excerpt.js b/lib/plugins/filter/after_post_render/excerpt.js index d5705c09be..5da8564135 100644 --- a/lib/plugins/filter/after_post_render/excerpt.js +++ b/lib/plugins/filter/after_post_render/excerpt.js @@ -20,4 +20,4 @@ function excerptFilter(data) { } } -module.exports = excerptFilter; +export default excerptFilter; diff --git a/lib/plugins/filter/after_post_render/external_link.js b/lib/plugins/filter/after_post_render/external_link.js index cd7bec136c..19d25a0bf0 100644 --- a/lib/plugins/filter/after_post_render/external_link.js +++ b/lib/plugins/filter/after_post_render/external_link.js @@ -1,6 +1,6 @@ 'use strict'; -const { isExternalLink } = require('hexo-util'); +import {isExternalLink} from 'hexo-util'; let EXTERNAL_LINK_POST_ENABLED = true; const rATag = /]+?\s+?)href=["']((?:https?:|\/\/)[^<>"']+)["'][^<>]*>/gi; const rTargetAttr = /target=/i; @@ -31,4 +31,4 @@ function externalLinkFilter(data) { }); } -module.exports = externalLinkFilter; +export default externalLinkFilter; diff --git a/lib/plugins/filter/after_post_render/index.js b/lib/plugins/filter/after_post_render/index.js index fbc7a7822c..1d0297039d 100644 --- a/lib/plugins/filter/after_post_render/index.js +++ b/lib/plugins/filter/after_post_render/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; filter.register('after_post_render', require('./external_link')); diff --git a/lib/plugins/filter/after_render/external_link.js b/lib/plugins/filter/after_render/external_link.js index 40ff7b6b65..d3c22f10d6 100644 --- a/lib/plugins/filter/after_render/external_link.js +++ b/lib/plugins/filter/after_render/external_link.js @@ -1,6 +1,6 @@ 'use strict'; -const { isExternalLink } = require('hexo-util'); +import {isExternalLink} from 'hexo-util'; let EXTERNAL_LINK_SITE_ENABLED = true; const rATag = /]+?\s+?)href=["']((?:https?:|\/\/)[^<>"']+)["'][^<>]*>/gi; @@ -32,4 +32,4 @@ function externalLinkFilter(data) { }); } -module.exports = externalLinkFilter; +export default externalLinkFilter; diff --git a/lib/plugins/filter/after_render/index.js b/lib/plugins/filter/after_render/index.js index 819e0490ce..531cace679 100644 --- a/lib/plugins/filter/after_render/index.js +++ b/lib/plugins/filter/after_render/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; filter.register('after_render:html', require('./external_link')); diff --git a/lib/plugins/filter/after_render/meta_generator.js b/lib/plugins/filter/after_render/meta_generator.js index d5e4f2c2f3..1b1b541ac6 100644 --- a/lib/plugins/filter/after_render/meta_generator.js +++ b/lib/plugins/filter/after_render/meta_generator.js @@ -17,4 +17,4 @@ function hexoMetaGeneratorInject(data) { return data.replace('', `${META_GENERATOR_TAG}`); } -module.exports = hexoMetaGeneratorInject; +export default hexoMetaGeneratorInject; diff --git a/lib/plugins/filter/before_exit/index.js b/lib/plugins/filter/before_exit/index.js index 374eb8a225..ba555dd8aa 100644 --- a/lib/plugins/filter/before_exit/index.js +++ b/lib/plugins/filter/before_exit/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; filter.register('before_exit', require('./save_database')); diff --git a/lib/plugins/filter/before_exit/save_database.js b/lib/plugins/filter/before_exit/save_database.js index a5388e399e..bb970d45d0 100644 --- a/lib/plugins/filter/before_exit/save_database.js +++ b/lib/plugins/filter/before_exit/save_database.js @@ -8,4 +8,4 @@ function saveDatabaseFilter() { }); } -module.exports = saveDatabaseFilter; +export default saveDatabaseFilter; diff --git a/lib/plugins/filter/before_generate/index.js b/lib/plugins/filter/before_generate/index.js index 960e469e3c..033ce01cfa 100644 --- a/lib/plugins/filter/before_generate/index.js +++ b/lib/plugins/filter/before_generate/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; filter.register('before_generate', require('./render_post')); diff --git a/lib/plugins/filter/before_generate/render_post.js b/lib/plugins/filter/before_generate/render_post.js index 100450004a..7c4deffb0f 100644 --- a/lib/plugins/filter/before_generate/render_post.js +++ b/lib/plugins/filter/before_generate/render_post.js @@ -1,6 +1,6 @@ 'use strict'; -const Promise = require('bluebird'); +import Promise from 'bluebird'; function renderPostFilter(data) { const renderPosts = model => { @@ -20,4 +20,4 @@ function renderPostFilter(data) { ]); } -module.exports = renderPostFilter; +export default renderPostFilter; diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.js b/lib/plugins/filter/before_post_render/backtick_code_block.js index 32f3590e27..09d451246d 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.js +++ b/lib/plugins/filter/before_post_render/backtick_code_block.js @@ -6,7 +6,7 @@ const rLangCaption = /([^\s]+)\s*(.+)?/; const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); -module.exports = ctx => { +export default ctx => { return function backtickCodeBlock(data) { const dataContent = data.content; diff --git a/lib/plugins/filter/before_post_render/index.js b/lib/plugins/filter/before_post_render/index.js index bcff7246b4..5bd933cb9f 100644 --- a/lib/plugins/filter/before_post_render/index.js +++ b/lib/plugins/filter/before_post_render/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; filter.register('before_post_render', require('./backtick_code_block')(ctx)); diff --git a/lib/plugins/filter/before_post_render/titlecase.js b/lib/plugins/filter/before_post_render/titlecase.js index 0fad5bc4e9..30da444c6a 100644 --- a/lib/plugins/filter/before_post_render/titlecase.js +++ b/lib/plugins/filter/before_post_render/titlecase.js @@ -9,4 +9,4 @@ function titlecaseFilter(data) { data.title = titlecase(data.title); } -module.exports = titlecaseFilter; +export default titlecaseFilter; diff --git a/lib/plugins/filter/index.js b/lib/plugins/filter/index.js index f349b99b29..5f82ca1663 100644 --- a/lib/plugins/filter/index.js +++ b/lib/plugins/filter/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; require('./after_render')(ctx); diff --git a/lib/plugins/filter/new_post_path.js b/lib/plugins/filter/new_post_path.js index 706c8a2037..bb5b35deb2 100644 --- a/lib/plugins/filter/new_post_path.js +++ b/lib/plugins/filter/new_post_path.js @@ -1,10 +1,10 @@ 'use strict'; -const { join, extname } = require('path'); -const moment = require('moment'); -const Promise = require('bluebird'); -const { createSha1Hash, Permalink } = require('hexo-util'); -const fs = require('hexo-fs'); +import {join, extname} from 'path'; +import moment from 'moment'; +import Promise from 'bluebird'; +import {createSha1Hash, Permalink} from 'hexo-util'; +import fs from 'hexo-fs'; let permalink; const reservedKeys = { @@ -97,4 +97,4 @@ function newPostPathFilter(data = {}, replace) { return fs.ensurePath(target); } -module.exports = newPostPathFilter; +export default newPostPathFilter; diff --git a/lib/plugins/filter/post_permalink.js b/lib/plugins/filter/post_permalink.js index 1087c5ef37..223438696b 100644 --- a/lib/plugins/filter/post_permalink.js +++ b/lib/plugins/filter/post_permalink.js @@ -1,7 +1,7 @@ 'use strict'; -const { createSha1Hash, Permalink, slugize } = require('hexo-util'); -const { basename } = require('path'); +import {createSha1Hash, Permalink, slugize} from 'hexo-util'; +import {basename} from 'path'; let permalink; function postPermalinkFilter(data) { @@ -67,4 +67,4 @@ function postPermalinkFilter(data) { return permalink.stringify(meta); } -module.exports = postPermalinkFilter; +export default postPermalinkFilter; diff --git a/lib/plugins/filter/template_locals/i18n.js b/lib/plugins/filter/template_locals/i18n.js index 9bdddb1fb6..a94f77abb7 100644 --- a/lib/plugins/filter/template_locals/i18n.js +++ b/lib/plugins/filter/template_locals/i18n.js @@ -1,6 +1,6 @@ 'use strict'; -const { Pattern } = require('hexo-util'); +import {Pattern} from 'hexo-util'; function i18nLocalsFilter(locals) { const { i18n } = this.theme; @@ -33,4 +33,4 @@ function i18nLocalsFilter(locals) { locals._p = i18n._p(languages); } -module.exports = i18nLocalsFilter; +export default i18nLocalsFilter; diff --git a/lib/plugins/filter/template_locals/index.js b/lib/plugins/filter/template_locals/index.js index 53ce0da6d3..082cd71ff8 100644 --- a/lib/plugins/filter/template_locals/index.js +++ b/lib/plugins/filter/template_locals/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { filter } = ctx.extend; filter.register('template_locals', require('./i18n')); diff --git a/lib/plugins/generator/asset.js b/lib/plugins/generator/asset.js index 3fda4db77d..e3504dc624 100644 --- a/lib/plugins/generator/asset.js +++ b/lib/plugins/generator/asset.js @@ -1,9 +1,9 @@ 'use strict'; -const fs = require('hexo-fs'); -const Promise = require('bluebird'); -const { extname } = require('path'); -const { magenta } = require('picocolors'); +import fs from 'hexo-fs'; +import Promise from 'bluebird'; +import {extname} from 'path'; +import {magenta} from 'picocolors'; const process = (name, ctx) => { return Promise.filter(ctx.model(name).toArray(), asset => fs.exists(asset.source).tap(exist => { @@ -42,4 +42,4 @@ function assetGenerator() { ]).then(data => [].concat(...data)); } -module.exports = assetGenerator; +export default assetGenerator; diff --git a/lib/plugins/generator/index.js b/lib/plugins/generator/index.js index da39f2680f..bb3c1b769e 100644 --- a/lib/plugins/generator/index.js +++ b/lib/plugins/generator/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { generator } = ctx.extend; generator.register('asset', require('./asset')); diff --git a/lib/plugins/generator/page.js b/lib/plugins/generator/page.js index a80d42254c..c8c3dd0275 100644 --- a/lib/plugins/generator/page.js +++ b/lib/plugins/generator/page.js @@ -24,4 +24,4 @@ function pageGenerator(locals) { }); } -module.exports = pageGenerator; +export default pageGenerator; diff --git a/lib/plugins/generator/post.js b/lib/plugins/generator/post.js index 0d32332329..343e0df380 100644 --- a/lib/plugins/generator/post.js +++ b/lib/plugins/generator/post.js @@ -30,4 +30,4 @@ function postGenerator(locals) { }); } -module.exports = postGenerator; +export default postGenerator; diff --git a/lib/plugins/helper/css.js b/lib/plugins/helper/css.js index 0e728bd1b6..88193cb5bb 100644 --- a/lib/plugins/helper/css.js +++ b/lib/plugins/helper/css.js @@ -1,7 +1,7 @@ 'use strict'; -const { htmlTag, url_for } = require('hexo-util'); -const { default: moize } = require('moize'); +import {htmlTag, url_for} from 'hexo-util'; +import moize from 'moize'; function cssHelper(...args) { let result = '\n'; @@ -23,7 +23,7 @@ function cssHelper(...args) { return result; } -module.exports = moize(cssHelper, { +export default moize(cssHelper, { maxSize: 10, isDeepEqual: true }); diff --git a/lib/plugins/helper/date.js b/lib/plugins/helper/date.js index 8235e5fff4..bf0514e085 100644 --- a/lib/plugins/helper/date.js +++ b/lib/plugins/helper/date.js @@ -1,8 +1,8 @@ 'use strict'; -const moment = require('moment-timezone'); +import moment from 'moment-timezone'; const { isMoment } = moment; -const { default: moize } = require('moize'); +import moize from 'moize'; const isDate = value => typeof value === 'object' && value instanceof Date && !isNaN(value.getTime()); @@ -87,11 +87,11 @@ function toMomentLocale(lang) { return lang.toLowerCase().replace('_', '-'); } -exports.date = dateHelper; -exports.date_xml = toISOString; -exports.time = timeHelper; -exports.full_date = fullDateHelper; -exports.relative_date = relativeDateHelper; -exports.time_tag = timeTagHelper; -exports.moment = moment; -exports.toMomentLocale = moize.shallow(toMomentLocale); +export {dateHelper as date}; +export {toISOString as date_xml}; +export {timeHelper as time}; +export {fullDateHelper as full_date}; +export {relativeDateHelper as relative_date}; +export {timeTagHelper as time_tag}; +export {moment}; +export var toMomentLocale = moize.shallow(toMomentLocale); diff --git a/lib/plugins/helper/debug.js b/lib/plugins/helper/debug.js index 22b7935385..62a4b473d4 100644 --- a/lib/plugins/helper/debug.js +++ b/lib/plugins/helper/debug.js @@ -1,6 +1,6 @@ 'use strict'; -const { inspect } = require('util'); +import {inspect} from 'util'; // this format object as string, resolves circular reference function inspectObject(object, options) { @@ -12,5 +12,5 @@ function log(...args) { return Reflect.apply(console.log, null, args); } -exports.inspectObject = inspectObject; -exports.log = log; +export {inspectObject}; +export {log}; diff --git a/lib/plugins/helper/favicon_tag.js b/lib/plugins/helper/favicon_tag.js index e2b756bcc8..c778233a15 100644 --- a/lib/plugins/helper/favicon_tag.js +++ b/lib/plugins/helper/favicon_tag.js @@ -1,9 +1,9 @@ 'use strict'; -const { url_for } = require('hexo-util'); +import {url_for} from 'hexo-util'; function faviconTagHelper(path) { return ``; } -module.exports = faviconTagHelper; +export default faviconTagHelper; diff --git a/lib/plugins/helper/feed_tag.js b/lib/plugins/helper/feed_tag.js index a72af70f12..4b0d23ed20 100644 --- a/lib/plugins/helper/feed_tag.js +++ b/lib/plugins/helper/feed_tag.js @@ -1,7 +1,7 @@ 'use strict'; -const { url_for } = require('hexo-util'); -const { default: moize } = require('moize'); +import {url_for} from 'hexo-util'; +import moize from 'moize'; const feedFn = (str = '') => { if (str) return str.replace(/2$/, ''); @@ -48,4 +48,4 @@ function feedTagHelper(path, options = {}) { return moize.deep(makeFeedTag.bind(this))(path, options, config.feed, config.title); } -module.exports = feedTagHelper; +export default feedTagHelper; diff --git a/lib/plugins/helper/format.js b/lib/plugins/helper/format.js index e80f54b50f..b1d364c9dd 100644 --- a/lib/plugins/helper/format.js +++ b/lib/plugins/helper/format.js @@ -1,19 +1,17 @@ 'use strict'; -const { stripHTML, wordWrap, truncate, escapeHTML } = require('hexo-util'); -const titlecase = require('titlecase'); +import {stripHTML, wordWrap, truncate, escapeHTML} from 'hexo-util'; +import titlecase from 'titlecase'; +export {stripHTML as strip_html}; +export {stripHTML}; -exports.strip_html = stripHTML; -exports.stripHTML = stripHTML; +export function trim(str) { + return str.trim(); +} -exports.trim = str => str.trim(); - -exports.titlecase = titlecase; - -exports.word_wrap = wordWrap; -exports.wordWrap = wordWrap; - -exports.truncate = truncate; - -exports.escape_html = escapeHTML; -exports.escapeHTML = escapeHTML; +export {titlecase}; +export {wordWrap as word_wrap}; +export {wordWrap}; +export {truncate}; +export {escapeHTML as escape_html}; +export {escapeHTML}; diff --git a/lib/plugins/helper/fragment_cache.js b/lib/plugins/helper/fragment_cache.js index 19e4f675a0..4fb9f389ec 100644 --- a/lib/plugins/helper/fragment_cache.js +++ b/lib/plugins/helper/fragment_cache.js @@ -1,7 +1,7 @@ 'use strict'; -const { Cache } = require('hexo-util'); +import {Cache} from 'hexo-util'; -module.exports = ctx => { +export default ctx => { const cache = new Cache(); // reset cache for watch mode diff --git a/lib/plugins/helper/full_url_for.js b/lib/plugins/helper/full_url_for.js index 997db74ab6..f805ff5b82 100755 --- a/lib/plugins/helper/full_url_for.js +++ b/lib/plugins/helper/full_url_for.js @@ -1,6 +1,6 @@ 'use strict'; -const { full_url_for } = require('hexo-util'); +import {full_url_for} from 'hexo-util'; -module.exports = function(path) { +export default function(path) { return full_url_for.call(this, path); }; diff --git a/lib/plugins/helper/gravatar.js b/lib/plugins/helper/gravatar.js index 888a5eef30..bfcd4a343b 100644 --- a/lib/plugins/helper/gravatar.js +++ b/lib/plugins/helper/gravatar.js @@ -1,5 +1,4 @@ 'use strict'; -const { gravatar } = require('hexo-util'); - -module.exports = gravatar; +import {gravatar} from 'hexo-util'; +export default gravatar; diff --git a/lib/plugins/helper/image_tag.js b/lib/plugins/helper/image_tag.js index 5ca27c1f5c..841e656bea 100644 --- a/lib/plugins/helper/image_tag.js +++ b/lib/plugins/helper/image_tag.js @@ -1,6 +1,6 @@ 'use strict'; -const { htmlTag, url_for } = require('hexo-util'); +import {htmlTag, url_for} from 'hexo-util'; function imageTagHelper(path, options = {}) { const attrs = Object.assign({ @@ -14,4 +14,4 @@ function imageTagHelper(path, options = {}) { return htmlTag('img', attrs); } -module.exports = imageTagHelper; +export default imageTagHelper; diff --git a/lib/plugins/helper/index.js b/lib/plugins/helper/index.js index fc86aa6074..d2e2d03b81 100644 --- a/lib/plugins/helper/index.js +++ b/lib/plugins/helper/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { helper } = ctx.extend; const date = require('./date'); diff --git a/lib/plugins/helper/is.js b/lib/plugins/helper/is.js index 9f74f3b6d6..26a110d37f 100644 --- a/lib/plugins/helper/is.js +++ b/lib/plugins/helper/is.js @@ -81,13 +81,13 @@ function isTagHelper(tag) { return Boolean(this.page.tag); } -exports.current = isCurrentHelper; -exports.home = isHomeHelper; -exports.home_first_page = isHomeFirstPageHelper; -exports.post = isPostHelper; -exports.page = isPageHelper; -exports.archive = isArchiveHelper; -exports.year = isYearHelper; -exports.month = isMonthHelper; -exports.category = isCategoryHelper; -exports.tag = isTagHelper; +export {isCurrentHelper as current}; +export {isHomeHelper as home}; +export {isHomeFirstPageHelper as home_first_page}; +export {isPostHelper as post}; +export {isPageHelper as page}; +export {isArchiveHelper as archive}; +export {isYearHelper as year}; +export {isMonthHelper as month}; +export {isCategoryHelper as category}; +export {isTagHelper as tag}; diff --git a/lib/plugins/helper/js.js b/lib/plugins/helper/js.js index 1ab2ebcff4..d001e00f88 100644 --- a/lib/plugins/helper/js.js +++ b/lib/plugins/helper/js.js @@ -1,7 +1,7 @@ 'use strict'; -const { htmlTag, url_for } = require('hexo-util'); -const { default: moize } = require('moize'); +import {htmlTag, url_for} from 'hexo-util'; +import moize from 'moize'; function jsHelper(...args) { let result = '\n'; @@ -23,7 +23,7 @@ function jsHelper(...args) { return result; } -module.exports = moize(jsHelper, { +export default moize(jsHelper, { maxSize: 10, isDeepEqual: true }); diff --git a/lib/plugins/helper/link_to.js b/lib/plugins/helper/link_to.js index 09daed2176..56afb3374c 100644 --- a/lib/plugins/helper/link_to.js +++ b/lib/plugins/helper/link_to.js @@ -1,6 +1,6 @@ 'use strict'; -const { htmlTag, url_for } = require('hexo-util'); +import {htmlTag, url_for} from 'hexo-util'; function linkToHelper(path, text, options = {}) { if (typeof options === 'boolean') options = {external: options}; @@ -25,4 +25,4 @@ function linkToHelper(path, text, options = {}) { return htmlTag('a', attrs, text); } -module.exports = linkToHelper; +export default linkToHelper; diff --git a/lib/plugins/helper/list_archives.js b/lib/plugins/helper/list_archives.js index 89b2b69414..1fbbababe1 100644 --- a/lib/plugins/helper/list_archives.js +++ b/lib/plugins/helper/list_archives.js @@ -1,7 +1,7 @@ 'use strict'; -const { toMomentLocale } = require('./date'); -const { url_for } = require('hexo-util'); +import {toMomentLocale} from './date'; +import {url_for} from 'hexo-util'; function listArchivesHelper(options = {}) { const { config } = this; @@ -105,4 +105,4 @@ function listArchivesHelper(options = {}) { return result; } -module.exports = listArchivesHelper; +export default listArchivesHelper; diff --git a/lib/plugins/helper/list_categories.js b/lib/plugins/helper/list_categories.js index 51455f2294..e2fd6c5ff8 100644 --- a/lib/plugins/helper/list_categories.js +++ b/lib/plugins/helper/list_categories.js @@ -1,6 +1,6 @@ 'use strict'; -const { url_for } = require('hexo-util'); +import {url_for} from 'hexo-util'; function listCategoriesHelper(categories, options) { if (!options && (!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))) { @@ -107,4 +107,4 @@ function listCategoriesHelper(categories, options) { return flatList(0); } -module.exports = listCategoriesHelper; +export default listCategoriesHelper; diff --git a/lib/plugins/helper/list_posts.js b/lib/plugins/helper/list_posts.js index 156ebff2fc..2a23bc478d 100644 --- a/lib/plugins/helper/list_posts.js +++ b/lib/plugins/helper/list_posts.js @@ -1,6 +1,6 @@ 'use strict'; -const { url_for } = require('hexo-util'); +import {url_for} from 'hexo-util'; function listPostsHelper(posts, options) { if (!options && (!posts || !Object.prototype.hasOwnProperty.call(posts, 'length'))) { @@ -55,4 +55,4 @@ function listPostsHelper(posts, options) { return result; } -module.exports = listPostsHelper; +export default listPostsHelper; diff --git a/lib/plugins/helper/list_tags.js b/lib/plugins/helper/list_tags.js index c75626f720..58f897ec90 100644 --- a/lib/plugins/helper/list_tags.js +++ b/lib/plugins/helper/list_tags.js @@ -1,7 +1,7 @@ 'use strict'; -const { url_for, escapeHTML } = require('hexo-util'); -const { default: moize } = require('moize'); +import {url_for, escapeHTML} from 'hexo-util'; +import moize from 'moize'; function listTagsHelper(tags, options) { if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { @@ -107,4 +107,4 @@ function listTagsHelperFactory(tags, options) { }).call(this, tags, options); } -module.exports = listTagsHelperFactory; +export default listTagsHelperFactory; diff --git a/lib/plugins/helper/mail_to.js b/lib/plugins/helper/mail_to.js index 9752f0055d..da18443b12 100644 --- a/lib/plugins/helper/mail_to.js +++ b/lib/plugins/helper/mail_to.js @@ -1,7 +1,7 @@ 'use strict'; -const { htmlTag } = require('hexo-util'); -const { default: moize } = require('moize'); +import {htmlTag} from 'hexo-util'; +import moize from 'moize'; function mailToHelper(path, text, options = {}) { if (Array.isArray(path)) path = path.join(','); @@ -33,7 +33,7 @@ function mailToHelper(path, text, options = {}) { return htmlTag('a', attrs, text); } -module.exports = moize(mailToHelper, { +export default moize(mailToHelper, { maxSize: 10, isDeepEqual: true }); diff --git a/lib/plugins/helper/markdown.js b/lib/plugins/helper/markdown.js index 7df352843d..5e90988ba6 100644 --- a/lib/plugins/helper/markdown.js +++ b/lib/plugins/helper/markdown.js @@ -4,4 +4,4 @@ function markdownHelper(text, options) { return this.render(text, 'markdown', options); } -module.exports = markdownHelper; +export default markdownHelper; diff --git a/lib/plugins/helper/meta_generator.js b/lib/plugins/helper/meta_generator.js index 20b7613939..ba9e6c9fc8 100755 --- a/lib/plugins/helper/meta_generator.js +++ b/lib/plugins/helper/meta_generator.js @@ -4,4 +4,4 @@ function metaGeneratorHelper() { return ``; } -module.exports = metaGeneratorHelper; +export default metaGeneratorHelper; diff --git a/lib/plugins/helper/number_format.js b/lib/plugins/helper/number_format.js index c6c2c0985d..f47d92716e 100644 --- a/lib/plugins/helper/number_format.js +++ b/lib/plugins/helper/number_format.js @@ -46,4 +46,4 @@ function numberFormatHelper(num, options = {}) { return before + (after ? separator + after : ''); } -module.exports = numberFormatHelper; +export default numberFormatHelper; diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.js index e9c3eb0dbe..64858287e3 100644 --- a/lib/plugins/helper/open_graph.js +++ b/lib/plugins/helper/open_graph.js @@ -1,8 +1,8 @@ 'use strict'; -const { isMoment, isDate } = require('moment'); -const { encodeURL, prettyUrls, stripHTML, escapeHTML } = require('hexo-util'); -const { default: moize } = require('moize'); +import {isMoment, isDate} from 'moment'; +import {encodeURL, prettyUrls, stripHTML, escapeHTML} from 'hexo-util'; +import moize from 'moize'; const localeMap = { 'en': 'en_US', @@ -180,4 +180,4 @@ function openGraphHelper(options = {}) { return result.trim(); } -module.exports = openGraphHelper; +export default openGraphHelper; diff --git a/lib/plugins/helper/paginator.js b/lib/plugins/helper/paginator.js index 662c61022c..c52749ce6c 100644 --- a/lib/plugins/helper/paginator.js +++ b/lib/plugins/helper/paginator.js @@ -1,6 +1,6 @@ 'use strict'; -const { htmlTag, url_for } = require('hexo-util'); +import {htmlTag, url_for} from 'hexo-util'; const createLink = (options, ctx) => { const { base, format } = options; @@ -150,4 +150,4 @@ function paginatorHelper(options = {}) { return tags.join(''); } -module.exports = paginatorHelper; +export default paginatorHelper; diff --git a/lib/plugins/helper/partial.js b/lib/plugins/helper/partial.js index bc3994189c..18f8198811 100644 --- a/lib/plugins/helper/partial.js +++ b/lib/plugins/helper/partial.js @@ -1,8 +1,8 @@ 'use strict'; -const { dirname, join } = require('path'); +import {dirname, join} from 'path'; -module.exports = ctx => function partial(name, locals, options = {}) { +export default ctx => (function partial(name, locals, options = {}) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); const { cache } = options; @@ -32,4 +32,4 @@ module.exports = ctx => function partial(name, locals, options = {}) { } return view.renderSync(viewLocals); -}; +}); diff --git a/lib/plugins/helper/relative_url.js b/lib/plugins/helper/relative_url.js index db1fba37fc..51efcc2545 100644 --- a/lib/plugins/helper/relative_url.js +++ b/lib/plugins/helper/relative_url.js @@ -1,7 +1,7 @@ 'use strict'; -const { relative_url } = require('hexo-util'); +import {relative_url} from 'hexo-util'; -module.exports = function(from, to) { +export default function(from, to) { return relative_url(from, to); }; diff --git a/lib/plugins/helper/render.js b/lib/plugins/helper/render.js index f71bdb2917..7aa6f88082 100644 --- a/lib/plugins/helper/render.js +++ b/lib/plugins/helper/render.js @@ -1,8 +1,8 @@ 'use strict'; -module.exports = ctx => function render(text, engine, options) { +export default ctx => (function render(text, engine, options) { return ctx.render.renderSync({ text, engine }, options); -}; +}); diff --git a/lib/plugins/helper/search_form.js b/lib/plugins/helper/search_form.js index f90a99b6d7..5f0032c7d2 100644 --- a/lib/plugins/helper/search_form.js +++ b/lib/plugins/helper/search_form.js @@ -1,6 +1,6 @@ 'use strict'; -const { default: moize } = require('moize'); +import moize from 'moize'; function searchFormHelper(options = {}) { const { config } = this; @@ -10,4 +10,4 @@ function searchFormHelper(options = {}) { return `
${button ? `` : ''}
`; } -module.exports = moize.deep(searchFormHelper); +export default moize.deep(searchFormHelper); diff --git a/lib/plugins/helper/tagcloud.js b/lib/plugins/helper/tagcloud.js index c6ee5f718d..e4bf1d5087 100644 --- a/lib/plugins/helper/tagcloud.js +++ b/lib/plugins/helper/tagcloud.js @@ -1,7 +1,7 @@ 'use strict'; -const { Color, url_for } = require('hexo-util'); -const { default: moize } = require('moize'); +import {Color, url_for} from 'hexo-util'; +import moize from 'moize'; function tagcloudHelper(tags, options) { if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { @@ -94,4 +94,4 @@ function tagcloudHelperFactory(tags, options) { }).call(this, tags, options); } -module.exports = tagcloudHelperFactory; +export default tagcloudHelperFactory; diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.js index e055ffd6f2..6d8fa69720 100644 --- a/lib/plugins/helper/toc.js +++ b/lib/plugins/helper/toc.js @@ -1,6 +1,6 @@ 'use strict'; -const { tocObj, escapeHTML, encodeURL } = require('hexo-util'); +import {tocObj, escapeHTML, encodeURL} from 'hexo-util'; function tocHelper(str, options = {}) { options = Object.assign({ @@ -91,4 +91,4 @@ function tocHelper(str, options = {}) { return result; } -module.exports = tocHelper; +export default tocHelper; diff --git a/lib/plugins/helper/url_for.js b/lib/plugins/helper/url_for.js index a31379a29b..5aea652ce2 100644 --- a/lib/plugins/helper/url_for.js +++ b/lib/plugins/helper/url_for.js @@ -1,7 +1,7 @@ 'use strict'; -const { url_for } = require('hexo-util'); +import {url_for} from 'hexo-util'; -module.exports = function(path, options) { +export default function(path, options) { return url_for.call(this, path, options); }; diff --git a/lib/plugins/injector/index.js b/lib/plugins/injector/index.js index be1a9aaca9..9ee9002d4c 100644 --- a/lib/plugins/injector/index.js +++ b/lib/plugins/injector/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { // eslint-disable-next-line no-unused-vars const { injector } = ctx.extend; }; diff --git a/lib/plugins/processor/asset.js b/lib/plugins/processor/asset.js index 113dab4e8d..675589c644 100644 --- a/lib/plugins/processor/asset.js +++ b/lib/plugins/processor/asset.js @@ -1,13 +1,13 @@ 'use strict'; -const { timezone, toDate, isExcludedFile, isMatch } = require('./common'); -const Promise = require('bluebird'); -const { parse: yfm } = require('hexo-front-matter'); -const { extname, relative } = require('path'); -const { Pattern } = require('hexo-util'); -const { magenta } = require('picocolors'); - -module.exports = ctx => { +import {timezone, toDate, isExcludedFile, isMatch} from './common'; +import Promise from 'bluebird'; +import {parse as yfm} from 'hexo-front-matter'; +import {extname, relative} from 'path'; +import {Pattern} from 'hexo-util'; +import {magenta} from 'picocolors'; + +export default ctx => { return { pattern: new Pattern(path => { if (isExcludedFile(path, ctx.config)) return; diff --git a/lib/plugins/processor/common.js b/lib/plugins/processor/common.js index e29c05ecb4..c0f4082b9c 100644 --- a/lib/plugins/processor/common.js +++ b/lib/plugins/processor/common.js @@ -1,8 +1,8 @@ 'use strict'; -const { Pattern } = require('hexo-util'); -const moment = require('moment-timezone'); -const micromatch = require('micromatch'); +import {Pattern} from 'hexo-util'; +import moment from 'moment-timezone'; +import micromatch from 'micromatch'; const DURATION_MINUTE = 1000 * 60; @@ -27,16 +27,16 @@ function isExcludedFile(path, config) { return false; } -exports.ignoreTmpAndHiddenFile = new Pattern(path => { +export var ignoreTmpAndHiddenFile = new Pattern(path => { if (isTmpFile(path) || isHiddenFile(path)) return false; return true; }); -exports.isTmpFile = isTmpFile; -exports.isHiddenFile = isHiddenFile; -exports.isExcludedFile = isExcludedFile; +export {isTmpFile}; +export {isHiddenFile}; +export {isExcludedFile}; -exports.toDate = date => { +export function toDate(date) { if (!date || moment.isMoment(date)) return date; if (!(date instanceof Date)) { @@ -46,9 +46,9 @@ exports.toDate = date => { if (isNaN(date.getTime())) return; return date; -}; +} -exports.timezone = (date, timezone) => { +export function timezone(date, timezone) { if (moment.isMoment(date)) date = date.toDate(); const offset = date.getTimezoneOffset(); @@ -57,6 +57,6 @@ exports.timezone = (date, timezone) => { const diff = (offset - target) * DURATION_MINUTE; return new Date(ms - diff); -}; +} -exports.isMatch = isMatch; +export {isMatch}; diff --git a/lib/plugins/processor/data.js b/lib/plugins/processor/data.js index e6878f24b5..6e3d79a896 100644 --- a/lib/plugins/processor/data.js +++ b/lib/plugins/processor/data.js @@ -1,9 +1,9 @@ 'use strict'; -const { Pattern } = require('hexo-util'); -const { extname } = require('path'); +import {Pattern} from 'hexo-util'; +import {extname} from 'path'; -module.exports = ctx => ({ +export default ctx => ({ pattern: new Pattern('_data/*path'), process: function dataProcessor(file) { diff --git a/lib/plugins/processor/index.js b/lib/plugins/processor/index.js index caa18dbaca..02c1f7da58 100644 --- a/lib/plugins/processor/index.js +++ b/lib/plugins/processor/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { processor } = ctx.extend; function register(name) { diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.js index 4e61712800..8c72461cfd 100644 --- a/lib/plugins/processor/post.js +++ b/lib/plugins/processor/post.js @@ -1,12 +1,12 @@ 'use strict'; -const { toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch } = require('./common'); -const Promise = require('bluebird'); -const { parse: yfm } = require('hexo-front-matter'); -const { extname, join } = require('path'); -const { stat, listDir } = require('hexo-fs'); -const { slugize, Pattern, Permalink } = require('hexo-util'); -const { magenta } = require('picocolors'); +import {toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch} from './common'; +import Promise from 'bluebird'; +import {parse as yfm} from 'hexo-front-matter'; +import {extname, join} from 'path'; +import {stat, listDir} from 'hexo-fs'; +import {slugize, Pattern, Permalink} from 'hexo-util'; +import {magenta} from 'picocolors'; const postDir = '_posts/'; const draftDir = '_drafts/'; @@ -22,7 +22,7 @@ const preservedKeys = { hash: true }; -module.exports = ctx => { +export default ctx => { return { pattern: new Pattern(path => { if (isTmpFile(path)) return; diff --git a/lib/plugins/renderer/index.js b/lib/plugins/renderer/index.js index d9f03fe718..65a4b1e564 100644 --- a/lib/plugins/renderer/index.js +++ b/lib/plugins/renderer/index.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = ctx => { +export default ctx => { const { renderer } = ctx.extend; const plain = require('./plain'); diff --git a/lib/plugins/renderer/json.js b/lib/plugins/renderer/json.js index 8dbe42cacc..7951689e52 100644 --- a/lib/plugins/renderer/json.js +++ b/lib/plugins/renderer/json.js @@ -4,4 +4,4 @@ function jsonRenderer(data) { return JSON.parse(data.text); } -module.exports = jsonRenderer; +export default jsonRenderer; diff --git a/lib/plugins/renderer/nunjucks.js b/lib/plugins/renderer/nunjucks.js index b6760e0e00..6fff27c4b5 100644 --- a/lib/plugins/renderer/nunjucks.js +++ b/lib/plugins/renderer/nunjucks.js @@ -1,9 +1,9 @@ 'use strict'; -const nunjucks = require('nunjucks'); -const { readFileSync } = require('hexo-fs'); -const { dirname } = require('path'); +import nunjucks from 'nunjucks'; +import {readFileSync} from 'hexo-fs'; +import {dirname} from 'path'; function toArray(value) { if (Array.isArray(value)) { @@ -67,4 +67,4 @@ njkRenderer.compile = data => { return locals => njkCompile(data).render(locals); }; -module.exports = njkRenderer; +export default njkRenderer; diff --git a/lib/plugins/renderer/plain.js b/lib/plugins/renderer/plain.js index 2961bd8e7a..15e775cbbb 100644 --- a/lib/plugins/renderer/plain.js +++ b/lib/plugins/renderer/plain.js @@ -4,4 +4,4 @@ function plainRenderer(data) { return data.text; } -module.exports = plainRenderer; +export default plainRenderer; diff --git a/lib/plugins/renderer/yaml.js b/lib/plugins/renderer/yaml.js index ad9a8a6c02..145dba617d 100644 --- a/lib/plugins/renderer/yaml.js +++ b/lib/plugins/renderer/yaml.js @@ -1,8 +1,8 @@ 'use strict'; -const yaml = require('js-yaml'); -const { escape } = require('hexo-front-matter'); -const log = require('hexo-log').default(); +import yaml from 'js-yaml'; +import {escape} from 'hexo-front-matter'; +const log = require('hexo-log')(); let schema = {}; // FIXME: workaround for https://github.com/hexojs/hexo/issues/4917 @@ -20,4 +20,4 @@ function yamlHelper(data) { return yaml.load(escape(data.text), { schema }); } -module.exports = yamlHelper; +export default yamlHelper; diff --git a/lib/plugins/tag/asset_img.js b/lib/plugins/tag/asset_img.js index 5189c28a27..657a4c1e01 100644 --- a/lib/plugins/tag/asset_img.js +++ b/lib/plugins/tag/asset_img.js @@ -1,7 +1,7 @@ 'use strict'; -const img = require('./img'); -const { encodeURL } = require('hexo-util'); +import img from './img'; +import {encodeURL} from 'hexo-util'; /** * Asset image tag @@ -9,7 +9,7 @@ const { encodeURL } = require('hexo-util'); * Syntax: * {% asset_img [class names] slug [width] [height] [title text [alt text]]%} */ -module.exports = ctx => { +export default ctx => { const PostAsset = ctx.model('PostAsset'); return function assetImgTag(args) { diff --git a/lib/plugins/tag/asset_link.js b/lib/plugins/tag/asset_link.js index 8f3225e297..ec7e256609 100644 --- a/lib/plugins/tag/asset_link.js +++ b/lib/plugins/tag/asset_link.js @@ -1,6 +1,6 @@ 'use strict'; -const { encodeURL, escapeHTML } = require('hexo-util'); +import {encodeURL, escapeHTML} from 'hexo-util'; /** * Asset link tag @@ -8,7 +8,7 @@ const { encodeURL, escapeHTML } = require('hexo-util'); * Syntax: * {% asset_link slug [title] [escape] %} */ -module.exports = ctx => { +export default ctx => { const PostAsset = ctx.model('PostAsset'); return function assetLinkTag(args) { diff --git a/lib/plugins/tag/asset_path.js b/lib/plugins/tag/asset_path.js index d988176d30..0457a0877c 100644 --- a/lib/plugins/tag/asset_path.js +++ b/lib/plugins/tag/asset_path.js @@ -1,6 +1,6 @@ 'use strict'; -const { encodeURL } = require('hexo-util'); +import {encodeURL} from 'hexo-util'; /** * Asset path tag @@ -8,7 +8,7 @@ const { encodeURL } = require('hexo-util'); * Syntax: * {% asset_path slug %} */ -module.exports = ctx => { +export default ctx => { const PostAsset = ctx.model('PostAsset'); return function assetPathTag(args) { diff --git a/lib/plugins/tag/blockquote.js b/lib/plugins/tag/blockquote.js index 847727da92..646dbb8b58 100644 --- a/lib/plugins/tag/blockquote.js +++ b/lib/plugins/tag/blockquote.js @@ -2,7 +2,7 @@ // Based on: https://raw.github.com/imathis/octopress/master/plugins/blockquote.rb -const titlecase = require('titlecase'); +import titlecase from 'titlecase'; const rFullCiteWithTitle = /(\S.*)\s+(https?:\/\/\S+)\s+(.+)/i; const rFullCite = /(\S.*)\s+(https?:\/\/\S+)/i; @@ -57,7 +57,7 @@ const parseFooter = (args, ctx) => { * {% endblockquote %} */ -module.exports = ctx => function blockquoteTag(args, content) { +export default ctx => (function blockquoteTag(args, content) { const footer = parseFooter(args, ctx); let result = '
'; @@ -66,4 +66,4 @@ module.exports = ctx => function blockquoteTag(args, content) { result += '
'; return result; -}; +}); diff --git a/lib/plugins/tag/code.js b/lib/plugins/tag/code.js index d4620dcccc..7d24a8f36a 100644 --- a/lib/plugins/tag/code.js +++ b/lib/plugins/tag/code.js @@ -2,7 +2,7 @@ // Based on: https://raw.github.com/imathis/octopress/master/plugins/code_block.rb -const { escapeHTML } = require('hexo-util'); +import {escapeHTML} from 'hexo-util'; const rCaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+)\s+(.+)/i; const rCaptionUrl = /(\S[\S\s]*)\s+(https?:\/\/\S+)/i; @@ -116,7 +116,7 @@ function parseArgs(args) { }; } -module.exports = ctx => function codeTag(args, content) { +export default ctx => function codeTag(args, content) { // If neither highlight.js nor prism.js is enabled, return escaped code directly if (!ctx.extend.highlight.query(ctx.config.syntax_highlighter)) { @@ -146,4 +146,4 @@ module.exports = ctx => function codeTag(args, content) { }); return content.replace(/{/g, '{').replace(/}/g, '}'); -}; +}); diff --git a/lib/plugins/tag/iframe.js b/lib/plugins/tag/iframe.js index ec8b7875f9..d0e517aa04 100644 --- a/lib/plugins/tag/iframe.js +++ b/lib/plugins/tag/iframe.js @@ -1,6 +1,6 @@ 'use strict'; -const { htmlTag } = require('hexo-util'); +import {htmlTag} from 'hexo-util'; /** * Iframe tag @@ -26,4 +26,4 @@ function iframeTag(args) { return htmlTag('iframe', attrs, ''); } -module.exports = iframeTag; +export default iframeTag; diff --git a/lib/plugins/tag/img.js b/lib/plugins/tag/img.js index e474d27b32..5226341714 100644 --- a/lib/plugins/tag/img.js +++ b/lib/plugins/tag/img.js @@ -1,6 +1,6 @@ 'use strict'; -const { htmlTag, url_for } = require('hexo-util'); +import {htmlTag, url_for} from 'hexo-util'; const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/; const rMetaDoubleQuote = /"?([^"]+)?"?/; @@ -12,7 +12,7 @@ const rMetaSingleQuote = /'?([^']+)?'?/; * Syntax: * {% img [class names] /path/to/image [width] [height] [title text [alt text]] %} */ -module.exports = ctx => { +export default ctx => { return function imgTag(args) { const classes = []; diff --git a/lib/plugins/tag/include_code.js b/lib/plugins/tag/include_code.js index 8d9d1a9a95..8394925918 100644 --- a/lib/plugins/tag/include_code.js +++ b/lib/plugins/tag/include_code.js @@ -1,7 +1,7 @@ 'use strict'; -const { exists, readFile } = require('hexo-fs'); -const { basename, extname, join, posix } = require('path'); +import {exists, readFile} from 'hexo-fs'; +import {basename, extname, join, posix} from 'path'; const rCaptionTitleFile = /(.*)?(?:\s+|^)(\/*\S+)/; const rLang = /\s*lang:(\w+)/i; @@ -15,7 +15,7 @@ const rTo = /\s*to:(\d+)/i; * {% include_code [title] [lang:language] path/to/file %} */ -module.exports = ctx => function includeCodeTag(args) { +export default ctx => (function includeCodeTag(args) { let codeDir = ctx.config.code_dir; let arg = args.join(' '); @@ -76,4 +76,4 @@ module.exports = ctx => function includeCodeTag(args) { return `
${code}
`; }); -}; +}); diff --git a/lib/plugins/tag/index.js b/lib/plugins/tag/index.js index 4b6aa2531f..085cc418a1 100644 --- a/lib/plugins/tag/index.js +++ b/lib/plugins/tag/index.js @@ -1,8 +1,8 @@ 'use strict'; -const { default: moize } = require('moize'); +import moize from 'moize'; -module.exports = ctx => { +export default ctx => { const { tag } = ctx.extend; const blockquote = require('./blockquote')(ctx); @@ -50,7 +50,7 @@ module.exports = ctx => { // Use WeakMap to track different ctx (in case there is any) const moized = new WeakMap(); -module.exports.postFindOneFactory = function postFindOneFactory(ctx) { +export function postFindOneFactory(ctx) { if (moized.has(ctx)) { return moized.get(ctx); } @@ -62,7 +62,7 @@ module.exports.postFindOneFactory = function postFindOneFactory(ctx) { moized.set(ctx, moizedPostFindOne); return moizedPostFindOne; -}; +} function createPostFindOne(ctx) { const Post = ctx.model('Post'); diff --git a/lib/plugins/tag/link.js b/lib/plugins/tag/link.js index 744f874f88..87a7d8f480 100644 --- a/lib/plugins/tag/link.js +++ b/lib/plugins/tag/link.js @@ -1,6 +1,6 @@ 'use strict'; -const { htmlTag } = require('hexo-util'); +import {htmlTag} from 'hexo-util'; const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/; @@ -56,4 +56,4 @@ function linkTag(args, content) { return htmlTag('a', attrs, text.join(' ')); } -module.exports = linkTag; +export default linkTag; diff --git a/lib/plugins/tag/post_link.js b/lib/plugins/tag/post_link.js index 838b046560..af8355afad 100644 --- a/lib/plugins/tag/post_link.js +++ b/lib/plugins/tag/post_link.js @@ -1,7 +1,7 @@ 'use strict'; -const { encodeURL, escapeHTML } = require('hexo-util'); -const { postFindOneFactory } = require('./'); +import {encodeURL, escapeHTML} from 'hexo-util'; +import {postFindOneFactory} from './'; /** * Post link tag @@ -9,7 +9,7 @@ const { postFindOneFactory } = require('./'); * Syntax: * {% post_link slug | title [title] [escape] %} */ -module.exports = ctx => { +export default ctx => { return function postLinkTag(args) { const slug = args.shift(); if (!slug) { diff --git a/lib/plugins/tag/post_path.js b/lib/plugins/tag/post_path.js index 679f65039f..bbcd0a46f0 100644 --- a/lib/plugins/tag/post_path.js +++ b/lib/plugins/tag/post_path.js @@ -1,7 +1,7 @@ 'use strict'; -const { encodeURL } = require('hexo-util'); -const { postFindOneFactory } = require('./'); +import {encodeURL} from 'hexo-util'; +import {postFindOneFactory} from './'; /** * Post path tag @@ -9,7 +9,7 @@ const { postFindOneFactory } = require('./'); * Syntax: * {% post_path slug | title %} */ -module.exports = ctx => { +export default ctx => { return function postPathTag(args) { const slug = args.shift(); if (!slug) return; diff --git a/lib/plugins/tag/pullquote.js b/lib/plugins/tag/pullquote.js index 8a2f945d4a..e0c2a8ac52 100644 --- a/lib/plugins/tag/pullquote.js +++ b/lib/plugins/tag/pullquote.js @@ -8,10 +8,10 @@ * Quote string * {% endpullquote %} */ -module.exports = ctx => function pullquoteTag(args, content) { +export default ctx => (function pullquoteTag(args, content) { args.unshift('pullquote'); const result = ctx.render.renderSync({text: content, engine: 'markdown'}); return `
${result}
`; -}; +}); diff --git a/lib/theme/index.js b/lib/theme/index.js index 95f21aed4d..a26bbc35d0 100644 --- a/lib/theme/index.js +++ b/lib/theme/index.js @@ -1,9 +1,9 @@ 'use strict'; -const { extname } = require('path'); -const Box = require('../box'); -const View = require('./view'); -const I18n = require('hexo-i18n'); +import {extname} from 'path'; +import Box from '../box'; +import View from './view'; +import I18n from 'hexo-i18n'; class Theme extends Box { constructor(ctx, options) { @@ -76,4 +76,4 @@ class Theme extends Box { } } -module.exports = Theme; +export default Theme; diff --git a/lib/theme/processors/config.js b/lib/theme/processors/config.js index 53ce70ff09..60af5dffe9 100644 --- a/lib/theme/processors/config.js +++ b/lib/theme/processors/config.js @@ -1,8 +1,8 @@ 'use strict'; -const { Pattern } = require('hexo-util'); +import {Pattern} from 'hexo-util'; -exports.process = function(file) { +export function process(file) { if (file.type === 'delete') { file.box.config = {}; return; @@ -15,6 +15,6 @@ exports.process = function(file) { this.log.error('Theme config load failed.'); throw err; }); -}; +} -exports.pattern = new Pattern(/^_config\.\w+$/); +export var pattern = new Pattern(/^_config\.\w+$/); diff --git a/lib/theme/processors/i18n.js b/lib/theme/processors/i18n.js index 1fe8983671..166ba35b80 100644 --- a/lib/theme/processors/i18n.js +++ b/lib/theme/processors/i18n.js @@ -1,9 +1,9 @@ 'use strict'; -const { Pattern } = require('hexo-util'); -const { extname } = require('path'); +import {Pattern} from 'hexo-util'; +import {extname} from 'path'; -exports.process = file => { +export function process(file) { const { path } = file.params; const ext = extname(path); const name = path.substring(0, path.length - ext.length); @@ -18,6 +18,6 @@ exports.process = file => { if (typeof data !== 'object') return; i18n.set(name, data); }); -}; +} -exports.pattern = new Pattern('languages/*path'); +export var pattern = new Pattern('languages/*path'); diff --git a/lib/theme/processors/source.js b/lib/theme/processors/source.js index 826b6a109e..16ba62c7a2 100644 --- a/lib/theme/processors/source.js +++ b/lib/theme/processors/source.js @@ -1,9 +1,9 @@ 'use strict'; -const { Pattern } = require('hexo-util'); -const common = require('../../plugins/processor/common'); +import {Pattern} from 'hexo-util'; +import common from '../../plugins/processor/common'; -exports.process = function(file) { +export function process(file) { const Asset = this.model('Asset'); const id = file.source.substring(this.base_dir.length).replace(/\\/g, '/'); const { path } = file.params; @@ -22,9 +22,9 @@ exports.process = function(file) { path, modified: file.type !== 'skip' }); -}; +} -exports.pattern = new Pattern(path => { +export var pattern = new Pattern(path => { if (!path.startsWith('source/')) return false; path = path.substring(7); diff --git a/lib/theme/processors/view.js b/lib/theme/processors/view.js index b7cdd4a5bb..3f4ce3dab9 100644 --- a/lib/theme/processors/view.js +++ b/lib/theme/processors/view.js @@ -1,8 +1,8 @@ 'use strict'; -const { Pattern } = require('hexo-util'); +import {Pattern} from 'hexo-util'; -exports.process = file => { +export function process(file) { const { path } = file.params; if (file.type === 'delete') { @@ -13,6 +13,6 @@ exports.process = file => { return file.read().then(result => { file.box.setView(path, result); }); -}; +} -exports.pattern = new Pattern('layout/*path'); +export var pattern = new Pattern('layout/*path'); diff --git a/lib/theme/view.js b/lib/theme/view.js index 6c0439bc48..9600183262 100644 --- a/lib/theme/view.js +++ b/lib/theme/view.js @@ -1,8 +1,8 @@ 'use strict'; -const { dirname, extname, join } = require('path'); -const { parse: yfm } = require('hexo-front-matter'); -const Promise = require('bluebird'); +import {dirname, extname, join} from 'path'; +import {parse as yfm} from 'hexo-front-matter'; +import Promise from 'bluebird'; const assignIn = (target, ...sources) => { const length = sources.length; @@ -143,4 +143,4 @@ class View { } } -module.exports = View; +export default View; From 0913097dae3d786207daf70e5887fd3c55042f1e Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 00:39:03 +0800 Subject: [PATCH 02/45] refactor: migrate typescript --- lib/box/{file.js => file.ts} | 5 +++ lib/box/{index.js => index.ts} | 15 +++++++- lib/extend/{console.js => console.ts} | 3 ++ lib/extend/{deployer.js => deployer.ts} | 2 + lib/extend/{filter.js => filter.ts} | 2 + lib/extend/{generator.js => generator.ts} | 3 ++ lib/extend/{helper.js => helper.ts} | 2 + lib/extend/{index.js => index.ts} | 0 lib/extend/{injector.js => injector.ts} | 4 ++ lib/extend/{migrator.js => migrator.ts} | 2 + lib/extend/{processor.js => processor.ts} | 2 + lib/extend/{renderer.js => renderer.ts} | 5 ++- lib/extend/{tag.js => tag.ts} | 6 +++ .../{default_config.js => default_config.ts} | 0 lib/hexo/{index.js => index.ts} | 37 +++++++++++++++++++ lib/hexo/{load_config.js => load_config.ts} | 0 .../{load_database.js => load_database.ts} | 0 lib/hexo/{load_plugins.js => load_plugins.ts} | 0 ...d_theme_config.js => load_theme_config.ts} | 0 lib/hexo/{locals.js => locals.ts} | 3 ++ ...ti_config_path.js => multi_config_path.ts} | 0 lib/hexo/{post.js => post.ts} | 10 ++++- ...{register_models.js => register_models.ts} | 0 lib/hexo/{render.js => render.ts} | 5 ++- lib/hexo/{router.js => router.ts} | 9 +++++ lib/hexo/{scaffold.js => scaffold.ts} | 4 ++ lib/hexo/{source.js => source.ts} | 0 .../{update_package.js => update_package.ts} | 0 ...{validate_config.js => validate_config.ts} | 0 lib/models/{asset.js => asset.ts} | 0 lib/models/{cache.js => cache.ts} | 0 lib/models/{category.js => category.ts} | 0 lib/models/{data.js => data.ts} | 0 lib/models/{index.js => index.ts} | 0 lib/models/{page.js => page.ts} | 0 lib/models/{post.js => post.ts} | 0 lib/models/{post_asset.js => post_asset.ts} | 0 .../{post_category.js => post_category.ts} | 0 lib/models/{post_tag.js => post_tag.ts} | 0 lib/models/{tag.js => tag.ts} | 0 lib/models/types/{moment.js => moment.ts} | 2 + lib/plugins/console/{clean.js => clean.ts} | 0 lib/plugins/console/{config.js => config.ts} | 0 lib/plugins/console/{deploy.js => deploy.ts} | 0 .../console/{generate.js => generate.ts} | 14 ++++++- lib/plugins/console/{index.js => index.ts} | 0 .../console/list/{category.js => category.ts} | 0 .../console/list/{common.js => common.ts} | 0 .../console/list/{index.js => index.ts} | 0 lib/plugins/console/list/{page.js => page.ts} | 0 lib/plugins/console/list/{post.js => post.ts} | 0 .../console/list/{route.js => route.ts} | 0 lib/plugins/console/list/{tag.js => tag.ts} | 0 .../console/{migrate.js => migrate.ts} | 0 lib/plugins/console/{new.js => new.ts} | 0 .../console/{publish.js => publish.ts} | 0 lib/plugins/console/{render.js => render.ts} | 0 .../{excerpt.js => excerpt.ts} | 0 .../{external_link.js => external_link.ts} | 0 .../after_post_render/{index.js => index.ts} | 0 .../{external_link.js => external_link.ts} | 0 .../after_render/{index.js => index.ts} | 0 .../{meta_generator.js => meta_generator.ts} | 0 .../filter/before_exit/{index.js => index.ts} | 0 .../{save_database.js => save_database.ts} | 0 .../before_generate/{index.js => index.ts} | 0 .../{render_post.js => render_post.ts} | 0 ...k_code_block.js => backtick_code_block.ts} | 0 .../before_post_render/{index.js => index.ts} | 0 .../{titlecase.js => titlecase.ts} | 0 lib/plugins/filter/{index.js => index.ts} | 0 .../{new_post_path.js => new_post_path.ts} | 0 .../{post_permalink.js => post_permalink.ts} | 0 .../template_locals/{i18n.js => i18n.ts} | 0 .../template_locals/{index.js => index.ts} | 0 lib/plugins/generator/{asset.js => asset.ts} | 0 lib/plugins/generator/{index.js => index.ts} | 0 lib/plugins/generator/{page.js => page.ts} | 0 lib/plugins/generator/{post.js => post.ts} | 0 lib/plugins/helper/{css.js => css.ts} | 0 lib/plugins/helper/{date.js => date.ts} | 0 lib/plugins/helper/{debug.js => debug.ts} | 0 .../helper/{favicon_tag.js => favicon_tag.ts} | 0 .../helper/{feed_tag.js => feed_tag.ts} | 2 +- lib/plugins/helper/{format.js => format.ts} | 0 .../{fragment_cache.js => fragment_cache.ts} | 0 .../{full_url_for.js => full_url_for.ts} | 0 .../helper/{gravatar.js => gravatar.ts} | 0 .../helper/{image_tag.js => image_tag.ts} | 0 lib/plugins/helper/{index.js => index.ts} | 0 lib/plugins/helper/{is.js => is.ts} | 0 lib/plugins/helper/{js.js => js.ts} | 0 lib/plugins/helper/{link_to.js => link_to.ts} | 0 .../{list_archives.js => list_archives.ts} | 0 ...{list_categories.js => list_categories.ts} | 0 .../helper/{list_posts.js => list_posts.ts} | 0 .../helper/{list_tags.js => list_tags.ts} | 2 +- lib/plugins/helper/{mail_to.js => mail_to.ts} | 0 .../helper/{markdown.js => markdown.ts} | 0 .../{meta_generator.js => meta_generator.ts} | 0 .../{number_format.js => number_format.ts} | 0 .../helper/{open_graph.js => open_graph.ts} | 0 .../helper/{paginator.js => paginator.ts} | 0 lib/plugins/helper/{partial.js => partial.ts} | 0 .../{relative_url.js => relative_url.ts} | 0 lib/plugins/helper/{render.js => render.ts} | 0 .../helper/{search_form.js => search_form.ts} | 0 .../helper/{tagcloud.js => tagcloud.ts} | 2 +- lib/plugins/helper/{toc.js => toc.ts} | 0 lib/plugins/helper/{url_for.js => url_for.ts} | 0 lib/plugins/injector/{index.js => index.ts} | 0 lib/plugins/processor/{asset.js => asset.ts} | 0 .../processor/{common.js => common.ts} | 0 lib/plugins/processor/{data.js => data.ts} | 0 lib/plugins/processor/{index.js => index.ts} | 0 lib/plugins/processor/{post.js => post.ts} | 0 lib/plugins/renderer/{index.js => index.ts} | 0 lib/plugins/renderer/{json.js => json.ts} | 0 .../renderer/{nunjucks.js => nunjucks.ts} | 0 lib/plugins/renderer/{plain.js => plain.ts} | 0 lib/plugins/renderer/{yaml.js => yaml.ts} | 0 .../tag/{asset_img.js => asset_img.ts} | 0 .../tag/{asset_link.js => asset_link.ts} | 0 .../tag/{asset_path.js => asset_path.ts} | 0 .../tag/{blockquote.js => blockquote.ts} | 0 lib/plugins/tag/{code.js => code.ts} | 0 lib/plugins/tag/{iframe.js => iframe.ts} | 0 lib/plugins/tag/{img.js => img.ts} | 0 .../tag/{include_code.js => include_code.ts} | 0 lib/plugins/tag/{index.js => index.ts} | 0 lib/plugins/tag/{link.js => link.ts} | 0 .../tag/{post_link.js => post_link.ts} | 0 .../tag/{post_path.js => post_path.ts} | 0 .../tag/{pullquote.js => pullquote.ts} | 0 lib/theme/{index.js => index.ts} | 7 +++- lib/theme/processors/{config.js => config.ts} | 0 lib/theme/processors/{i18n.js => i18n.ts} | 0 lib/theme/processors/{source.js => source.ts} | 0 lib/theme/processors/{view.js => view.ts} | 0 lib/theme/{view.js => view.ts} | 11 ++++++ 140 files changed, 150 insertions(+), 9 deletions(-) rename lib/box/{file.js => file.ts} (88%) rename lib/box/{index.js => index.ts} (96%) rename lib/extend/{console.js => console.ts} (98%) rename lib/extend/{deployer.js => deployer.ts} (96%) rename lib/extend/{filter.js => filter.ts} (99%) rename lib/extend/{generator.js => generator.ts} (93%) rename lib/extend/{helper.js => helper.ts} (97%) rename lib/extend/{index.js => index.ts} (100%) rename lib/extend/{injector.js => injector.ts} (97%) rename lib/extend/{migrator.js => migrator.ts} (96%) rename lib/extend/{processor.js => processor.ts} (96%) rename lib/extend/{renderer.js => renderer.ts} (95%) rename lib/extend/{tag.js => tag.ts} (98%) rename lib/hexo/{default_config.js => default_config.ts} (100%) rename lib/hexo/{index.js => index.ts} (94%) rename lib/hexo/{load_config.js => load_config.ts} (100%) rename lib/hexo/{load_database.js => load_database.ts} (100%) rename lib/hexo/{load_plugins.js => load_plugins.ts} (100%) rename lib/hexo/{load_theme_config.js => load_theme_config.ts} (100%) rename lib/hexo/{locals.js => locals.ts} (96%) rename lib/hexo/{multi_config_path.js => multi_config_path.ts} (100%) rename lib/hexo/{post.js => post.ts} (98%) rename lib/hexo/{register_models.js => register_models.ts} (100%) rename lib/hexo/{render.js => render.ts} (97%) rename lib/hexo/{router.js => router.ts} (96%) rename lib/hexo/{scaffold.js => scaffold.ts} (95%) rename lib/hexo/{source.js => source.ts} (100%) rename lib/hexo/{update_package.js => update_package.ts} (100%) rename lib/hexo/{validate_config.js => validate_config.ts} (100%) rename lib/models/{asset.js => asset.ts} (100%) rename lib/models/{cache.js => cache.ts} (100%) rename lib/models/{category.js => category.ts} (100%) rename lib/models/{data.js => data.ts} (100%) rename lib/models/{index.js => index.ts} (100%) rename lib/models/{page.js => page.ts} (100%) rename lib/models/{post.js => post.ts} (100%) rename lib/models/{post_asset.js => post_asset.ts} (100%) rename lib/models/{post_category.js => post_category.ts} (100%) rename lib/models/{post_tag.js => post_tag.ts} (100%) rename lib/models/{tag.js => tag.ts} (100%) rename lib/models/types/{moment.js => moment.ts} (98%) rename lib/plugins/console/{clean.js => clean.ts} (100%) rename lib/plugins/console/{config.js => config.ts} (100%) rename lib/plugins/console/{deploy.js => deploy.ts} (100%) rename lib/plugins/console/{generate.js => generate.ts} (95%) rename lib/plugins/console/{index.js => index.ts} (100%) rename lib/plugins/console/list/{category.js => category.ts} (100%) rename lib/plugins/console/list/{common.js => common.ts} (100%) rename lib/plugins/console/list/{index.js => index.ts} (100%) rename lib/plugins/console/list/{page.js => page.ts} (100%) rename lib/plugins/console/list/{post.js => post.ts} (100%) rename lib/plugins/console/list/{route.js => route.ts} (100%) rename lib/plugins/console/list/{tag.js => tag.ts} (100%) rename lib/plugins/console/{migrate.js => migrate.ts} (100%) rename lib/plugins/console/{new.js => new.ts} (100%) rename lib/plugins/console/{publish.js => publish.ts} (100%) rename lib/plugins/console/{render.js => render.ts} (100%) rename lib/plugins/filter/after_post_render/{excerpt.js => excerpt.ts} (100%) rename lib/plugins/filter/after_post_render/{external_link.js => external_link.ts} (100%) rename lib/plugins/filter/after_post_render/{index.js => index.ts} (100%) rename lib/plugins/filter/after_render/{external_link.js => external_link.ts} (100%) rename lib/plugins/filter/after_render/{index.js => index.ts} (100%) rename lib/plugins/filter/after_render/{meta_generator.js => meta_generator.ts} (100%) rename lib/plugins/filter/before_exit/{index.js => index.ts} (100%) rename lib/plugins/filter/before_exit/{save_database.js => save_database.ts} (100%) rename lib/plugins/filter/before_generate/{index.js => index.ts} (100%) rename lib/plugins/filter/before_generate/{render_post.js => render_post.ts} (100%) rename lib/plugins/filter/before_post_render/{backtick_code_block.js => backtick_code_block.ts} (100%) rename lib/plugins/filter/before_post_render/{index.js => index.ts} (100%) rename lib/plugins/filter/before_post_render/{titlecase.js => titlecase.ts} (100%) rename lib/plugins/filter/{index.js => index.ts} (100%) rename lib/plugins/filter/{new_post_path.js => new_post_path.ts} (100%) rename lib/plugins/filter/{post_permalink.js => post_permalink.ts} (100%) rename lib/plugins/filter/template_locals/{i18n.js => i18n.ts} (100%) rename lib/plugins/filter/template_locals/{index.js => index.ts} (100%) rename lib/plugins/generator/{asset.js => asset.ts} (100%) rename lib/plugins/generator/{index.js => index.ts} (100%) rename lib/plugins/generator/{page.js => page.ts} (100%) rename lib/plugins/generator/{post.js => post.ts} (100%) rename lib/plugins/helper/{css.js => css.ts} (100%) rename lib/plugins/helper/{date.js => date.ts} (100%) rename lib/plugins/helper/{debug.js => debug.ts} (100%) rename lib/plugins/helper/{favicon_tag.js => favicon_tag.ts} (100%) rename lib/plugins/helper/{feed_tag.js => feed_tag.ts} (95%) rename lib/plugins/helper/{format.js => format.ts} (100%) rename lib/plugins/helper/{fragment_cache.js => fragment_cache.ts} (100%) rename lib/plugins/helper/{full_url_for.js => full_url_for.ts} (100%) mode change 100755 => 100644 rename lib/plugins/helper/{gravatar.js => gravatar.ts} (100%) rename lib/plugins/helper/{image_tag.js => image_tag.ts} (100%) rename lib/plugins/helper/{index.js => index.ts} (100%) rename lib/plugins/helper/{is.js => is.ts} (100%) rename lib/plugins/helper/{js.js => js.ts} (100%) rename lib/plugins/helper/{link_to.js => link_to.ts} (100%) rename lib/plugins/helper/{list_archives.js => list_archives.ts} (100%) rename lib/plugins/helper/{list_categories.js => list_categories.ts} (100%) rename lib/plugins/helper/{list_posts.js => list_posts.ts} (100%) rename lib/plugins/helper/{list_tags.js => list_tags.ts} (98%) rename lib/plugins/helper/{mail_to.js => mail_to.ts} (100%) rename lib/plugins/helper/{markdown.js => markdown.ts} (100%) rename lib/plugins/helper/{meta_generator.js => meta_generator.ts} (100%) mode change 100755 => 100644 rename lib/plugins/helper/{number_format.js => number_format.ts} (100%) rename lib/plugins/helper/{open_graph.js => open_graph.ts} (100%) rename lib/plugins/helper/{paginator.js => paginator.ts} (100%) rename lib/plugins/helper/{partial.js => partial.ts} (100%) rename lib/plugins/helper/{relative_url.js => relative_url.ts} (100%) rename lib/plugins/helper/{render.js => render.ts} (100%) rename lib/plugins/helper/{search_form.js => search_form.ts} (100%) rename lib/plugins/helper/{tagcloud.js => tagcloud.ts} (98%) rename lib/plugins/helper/{toc.js => toc.ts} (100%) rename lib/plugins/helper/{url_for.js => url_for.ts} (100%) rename lib/plugins/injector/{index.js => index.ts} (100%) rename lib/plugins/processor/{asset.js => asset.ts} (100%) rename lib/plugins/processor/{common.js => common.ts} (100%) rename lib/plugins/processor/{data.js => data.ts} (100%) rename lib/plugins/processor/{index.js => index.ts} (100%) rename lib/plugins/processor/{post.js => post.ts} (100%) rename lib/plugins/renderer/{index.js => index.ts} (100%) rename lib/plugins/renderer/{json.js => json.ts} (100%) rename lib/plugins/renderer/{nunjucks.js => nunjucks.ts} (100%) rename lib/plugins/renderer/{plain.js => plain.ts} (100%) rename lib/plugins/renderer/{yaml.js => yaml.ts} (100%) rename lib/plugins/tag/{asset_img.js => asset_img.ts} (100%) rename lib/plugins/tag/{asset_link.js => asset_link.ts} (100%) rename lib/plugins/tag/{asset_path.js => asset_path.ts} (100%) rename lib/plugins/tag/{blockquote.js => blockquote.ts} (100%) rename lib/plugins/tag/{code.js => code.ts} (100%) rename lib/plugins/tag/{iframe.js => iframe.ts} (100%) rename lib/plugins/tag/{img.js => img.ts} (100%) rename lib/plugins/tag/{include_code.js => include_code.ts} (100%) rename lib/plugins/tag/{index.js => index.ts} (100%) rename lib/plugins/tag/{link.js => link.ts} (100%) rename lib/plugins/tag/{post_link.js => post_link.ts} (100%) rename lib/plugins/tag/{post_path.js => post_path.ts} (100%) rename lib/plugins/tag/{pullquote.js => pullquote.ts} (100%) rename lib/theme/{index.js => index.ts} (93%) rename lib/theme/processors/{config.js => config.ts} (100%) rename lib/theme/processors/{i18n.js => i18n.ts} (100%) rename lib/theme/processors/{source.js => source.ts} (100%) rename lib/theme/processors/{view.js => view.ts} (100%) rename lib/theme/{view.js => view.ts} (94%) diff --git a/lib/box/file.js b/lib/box/file.ts similarity index 88% rename from lib/box/file.js rename to lib/box/file.ts index d1f6192166..e1d57a3eed 100644 --- a/lib/box/file.js +++ b/lib/box/file.ts @@ -3,6 +3,11 @@ import {readFile, readFileSync, stat, statSync} from 'hexo-fs'; class File { + public source: any; + public path: any; + public params: any; + public type: any; + constructor({ source, path, params, type }) { this.source = source; this.path = path; diff --git a/lib/box/index.js b/lib/box/index.ts similarity index 96% rename from lib/box/index.js rename to lib/box/index.ts index e4ee6fc90c..2730db15c4 100644 --- a/lib/box/index.js +++ b/lib/box/index.ts @@ -12,6 +12,19 @@ import {isMatch, makeRe} from 'micromatch'; const defaultPattern = new Pattern(() => ({})); class Box extends EventEmitter { + public options: any; + public context: any; + public base: any; + public processors: any; + public _processingFiles: any; + public watcher: any; + public Cache: any; + public File: any; + public ignore: any; + public source: any; + public emit: any; + public ctx: any; + constructor(ctx, base, options) { super(); @@ -100,7 +113,7 @@ class Box extends EventEmitter { })); } - process(callback) { + process(callback?) { const { base, Cache, context: ctx } = this; return stat(base).then(stats => { diff --git a/lib/extend/console.js b/lib/extend/console.ts similarity index 98% rename from lib/extend/console.js rename to lib/extend/console.ts index 371bb61f04..9ec2932112 100644 --- a/lib/extend/console.js +++ b/lib/extend/console.ts @@ -12,6 +12,9 @@ import abbrev from 'abbrev'; */ class Console { + public store: any; + public alias: any; + constructor() { this.store = {}; this.alias = {}; diff --git a/lib/extend/deployer.js b/lib/extend/deployer.ts similarity index 96% rename from lib/extend/deployer.js rename to lib/extend/deployer.ts index 60615b6ad0..792d0e1a77 100644 --- a/lib/extend/deployer.js +++ b/lib/extend/deployer.ts @@ -3,6 +3,8 @@ import Promise from 'bluebird'; class Deployer { + public store: any; + constructor() { this.store = {}; } diff --git a/lib/extend/filter.js b/lib/extend/filter.ts similarity index 99% rename from lib/extend/filter.js rename to lib/extend/filter.ts index 1354233812..407db8bfc9 100644 --- a/lib/extend/filter.js +++ b/lib/extend/filter.ts @@ -9,6 +9,8 @@ const typeAlias = { }; class Filter { + public store: any; + constructor() { this.store = {}; } diff --git a/lib/extend/generator.js b/lib/extend/generator.ts similarity index 93% rename from lib/extend/generator.js rename to lib/extend/generator.ts index 903e6735ab..31ef689ea6 100644 --- a/lib/extend/generator.js +++ b/lib/extend/generator.ts @@ -3,6 +3,9 @@ import Promise from 'bluebird'; class Generator { + public id: any; + public store: any; + constructor() { this.id = 0; this.store = {}; diff --git a/lib/extend/helper.js b/lib/extend/helper.ts similarity index 97% rename from lib/extend/helper.js rename to lib/extend/helper.ts index 60ebd5d050..41b0cf03da 100644 --- a/lib/extend/helper.js +++ b/lib/extend/helper.ts @@ -1,6 +1,8 @@ 'use strict'; class Helper { + public store: any; + constructor() { this.store = {}; } diff --git a/lib/extend/index.js b/lib/extend/index.ts similarity index 100% rename from lib/extend/index.js rename to lib/extend/index.ts diff --git a/lib/extend/injector.js b/lib/extend/injector.ts similarity index 97% rename from lib/extend/injector.js rename to lib/extend/injector.ts index dfdfaa65ef..bc4dd87860 100644 --- a/lib/extend/injector.js +++ b/lib/extend/injector.ts @@ -3,6 +3,10 @@ import {Cache} from 'hexo-util'; class Injector { + public store: any; + public cache: any; + public page: any; + constructor() { this.store = { head_begin: {}, diff --git a/lib/extend/migrator.js b/lib/extend/migrator.ts similarity index 96% rename from lib/extend/migrator.js rename to lib/extend/migrator.ts index a418c6de55..8b49b6e0b2 100644 --- a/lib/extend/migrator.js +++ b/lib/extend/migrator.ts @@ -3,6 +3,8 @@ import Promise from 'bluebird'; class Migrator { + public store: any; + constructor() { this.store = {}; } diff --git a/lib/extend/processor.js b/lib/extend/processor.ts similarity index 96% rename from lib/extend/processor.js rename to lib/extend/processor.ts index cfbea335a5..aaf47b767a 100644 --- a/lib/extend/processor.js +++ b/lib/extend/processor.ts @@ -4,6 +4,8 @@ import Promise from 'bluebird'; import {Pattern} from 'hexo-util'; class Processor { + public store: any; + constructor() { this.store = []; } diff --git a/lib/extend/renderer.js b/lib/extend/renderer.ts similarity index 95% rename from lib/extend/renderer.js rename to lib/extend/renderer.ts index 5b12c0f4f1..f7941537c2 100644 --- a/lib/extend/renderer.js +++ b/lib/extend/renderer.ts @@ -11,6 +11,9 @@ const getExtname = str => { }; class Renderer { + public store: any; + public storeSync: any; + constructor() { this.store = {}; this.storeSync = {}; @@ -20,7 +23,7 @@ class Renderer { return sync ? this.storeSync : this.store; } - get(name, sync) { + get(name, sync?) { const store = this[sync ? 'storeSync' : 'store']; return store[getExtname(name)] || store[name]; diff --git a/lib/extend/tag.js b/lib/extend/tag.ts similarity index 98% rename from lib/extend/tag.js rename to lib/extend/tag.ts index fd8ad76726..8fb5a2be00 100644 --- a/lib/extend/tag.js +++ b/lib/extend/tag.ts @@ -9,6 +9,9 @@ const rCodeTag = /]*>[\s\S]+?<\/code>/g; const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); class NunjucksTag { + public tags: any; + public fn: any; + constructor(name, fn) { this.tags = [name]; this.fn = fn; @@ -180,6 +183,9 @@ const formatNunjucksError = (err, input, source = '') => { }; class Tag { + public env: any; + public source: any; + constructor() { this.env = new Environment(null, { autoescape: false diff --git a/lib/hexo/default_config.js b/lib/hexo/default_config.ts similarity index 100% rename from lib/hexo/default_config.js rename to lib/hexo/default_config.ts diff --git a/lib/hexo/index.js b/lib/hexo/index.ts similarity index 94% rename from lib/hexo/index.js rename to lib/hexo/index.ts index 6fbb9d1f0c..3f3eefeaac 100644 --- a/lib/hexo/index.js +++ b/lib/hexo/index.ts @@ -108,6 +108,43 @@ function debounce(func, wait) { } class Hexo extends EventEmitter { + public base_dir: any; + public public_dir: any; + public source_dir: any; + public plugin_dir: any; + public script_dir: any; + public scaffold_dir: any; + public theme_dir: any; + public theme_script_dir: any; + public env: any; + public extend: any; + public config: any; + public log: any; + public render: any; + public route: any; + public post: any; + public scaffold: any; + public _dbLoaded: any; + public _isGenerating: any; + public database: any; + public config_path: any; + public source: any; + public theme: any; + public locals: any; + public version: any; + public emit: any; + public _watchBox: any; + public page: any; + public path: any; + public url: any; + public layout: any; + public view_dir: any; + public site: any; + public args: any; + public cache: any; + public alias: any; + public data: any; + constructor(base = process.cwd(), args = {}) { super(); diff --git a/lib/hexo/load_config.js b/lib/hexo/load_config.ts similarity index 100% rename from lib/hexo/load_config.js rename to lib/hexo/load_config.ts diff --git a/lib/hexo/load_database.js b/lib/hexo/load_database.ts similarity index 100% rename from lib/hexo/load_database.js rename to lib/hexo/load_database.ts diff --git a/lib/hexo/load_plugins.js b/lib/hexo/load_plugins.ts similarity index 100% rename from lib/hexo/load_plugins.js rename to lib/hexo/load_plugins.ts diff --git a/lib/hexo/load_theme_config.js b/lib/hexo/load_theme_config.ts similarity index 100% rename from lib/hexo/load_theme_config.js rename to lib/hexo/load_theme_config.ts diff --git a/lib/hexo/locals.js b/lib/hexo/locals.ts similarity index 96% rename from lib/hexo/locals.js rename to lib/hexo/locals.ts index 751852cd4d..357f27976e 100644 --- a/lib/hexo/locals.js +++ b/lib/hexo/locals.ts @@ -3,6 +3,9 @@ import {Cache} from 'hexo-util'; class Locals { + public cache: any; + public getters: any; + constructor() { this.cache = new Cache(); this.getters = {}; diff --git a/lib/hexo/multi_config_path.js b/lib/hexo/multi_config_path.ts similarity index 100% rename from lib/hexo/multi_config_path.js rename to lib/hexo/multi_config_path.ts diff --git a/lib/hexo/post.js b/lib/hexo/post.ts similarity index 98% rename from lib/hexo/post.js rename to lib/hexo/post.ts index 4b74896b42..195642215c 100644 --- a/lib/hexo/post.js +++ b/lib/hexo/post.ts @@ -30,6 +30,9 @@ const isNonWhiteSpaceChar = char => char !== '\r' && char !== ' '; class PostRenderEscape { + public stored: any; + public length: any; + constructor() { this.stored = []; } @@ -218,11 +221,16 @@ const createAssetFolder = (path, assetFolder) => { }; class Post { + public context: any; + public config: any; + public tag: any; + public separator: any; + constructor(context) { this.context = context; } - create(data, replace, callback) { + create(data, replace, callback?) { if (!callback && typeof replace === 'function') { callback = replace; replace = false; diff --git a/lib/hexo/register_models.js b/lib/hexo/register_models.ts similarity index 100% rename from lib/hexo/register_models.js rename to lib/hexo/register_models.ts diff --git a/lib/hexo/render.js b/lib/hexo/render.ts similarity index 97% rename from lib/hexo/render.js rename to lib/hexo/render.ts index 7810f8bdc3..030abcbe47 100644 --- a/lib/hexo/render.js +++ b/lib/hexo/render.ts @@ -26,6 +26,9 @@ const toString = (result, options) => { }; class Render { + public context: any; + public renderer: any; + constructor(ctx) { this.context = ctx; this.renderer = ctx.extend.renderer; @@ -43,7 +46,7 @@ class Render { return this.renderer.getOutput(path); } - getRenderer(ext, sync) { + getRenderer(ext, sync?) { return this.renderer.get(ext, sync); } diff --git a/lib/hexo/router.js b/lib/hexo/router.ts similarity index 96% rename from lib/hexo/router.js rename to lib/hexo/router.ts index fed1d5cd4b..c2355c5f88 100644 --- a/lib/hexo/router.js +++ b/lib/hexo/router.ts @@ -6,6 +6,12 @@ import Stream from 'stream'; const { Readable } = Stream; class RouteStream extends Readable { + public _data: any; + public _ended: any; + public modified: any; + public push: any; + public emit: any; + constructor(data) { super({ objectMode: true }); @@ -89,6 +95,9 @@ const _format = path => { }; class Router extends EventEmitter { + public routes: any; + public emit: any; + constructor() { super(); diff --git a/lib/hexo/scaffold.js b/lib/hexo/scaffold.ts similarity index 95% rename from lib/hexo/scaffold.js rename to lib/hexo/scaffold.ts index 0706eac78a..2e7fb99170 100644 --- a/lib/hexo/scaffold.js +++ b/lib/hexo/scaffold.ts @@ -4,6 +4,10 @@ import {extname, join} from 'path'; import {exists, listDir, readFile, unlink, writeFile} from 'hexo-fs'; class Scaffold { + public context: any; + public scaffoldDir: any; + public defaults: any; + constructor(context) { this.context = context; this.scaffoldDir = context.scaffold_dir; diff --git a/lib/hexo/source.js b/lib/hexo/source.ts similarity index 100% rename from lib/hexo/source.js rename to lib/hexo/source.ts diff --git a/lib/hexo/update_package.js b/lib/hexo/update_package.ts similarity index 100% rename from lib/hexo/update_package.js rename to lib/hexo/update_package.ts diff --git a/lib/hexo/validate_config.js b/lib/hexo/validate_config.ts similarity index 100% rename from lib/hexo/validate_config.js rename to lib/hexo/validate_config.ts diff --git a/lib/models/asset.js b/lib/models/asset.ts similarity index 100% rename from lib/models/asset.js rename to lib/models/asset.ts diff --git a/lib/models/cache.js b/lib/models/cache.ts similarity index 100% rename from lib/models/cache.js rename to lib/models/cache.ts diff --git a/lib/models/category.js b/lib/models/category.ts similarity index 100% rename from lib/models/category.js rename to lib/models/category.ts diff --git a/lib/models/data.js b/lib/models/data.ts similarity index 100% rename from lib/models/data.js rename to lib/models/data.ts diff --git a/lib/models/index.js b/lib/models/index.ts similarity index 100% rename from lib/models/index.js rename to lib/models/index.ts diff --git a/lib/models/page.js b/lib/models/page.ts similarity index 100% rename from lib/models/page.js rename to lib/models/page.ts diff --git a/lib/models/post.js b/lib/models/post.ts similarity index 100% rename from lib/models/post.js rename to lib/models/post.ts diff --git a/lib/models/post_asset.js b/lib/models/post_asset.ts similarity index 100% rename from lib/models/post_asset.js rename to lib/models/post_asset.ts diff --git a/lib/models/post_category.js b/lib/models/post_category.ts similarity index 100% rename from lib/models/post_category.js rename to lib/models/post_category.ts diff --git a/lib/models/post_tag.js b/lib/models/post_tag.ts similarity index 100% rename from lib/models/post_tag.js rename to lib/models/post_tag.ts diff --git a/lib/models/tag.js b/lib/models/tag.ts similarity index 100% rename from lib/models/tag.js rename to lib/models/tag.ts diff --git a/lib/models/types/moment.js b/lib/models/types/moment.ts similarity index 98% rename from lib/models/types/moment.js rename to lib/models/types/moment.ts index 1347d8b558..70bafa229b 100644 --- a/lib/models/types/moment.js +++ b/lib/models/types/moment.ts @@ -4,6 +4,8 @@ import {SchemaType} from 'warehouse'; import {moment, toMomentLocale} from '../../plugins/helper/date'; class SchemaTypeMoment extends SchemaType { + public options: any; + constructor(name, options = {}) { super(name, options); } diff --git a/lib/plugins/console/clean.js b/lib/plugins/console/clean.ts similarity index 100% rename from lib/plugins/console/clean.js rename to lib/plugins/console/clean.ts diff --git a/lib/plugins/console/config.js b/lib/plugins/console/config.ts similarity index 100% rename from lib/plugins/console/config.js rename to lib/plugins/console/config.ts diff --git a/lib/plugins/console/deploy.js b/lib/plugins/console/deploy.ts similarity index 100% rename from lib/plugins/console/deploy.js rename to lib/plugins/console/deploy.ts diff --git a/lib/plugins/console/generate.js b/lib/plugins/console/generate.ts similarity index 95% rename from lib/plugins/console/generate.js rename to lib/plugins/console/generate.ts index cc69f52a6c..ccc14b9140 100644 --- a/lib/plugins/console/generate.js +++ b/lib/plugins/console/generate.ts @@ -10,6 +10,18 @@ import {PassThrough} from 'stream'; import {createSha1Hash} from 'hexo-util'; class Generater { + public context: any; + public force: any; + public bail: any; + public concurrency: any; + public watch: any; + public deploy: any; + public generatingFiles: any; + public start: any; + public args: any; + public route: any; + public log: any; + constructor(ctx, args) { this.context = ctx; this.force = args.f || args.force; @@ -48,7 +60,7 @@ class Generater { generatingFiles.delete(path); }); } - writeFile(path, force) { + writeFile(path, force?) { const { route, log } = this.context; const publicDir = this.context.public_dir; const Cache = this.context.model('Cache'); diff --git a/lib/plugins/console/index.js b/lib/plugins/console/index.ts similarity index 100% rename from lib/plugins/console/index.js rename to lib/plugins/console/index.ts diff --git a/lib/plugins/console/list/category.js b/lib/plugins/console/list/category.ts similarity index 100% rename from lib/plugins/console/list/category.js rename to lib/plugins/console/list/category.ts diff --git a/lib/plugins/console/list/common.js b/lib/plugins/console/list/common.ts similarity index 100% rename from lib/plugins/console/list/common.js rename to lib/plugins/console/list/common.ts diff --git a/lib/plugins/console/list/index.js b/lib/plugins/console/list/index.ts similarity index 100% rename from lib/plugins/console/list/index.js rename to lib/plugins/console/list/index.ts diff --git a/lib/plugins/console/list/page.js b/lib/plugins/console/list/page.ts similarity index 100% rename from lib/plugins/console/list/page.js rename to lib/plugins/console/list/page.ts diff --git a/lib/plugins/console/list/post.js b/lib/plugins/console/list/post.ts similarity index 100% rename from lib/plugins/console/list/post.js rename to lib/plugins/console/list/post.ts diff --git a/lib/plugins/console/list/route.js b/lib/plugins/console/list/route.ts similarity index 100% rename from lib/plugins/console/list/route.js rename to lib/plugins/console/list/route.ts diff --git a/lib/plugins/console/list/tag.js b/lib/plugins/console/list/tag.ts similarity index 100% rename from lib/plugins/console/list/tag.js rename to lib/plugins/console/list/tag.ts diff --git a/lib/plugins/console/migrate.js b/lib/plugins/console/migrate.ts similarity index 100% rename from lib/plugins/console/migrate.js rename to lib/plugins/console/migrate.ts diff --git a/lib/plugins/console/new.js b/lib/plugins/console/new.ts similarity index 100% rename from lib/plugins/console/new.js rename to lib/plugins/console/new.ts diff --git a/lib/plugins/console/publish.js b/lib/plugins/console/publish.ts similarity index 100% rename from lib/plugins/console/publish.js rename to lib/plugins/console/publish.ts diff --git a/lib/plugins/console/render.js b/lib/plugins/console/render.ts similarity index 100% rename from lib/plugins/console/render.js rename to lib/plugins/console/render.ts diff --git a/lib/plugins/filter/after_post_render/excerpt.js b/lib/plugins/filter/after_post_render/excerpt.ts similarity index 100% rename from lib/plugins/filter/after_post_render/excerpt.js rename to lib/plugins/filter/after_post_render/excerpt.ts diff --git a/lib/plugins/filter/after_post_render/external_link.js b/lib/plugins/filter/after_post_render/external_link.ts similarity index 100% rename from lib/plugins/filter/after_post_render/external_link.js rename to lib/plugins/filter/after_post_render/external_link.ts diff --git a/lib/plugins/filter/after_post_render/index.js b/lib/plugins/filter/after_post_render/index.ts similarity index 100% rename from lib/plugins/filter/after_post_render/index.js rename to lib/plugins/filter/after_post_render/index.ts diff --git a/lib/plugins/filter/after_render/external_link.js b/lib/plugins/filter/after_render/external_link.ts similarity index 100% rename from lib/plugins/filter/after_render/external_link.js rename to lib/plugins/filter/after_render/external_link.ts diff --git a/lib/plugins/filter/after_render/index.js b/lib/plugins/filter/after_render/index.ts similarity index 100% rename from lib/plugins/filter/after_render/index.js rename to lib/plugins/filter/after_render/index.ts diff --git a/lib/plugins/filter/after_render/meta_generator.js b/lib/plugins/filter/after_render/meta_generator.ts similarity index 100% rename from lib/plugins/filter/after_render/meta_generator.js rename to lib/plugins/filter/after_render/meta_generator.ts diff --git a/lib/plugins/filter/before_exit/index.js b/lib/plugins/filter/before_exit/index.ts similarity index 100% rename from lib/plugins/filter/before_exit/index.js rename to lib/plugins/filter/before_exit/index.ts diff --git a/lib/plugins/filter/before_exit/save_database.js b/lib/plugins/filter/before_exit/save_database.ts similarity index 100% rename from lib/plugins/filter/before_exit/save_database.js rename to lib/plugins/filter/before_exit/save_database.ts diff --git a/lib/plugins/filter/before_generate/index.js b/lib/plugins/filter/before_generate/index.ts similarity index 100% rename from lib/plugins/filter/before_generate/index.js rename to lib/plugins/filter/before_generate/index.ts diff --git a/lib/plugins/filter/before_generate/render_post.js b/lib/plugins/filter/before_generate/render_post.ts similarity index 100% rename from lib/plugins/filter/before_generate/render_post.js rename to lib/plugins/filter/before_generate/render_post.ts diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.js b/lib/plugins/filter/before_post_render/backtick_code_block.ts similarity index 100% rename from lib/plugins/filter/before_post_render/backtick_code_block.js rename to lib/plugins/filter/before_post_render/backtick_code_block.ts diff --git a/lib/plugins/filter/before_post_render/index.js b/lib/plugins/filter/before_post_render/index.ts similarity index 100% rename from lib/plugins/filter/before_post_render/index.js rename to lib/plugins/filter/before_post_render/index.ts diff --git a/lib/plugins/filter/before_post_render/titlecase.js b/lib/plugins/filter/before_post_render/titlecase.ts similarity index 100% rename from lib/plugins/filter/before_post_render/titlecase.js rename to lib/plugins/filter/before_post_render/titlecase.ts diff --git a/lib/plugins/filter/index.js b/lib/plugins/filter/index.ts similarity index 100% rename from lib/plugins/filter/index.js rename to lib/plugins/filter/index.ts diff --git a/lib/plugins/filter/new_post_path.js b/lib/plugins/filter/new_post_path.ts similarity index 100% rename from lib/plugins/filter/new_post_path.js rename to lib/plugins/filter/new_post_path.ts diff --git a/lib/plugins/filter/post_permalink.js b/lib/plugins/filter/post_permalink.ts similarity index 100% rename from lib/plugins/filter/post_permalink.js rename to lib/plugins/filter/post_permalink.ts diff --git a/lib/plugins/filter/template_locals/i18n.js b/lib/plugins/filter/template_locals/i18n.ts similarity index 100% rename from lib/plugins/filter/template_locals/i18n.js rename to lib/plugins/filter/template_locals/i18n.ts diff --git a/lib/plugins/filter/template_locals/index.js b/lib/plugins/filter/template_locals/index.ts similarity index 100% rename from lib/plugins/filter/template_locals/index.js rename to lib/plugins/filter/template_locals/index.ts diff --git a/lib/plugins/generator/asset.js b/lib/plugins/generator/asset.ts similarity index 100% rename from lib/plugins/generator/asset.js rename to lib/plugins/generator/asset.ts diff --git a/lib/plugins/generator/index.js b/lib/plugins/generator/index.ts similarity index 100% rename from lib/plugins/generator/index.js rename to lib/plugins/generator/index.ts diff --git a/lib/plugins/generator/page.js b/lib/plugins/generator/page.ts similarity index 100% rename from lib/plugins/generator/page.js rename to lib/plugins/generator/page.ts diff --git a/lib/plugins/generator/post.js b/lib/plugins/generator/post.ts similarity index 100% rename from lib/plugins/generator/post.js rename to lib/plugins/generator/post.ts diff --git a/lib/plugins/helper/css.js b/lib/plugins/helper/css.ts similarity index 100% rename from lib/plugins/helper/css.js rename to lib/plugins/helper/css.ts diff --git a/lib/plugins/helper/date.js b/lib/plugins/helper/date.ts similarity index 100% rename from lib/plugins/helper/date.js rename to lib/plugins/helper/date.ts diff --git a/lib/plugins/helper/debug.js b/lib/plugins/helper/debug.ts similarity index 100% rename from lib/plugins/helper/debug.js rename to lib/plugins/helper/debug.ts diff --git a/lib/plugins/helper/favicon_tag.js b/lib/plugins/helper/favicon_tag.ts similarity index 100% rename from lib/plugins/helper/favicon_tag.js rename to lib/plugins/helper/favicon_tag.ts diff --git a/lib/plugins/helper/feed_tag.js b/lib/plugins/helper/feed_tag.ts similarity index 95% rename from lib/plugins/helper/feed_tag.js rename to lib/plugins/helper/feed_tag.ts index 4b0d23ed20..4633efbb9d 100644 --- a/lib/plugins/helper/feed_tag.js +++ b/lib/plugins/helper/feed_tag.ts @@ -8,7 +8,7 @@ const feedFn = (str = '') => { return str; }; -function makeFeedTag(path, options = {}, configFeed, configTitle) { +function makeFeedTag(path, options = {}, configFeed?, configTitle?) { const title = options.title || configTitle; if (path) { diff --git a/lib/plugins/helper/format.js b/lib/plugins/helper/format.ts similarity index 100% rename from lib/plugins/helper/format.js rename to lib/plugins/helper/format.ts diff --git a/lib/plugins/helper/fragment_cache.js b/lib/plugins/helper/fragment_cache.ts similarity index 100% rename from lib/plugins/helper/fragment_cache.js rename to lib/plugins/helper/fragment_cache.ts diff --git a/lib/plugins/helper/full_url_for.js b/lib/plugins/helper/full_url_for.ts old mode 100755 new mode 100644 similarity index 100% rename from lib/plugins/helper/full_url_for.js rename to lib/plugins/helper/full_url_for.ts diff --git a/lib/plugins/helper/gravatar.js b/lib/plugins/helper/gravatar.ts similarity index 100% rename from lib/plugins/helper/gravatar.js rename to lib/plugins/helper/gravatar.ts diff --git a/lib/plugins/helper/image_tag.js b/lib/plugins/helper/image_tag.ts similarity index 100% rename from lib/plugins/helper/image_tag.js rename to lib/plugins/helper/image_tag.ts diff --git a/lib/plugins/helper/index.js b/lib/plugins/helper/index.ts similarity index 100% rename from lib/plugins/helper/index.js rename to lib/plugins/helper/index.ts diff --git a/lib/plugins/helper/is.js b/lib/plugins/helper/is.ts similarity index 100% rename from lib/plugins/helper/is.js rename to lib/plugins/helper/is.ts diff --git a/lib/plugins/helper/js.js b/lib/plugins/helper/js.ts similarity index 100% rename from lib/plugins/helper/js.js rename to lib/plugins/helper/js.ts diff --git a/lib/plugins/helper/link_to.js b/lib/plugins/helper/link_to.ts similarity index 100% rename from lib/plugins/helper/link_to.js rename to lib/plugins/helper/link_to.ts diff --git a/lib/plugins/helper/list_archives.js b/lib/plugins/helper/list_archives.ts similarity index 100% rename from lib/plugins/helper/list_archives.js rename to lib/plugins/helper/list_archives.ts diff --git a/lib/plugins/helper/list_categories.js b/lib/plugins/helper/list_categories.ts similarity index 100% rename from lib/plugins/helper/list_categories.js rename to lib/plugins/helper/list_categories.ts diff --git a/lib/plugins/helper/list_posts.js b/lib/plugins/helper/list_posts.ts similarity index 100% rename from lib/plugins/helper/list_posts.js rename to lib/plugins/helper/list_posts.ts diff --git a/lib/plugins/helper/list_tags.js b/lib/plugins/helper/list_tags.ts similarity index 98% rename from lib/plugins/helper/list_tags.js rename to lib/plugins/helper/list_tags.ts index 58f897ec90..64d2c9e397 100644 --- a/lib/plugins/helper/list_tags.js +++ b/lib/plugins/helper/list_tags.ts @@ -3,7 +3,7 @@ import {url_for, escapeHTML} from 'hexo-util'; import moize from 'moize'; -function listTagsHelper(tags, options) { +function listTagsHelper(tags, options?) { if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { options = tags; tags = this.site.tags; diff --git a/lib/plugins/helper/mail_to.js b/lib/plugins/helper/mail_to.ts similarity index 100% rename from lib/plugins/helper/mail_to.js rename to lib/plugins/helper/mail_to.ts diff --git a/lib/plugins/helper/markdown.js b/lib/plugins/helper/markdown.ts similarity index 100% rename from lib/plugins/helper/markdown.js rename to lib/plugins/helper/markdown.ts diff --git a/lib/plugins/helper/meta_generator.js b/lib/plugins/helper/meta_generator.ts old mode 100755 new mode 100644 similarity index 100% rename from lib/plugins/helper/meta_generator.js rename to lib/plugins/helper/meta_generator.ts diff --git a/lib/plugins/helper/number_format.js b/lib/plugins/helper/number_format.ts similarity index 100% rename from lib/plugins/helper/number_format.js rename to lib/plugins/helper/number_format.ts diff --git a/lib/plugins/helper/open_graph.js b/lib/plugins/helper/open_graph.ts similarity index 100% rename from lib/plugins/helper/open_graph.js rename to lib/plugins/helper/open_graph.ts diff --git a/lib/plugins/helper/paginator.js b/lib/plugins/helper/paginator.ts similarity index 100% rename from lib/plugins/helper/paginator.js rename to lib/plugins/helper/paginator.ts diff --git a/lib/plugins/helper/partial.js b/lib/plugins/helper/partial.ts similarity index 100% rename from lib/plugins/helper/partial.js rename to lib/plugins/helper/partial.ts diff --git a/lib/plugins/helper/relative_url.js b/lib/plugins/helper/relative_url.ts similarity index 100% rename from lib/plugins/helper/relative_url.js rename to lib/plugins/helper/relative_url.ts diff --git a/lib/plugins/helper/render.js b/lib/plugins/helper/render.ts similarity index 100% rename from lib/plugins/helper/render.js rename to lib/plugins/helper/render.ts diff --git a/lib/plugins/helper/search_form.js b/lib/plugins/helper/search_form.ts similarity index 100% rename from lib/plugins/helper/search_form.js rename to lib/plugins/helper/search_form.ts diff --git a/lib/plugins/helper/tagcloud.js b/lib/plugins/helper/tagcloud.ts similarity index 98% rename from lib/plugins/helper/tagcloud.js rename to lib/plugins/helper/tagcloud.ts index e4bf1d5087..b872c9319a 100644 --- a/lib/plugins/helper/tagcloud.js +++ b/lib/plugins/helper/tagcloud.ts @@ -3,7 +3,7 @@ import {Color, url_for} from 'hexo-util'; import moize from 'moize'; -function tagcloudHelper(tags, options) { +function tagcloudHelper(tags, options?) { if (!options && (!tags || !Object.prototype.hasOwnProperty.call(tags, 'length'))) { options = tags; tags = this.site.tags; diff --git a/lib/plugins/helper/toc.js b/lib/plugins/helper/toc.ts similarity index 100% rename from lib/plugins/helper/toc.js rename to lib/plugins/helper/toc.ts diff --git a/lib/plugins/helper/url_for.js b/lib/plugins/helper/url_for.ts similarity index 100% rename from lib/plugins/helper/url_for.js rename to lib/plugins/helper/url_for.ts diff --git a/lib/plugins/injector/index.js b/lib/plugins/injector/index.ts similarity index 100% rename from lib/plugins/injector/index.js rename to lib/plugins/injector/index.ts diff --git a/lib/plugins/processor/asset.js b/lib/plugins/processor/asset.ts similarity index 100% rename from lib/plugins/processor/asset.js rename to lib/plugins/processor/asset.ts diff --git a/lib/plugins/processor/common.js b/lib/plugins/processor/common.ts similarity index 100% rename from lib/plugins/processor/common.js rename to lib/plugins/processor/common.ts diff --git a/lib/plugins/processor/data.js b/lib/plugins/processor/data.ts similarity index 100% rename from lib/plugins/processor/data.js rename to lib/plugins/processor/data.ts diff --git a/lib/plugins/processor/index.js b/lib/plugins/processor/index.ts similarity index 100% rename from lib/plugins/processor/index.js rename to lib/plugins/processor/index.ts diff --git a/lib/plugins/processor/post.js b/lib/plugins/processor/post.ts similarity index 100% rename from lib/plugins/processor/post.js rename to lib/plugins/processor/post.ts diff --git a/lib/plugins/renderer/index.js b/lib/plugins/renderer/index.ts similarity index 100% rename from lib/plugins/renderer/index.js rename to lib/plugins/renderer/index.ts diff --git a/lib/plugins/renderer/json.js b/lib/plugins/renderer/json.ts similarity index 100% rename from lib/plugins/renderer/json.js rename to lib/plugins/renderer/json.ts diff --git a/lib/plugins/renderer/nunjucks.js b/lib/plugins/renderer/nunjucks.ts similarity index 100% rename from lib/plugins/renderer/nunjucks.js rename to lib/plugins/renderer/nunjucks.ts diff --git a/lib/plugins/renderer/plain.js b/lib/plugins/renderer/plain.ts similarity index 100% rename from lib/plugins/renderer/plain.js rename to lib/plugins/renderer/plain.ts diff --git a/lib/plugins/renderer/yaml.js b/lib/plugins/renderer/yaml.ts similarity index 100% rename from lib/plugins/renderer/yaml.js rename to lib/plugins/renderer/yaml.ts diff --git a/lib/plugins/tag/asset_img.js b/lib/plugins/tag/asset_img.ts similarity index 100% rename from lib/plugins/tag/asset_img.js rename to lib/plugins/tag/asset_img.ts diff --git a/lib/plugins/tag/asset_link.js b/lib/plugins/tag/asset_link.ts similarity index 100% rename from lib/plugins/tag/asset_link.js rename to lib/plugins/tag/asset_link.ts diff --git a/lib/plugins/tag/asset_path.js b/lib/plugins/tag/asset_path.ts similarity index 100% rename from lib/plugins/tag/asset_path.js rename to lib/plugins/tag/asset_path.ts diff --git a/lib/plugins/tag/blockquote.js b/lib/plugins/tag/blockquote.ts similarity index 100% rename from lib/plugins/tag/blockquote.js rename to lib/plugins/tag/blockquote.ts diff --git a/lib/plugins/tag/code.js b/lib/plugins/tag/code.ts similarity index 100% rename from lib/plugins/tag/code.js rename to lib/plugins/tag/code.ts diff --git a/lib/plugins/tag/iframe.js b/lib/plugins/tag/iframe.ts similarity index 100% rename from lib/plugins/tag/iframe.js rename to lib/plugins/tag/iframe.ts diff --git a/lib/plugins/tag/img.js b/lib/plugins/tag/img.ts similarity index 100% rename from lib/plugins/tag/img.js rename to lib/plugins/tag/img.ts diff --git a/lib/plugins/tag/include_code.js b/lib/plugins/tag/include_code.ts similarity index 100% rename from lib/plugins/tag/include_code.js rename to lib/plugins/tag/include_code.ts diff --git a/lib/plugins/tag/index.js b/lib/plugins/tag/index.ts similarity index 100% rename from lib/plugins/tag/index.js rename to lib/plugins/tag/index.ts diff --git a/lib/plugins/tag/link.js b/lib/plugins/tag/link.ts similarity index 100% rename from lib/plugins/tag/link.js rename to lib/plugins/tag/link.ts diff --git a/lib/plugins/tag/post_link.js b/lib/plugins/tag/post_link.ts similarity index 100% rename from lib/plugins/tag/post_link.js rename to lib/plugins/tag/post_link.ts diff --git a/lib/plugins/tag/post_path.js b/lib/plugins/tag/post_path.ts similarity index 100% rename from lib/plugins/tag/post_path.js rename to lib/plugins/tag/post_path.ts diff --git a/lib/plugins/tag/pullquote.js b/lib/plugins/tag/pullquote.ts similarity index 100% rename from lib/plugins/tag/pullquote.js rename to lib/plugins/tag/pullquote.ts diff --git a/lib/theme/index.js b/lib/theme/index.ts similarity index 93% rename from lib/theme/index.js rename to lib/theme/index.ts index a26bbc35d0..e4891433bb 100644 --- a/lib/theme/index.js +++ b/lib/theme/index.ts @@ -6,7 +6,12 @@ import View from './view'; import I18n from 'hexo-i18n'; class Theme extends Box { - constructor(ctx, options) { + public config: any; + public views: any; + public i18n: any; + public View: any; + + constructor(ctx, options?) { super(ctx, ctx.theme_dir, options); this.config = {}; diff --git a/lib/theme/processors/config.js b/lib/theme/processors/config.ts similarity index 100% rename from lib/theme/processors/config.js rename to lib/theme/processors/config.ts diff --git a/lib/theme/processors/i18n.js b/lib/theme/processors/i18n.ts similarity index 100% rename from lib/theme/processors/i18n.js rename to lib/theme/processors/i18n.ts diff --git a/lib/theme/processors/source.js b/lib/theme/processors/source.ts similarity index 100% rename from lib/theme/processors/source.js rename to lib/theme/processors/source.ts diff --git a/lib/theme/processors/view.js b/lib/theme/processors/view.ts similarity index 100% rename from lib/theme/processors/view.js rename to lib/theme/processors/view.ts diff --git a/lib/theme/view.js b/lib/theme/view.ts similarity index 94% rename from lib/theme/view.js rename to lib/theme/view.ts index 9600183262..1157b68085 100644 --- a/lib/theme/view.js +++ b/lib/theme/view.ts @@ -19,6 +19,17 @@ const assignIn = (target, ...sources) => { }; class View { + public path: any; + public source: any; + public _theme: any; + public data: any; + public _compiled: any; + public _compiledSync: any; + public _helper: any; + public _render: any; + public layout: any; + public _content: any; + constructor(path, data) { this.path = path; this.source = join(this._theme.base, 'layout', path); From 66c1a39f0e9222b82607f23e8d16b90085697c2d Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 00:44:24 +0800 Subject: [PATCH 03/45] update files --- .eslintrc.json | 12 ++++++++---- .husky/pre-commit | 2 +- package.json | 14 ++++++++++++-- tsconfig.json | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tsconfig.json diff --git a/.eslintrc.json b/.eslintrc.json index 2cf72c2756..6be9a4c7cc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,8 @@ -{ - "extends": "hexo", - "root": true -} +{ + "root": true, + "extends": "hexo/ts.js", + "parserOptions": { + "sourceType": "module", + "ecmaVersion": 2020 + } +} diff --git a/.husky/pre-commit b/.husky/pre-commit index 36af219892..d5b5fd41c7 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -npx lint-staged +#npx lint-staged diff --git a/package.json b/package.json index c8fc3c53da..680eb3c986 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,12 @@ "hexo": "./bin/hexo" }, "scripts": { + "prepublish ": "npm run clean && npm run build", + "build": "tsc -b", + "clean": "tsc -b --clean", "eslint": "eslint .", - "test": "mocha test/index.js", + "pretest": "npm run clean && npm run build", + "test": "mocha test/index.js --require ts-node/register", "test-cov": "c8 --reporter=lcovonly npm test -- --no-parallel", "prepare": "husky install" }, @@ -66,6 +70,10 @@ }, "devDependencies": { "@easyops/git-exec-and-restage": "^1.0.4", + "@types/bluebird": "^3.5.37", + "@types/node": "^18.11.8", + "@typescript-eslint/eslint-plugin": "^5.41.0", + "@typescript-eslint/parser": "^5.41.0", "0x": "^5.1.2", "c8": "^7.12.0", "chai": "^4.3.6", @@ -77,7 +85,9 @@ "husky": "^8.0.1", "lint-staged": "^13.0.3", "mocha": "^10.0.0", - "sinon": "^15.0.0" + "sinon": "^15.0.0", + "ts-node": "^10.9.1", + "typescript": "^4.8.4" }, "engines": { "node": ">=14" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..a212ecebe0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "sourceMap": true, + "outDir": "dist", + "declaration": true, + "esModuleInterop": true, + "types": [ + "node" + ] + }, + "include": [ + "lib/hexo/index.ts" + ], + "exclude": [ + "node_modules" + ] +} \ No newline at end of file From a4dad2c2ba9c522ef7a526ee84ab4db89208c77a Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 09:57:49 +0800 Subject: [PATCH 04/45] remove `use strict` --- lib/box/file.ts | 2 -- lib/box/index.ts | 2 -- lib/extend/console.ts | 2 -- lib/extend/deployer.ts | 2 -- lib/extend/filter.ts | 2 -- lib/extend/generator.ts | 2 -- lib/extend/helper.ts | 2 -- lib/extend/index.ts | 2 -- lib/extend/injector.ts | 2 -- lib/extend/migrator.ts | 2 -- lib/extend/processor.ts | 2 -- lib/extend/renderer.ts | 2 -- lib/extend/tag.ts | 2 -- lib/hexo/default_config.ts | 2 -- lib/hexo/index.ts | 2 -- lib/hexo/load_config.ts | 2 -- lib/hexo/load_database.ts | 2 -- lib/hexo/load_plugins.ts | 2 -- lib/hexo/load_theme_config.ts | 2 -- lib/hexo/locals.ts | 2 -- lib/hexo/multi_config_path.ts | 2 -- lib/hexo/post.ts | 2 -- lib/hexo/register_models.ts | 4 +--- lib/hexo/render.ts | 2 -- lib/hexo/router.ts | 2 -- lib/hexo/scaffold.ts | 2 -- lib/hexo/source.ts | 2 -- lib/hexo/update_package.ts | 2 -- lib/hexo/validate_config.ts | 2 -- lib/models/asset.ts | 2 -- lib/models/cache.ts | 2 -- lib/models/category.ts | 2 -- lib/models/data.ts | 2 -- lib/models/index.ts | 2 -- lib/models/page.ts | 2 -- lib/models/post.ts | 2 -- lib/models/post_asset.ts | 2 -- lib/models/post_category.ts | 2 -- lib/models/post_tag.ts | 2 -- lib/models/tag.ts | 2 -- lib/models/types/moment.ts | 2 -- lib/plugins/console/clean.ts | 2 -- lib/plugins/console/config.ts | 2 -- lib/plugins/console/deploy.ts | 2 -- lib/plugins/console/generate.ts | 2 -- lib/plugins/console/index.ts | 2 -- lib/plugins/console/list/category.ts | 2 -- lib/plugins/console/list/common.ts | 2 -- lib/plugins/console/list/index.ts | 2 -- lib/plugins/console/list/page.ts | 2 -- lib/plugins/console/list/post.ts | 2 -- lib/plugins/console/list/route.ts | 2 -- lib/plugins/console/list/tag.ts | 2 -- lib/plugins/console/migrate.ts | 2 -- lib/plugins/console/new.ts | 2 -- lib/plugins/console/publish.ts | 2 -- lib/plugins/console/render.ts | 2 -- lib/plugins/filter/after_post_render/excerpt.ts | 2 -- lib/plugins/filter/after_post_render/external_link.ts | 2 -- lib/plugins/filter/after_post_render/index.ts | 2 -- lib/plugins/filter/after_render/external_link.ts | 2 -- lib/plugins/filter/after_render/index.ts | 2 -- lib/plugins/filter/after_render/meta_generator.ts | 2 -- lib/plugins/filter/before_exit/index.ts | 2 -- lib/plugins/filter/before_exit/save_database.ts | 2 -- lib/plugins/filter/before_generate/index.ts | 2 -- lib/plugins/filter/before_generate/render_post.ts | 2 -- lib/plugins/filter/before_post_render/backtick_code_block.ts | 2 -- lib/plugins/filter/before_post_render/index.ts | 2 -- lib/plugins/filter/before_post_render/titlecase.ts | 2 -- lib/plugins/filter/index.ts | 2 -- lib/plugins/filter/new_post_path.ts | 2 -- lib/plugins/filter/post_permalink.ts | 2 -- lib/plugins/filter/template_locals/i18n.ts | 2 -- lib/plugins/filter/template_locals/index.ts | 2 -- lib/plugins/generator/asset.ts | 2 -- lib/plugins/generator/index.ts | 2 -- lib/plugins/generator/page.ts | 2 -- lib/plugins/generator/post.ts | 2 -- lib/plugins/helper/css.ts | 2 -- lib/plugins/helper/date.ts | 2 -- lib/plugins/helper/debug.ts | 2 -- lib/plugins/helper/favicon_tag.ts | 2 -- lib/plugins/helper/feed_tag.ts | 2 -- lib/plugins/helper/format.ts | 2 -- lib/plugins/helper/gravatar.ts | 2 -- lib/plugins/helper/image_tag.ts | 2 -- lib/plugins/helper/index.ts | 2 -- lib/plugins/helper/is.ts | 2 -- lib/plugins/helper/js.ts | 2 -- lib/plugins/helper/link_to.ts | 2 -- lib/plugins/helper/list_archives.ts | 2 -- lib/plugins/helper/list_categories.ts | 2 -- lib/plugins/helper/list_posts.ts | 2 -- lib/plugins/helper/list_tags.ts | 2 -- lib/plugins/helper/mail_to.ts | 2 -- lib/plugins/helper/markdown.ts | 2 -- lib/plugins/helper/meta_generator.ts | 2 -- lib/plugins/helper/number_format.ts | 2 -- lib/plugins/helper/open_graph.ts | 2 -- lib/plugins/helper/paginator.ts | 2 -- lib/plugins/helper/partial.ts | 2 -- lib/plugins/helper/relative_url.ts | 2 -- lib/plugins/helper/render.ts | 2 -- lib/plugins/helper/search_form.ts | 2 -- lib/plugins/helper/tagcloud.ts | 2 -- lib/plugins/helper/toc.ts | 2 -- lib/plugins/helper/url_for.ts | 2 -- lib/plugins/injector/index.ts | 2 -- lib/plugins/processor/asset.ts | 2 -- lib/plugins/processor/common.ts | 2 -- lib/plugins/processor/data.ts | 2 -- lib/plugins/processor/index.ts | 2 -- lib/plugins/processor/post.ts | 2 -- lib/plugins/renderer/index.ts | 2 -- lib/plugins/renderer/json.ts | 2 -- lib/plugins/renderer/nunjucks.ts | 2 -- lib/plugins/renderer/plain.ts | 2 -- lib/plugins/renderer/yaml.ts | 2 -- lib/plugins/tag/asset_img.ts | 2 -- lib/plugins/tag/asset_link.ts | 2 -- lib/plugins/tag/asset_path.ts | 2 -- lib/plugins/tag/blockquote.ts | 2 -- lib/plugins/tag/code.ts | 2 -- lib/plugins/tag/iframe.ts | 2 -- lib/plugins/tag/img.ts | 2 -- lib/plugins/tag/include_code.ts | 2 -- lib/plugins/tag/index.ts | 2 -- lib/plugins/tag/link.ts | 2 -- lib/plugins/tag/post_link.ts | 2 -- lib/plugins/tag/post_path.ts | 2 -- lib/plugins/tag/pullquote.ts | 2 -- lib/theme/index.ts | 2 -- lib/theme/processors/config.ts | 2 -- lib/theme/processors/i18n.ts | 2 -- lib/theme/processors/source.ts | 2 -- lib/theme/processors/view.ts | 2 -- lib/theme/view.ts | 2 -- 138 files changed, 1 insertion(+), 277 deletions(-) diff --git a/lib/box/file.ts b/lib/box/file.ts index e1d57a3eed..342319c9d8 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -1,5 +1,3 @@ -'use strict'; - import {readFile, readFileSync, stat, statSync} from 'hexo-fs'; class File { diff --git a/lib/box/index.ts b/lib/box/index.ts index 2730db15c4..9ef31961d5 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import {join, sep} from 'path'; import Promise from 'bluebird'; import File from './file'; diff --git a/lib/extend/console.ts b/lib/extend/console.ts index 9ec2932112..f8bf2245c5 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; import abbrev from 'abbrev'; diff --git a/lib/extend/deployer.ts b/lib/extend/deployer.ts index 792d0e1a77..43dfaf8853 100644 --- a/lib/extend/deployer.ts +++ b/lib/extend/deployer.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; class Deployer { diff --git a/lib/extend/filter.ts b/lib/extend/filter.ts index 407db8bfc9..31d28809f0 100644 --- a/lib/extend/filter.ts +++ b/lib/extend/filter.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; const typeAlias = { diff --git a/lib/extend/generator.ts b/lib/extend/generator.ts index 31ef689ea6..b3e1756cfb 100644 --- a/lib/extend/generator.ts +++ b/lib/extend/generator.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; class Generator { diff --git a/lib/extend/helper.ts b/lib/extend/helper.ts index 41b0cf03da..48d17584e4 100644 --- a/lib/extend/helper.ts +++ b/lib/extend/helper.ts @@ -1,5 +1,3 @@ -'use strict'; - class Helper { public store: any; diff --git a/lib/extend/index.ts b/lib/extend/index.ts index e5fcd71b32..46da4a8f69 100644 --- a/lib/extend/index.ts +++ b/lib/extend/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import Console from './console'; import Deployer from './deployer'; import Filter from './filter'; diff --git a/lib/extend/injector.ts b/lib/extend/injector.ts index bc4dd87860..5e16e63e2a 100644 --- a/lib/extend/injector.ts +++ b/lib/extend/injector.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Cache} from 'hexo-util'; class Injector { diff --git a/lib/extend/migrator.ts b/lib/extend/migrator.ts index 8b49b6e0b2..1abee6addd 100644 --- a/lib/extend/migrator.ts +++ b/lib/extend/migrator.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; class Migrator { diff --git a/lib/extend/processor.ts b/lib/extend/processor.ts index aaf47b767a..655dd84d3c 100644 --- a/lib/extend/processor.ts +++ b/lib/extend/processor.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; import {Pattern} from 'hexo-util'; diff --git a/lib/extend/renderer.ts b/lib/extend/renderer.ts index f7941537c2..09e4540570 100644 --- a/lib/extend/renderer.ts +++ b/lib/extend/renderer.ts @@ -1,5 +1,3 @@ -'use strict'; - import {extname} from 'path'; import Promise from 'bluebird'; diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index 8fb5a2be00..d206d57958 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {stripIndent} from 'hexo-util'; import {cyan, magenta, red, bold} from 'picocolors'; import {Environment} from 'nunjucks'; diff --git a/lib/hexo/default_config.ts b/lib/hexo/default_config.ts index 4982d7813a..75f6c7810c 100644 --- a/lib/hexo/default_config.ts +++ b/lib/hexo/default_config.ts @@ -1,5 +1,3 @@ -'use strict'; - export default { // Site title: 'Hexo', diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index 3f3eefeaac..727514c760 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; import {sep, join, dirname} from 'path'; import tildify from 'tildify'; diff --git a/lib/hexo/load_config.ts b/lib/hexo/load_config.ts index 6e87bdb43c..d492b0fdf6 100644 --- a/lib/hexo/load_config.ts +++ b/lib/hexo/load_config.ts @@ -1,5 +1,3 @@ -'use strict'; - import {sep, resolve, join, parse} from 'path'; import tildify from 'tildify'; import Theme from '../theme'; diff --git a/lib/hexo/load_database.ts b/lib/hexo/load_database.ts index 29c9d32175..8b625f910a 100644 --- a/lib/hexo/load_database.ts +++ b/lib/hexo/load_database.ts @@ -1,5 +1,3 @@ -'use strict'; - import fs from 'hexo-fs'; import Promise from 'bluebird'; diff --git a/lib/hexo/load_plugins.ts b/lib/hexo/load_plugins.ts index 4668233416..4287d1d531 100644 --- a/lib/hexo/load_plugins.ts +++ b/lib/hexo/load_plugins.ts @@ -1,5 +1,3 @@ -'use strict'; - import {join} from 'path'; import {exists, readFile, listDir} from 'hexo-fs'; import Promise from 'bluebird'; diff --git a/lib/hexo/load_theme_config.ts b/lib/hexo/load_theme_config.ts index 5856e89d72..e7cdf90556 100644 --- a/lib/hexo/load_theme_config.ts +++ b/lib/hexo/load_theme_config.ts @@ -1,5 +1,3 @@ -'use strict'; - import {join, parse} from 'path'; import tildify from 'tildify'; import {exists, readdir} from 'hexo-fs'; diff --git a/lib/hexo/locals.ts b/lib/hexo/locals.ts index 357f27976e..501bef1425 100644 --- a/lib/hexo/locals.ts +++ b/lib/hexo/locals.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Cache} from 'hexo-util'; class Locals { diff --git a/lib/hexo/multi_config_path.ts b/lib/hexo/multi_config_path.ts index 26667bf2bd..5df322d3ca 100644 --- a/lib/hexo/multi_config_path.ts +++ b/lib/hexo/multi_config_path.ts @@ -1,5 +1,3 @@ -'use strict'; - import {isAbsolute, resolve, join, extname} from 'path'; import fs from 'hexo-fs'; import yml from 'js-yaml'; diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 195642215c..9ca67e529f 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -1,5 +1,3 @@ -'use strict'; - import assert from 'assert'; import moment from 'moment'; import Promise from 'bluebird'; diff --git a/lib/hexo/register_models.ts b/lib/hexo/register_models.ts index 6cd8ab63c5..a30c38bf50 100644 --- a/lib/hexo/register_models.ts +++ b/lib/hexo/register_models.ts @@ -1,6 +1,4 @@ -'use strict'; - -import models from '../models'; +import * as models from '../models'; export default ctx => { const db = ctx.database; diff --git a/lib/hexo/render.ts b/lib/hexo/render.ts index 030abcbe47..f11c80b189 100644 --- a/lib/hexo/render.ts +++ b/lib/hexo/render.ts @@ -1,5 +1,3 @@ -'use strict'; - import {extname} from 'path'; import Promise from 'bluebird'; import {readFile, readFileSync} from 'hexo-fs'; diff --git a/lib/hexo/router.ts b/lib/hexo/router.ts index c2355c5f88..a4a214924c 100644 --- a/lib/hexo/router.ts +++ b/lib/hexo/router.ts @@ -1,5 +1,3 @@ -'use strict'; - import {EventEmitter} from 'events'; import Promise from 'bluebird'; import Stream from 'stream'; diff --git a/lib/hexo/scaffold.ts b/lib/hexo/scaffold.ts index 2e7fb99170..87f74a1e39 100644 --- a/lib/hexo/scaffold.ts +++ b/lib/hexo/scaffold.ts @@ -1,5 +1,3 @@ -'use strict'; - import {extname, join} from 'path'; import {exists, listDir, readFile, unlink, writeFile} from 'hexo-fs'; diff --git a/lib/hexo/source.ts b/lib/hexo/source.ts index 7a186db2c4..2b5627aa41 100644 --- a/lib/hexo/source.ts +++ b/lib/hexo/source.ts @@ -1,5 +1,3 @@ -'use strict'; - import Box from '../box'; class Source extends Box { diff --git a/lib/hexo/update_package.ts b/lib/hexo/update_package.ts index 7247dbd952..f7e80e3bec 100644 --- a/lib/hexo/update_package.ts +++ b/lib/hexo/update_package.ts @@ -1,5 +1,3 @@ -'use strict'; - import {join} from 'path'; import fs from 'hexo-fs'; diff --git a/lib/hexo/validate_config.ts b/lib/hexo/validate_config.ts index 347feea886..7482596ad4 100644 --- a/lib/hexo/validate_config.ts +++ b/lib/hexo/validate_config.ts @@ -1,5 +1,3 @@ -'use strict'; - module.exports = ctx => { const { config, log } = ctx; diff --git a/lib/models/asset.ts b/lib/models/asset.ts index ae100fae03..59d4e6eb7d 100644 --- a/lib/models/asset.ts +++ b/lib/models/asset.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import {join} from 'path'; diff --git a/lib/models/cache.ts b/lib/models/cache.ts index 9b0f570d63..09804879af 100644 --- a/lib/models/cache.ts +++ b/lib/models/cache.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import Promise from 'bluebird'; diff --git a/lib/models/category.ts b/lib/models/category.ts index a9b0165c74..307c201cfc 100644 --- a/lib/models/category.ts +++ b/lib/models/category.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import {slugize, full_url_for} from 'hexo-util'; diff --git a/lib/models/data.ts b/lib/models/data.ts index 138aac85fb..ffbde10717 100644 --- a/lib/models/data.ts +++ b/lib/models/data.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; export default ctx => { diff --git a/lib/models/index.ts b/lib/models/index.ts index a8639fec6d..c641b71790 100644 --- a/lib/models/index.ts +++ b/lib/models/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import Asset from './asset'; import Cache from './cache'; import Category from './category'; diff --git a/lib/models/page.ts b/lib/models/page.ts index 0a38670002..d40047c2cc 100644 --- a/lib/models/page.ts +++ b/lib/models/page.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import {join} from 'path'; import Moment from './types/moment'; diff --git a/lib/models/post.ts b/lib/models/post.ts index 2e4d19b010..6b6fe714db 100644 --- a/lib/models/post.ts +++ b/lib/models/post.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import moment from 'moment'; import {extname, join, sep} from 'path'; diff --git a/lib/models/post_asset.ts b/lib/models/post_asset.ts index 18250e09a2..3cefffc167 100644 --- a/lib/models/post_asset.ts +++ b/lib/models/post_asset.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import {join} from 'path'; diff --git a/lib/models/post_category.ts b/lib/models/post_category.ts index e34c427205..9bcbd0c9d5 100644 --- a/lib/models/post_category.ts +++ b/lib/models/post_category.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; export default ctx => { diff --git a/lib/models/post_tag.ts b/lib/models/post_tag.ts index ddc3f193df..5c25d15ac9 100644 --- a/lib/models/post_tag.ts +++ b/lib/models/post_tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; export default ctx => { diff --git a/lib/models/tag.ts b/lib/models/tag.ts index 4b0a2b22a9..12a58bc9a3 100644 --- a/lib/models/tag.ts +++ b/lib/models/tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Schema} from 'warehouse'; import {slugize, full_url_for} from 'hexo-util'; const { hasOwnProperty: hasOwn } = Object.prototype; diff --git a/lib/models/types/moment.ts b/lib/models/types/moment.ts index 70bafa229b..46b0bf80db 100644 --- a/lib/models/types/moment.ts +++ b/lib/models/types/moment.ts @@ -1,5 +1,3 @@ -'use strict'; - import {SchemaType} from 'warehouse'; import {moment, toMomentLocale} from '../../plugins/helper/date'; diff --git a/lib/plugins/console/clean.ts b/lib/plugins/console/clean.ts index 588d5350da..127562b8e0 100644 --- a/lib/plugins/console/clean.ts +++ b/lib/plugins/console/clean.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; import fs from 'hexo-fs'; diff --git a/lib/plugins/console/config.ts b/lib/plugins/console/config.ts index 0d57d80d88..c5f859c95f 100644 --- a/lib/plugins/console/config.ts +++ b/lib/plugins/console/config.ts @@ -1,5 +1,3 @@ -'use strict'; - import yaml from 'js-yaml'; import fs from 'hexo-fs'; import {extname} from 'path'; diff --git a/lib/plugins/console/deploy.ts b/lib/plugins/console/deploy.ts index 485e24be79..6f4fa1c5af 100644 --- a/lib/plugins/console/deploy.ts +++ b/lib/plugins/console/deploy.ts @@ -1,5 +1,3 @@ -'use strict'; - import {exists} from 'hexo-fs'; import {underline, magenta} from 'picocolors'; diff --git a/lib/plugins/console/generate.ts b/lib/plugins/console/generate.ts index ccc14b9140..f4048111b9 100644 --- a/lib/plugins/console/generate.ts +++ b/lib/plugins/console/generate.ts @@ -1,5 +1,3 @@ -'use strict'; - import {exists, writeFile, unlink, stat, mkdirs} from 'hexo-fs'; import {join} from 'path'; import Promise from 'bluebird'; diff --git a/lib/plugins/console/index.ts b/lib/plugins/console/index.ts index 12db73f207..347cd89254 100644 --- a/lib/plugins/console/index.ts +++ b/lib/plugins/console/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default function(ctx) { const { console } = ctx.extend; diff --git a/lib/plugins/console/list/category.ts b/lib/plugins/console/list/category.ts index c53fceea42..666e5d31b4 100644 --- a/lib/plugins/console/list/category.ts +++ b/lib/plugins/console/list/category.ts @@ -1,5 +1,3 @@ -'use strict'; - import {underline} from 'picocolors'; import table from 'text-table'; import {stringLength} from './common'; diff --git a/lib/plugins/console/list/common.ts b/lib/plugins/console/list/common.ts index 963e4135e7..5adcb8022c 100644 --- a/lib/plugins/console/list/common.ts +++ b/lib/plugins/console/list/common.ts @@ -1,5 +1,3 @@ -'use strict'; - import strip from 'strip-ansi'; export function stringLength(str) { diff --git a/lib/plugins/console/list/index.ts b/lib/plugins/console/list/index.ts index de85552bdb..6dc2805462 100644 --- a/lib/plugins/console/list/index.ts +++ b/lib/plugins/console/list/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import abbrev from 'abbrev'; import page from './page'; import post from './post'; diff --git a/lib/plugins/console/list/page.ts b/lib/plugins/console/list/page.ts index 443bbc383c..92a3b3ae5b 100644 --- a/lib/plugins/console/list/page.ts +++ b/lib/plugins/console/list/page.ts @@ -1,5 +1,3 @@ -'use strict'; - import {magenta, underline, gray} from 'picocolors'; import table from 'text-table'; import {stringLength} from './common'; diff --git a/lib/plugins/console/list/post.ts b/lib/plugins/console/list/post.ts index 58ecf673df..366ee6a63c 100644 --- a/lib/plugins/console/list/post.ts +++ b/lib/plugins/console/list/post.ts @@ -1,5 +1,3 @@ -'use strict'; - import {gray, magenta, underline} from 'picocolors'; import table from 'text-table'; import {stringLength} from './common'; diff --git a/lib/plugins/console/list/route.ts b/lib/plugins/console/list/route.ts index 29ab342e9e..df26b81c0f 100644 --- a/lib/plugins/console/list/route.ts +++ b/lib/plugins/console/list/route.ts @@ -1,5 +1,3 @@ -'use strict'; - import archy from 'archy'; function listRoute() { diff --git a/lib/plugins/console/list/tag.ts b/lib/plugins/console/list/tag.ts index 69710978a8..b93bc3d911 100644 --- a/lib/plugins/console/list/tag.ts +++ b/lib/plugins/console/list/tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {magenta, underline} from 'picocolors'; import table from 'text-table'; import {stringLength} from './common'; diff --git a/lib/plugins/console/migrate.ts b/lib/plugins/console/migrate.ts index fff1d3e811..a04436138e 100644 --- a/lib/plugins/console/migrate.ts +++ b/lib/plugins/console/migrate.ts @@ -1,5 +1,3 @@ -'use strict'; - import {underline, magenta} from 'picocolors'; function migrateConsole(args) { diff --git a/lib/plugins/console/new.ts b/lib/plugins/console/new.ts index 4b44177965..4abbcb9eb6 100644 --- a/lib/plugins/console/new.ts +++ b/lib/plugins/console/new.ts @@ -1,5 +1,3 @@ -'use strict'; - import tildify from 'tildify'; import {magenta} from 'picocolors'; import { basename } from 'path'; diff --git a/lib/plugins/console/publish.ts b/lib/plugins/console/publish.ts index 420d03c6bc..e6f69e59bb 100644 --- a/lib/plugins/console/publish.ts +++ b/lib/plugins/console/publish.ts @@ -1,5 +1,3 @@ -'use strict'; - import tildify from 'tildify'; import {magenta} from 'picocolors'; diff --git a/lib/plugins/console/render.ts b/lib/plugins/console/render.ts index 768426e054..ea6c99fa10 100644 --- a/lib/plugins/console/render.ts +++ b/lib/plugins/console/render.ts @@ -1,5 +1,3 @@ -'use strict'; - import {resolve} from 'path'; import tildify from 'tildify'; import prettyHrtime from 'pretty-hrtime'; diff --git a/lib/plugins/filter/after_post_render/excerpt.ts b/lib/plugins/filter/after_post_render/excerpt.ts index 5da8564135..e53508c57a 100644 --- a/lib/plugins/filter/after_post_render/excerpt.ts +++ b/lib/plugins/filter/after_post_render/excerpt.ts @@ -1,5 +1,3 @@ -'use strict'; - const rExcerpt = //i; function excerptFilter(data) { diff --git a/lib/plugins/filter/after_post_render/external_link.ts b/lib/plugins/filter/after_post_render/external_link.ts index 19d25a0bf0..c6c7430751 100644 --- a/lib/plugins/filter/after_post_render/external_link.ts +++ b/lib/plugins/filter/after_post_render/external_link.ts @@ -1,5 +1,3 @@ -'use strict'; - import {isExternalLink} from 'hexo-util'; let EXTERNAL_LINK_POST_ENABLED = true; const rATag = /]+?\s+?)href=["']((?:https?:|\/\/)[^<>"']+)["'][^<>]*>/gi; diff --git a/lib/plugins/filter/after_post_render/index.ts b/lib/plugins/filter/after_post_render/index.ts index 1d0297039d..75be684c60 100644 --- a/lib/plugins/filter/after_post_render/index.ts +++ b/lib/plugins/filter/after_post_render/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/filter/after_render/external_link.ts b/lib/plugins/filter/after_render/external_link.ts index d3c22f10d6..35e3f7d95e 100644 --- a/lib/plugins/filter/after_render/external_link.ts +++ b/lib/plugins/filter/after_render/external_link.ts @@ -1,5 +1,3 @@ -'use strict'; - import {isExternalLink} from 'hexo-util'; let EXTERNAL_LINK_SITE_ENABLED = true; diff --git a/lib/plugins/filter/after_render/index.ts b/lib/plugins/filter/after_render/index.ts index 531cace679..7bf9c72644 100644 --- a/lib/plugins/filter/after_render/index.ts +++ b/lib/plugins/filter/after_render/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/filter/after_render/meta_generator.ts b/lib/plugins/filter/after_render/meta_generator.ts index 1b1b541ac6..dc396b1e25 100644 --- a/lib/plugins/filter/after_render/meta_generator.ts +++ b/lib/plugins/filter/after_render/meta_generator.ts @@ -1,5 +1,3 @@ -'use strict'; - let NEED_INJECT = true; let META_GENERATOR_TAG; diff --git a/lib/plugins/filter/before_exit/index.ts b/lib/plugins/filter/before_exit/index.ts index ba555dd8aa..e2670adb48 100644 --- a/lib/plugins/filter/before_exit/index.ts +++ b/lib/plugins/filter/before_exit/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/filter/before_exit/save_database.ts b/lib/plugins/filter/before_exit/save_database.ts index bb970d45d0..ea67d1b5e5 100644 --- a/lib/plugins/filter/before_exit/save_database.ts +++ b/lib/plugins/filter/before_exit/save_database.ts @@ -1,5 +1,3 @@ -'use strict'; - function saveDatabaseFilter() { if (!this.env.init || !this._dbLoaded) return; diff --git a/lib/plugins/filter/before_generate/index.ts b/lib/plugins/filter/before_generate/index.ts index 033ce01cfa..8052c5cc03 100644 --- a/lib/plugins/filter/before_generate/index.ts +++ b/lib/plugins/filter/before_generate/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/filter/before_generate/render_post.ts b/lib/plugins/filter/before_generate/render_post.ts index 7c4deffb0f..a55f3e4e66 100644 --- a/lib/plugins/filter/before_generate/render_post.ts +++ b/lib/plugins/filter/before_generate/render_post.ts @@ -1,5 +1,3 @@ -'use strict'; - import Promise from 'bluebird'; function renderPostFilter(data) { diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.ts b/lib/plugins/filter/before_post_render/backtick_code_block.ts index 09d451246d..926054be9d 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.ts +++ b/lib/plugins/filter/before_post_render/backtick_code_block.ts @@ -1,5 +1,3 @@ -'use strict'; - const rBacktick = /^((?:[^\S\r\n]*>){0,3}[^\S\r\n]*)(`{3,}|~{3,})[^\S\r\n]*((?:.*?[^`\s])?)[^\S\r\n]*\n((?:[\s\S]*?\n)?)(?:(?:[^\S\r\n]*>){0,3}[^\S\r\n]*)\2[^\S\r\n]?(\n+|$)/gm; const rAllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/; const rLangCaption = /([^\s]+)\s*(.+)?/; diff --git a/lib/plugins/filter/before_post_render/index.ts b/lib/plugins/filter/before_post_render/index.ts index 5bd933cb9f..d27d5a6aa8 100644 --- a/lib/plugins/filter/before_post_render/index.ts +++ b/lib/plugins/filter/before_post_render/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/filter/before_post_render/titlecase.ts b/lib/plugins/filter/before_post_render/titlecase.ts index 30da444c6a..27baef4074 100644 --- a/lib/plugins/filter/before_post_render/titlecase.ts +++ b/lib/plugins/filter/before_post_render/titlecase.ts @@ -1,5 +1,3 @@ -'use strict'; - let titlecase; function titlecaseFilter(data) { diff --git a/lib/plugins/filter/index.ts b/lib/plugins/filter/index.ts index 5f82ca1663..b7a6bb246f 100644 --- a/lib/plugins/filter/index.ts +++ b/lib/plugins/filter/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index bb5b35deb2..047b987267 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -1,5 +1,3 @@ -'use strict'; - import {join, extname} from 'path'; import moment from 'moment'; import Promise from 'bluebird'; diff --git a/lib/plugins/filter/post_permalink.ts b/lib/plugins/filter/post_permalink.ts index 223438696b..c2782fdf5d 100644 --- a/lib/plugins/filter/post_permalink.ts +++ b/lib/plugins/filter/post_permalink.ts @@ -1,5 +1,3 @@ -'use strict'; - import {createSha1Hash, Permalink, slugize} from 'hexo-util'; import {basename} from 'path'; let permalink; diff --git a/lib/plugins/filter/template_locals/i18n.ts b/lib/plugins/filter/template_locals/i18n.ts index a94f77abb7..58205b03a7 100644 --- a/lib/plugins/filter/template_locals/i18n.ts +++ b/lib/plugins/filter/template_locals/i18n.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; function i18nLocalsFilter(locals) { diff --git a/lib/plugins/filter/template_locals/index.ts b/lib/plugins/filter/template_locals/index.ts index 082cd71ff8..f75d6ebbee 100644 --- a/lib/plugins/filter/template_locals/index.ts +++ b/lib/plugins/filter/template_locals/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { filter } = ctx.extend; diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index e3504dc624..c44199d955 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -1,5 +1,3 @@ -'use strict'; - import fs from 'hexo-fs'; import Promise from 'bluebird'; import {extname} from 'path'; diff --git a/lib/plugins/generator/index.ts b/lib/plugins/generator/index.ts index bb3c1b769e..46d84380cb 100644 --- a/lib/plugins/generator/index.ts +++ b/lib/plugins/generator/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { generator } = ctx.extend; diff --git a/lib/plugins/generator/page.ts b/lib/plugins/generator/page.ts index c8c3dd0275..4cdae9f394 100644 --- a/lib/plugins/generator/page.ts +++ b/lib/plugins/generator/page.ts @@ -1,5 +1,3 @@ -'use strict'; - function pageGenerator(locals) { return locals.pages.map(page => { const { path, layout } = page; diff --git a/lib/plugins/generator/post.ts b/lib/plugins/generator/post.ts index 343e0df380..bd4a04f6ce 100644 --- a/lib/plugins/generator/post.ts +++ b/lib/plugins/generator/post.ts @@ -1,5 +1,3 @@ -'use strict'; - function postGenerator(locals) { const posts = locals.posts.sort('-date').toArray(); const { length } = posts; diff --git a/lib/plugins/helper/css.ts b/lib/plugins/helper/css.ts index 88193cb5bb..5b42a6a761 100644 --- a/lib/plugins/helper/css.ts +++ b/lib/plugins/helper/css.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag, url_for} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/date.ts b/lib/plugins/helper/date.ts index bf0514e085..c160785836 100644 --- a/lib/plugins/helper/date.ts +++ b/lib/plugins/helper/date.ts @@ -1,5 +1,3 @@ -'use strict'; - import moment from 'moment-timezone'; const { isMoment } = moment; import moize from 'moize'; diff --git a/lib/plugins/helper/debug.ts b/lib/plugins/helper/debug.ts index 62a4b473d4..59cda3d42a 100644 --- a/lib/plugins/helper/debug.ts +++ b/lib/plugins/helper/debug.ts @@ -1,5 +1,3 @@ -'use strict'; - import {inspect} from 'util'; // this format object as string, resolves circular reference diff --git a/lib/plugins/helper/favicon_tag.ts b/lib/plugins/helper/favicon_tag.ts index c778233a15..b8affd6878 100644 --- a/lib/plugins/helper/favicon_tag.ts +++ b/lib/plugins/helper/favicon_tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {url_for} from 'hexo-util'; function faviconTagHelper(path) { diff --git a/lib/plugins/helper/feed_tag.ts b/lib/plugins/helper/feed_tag.ts index 4633efbb9d..81dfdb9daa 100644 --- a/lib/plugins/helper/feed_tag.ts +++ b/lib/plugins/helper/feed_tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {url_for} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/format.ts b/lib/plugins/helper/format.ts index b1d364c9dd..a66a848526 100644 --- a/lib/plugins/helper/format.ts +++ b/lib/plugins/helper/format.ts @@ -1,5 +1,3 @@ -'use strict'; - import {stripHTML, wordWrap, truncate, escapeHTML} from 'hexo-util'; import titlecase from 'titlecase'; export {stripHTML as strip_html}; diff --git a/lib/plugins/helper/gravatar.ts b/lib/plugins/helper/gravatar.ts index bfcd4a343b..1146e990f4 100644 --- a/lib/plugins/helper/gravatar.ts +++ b/lib/plugins/helper/gravatar.ts @@ -1,4 +1,2 @@ -'use strict'; - import {gravatar} from 'hexo-util'; export default gravatar; diff --git a/lib/plugins/helper/image_tag.ts b/lib/plugins/helper/image_tag.ts index 841e656bea..009286ba92 100644 --- a/lib/plugins/helper/image_tag.ts +++ b/lib/plugins/helper/image_tag.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag, url_for} from 'hexo-util'; function imageTagHelper(path, options = {}) { diff --git a/lib/plugins/helper/index.ts b/lib/plugins/helper/index.ts index d2e2d03b81..7c0bf0773f 100644 --- a/lib/plugins/helper/index.ts +++ b/lib/plugins/helper/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { helper } = ctx.extend; diff --git a/lib/plugins/helper/is.ts b/lib/plugins/helper/is.ts index 26a110d37f..1f843cf3ff 100644 --- a/lib/plugins/helper/is.ts +++ b/lib/plugins/helper/is.ts @@ -1,5 +1,3 @@ -'use strict'; - function isCurrentHelper(path = '/', strict) { const currentPath = this.path.replace(/^[^/].*/, '/$&'); diff --git a/lib/plugins/helper/js.ts b/lib/plugins/helper/js.ts index d001e00f88..5362625440 100644 --- a/lib/plugins/helper/js.ts +++ b/lib/plugins/helper/js.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag, url_for} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/link_to.ts b/lib/plugins/helper/link_to.ts index 56afb3374c..46038d0825 100644 --- a/lib/plugins/helper/link_to.ts +++ b/lib/plugins/helper/link_to.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag, url_for} from 'hexo-util'; function linkToHelper(path, text, options = {}) { diff --git a/lib/plugins/helper/list_archives.ts b/lib/plugins/helper/list_archives.ts index 1fbbababe1..69c2fe4e79 100644 --- a/lib/plugins/helper/list_archives.ts +++ b/lib/plugins/helper/list_archives.ts @@ -1,5 +1,3 @@ -'use strict'; - import {toMomentLocale} from './date'; import {url_for} from 'hexo-util'; diff --git a/lib/plugins/helper/list_categories.ts b/lib/plugins/helper/list_categories.ts index e2fd6c5ff8..74c2bd6dfa 100644 --- a/lib/plugins/helper/list_categories.ts +++ b/lib/plugins/helper/list_categories.ts @@ -1,5 +1,3 @@ -'use strict'; - import {url_for} from 'hexo-util'; function listCategoriesHelper(categories, options) { diff --git a/lib/plugins/helper/list_posts.ts b/lib/plugins/helper/list_posts.ts index 2a23bc478d..a3de444b77 100644 --- a/lib/plugins/helper/list_posts.ts +++ b/lib/plugins/helper/list_posts.ts @@ -1,5 +1,3 @@ -'use strict'; - import {url_for} from 'hexo-util'; function listPostsHelper(posts, options) { diff --git a/lib/plugins/helper/list_tags.ts b/lib/plugins/helper/list_tags.ts index 64d2c9e397..9437bc92cf 100644 --- a/lib/plugins/helper/list_tags.ts +++ b/lib/plugins/helper/list_tags.ts @@ -1,5 +1,3 @@ -'use strict'; - import {url_for, escapeHTML} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/mail_to.ts b/lib/plugins/helper/mail_to.ts index da18443b12..d747edb10a 100644 --- a/lib/plugins/helper/mail_to.ts +++ b/lib/plugins/helper/mail_to.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/markdown.ts b/lib/plugins/helper/markdown.ts index 5e90988ba6..4f7731600e 100644 --- a/lib/plugins/helper/markdown.ts +++ b/lib/plugins/helper/markdown.ts @@ -1,5 +1,3 @@ -'use strict'; - function markdownHelper(text, options) { return this.render(text, 'markdown', options); } diff --git a/lib/plugins/helper/meta_generator.ts b/lib/plugins/helper/meta_generator.ts index ba9e6c9fc8..e9513838e1 100644 --- a/lib/plugins/helper/meta_generator.ts +++ b/lib/plugins/helper/meta_generator.ts @@ -1,5 +1,3 @@ -'use strict'; - function metaGeneratorHelper() { return ``; } diff --git a/lib/plugins/helper/number_format.ts b/lib/plugins/helper/number_format.ts index f47d92716e..23c9700124 100644 --- a/lib/plugins/helper/number_format.ts +++ b/lib/plugins/helper/number_format.ts @@ -1,5 +1,3 @@ -'use strict'; - function numberFormatHelper(num, options = {}) { const split = num.toString().split('.'); let before = split.shift(); diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index 64858287e3..3d916bb7c6 100644 --- a/lib/plugins/helper/open_graph.ts +++ b/lib/plugins/helper/open_graph.ts @@ -1,5 +1,3 @@ -'use strict'; - import {isMoment, isDate} from 'moment'; import {encodeURL, prettyUrls, stripHTML, escapeHTML} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/paginator.ts b/lib/plugins/helper/paginator.ts index c52749ce6c..4ff8edff71 100644 --- a/lib/plugins/helper/paginator.ts +++ b/lib/plugins/helper/paginator.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag, url_for} from 'hexo-util'; const createLink = (options, ctx) => { diff --git a/lib/plugins/helper/partial.ts b/lib/plugins/helper/partial.ts index 18f8198811..832d5ae583 100644 --- a/lib/plugins/helper/partial.ts +++ b/lib/plugins/helper/partial.ts @@ -1,5 +1,3 @@ -'use strict'; - import {dirname, join} from 'path'; export default ctx => (function partial(name, locals, options = {}) { diff --git a/lib/plugins/helper/relative_url.ts b/lib/plugins/helper/relative_url.ts index 51efcc2545..c994b85ad0 100644 --- a/lib/plugins/helper/relative_url.ts +++ b/lib/plugins/helper/relative_url.ts @@ -1,5 +1,3 @@ -'use strict'; - import {relative_url} from 'hexo-util'; export default function(from, to) { diff --git a/lib/plugins/helper/render.ts b/lib/plugins/helper/render.ts index 7aa6f88082..e55842d5fb 100644 --- a/lib/plugins/helper/render.ts +++ b/lib/plugins/helper/render.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => (function render(text, engine, options) { return ctx.render.renderSync({ text, diff --git a/lib/plugins/helper/search_form.ts b/lib/plugins/helper/search_form.ts index 5f0032c7d2..4f6509a1bb 100644 --- a/lib/plugins/helper/search_form.ts +++ b/lib/plugins/helper/search_form.ts @@ -1,5 +1,3 @@ -'use strict'; - import moize from 'moize'; function searchFormHelper(options = {}) { diff --git a/lib/plugins/helper/tagcloud.ts b/lib/plugins/helper/tagcloud.ts index b872c9319a..32f0ec9986 100644 --- a/lib/plugins/helper/tagcloud.ts +++ b/lib/plugins/helper/tagcloud.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Color, url_for} from 'hexo-util'; import moize from 'moize'; diff --git a/lib/plugins/helper/toc.ts b/lib/plugins/helper/toc.ts index 6d8fa69720..4932a07fe1 100644 --- a/lib/plugins/helper/toc.ts +++ b/lib/plugins/helper/toc.ts @@ -1,5 +1,3 @@ -'use strict'; - import {tocObj, escapeHTML, encodeURL} from 'hexo-util'; function tocHelper(str, options = {}) { diff --git a/lib/plugins/helper/url_for.ts b/lib/plugins/helper/url_for.ts index 5aea652ce2..2a17cd4597 100644 --- a/lib/plugins/helper/url_for.ts +++ b/lib/plugins/helper/url_for.ts @@ -1,5 +1,3 @@ -'use strict'; - import {url_for} from 'hexo-util'; export default function(path, options) { diff --git a/lib/plugins/injector/index.ts b/lib/plugins/injector/index.ts index 9ee9002d4c..92e3f30837 100644 --- a/lib/plugins/injector/index.ts +++ b/lib/plugins/injector/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { // eslint-disable-next-line no-unused-vars const { injector } = ctx.extend; diff --git a/lib/plugins/processor/asset.ts b/lib/plugins/processor/asset.ts index 675589c644..451544b76d 100644 --- a/lib/plugins/processor/asset.ts +++ b/lib/plugins/processor/asset.ts @@ -1,5 +1,3 @@ -'use strict'; - import {timezone, toDate, isExcludedFile, isMatch} from './common'; import Promise from 'bluebird'; import {parse as yfm} from 'hexo-front-matter'; diff --git a/lib/plugins/processor/common.ts b/lib/plugins/processor/common.ts index c0f4082b9c..272b910446 100644 --- a/lib/plugins/processor/common.ts +++ b/lib/plugins/processor/common.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; import moment from 'moment-timezone'; import micromatch from 'micromatch'; diff --git a/lib/plugins/processor/data.ts b/lib/plugins/processor/data.ts index 6e3d79a896..1ed3df1caf 100644 --- a/lib/plugins/processor/data.ts +++ b/lib/plugins/processor/data.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; import {extname} from 'path'; diff --git a/lib/plugins/processor/index.ts b/lib/plugins/processor/index.ts index 02c1f7da58..9342b9a779 100644 --- a/lib/plugins/processor/index.ts +++ b/lib/plugins/processor/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { processor } = ctx.extend; diff --git a/lib/plugins/processor/post.ts b/lib/plugins/processor/post.ts index 8c72461cfd..f3044a2b08 100644 --- a/lib/plugins/processor/post.ts +++ b/lib/plugins/processor/post.ts @@ -1,5 +1,3 @@ -'use strict'; - import {toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch} from './common'; import Promise from 'bluebird'; import {parse as yfm} from 'hexo-front-matter'; diff --git a/lib/plugins/renderer/index.ts b/lib/plugins/renderer/index.ts index 65a4b1e564..2ca5e36957 100644 --- a/lib/plugins/renderer/index.ts +++ b/lib/plugins/renderer/index.ts @@ -1,5 +1,3 @@ -'use strict'; - export default ctx => { const { renderer } = ctx.extend; diff --git a/lib/plugins/renderer/json.ts b/lib/plugins/renderer/json.ts index 7951689e52..883785c65b 100644 --- a/lib/plugins/renderer/json.ts +++ b/lib/plugins/renderer/json.ts @@ -1,5 +1,3 @@ -'use strict'; - function jsonRenderer(data) { return JSON.parse(data.text); } diff --git a/lib/plugins/renderer/nunjucks.ts b/lib/plugins/renderer/nunjucks.ts index 6fff27c4b5..008d84d87f 100644 --- a/lib/plugins/renderer/nunjucks.ts +++ b/lib/plugins/renderer/nunjucks.ts @@ -1,6 +1,4 @@ -'use strict'; - import nunjucks from 'nunjucks'; import {readFileSync} from 'hexo-fs'; import {dirname} from 'path'; diff --git a/lib/plugins/renderer/plain.ts b/lib/plugins/renderer/plain.ts index 15e775cbbb..666c122705 100644 --- a/lib/plugins/renderer/plain.ts +++ b/lib/plugins/renderer/plain.ts @@ -1,5 +1,3 @@ -'use strict'; - function plainRenderer(data) { return data.text; } diff --git a/lib/plugins/renderer/yaml.ts b/lib/plugins/renderer/yaml.ts index 145dba617d..d01c61d1c6 100644 --- a/lib/plugins/renderer/yaml.ts +++ b/lib/plugins/renderer/yaml.ts @@ -1,5 +1,3 @@ -'use strict'; - import yaml from 'js-yaml'; import {escape} from 'hexo-front-matter'; const log = require('hexo-log')(); diff --git a/lib/plugins/tag/asset_img.ts b/lib/plugins/tag/asset_img.ts index 657a4c1e01..7398509f2b 100644 --- a/lib/plugins/tag/asset_img.ts +++ b/lib/plugins/tag/asset_img.ts @@ -1,5 +1,3 @@ -'use strict'; - import img from './img'; import {encodeURL} from 'hexo-util'; diff --git a/lib/plugins/tag/asset_link.ts b/lib/plugins/tag/asset_link.ts index ec7e256609..4675e440ec 100644 --- a/lib/plugins/tag/asset_link.ts +++ b/lib/plugins/tag/asset_link.ts @@ -1,5 +1,3 @@ -'use strict'; - import {encodeURL, escapeHTML} from 'hexo-util'; /** diff --git a/lib/plugins/tag/asset_path.ts b/lib/plugins/tag/asset_path.ts index 0457a0877c..950cfe3e56 100644 --- a/lib/plugins/tag/asset_path.ts +++ b/lib/plugins/tag/asset_path.ts @@ -1,5 +1,3 @@ -'use strict'; - import {encodeURL} from 'hexo-util'; /** diff --git a/lib/plugins/tag/blockquote.ts b/lib/plugins/tag/blockquote.ts index 646dbb8b58..d709e6ab7e 100644 --- a/lib/plugins/tag/blockquote.ts +++ b/lib/plugins/tag/blockquote.ts @@ -1,5 +1,3 @@ -'use strict'; - // Based on: https://raw.github.com/imathis/octopress/master/plugins/blockquote.rb import titlecase from 'titlecase'; diff --git a/lib/plugins/tag/code.ts b/lib/plugins/tag/code.ts index 7d24a8f36a..e71f81199f 100644 --- a/lib/plugins/tag/code.ts +++ b/lib/plugins/tag/code.ts @@ -1,5 +1,3 @@ -'use strict'; - // Based on: https://raw.github.com/imathis/octopress/master/plugins/code_block.rb import {escapeHTML} from 'hexo-util'; diff --git a/lib/plugins/tag/iframe.ts b/lib/plugins/tag/iframe.ts index d0e517aa04..fbaefcb16b 100644 --- a/lib/plugins/tag/iframe.ts +++ b/lib/plugins/tag/iframe.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag} from 'hexo-util'; /** diff --git a/lib/plugins/tag/img.ts b/lib/plugins/tag/img.ts index 5226341714..e631b9aeb6 100644 --- a/lib/plugins/tag/img.ts +++ b/lib/plugins/tag/img.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag, url_for} from 'hexo-util'; const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/; diff --git a/lib/plugins/tag/include_code.ts b/lib/plugins/tag/include_code.ts index 8394925918..ea0e7a39da 100644 --- a/lib/plugins/tag/include_code.ts +++ b/lib/plugins/tag/include_code.ts @@ -1,5 +1,3 @@ -'use strict'; - import {exists, readFile} from 'hexo-fs'; import {basename, extname, join, posix} from 'path'; diff --git a/lib/plugins/tag/index.ts b/lib/plugins/tag/index.ts index 085cc418a1..a136ead63f 100644 --- a/lib/plugins/tag/index.ts +++ b/lib/plugins/tag/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import moize from 'moize'; export default ctx => { diff --git a/lib/plugins/tag/link.ts b/lib/plugins/tag/link.ts index 87a7d8f480..f04dbd9c5b 100644 --- a/lib/plugins/tag/link.ts +++ b/lib/plugins/tag/link.ts @@ -1,5 +1,3 @@ -'use strict'; - import {htmlTag} from 'hexo-util'; const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/; diff --git a/lib/plugins/tag/post_link.ts b/lib/plugins/tag/post_link.ts index af8355afad..c5e04baf20 100644 --- a/lib/plugins/tag/post_link.ts +++ b/lib/plugins/tag/post_link.ts @@ -1,5 +1,3 @@ -'use strict'; - import {encodeURL, escapeHTML} from 'hexo-util'; import {postFindOneFactory} from './'; diff --git a/lib/plugins/tag/post_path.ts b/lib/plugins/tag/post_path.ts index bbcd0a46f0..93a8c6365e 100644 --- a/lib/plugins/tag/post_path.ts +++ b/lib/plugins/tag/post_path.ts @@ -1,5 +1,3 @@ -'use strict'; - import {encodeURL} from 'hexo-util'; import {postFindOneFactory} from './'; diff --git a/lib/plugins/tag/pullquote.ts b/lib/plugins/tag/pullquote.ts index e0c2a8ac52..bf54bcac30 100644 --- a/lib/plugins/tag/pullquote.ts +++ b/lib/plugins/tag/pullquote.ts @@ -1,5 +1,3 @@ -'use strict'; - /** * Pullquote tag * diff --git a/lib/theme/index.ts b/lib/theme/index.ts index e4891433bb..34a188f5e6 100644 --- a/lib/theme/index.ts +++ b/lib/theme/index.ts @@ -1,5 +1,3 @@ -'use strict'; - import {extname} from 'path'; import Box from '../box'; import View from './view'; diff --git a/lib/theme/processors/config.ts b/lib/theme/processors/config.ts index 60af5dffe9..b2a175b2b0 100644 --- a/lib/theme/processors/config.ts +++ b/lib/theme/processors/config.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; export function process(file) { diff --git a/lib/theme/processors/i18n.ts b/lib/theme/processors/i18n.ts index 166ba35b80..515c6b2e5b 100644 --- a/lib/theme/processors/i18n.ts +++ b/lib/theme/processors/i18n.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; import {extname} from 'path'; diff --git a/lib/theme/processors/source.ts b/lib/theme/processors/source.ts index 16ba62c7a2..4233bac613 100644 --- a/lib/theme/processors/source.ts +++ b/lib/theme/processors/source.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; import common from '../../plugins/processor/common'; diff --git a/lib/theme/processors/view.ts b/lib/theme/processors/view.ts index 3f4ce3dab9..fe3cf1d04c 100644 --- a/lib/theme/processors/view.ts +++ b/lib/theme/processors/view.ts @@ -1,5 +1,3 @@ -'use strict'; - import {Pattern} from 'hexo-util'; export function process(file) { diff --git a/lib/theme/view.ts b/lib/theme/view.ts index 1157b68085..908b2fc2c0 100644 --- a/lib/theme/view.ts +++ b/lib/theme/view.ts @@ -1,5 +1,3 @@ -'use strict'; - import {dirname, extname, join} from 'path'; import {parse as yfm} from 'hexo-front-matter'; import Promise from 'bluebird'; From 73d5ef9610e67a16c4b0ca4bb74e312e9c15f9a0 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 09:59:07 +0800 Subject: [PATCH 05/45] fix indentation --- lib/box/file.ts | 8 +-- lib/box/index.ts | 24 ++++----- lib/extend/console.ts | 4 +- lib/extend/deployer.ts | 2 +- lib/extend/filter.ts | 2 +- lib/extend/generator.ts | 4 +- lib/extend/helper.ts | 2 +- lib/extend/injector.ts | 6 +-- lib/extend/migrator.ts | 2 +- lib/extend/processor.ts | 2 +- lib/extend/renderer.ts | 4 +- lib/extend/tag.ts | 8 +-- lib/hexo/index.ts | 74 ++++++++++++++-------------- lib/hexo/locals.ts | 4 +- lib/hexo/multi_config_path.ts | 4 +- lib/hexo/post.ts | 12 ++--- lib/hexo/render.ts | 4 +- lib/hexo/router.ts | 14 +++--- lib/hexo/scaffold.ts | 6 +-- lib/models/types/moment.ts | 2 +- lib/plugins/console/generate.ts | 22 ++++----- lib/plugins/console/index.ts | 2 +- lib/plugins/helper/fragment_cache.ts | 2 +- lib/plugins/helper/full_url_for.ts | 4 +- lib/plugins/helper/partial.ts | 4 +- lib/plugins/helper/relative_url.ts | 2 +- lib/plugins/helper/render.ts | 4 +- lib/plugins/helper/url_for.ts | 2 +- lib/plugins/tag/blockquote.ts | 4 +- lib/plugins/tag/code.ts | 2 +- lib/plugins/tag/include_code.ts | 4 +- lib/plugins/tag/pullquote.ts | 4 +- lib/theme/index.ts | 8 +-- lib/theme/view.ts | 20 ++++---- 34 files changed, 136 insertions(+), 136 deletions(-) diff --git a/lib/box/file.ts b/lib/box/file.ts index 342319c9d8..ce5da96658 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -1,10 +1,10 @@ import {readFile, readFileSync, stat, statSync} from 'hexo-fs'; class File { - public source: any; - public path: any; - public params: any; - public type: any; + public source: any; + public path: any; + public params: any; + public type: any; constructor({ source, path, params, type }) { this.source = source; diff --git a/lib/box/index.ts b/lib/box/index.ts index 9ef31961d5..40dc07b85f 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -10,18 +10,18 @@ import {isMatch, makeRe} from 'micromatch'; const defaultPattern = new Pattern(() => ({})); class Box extends EventEmitter { - public options: any; - public context: any; - public base: any; - public processors: any; - public _processingFiles: any; - public watcher: any; - public Cache: any; - public File: any; - public ignore: any; - public source: any; - public emit: any; - public ctx: any; + public options: any; + public context: any; + public base: any; + public processors: any; + public _processingFiles: any; + public watcher: any; + public Cache: any; + public File: any; + public ignore: any; + public source: any; + public emit: any; + public ctx: any; constructor(ctx, base, options) { super(); diff --git a/lib/extend/console.ts b/lib/extend/console.ts index f8bf2245c5..1944f23260 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -10,8 +10,8 @@ import abbrev from 'abbrev'; */ class Console { - public store: any; - public alias: any; + public store: any; + public alias: any; constructor() { this.store = {}; diff --git a/lib/extend/deployer.ts b/lib/extend/deployer.ts index 43dfaf8853..58a78339a3 100644 --- a/lib/extend/deployer.ts +++ b/lib/extend/deployer.ts @@ -1,7 +1,7 @@ import Promise from 'bluebird'; class Deployer { - public store: any; + public store: any; constructor() { this.store = {}; diff --git a/lib/extend/filter.ts b/lib/extend/filter.ts index 31d28809f0..9e7de35324 100644 --- a/lib/extend/filter.ts +++ b/lib/extend/filter.ts @@ -7,7 +7,7 @@ const typeAlias = { }; class Filter { - public store: any; + public store: any; constructor() { this.store = {}; diff --git a/lib/extend/generator.ts b/lib/extend/generator.ts index b3e1756cfb..10cc6d69d2 100644 --- a/lib/extend/generator.ts +++ b/lib/extend/generator.ts @@ -1,8 +1,8 @@ import Promise from 'bluebird'; class Generator { - public id: any; - public store: any; + public id: any; + public store: any; constructor() { this.id = 0; diff --git a/lib/extend/helper.ts b/lib/extend/helper.ts index 48d17584e4..6f8a25a4b4 100644 --- a/lib/extend/helper.ts +++ b/lib/extend/helper.ts @@ -1,5 +1,5 @@ class Helper { - public store: any; + public store: any; constructor() { this.store = {}; diff --git a/lib/extend/injector.ts b/lib/extend/injector.ts index 5e16e63e2a..ec5d8c75f4 100644 --- a/lib/extend/injector.ts +++ b/lib/extend/injector.ts @@ -1,9 +1,9 @@ import {Cache} from 'hexo-util'; class Injector { - public store: any; - public cache: any; - public page: any; + public store: any; + public cache: any; + public page: any; constructor() { this.store = { diff --git a/lib/extend/migrator.ts b/lib/extend/migrator.ts index 1abee6addd..b716f0fea4 100644 --- a/lib/extend/migrator.ts +++ b/lib/extend/migrator.ts @@ -1,7 +1,7 @@ import Promise from 'bluebird'; class Migrator { - public store: any; + public store: any; constructor() { this.store = {}; diff --git a/lib/extend/processor.ts b/lib/extend/processor.ts index 655dd84d3c..56407a6435 100644 --- a/lib/extend/processor.ts +++ b/lib/extend/processor.ts @@ -2,7 +2,7 @@ import Promise from 'bluebird'; import {Pattern} from 'hexo-util'; class Processor { - public store: any; + public store: any; constructor() { this.store = []; diff --git a/lib/extend/renderer.ts b/lib/extend/renderer.ts index 09e4540570..34c2ce1111 100644 --- a/lib/extend/renderer.ts +++ b/lib/extend/renderer.ts @@ -9,8 +9,8 @@ const getExtname = str => { }; class Renderer { - public store: any; - public storeSync: any; + public store: any; + public storeSync: any; constructor() { this.store = {}; diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index d206d57958..44f95bae6e 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -7,8 +7,8 @@ const rCodeTag = /]*>[\s\S]+?<\/code>/g; const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); class NunjucksTag { - public tags: any; - public fn: any; + public tags: any; + public fn: any; constructor(name, fn) { this.tags = [name]; @@ -181,8 +181,8 @@ const formatNunjucksError = (err, input, source = '') => { }; class Tag { - public env: any; - public source: any; + public env: any; + public source: any; constructor() { this.env = new Environment(null, { diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index 727514c760..e176294e14 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -21,7 +21,7 @@ import { Migrator, Processor, Renderer, - Tag, + Tag } from '../extend'; import Render from './render'; @@ -106,42 +106,42 @@ function debounce(func, wait) { } class Hexo extends EventEmitter { - public base_dir: any; - public public_dir: any; - public source_dir: any; - public plugin_dir: any; - public script_dir: any; - public scaffold_dir: any; - public theme_dir: any; - public theme_script_dir: any; - public env: any; - public extend: any; - public config: any; - public log: any; - public render: any; - public route: any; - public post: any; - public scaffold: any; - public _dbLoaded: any; - public _isGenerating: any; - public database: any; - public config_path: any; - public source: any; - public theme: any; - public locals: any; - public version: any; - public emit: any; - public _watchBox: any; - public page: any; - public path: any; - public url: any; - public layout: any; - public view_dir: any; - public site: any; - public args: any; - public cache: any; - public alias: any; - public data: any; + public base_dir: any; + public public_dir: any; + public source_dir: any; + public plugin_dir: any; + public script_dir: any; + public scaffold_dir: any; + public theme_dir: any; + public theme_script_dir: any; + public env: any; + public extend: any; + public config: any; + public log: any; + public render: any; + public route: any; + public post: any; + public scaffold: any; + public _dbLoaded: any; + public _isGenerating: any; + public database: any; + public config_path: any; + public source: any; + public theme: any; + public locals: any; + public version: any; + public emit: any; + public _watchBox: any; + public page: any; + public path: any; + public url: any; + public layout: any; + public view_dir: any; + public site: any; + public args: any; + public cache: any; + public alias: any; + public data: any; constructor(base = process.cwd(), args = {}) { super(); diff --git a/lib/hexo/locals.ts b/lib/hexo/locals.ts index 501bef1425..1d86c95041 100644 --- a/lib/hexo/locals.ts +++ b/lib/hexo/locals.ts @@ -1,8 +1,8 @@ import {Cache} from 'hexo-util'; class Locals { - public cache: any; - public getters: any; + public cache: any; + public getters: any; constructor() { this.cache = new Cache(); diff --git a/lib/hexo/multi_config_path.ts b/lib/hexo/multi_config_path.ts index 5df322d3ca..0656f60f8a 100644 --- a/lib/hexo/multi_config_path.ts +++ b/lib/hexo/multi_config_path.ts @@ -3,7 +3,7 @@ import fs from 'hexo-fs'; import yml from 'js-yaml'; import {deepMerge} from 'hexo-util'; -export default ctx => (function multiConfigPath(base, configPaths, outputDir) { +export default ctx => function multiConfigPath(base, configPaths, outputDir) { const { log } = ctx; const defaultPath = join(base, '_config.yml'); @@ -72,4 +72,4 @@ export default ctx => (function multiConfigPath(base, configPaths, outputDir) { // write file and return path return outputPath; -}); +}; diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 9ca67e529f..967da8b349 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -28,8 +28,8 @@ const isNonWhiteSpaceChar = char => char !== '\r' && char !== ' '; class PostRenderEscape { - public stored: any; - public length: any; + public stored: any; + public length: any; constructor() { this.stored = []; @@ -219,10 +219,10 @@ const createAssetFolder = (path, assetFolder) => { }; class Post { - public context: any; - public config: any; - public tag: any; - public separator: any; + public context: any; + public config: any; + public tag: any; + public separator: any; constructor(context) { this.context = context; diff --git a/lib/hexo/render.ts b/lib/hexo/render.ts index f11c80b189..384d145c46 100644 --- a/lib/hexo/render.ts +++ b/lib/hexo/render.ts @@ -24,8 +24,8 @@ const toString = (result, options) => { }; class Render { - public context: any; - public renderer: any; + public context: any; + public renderer: any; constructor(ctx) { this.context = ctx; diff --git a/lib/hexo/router.ts b/lib/hexo/router.ts index a4a214924c..d593560800 100644 --- a/lib/hexo/router.ts +++ b/lib/hexo/router.ts @@ -4,11 +4,11 @@ import Stream from 'stream'; const { Readable } = Stream; class RouteStream extends Readable { - public _data: any; - public _ended: any; - public modified: any; - public push: any; - public emit: any; + public _data: any; + public _ended: any; + public modified: any; + public push: any; + public emit: any; constructor(data) { super({ objectMode: true }); @@ -93,8 +93,8 @@ const _format = path => { }; class Router extends EventEmitter { - public routes: any; - public emit: any; + public routes: any; + public emit: any; constructor() { super(); diff --git a/lib/hexo/scaffold.ts b/lib/hexo/scaffold.ts index 87f74a1e39..aacb72c918 100644 --- a/lib/hexo/scaffold.ts +++ b/lib/hexo/scaffold.ts @@ -2,9 +2,9 @@ import {extname, join} from 'path'; import {exists, listDir, readFile, unlink, writeFile} from 'hexo-fs'; class Scaffold { - public context: any; - public scaffoldDir: any; - public defaults: any; + public context: any; + public scaffoldDir: any; + public defaults: any; constructor(context) { this.context = context; diff --git a/lib/models/types/moment.ts b/lib/models/types/moment.ts index 46b0bf80db..22a54d3380 100644 --- a/lib/models/types/moment.ts +++ b/lib/models/types/moment.ts @@ -2,7 +2,7 @@ import {SchemaType} from 'warehouse'; import {moment, toMomentLocale} from '../../plugins/helper/date'; class SchemaTypeMoment extends SchemaType { - public options: any; + public options: any; constructor(name, options = {}) { super(name, options); diff --git a/lib/plugins/console/generate.ts b/lib/plugins/console/generate.ts index f4048111b9..6ca9175f7c 100644 --- a/lib/plugins/console/generate.ts +++ b/lib/plugins/console/generate.ts @@ -8,17 +8,17 @@ import {PassThrough} from 'stream'; import {createSha1Hash} from 'hexo-util'; class Generater { - public context: any; - public force: any; - public bail: any; - public concurrency: any; - public watch: any; - public deploy: any; - public generatingFiles: any; - public start: any; - public args: any; - public route: any; - public log: any; + public context: any; + public force: any; + public bail: any; + public concurrency: any; + public watch: any; + public deploy: any; + public generatingFiles: any; + public start: any; + public args: any; + public route: any; + public log: any; constructor(ctx, args) { this.context = ctx; diff --git a/lib/plugins/console/index.ts b/lib/plugins/console/index.ts index 347cd89254..600868a922 100644 --- a/lib/plugins/console/index.ts +++ b/lib/plugins/console/index.ts @@ -75,4 +75,4 @@ export default function(ctx) { {name: '--pretty', desc: 'Prettify JSON output'} ] }, require('./render')); -}; +} diff --git a/lib/plugins/helper/fragment_cache.ts b/lib/plugins/helper/fragment_cache.ts index 4fb9f389ec..64a0b6abad 100644 --- a/lib/plugins/helper/fragment_cache.ts +++ b/lib/plugins/helper/fragment_cache.ts @@ -1,4 +1,4 @@ -'use strict'; + import {Cache} from 'hexo-util'; export default ctx => { diff --git a/lib/plugins/helper/full_url_for.ts b/lib/plugins/helper/full_url_for.ts index f805ff5b82..454440c6a3 100644 --- a/lib/plugins/helper/full_url_for.ts +++ b/lib/plugins/helper/full_url_for.ts @@ -1,6 +1,6 @@ -'use strict'; + import {full_url_for} from 'hexo-util'; export default function(path) { return full_url_for.call(this, path); -}; +} diff --git a/lib/plugins/helper/partial.ts b/lib/plugins/helper/partial.ts index 832d5ae583..862f5cf506 100644 --- a/lib/plugins/helper/partial.ts +++ b/lib/plugins/helper/partial.ts @@ -1,6 +1,6 @@ import {dirname, join} from 'path'; -export default ctx => (function partial(name, locals, options = {}) { +export default ctx => function partial(name, locals, options = {}) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); const { cache } = options; @@ -30,4 +30,4 @@ export default ctx => (function partial(name, locals, options = {}) { } return view.renderSync(viewLocals); -}); +}; diff --git a/lib/plugins/helper/relative_url.ts b/lib/plugins/helper/relative_url.ts index c994b85ad0..96e7ba0259 100644 --- a/lib/plugins/helper/relative_url.ts +++ b/lib/plugins/helper/relative_url.ts @@ -2,4 +2,4 @@ import {relative_url} from 'hexo-util'; export default function(from, to) { return relative_url(from, to); -}; +} diff --git a/lib/plugins/helper/render.ts b/lib/plugins/helper/render.ts index e55842d5fb..ac5e04b962 100644 --- a/lib/plugins/helper/render.ts +++ b/lib/plugins/helper/render.ts @@ -1,6 +1,6 @@ -export default ctx => (function render(text, engine, options) { +export default ctx => function render(text, engine, options) { return ctx.render.renderSync({ text, engine }, options); -}); +}; diff --git a/lib/plugins/helper/url_for.ts b/lib/plugins/helper/url_for.ts index 2a17cd4597..a69557e49d 100644 --- a/lib/plugins/helper/url_for.ts +++ b/lib/plugins/helper/url_for.ts @@ -2,4 +2,4 @@ import {url_for} from 'hexo-util'; export default function(path, options) { return url_for.call(this, path, options); -}; +} diff --git a/lib/plugins/tag/blockquote.ts b/lib/plugins/tag/blockquote.ts index d709e6ab7e..5fb9e6977b 100644 --- a/lib/plugins/tag/blockquote.ts +++ b/lib/plugins/tag/blockquote.ts @@ -55,7 +55,7 @@ const parseFooter = (args, ctx) => { * {% endblockquote %} */ -export default ctx => (function blockquoteTag(args, content) { +export default ctx => function blockquoteTag(args, content) { const footer = parseFooter(args, ctx); let result = '
'; @@ -64,4 +64,4 @@ export default ctx => (function blockquoteTag(args, content) { result += '
'; return result; -}); +}; diff --git a/lib/plugins/tag/code.ts b/lib/plugins/tag/code.ts index e71f81199f..b1de94288e 100644 --- a/lib/plugins/tag/code.ts +++ b/lib/plugins/tag/code.ts @@ -144,4 +144,4 @@ export default ctx => function codeTag(args, content) { }); return content.replace(/{/g, '{').replace(/}/g, '}'); -}); +}; diff --git a/lib/plugins/tag/include_code.ts b/lib/plugins/tag/include_code.ts index ea0e7a39da..600c31f2b8 100644 --- a/lib/plugins/tag/include_code.ts +++ b/lib/plugins/tag/include_code.ts @@ -13,7 +13,7 @@ const rTo = /\s*to:(\d+)/i; * {% include_code [title] [lang:language] path/to/file %} */ -export default ctx => (function includeCodeTag(args) { +export default ctx => function includeCodeTag(args) { let codeDir = ctx.config.code_dir; let arg = args.join(' '); @@ -74,4 +74,4 @@ export default ctx => (function includeCodeTag(args) { return `
${code}
`; }); -}); +}; diff --git a/lib/plugins/tag/pullquote.ts b/lib/plugins/tag/pullquote.ts index bf54bcac30..228d63a775 100644 --- a/lib/plugins/tag/pullquote.ts +++ b/lib/plugins/tag/pullquote.ts @@ -6,10 +6,10 @@ * Quote string * {% endpullquote %} */ -export default ctx => (function pullquoteTag(args, content) { +export default ctx => function pullquoteTag(args, content) { args.unshift('pullquote'); const result = ctx.render.renderSync({text: content, engine: 'markdown'}); return `
${result}
`; -}); +}; diff --git a/lib/theme/index.ts b/lib/theme/index.ts index 34a188f5e6..7610b810ef 100644 --- a/lib/theme/index.ts +++ b/lib/theme/index.ts @@ -4,10 +4,10 @@ import View from './view'; import I18n from 'hexo-i18n'; class Theme extends Box { - public config: any; - public views: any; - public i18n: any; - public View: any; + public config: any; + public views: any; + public i18n: any; + public View: any; constructor(ctx, options?) { super(ctx, ctx.theme_dir, options); diff --git a/lib/theme/view.ts b/lib/theme/view.ts index 908b2fc2c0..96ab6ac209 100644 --- a/lib/theme/view.ts +++ b/lib/theme/view.ts @@ -17,16 +17,16 @@ const assignIn = (target, ...sources) => { }; class View { - public path: any; - public source: any; - public _theme: any; - public data: any; - public _compiled: any; - public _compiledSync: any; - public _helper: any; - public _render: any; - public layout: any; - public _content: any; + public path: any; + public source: any; + public _theme: any; + public data: any; + public _compiled: any; + public _compiledSync: any; + public _helper: any; + public _render: any; + public layout: any; + public _content: any; constructor(path, data) { this.path = path; From 7782709ff58a51aa6ec914ff008205b0f5614275 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 10:38:32 +0800 Subject: [PATCH 06/45] refactor: migrate typescript --- .eslintrc.json | 3 +++ lib/box/file.ts | 4 ++++ lib/box/index.ts | 29 +++++++++++++++++++---------- lib/hexo/index.ts | 13 +++++++++++-- lib/hexo/post.ts | 16 ++++++++++++++-- lib/hexo/router.ts | 21 ++++++++++++++------- lib/theme/view.ts | 10 +++++++--- 7 files changed, 72 insertions(+), 24 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 6be9a4c7cc..d82fdaa6b1 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,5 +4,8 @@ "parserOptions": { "sourceType": "module", "ecmaVersion": 2020 + }, + "rules": { + "@typescript-eslint/no-explicit-any": 0 } } diff --git a/lib/box/file.ts b/lib/box/file.ts index ce5da96658..82cfc257c0 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -5,6 +5,10 @@ class File { public path: any; public params: any; public type: any; + static TYPE_CREATE: 'create'; + static TYPE_UPDATE: 'update'; + static TYPE_SKIP: 'skip'; + static TYPE_DELETE: 'delete'; constructor({ source, path, params, type }) { this.source = source; diff --git a/lib/box/index.ts b/lib/box/index.ts index 40dc07b85f..9c65efef72 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -1,5 +1,5 @@ import {join, sep} from 'path'; -import Promise from 'bluebird'; +import BlueBirdPromise from 'bluebird'; import File from './file'; import {Pattern, createSha1Hash} from 'hexo-util'; import {createReadStream, readdir, stat, watch} from 'hexo-fs'; @@ -9,21 +9,27 @@ import {isMatch, makeRe} from 'micromatch'; const defaultPattern = new Pattern(() => ({})); +interface Processor { + pattern: Pattern; + process: (file: File) => void; +} + class Box extends EventEmitter { public options: any; public context: any; public base: any; - public processors: any; + public processors: Processor[]; public _processingFiles: any; public watcher: any; public Cache: any; + // TODO: replace runtime class _File public File: any; public ignore: any; public source: any; public emit: any; public ctx: any; - constructor(ctx, base, options) { + constructor(ctx, base, options?: object) { super(); this.options = Object.assign({ @@ -51,10 +57,13 @@ class Box extends EventEmitter { this.ignore = targets; this.options.ignored = targets.map(s => toRegExp(ctx, s)).filter(x => x); } + _createFileClass() { const ctx = this.context; class _File extends File { + public box: Box; + render(options) { return ctx.render.render({ path: this.source @@ -132,7 +141,7 @@ class Box extends EventEmitter { _processFile(type, path) { if (this._processingFiles[path]) { - return Promise.resolve(); + return BlueBirdPromise.resolve(); } this._processingFiles[path] = true; @@ -144,7 +153,7 @@ class Box extends EventEmitter { path }); - return Promise.reduce(this.processors, (count, processor) => { + return BlueBirdPromise.reduce(this.processors, (count, processor) => { const params = processor.pattern.match(path); if (!params) return count; @@ -155,7 +164,7 @@ class Box extends EventEmitter { type }); - return Reflect.apply(Promise.method(processor.process), ctx, [file]) + return Reflect.apply(BlueBirdPromise.method(processor.process), ctx, [file]) .thenReturn(count + 1); }, 0).then(count => { if (count) { @@ -175,7 +184,7 @@ class Box extends EventEmitter { watch(callback) { if (this.isWatching()) { - return Promise.reject(new Error('Watcher has already started.')).asCallback(callback); + return BlueBirdPromise.reject(new Error('Watcher has already started.')).asCallback(callback); } const { base } = this; @@ -229,7 +238,7 @@ function getHash(path) { const src = createReadStream(path); const hasher = createSha1Hash(); - const finishedPromise = new Promise((resolve, reject) => { + const finishedPromise = new BlueBirdPromise((resolve, reject) => { src.once('error', reject); src.once('end', resolve); }); @@ -258,9 +267,9 @@ function isIgnoreMatch(path, ignore) { } function readDirWalker(ctx, base, results, ignore, prefix) { - if (isIgnoreMatch(base, ignore)) return Promise.resolve(); + if (isIgnoreMatch(base, ignore)) return BlueBirdPromise.resolve(); - return Promise.map(readdir(base).catch(err => { + return BlueBirdPromise.map(readdir(base).catch(err => { ctx.log.error({ err }, 'Failed to read directory: %s', base); if (err && err.code === 'ENOENT') return []; throw err; diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index e176294e14..c6c98b1946 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -7,7 +7,7 @@ import {EventEmitter} from 'events'; import {readFile} from 'hexo-fs'; import Module from 'module'; import {runInThisContext} from 'vm'; -import {version} from '../../package.json'; +const {version} = require('../../package.json'); import logger from 'hexo-log'; import { @@ -105,6 +105,15 @@ function debounce(func, wait) { }; } +interface Args { + debug?: any; + safe?: any; + silent?: any; + _?: any[]; + output?: any; + config?: any; +} + class Hexo extends EventEmitter { public base_dir: any; public public_dir: any; @@ -143,7 +152,7 @@ class Hexo extends EventEmitter { public alias: any; public data: any; - constructor(base = process.cwd(), args = {}) { + constructor(base = process.cwd(), args: Args = {}) { super(); this.base_dir = base + sep; diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 967da8b349..1215b5aefa 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -218,6 +218,18 @@ const createAssetFolder = (path, assetFolder) => { }); }; +interface Result { + path?: string; + content?: string; +} + +interface Data { + engine?: string; + content?: string; + disableNunjucks?: boolean; + markdown?: object; +} + class Post { public context: any; public config: any; @@ -329,7 +341,7 @@ class Post { data.slug = slug; const regex = new RegExp(`^${escapeRegExp(slug)}(?:[^\\/\\\\]+)`); let src = ''; - const result = {}; + const result: Result = {}; data.layout = (data.layout || config.default_layout).toLowerCase(); @@ -367,7 +379,7 @@ class Post { }).thenReturn(result).asCallback(callback); } - render(source, data = {}, callback) { + render(source, data: Data = {}, callback) { const ctx = this.context; const { config } = ctx; const { tag } = ctx.extend; diff --git a/lib/hexo/router.ts b/lib/hexo/router.ts index d593560800..793e90a462 100644 --- a/lib/hexo/router.ts +++ b/lib/hexo/router.ts @@ -3,14 +3,19 @@ import Promise from 'bluebird'; import Stream from 'stream'; const { Readable } = Stream; +interface Data { + data: any; + modified: boolean; +} + class RouteStream extends Readable { public _data: any; - public _ended: any; + public _ended: boolean; public modified: any; public push: any; public emit: any; - constructor(data) { + constructor(data: Data) { super({ objectMode: true }); this._data = data.data; @@ -75,7 +80,7 @@ class RouteStream extends Readable { } } -const _format = path => { +const _format = (path: string) => { path = path || ''; if (typeof path !== 'string') throw new TypeError('path must be a string!'); @@ -93,7 +98,9 @@ const _format = path => { }; class Router extends EventEmitter { - public routes: any; + public routes: { + [key: string]: Data | null; + }; public emit: any; constructor() { @@ -107,11 +114,11 @@ class Router extends EventEmitter { return Object.keys(routes).filter(key => routes[key]); } - format(path) { + format(path: string) { return _format(path); } - get(path) { + get(path: string) { if (typeof path !== 'string') throw new TypeError('path must be a string!'); const data = this.routes[this.format(path)]; @@ -131,7 +138,7 @@ class Router extends EventEmitter { if (typeof path !== 'string') throw new TypeError('path must be a string!'); if (data == null) throw new TypeError('data is required!'); - let obj; + let obj: Data; if (typeof data === 'object' && data.data != null) { obj = data; diff --git a/lib/theme/view.ts b/lib/theme/view.ts index 96ab6ac209..422647ea21 100644 --- a/lib/theme/view.ts +++ b/lib/theme/view.ts @@ -16,6 +16,10 @@ const assignIn = (target, ...sources) => { return target; }; +class Options { + layout?: any; +} + class View { public path: any; public source: any; @@ -36,13 +40,13 @@ class View { this._precompile(); } - render(options = {}, callback) { + render(options: Options | Function = {}, callback) { if (!callback && typeof options === 'function') { callback = options; options = {}; } const { data } = this; - const { layout = options.layout } = data; + const { layout = (options as Options).layout } = data; const locals = this._buildLocals(options); return this._compiled(this._bindHelpers(locals)).then(result => { @@ -61,7 +65,7 @@ class View { }).asCallback(callback); } - renderSync(options = {}) { + renderSync(options: Options = {}) { const { data } = this; const { layout = options.layout } = data; const locals = this._buildLocals(options); From 5d6ab84475dc21154dd20a4e803c623456bccdf3 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 2 Nov 2022 11:10:41 +0800 Subject: [PATCH 07/45] refactor: migrate typescript --- lib/hexo/index.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index c6c98b1946..0cd5fa17d1 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -114,6 +114,11 @@ interface Args { config?: any; } +interface Query { + date?: any; + published?: boolean; +} + class Hexo extends EventEmitter { public base_dir: any; public public_dir: any; @@ -133,7 +138,7 @@ class Hexo extends EventEmitter { public scaffold: any; public _dbLoaded: any; public _isGenerating: any; - public database: any; + public database: Database; public config_path: any; public source: any; public theme: any; @@ -151,6 +156,11 @@ class Hexo extends EventEmitter { public cache: any; public alias: any; public data: any; + public lib_dir: string; + public core_dir: string; + static lib_dir: string; + static core_dir: string; + static version: string; constructor(base = process.cwd(), args: Args = {}) { super(); @@ -227,7 +237,7 @@ class Hexo extends EventEmitter { this.source = new Source(this); this.theme = new Theme(this); - this.locals = new Locals(this); + this.locals = new Locals(); this._bindLocals(); } @@ -236,7 +246,7 @@ class Hexo extends EventEmitter { const { locals } = this; locals.set('posts', () => { - const query = {}; + const query: Query = {}; if (!this.config.future) { query.date = { $lte: Date.now() }; @@ -250,7 +260,7 @@ class Hexo extends EventEmitter { }); locals.set('pages', () => { - const query = {}; + const query: Query = {}; if (!this.config.future) { query.date = { $lte: Date.now() }; @@ -430,6 +440,19 @@ class Hexo extends EventEmitter { const localsObj = this.locals.toObject(); class Locals { + page: { + path: string; + }; + path: string; + url: string; + config: object; + theme: object; + layout: string; + env: any; + view_dir: string; + site: object; + cache?: boolean; + constructor(path, locals) { this.page = { ...locals }; if (this.page.path == null) this.page.path = path; From ca8c64295c550f25dc4452b01dd00dc7f652bfe8 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 20 Nov 2022 16:34:01 +0800 Subject: [PATCH 08/45] update --- lib/hexo/post.ts | 2 +- package.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 1215b5aefa..98447c77c3 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -436,7 +436,7 @@ class Post { data.content = cacheObj.escapeAllSwigTags(data.content); } - const options = data.markdown || {}; + const options: { highlight?: boolean; } = data.markdown || {}; if (!config.syntax_highlighter) options.highlight = null; ctx.log.debug('Rendering post: %s', magenta(source)); diff --git a/package.json b/package.json index 680eb3c986..d633b06d04 100644 --- a/package.json +++ b/package.json @@ -48,9 +48,9 @@ "bluebird": "^3.7.2", "hexo-cli": "^4.3.0", "hexo-front-matter": "^4.0.0", - "hexo-fs": "^4.0.0", - "hexo-i18n": "^2.0.0", - "hexo-log": "^4.0.1", + "hexo-fs": "^4.1.1", + "hexo-i18n": "^1.0.0", + "hexo-log": "^3.2.0", "hexo-util": "^3.0.1", "js-yaml": "^4.1.0", "js-yaml-js-types": "^1.0.0", From 3ad21b970f104382ddddc8d852abe23f6da8a8ce Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 15:23:20 +0800 Subject: [PATCH 09/45] export from --- lib/extend/index.ts | 26 +++++++++++--------------- lib/models/index.ts | 24 ++++++++++-------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lib/extend/index.ts b/lib/extend/index.ts index 46da4a8f69..2c4dac82bc 100644 --- a/lib/extend/index.ts +++ b/lib/extend/index.ts @@ -1,15 +1,11 @@ -import Console from './console'; -import Deployer from './deployer'; -import Filter from './filter'; -import Generator from './generator'; -import Helper from './helper'; -import Highlight from './syntax_highlight'; -import Injector from './injector'; -import Migrator from './migrator'; -import Processor from './processor'; -import Renderer from './renderer'; -import Tag from './tag'; - -export default { - Console, Deployer, Filter, Generator, Helper, Highlight, Injector, Migrator, Processor, Renderer, Tag -}; +export { default as Console } from './console'; +export { default as Deployer } from './deployer'; +export { default as Filter } from './filter'; +export { default as Generator } from './generator'; +export { default as Helper } from './helper'; +export { default as Highlight } from './syntax_highlight'; +export { default as Injector } from './injector'; +export { default as Migrator } from './migrator'; +export { default as Processor } from './processor'; +export { default as Renderer } from './renderer'; +export { default as Tag } from './tag'; diff --git a/lib/models/index.ts b/lib/models/index.ts index c641b71790..d76aff60a9 100644 --- a/lib/models/index.ts +++ b/lib/models/index.ts @@ -1,14 +1,10 @@ -import Asset from './asset'; -import Cache from './cache'; -import Category from './category'; -import Data from './data'; -import Page from './page'; -import Post from './post'; -import PostAsset from './post_asset'; -import PostCategory from './post_category'; -import PostTag from './post_tag'; -import Tag from './tag'; - -export default { - Asset, Cache, Category, Data, Page, Post, PostAsset, PostCategory, PostTag, Tag -}; +export { default as Asset } from './asset'; +export { default as Cache } from './cache'; +export { default as Category } from './category'; +export { default as Data } from './data'; +export { default as Page } from './page'; +export { default as Post } from './post'; +export { default as PostAsset } from './post_asset'; +export { default as PostCategory } from './post_category'; +export { default as PostTag } from './post_tag'; +export { default as Tag } from './tag'; From b2b73debf44617a81df25c7116276a9021ceb337 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 15:50:43 +0800 Subject: [PATCH 10/45] extend/filter --- lib/extend/filter.ts | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/extend/filter.ts b/lib/extend/filter.ts index 9e7de35324..deb8b8fa73 100644 --- a/lib/extend/filter.ts +++ b/lib/extend/filter.ts @@ -6,22 +6,39 @@ const typeAlias = { 'after_render:html': '_after_html_render' }; +interface FilterOptions { + context?: any; + args?: any; +} + +interface StoreFunction { + (...args: any[]): any; + priority?: number; +} + +interface Store { + [key: string]: StoreFunction[] +} + class Filter { - public store: any; + public store: Store; constructor() { this.store = {}; } - list(type) { + list(): Store; + list(type: string): StoreFunction[]; + list(type?: string) { if (!type) return this.store; return this.store[type] || []; } - register(type, fn, priority) { + register(fn: StoreFunction, priority: number); + register(type?: string | StoreFunction, fn?: StoreFunction | number, priority?: number) { if (!priority) { if (typeof type === 'function') { - priority = fn; + priority = fn as number; fn = type; type = 'after_post_render'; } @@ -29,11 +46,11 @@ class Filter { if (typeof fn !== 'function') throw new TypeError('fn must be a function'); - type = typeAlias[type] || type; + type = typeAlias[type as string] || type; priority = priority == null ? 10 : priority; - const store = this.store[type] || []; - this.store[type] = store; + const store = this.store[type as string] || []; + this.store[type as string] = store; fn.priority = priority; store.push(fn); @@ -41,7 +58,7 @@ class Filter { store.sort((a, b) => a.priority - b.priority); } - unregister(type, fn) { + unregister(type: string, fn: StoreFunction) { if (!type) throw new TypeError('type is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); @@ -55,7 +72,7 @@ class Filter { if (index !== -1) list.splice(index, 1); } - exec(type, data, options = {}) { + exec(type: string, data, options: FilterOptions = {}) { const filters = this.list(type); if (filters.length === 0) return Promise.resolve(data); @@ -70,7 +87,7 @@ class Filter { })).then(() => args[0]); } - execSync(type, data, options = {}) { + execSync(type: string, data, options: FilterOptions = {}) { const filters = this.list(type); const filtersLen = filters.length; if (filtersLen === 0) return data; From 1a1f29e3212032aac2bd20438bf713afc4eeec9e Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 16:13:14 +0800 Subject: [PATCH 11/45] post --- lib/extend/tag.ts | 2 +- lib/hexo/post.ts | 2 +- lib/models/post.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index 44f95bae6e..2a141415b7 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -50,7 +50,7 @@ class NunjucksTag { return node; } - run(context, args) { + run(context, args, body) { return this._run(context, args, ''); } diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 98447c77c3..da70d07a1a 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -263,7 +263,7 @@ class Post { ]).spread((path, content) => { const result = { path, content }; - return Promise.all([ + return Promise.all([ // Write content to file writeFile(path, content), // Create asset folder diff --git a/lib/models/post.ts b/lib/models/post.ts index 6b6fe714db..bbbe688e28 100644 --- a/lib/models/post.ts +++ b/lib/models/post.ts @@ -126,7 +126,7 @@ export default ctx => { return Category.find({_id: {$in: ids}}); }); - Post.method('setCategories', function(cats) { + Post.method('setCategories', function(cats: string[]) { if (this.notPublished()) { cats = []; } @@ -145,7 +145,7 @@ export default ctx => { const hasHierarchy = cats.filter(Array.isArray).length > 0; // Add a hierarchy of categories - const addHierarchy = catHierarchy => { + const addHierarchy = (catHierarchy: string | string[]) => { const parentIds = []; if (!Array.isArray(catHierarchy)) catHierarchy = [catHierarchy]; // Don't use "Promise.map". It doesn't run in series. @@ -164,7 +164,7 @@ export default ctx => { } // Insert the category if not exist - const obj = {name: cat}; + const obj: {name: string, parent?: string} = {name: cat}; if (i) obj.parent = parentIds[i - 1]; return Category.insert(obj).catch(err => { From ce93be05cd430b00822ea5f29b97a83057d6648e Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 16:44:12 +0800 Subject: [PATCH 12/45] Schema and SchemaType --- lib/models/asset.ts | 4 ++-- lib/models/cache.ts | 4 ++-- lib/models/category.ts | 6 +++--- lib/models/data.ts | 4 ++-- lib/models/page.ts | 4 ++-- lib/models/post.ts | 4 ++-- lib/models/post_asset.ts | 6 +++--- lib/models/post_category.ts | 8 ++++---- lib/models/post_tag.ts | 8 ++++---- lib/models/tag.ts | 4 ++-- lib/models/types/moment.ts | 6 +++--- test/scripts/models/moment.js | 10 +++++----- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/lib/models/asset.ts b/lib/models/asset.ts index 59d4e6eb7d..04baa35777 100644 --- a/lib/models/asset.ts +++ b/lib/models/asset.ts @@ -1,8 +1,8 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import {join} from 'path'; export default ctx => { - const Asset = new Schema({ + const Asset = new warehouse.Schema({ _id: {type: String, required: true}, path: {type: String, required: true}, modified: {type: Boolean, default: true}, diff --git a/lib/models/cache.ts b/lib/models/cache.ts index 09804879af..66e8900ca8 100644 --- a/lib/models/cache.ts +++ b/lib/models/cache.ts @@ -1,8 +1,8 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import Promise from 'bluebird'; export default ctx => { - const Cache = new Schema({ + const Cache = new warehouse.Schema({ _id: {type: String, required: true}, hash: {type: String, default: ''}, modified: {type: Number, default: Date.now() } // UnixTime diff --git a/lib/models/category.ts b/lib/models/category.ts index 307c201cfc..5bfdb0b788 100644 --- a/lib/models/category.ts +++ b/lib/models/category.ts @@ -1,10 +1,10 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import {slugize, full_url_for} from 'hexo-util'; export default ctx => { - const Category = new Schema({ + const Category = new warehouse.Schema({ name: {type: String, required: true}, - parent: {type: Schema.Types.CUID, ref: 'Category'} + parent: { type: warehouse.Schema.Types.CUID, ref: 'Category'} }); Category.virtual('slug').get(function() { diff --git a/lib/models/data.ts b/lib/models/data.ts index ffbde10717..63c60c9161 100644 --- a/lib/models/data.ts +++ b/lib/models/data.ts @@ -1,7 +1,7 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; export default ctx => { - const Data = new Schema({ + const Data = new warehouse.Schema({ _id: {type: String, required: true}, data: Object }); diff --git a/lib/models/page.ts b/lib/models/page.ts index d40047c2cc..dd710f9d05 100644 --- a/lib/models/page.ts +++ b/lib/models/page.ts @@ -1,11 +1,11 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import {join} from 'path'; import Moment from './types/moment'; import moment from 'moment'; import {full_url_for} from 'hexo-util'; export default ctx => { - const Page = new Schema({ + const Page = new warehouse.Schema({ title: {type: String, default: ''}, date: { type: Moment, diff --git a/lib/models/post.ts b/lib/models/post.ts index bbbe688e28..c3919ef240 100644 --- a/lib/models/post.ts +++ b/lib/models/post.ts @@ -1,4 +1,4 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import moment from 'moment'; import {extname, join, sep} from 'path'; import Promise from 'bluebird'; @@ -14,7 +14,7 @@ function removeEmptyTag(tags) { } export default ctx => { - const Post = new Schema({ + const Post = new warehouse.Schema({ id: String, title: {type: String, default: ''}, date: { diff --git a/lib/models/post_asset.ts b/lib/models/post_asset.ts index 3cefffc167..a14f6676bb 100644 --- a/lib/models/post_asset.ts +++ b/lib/models/post_asset.ts @@ -1,12 +1,12 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import {join} from 'path'; export default ctx => { - const PostAsset = new Schema({ + const PostAsset = new warehouse.Schema({ _id: {type: String, required: true}, slug: {type: String, required: true}, modified: {type: Boolean, default: true}, - post: {type: Schema.Types.CUID, ref: 'Post'}, + post: {type: warehouse.Schema.Types.CUID, ref: 'Post'}, renderable: {type: Boolean, default: true} }); diff --git a/lib/models/post_category.ts b/lib/models/post_category.ts index 9bcbd0c9d5..6ff44d73ae 100644 --- a/lib/models/post_category.ts +++ b/lib/models/post_category.ts @@ -1,9 +1,9 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; export default ctx => { - const PostCategory = new Schema({ - post_id: {type: Schema.Types.CUID, ref: 'Post'}, - category_id: {type: Schema.Types.CUID, ref: 'Category'} + const PostCategory = new warehouse.Schema({ + post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'}, + category_id: {type: warehouse.Schema.Types.CUID, ref: 'Category'} }); return PostCategory; diff --git a/lib/models/post_tag.ts b/lib/models/post_tag.ts index 5c25d15ac9..20447ce14e 100644 --- a/lib/models/post_tag.ts +++ b/lib/models/post_tag.ts @@ -1,9 +1,9 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; export default ctx => { - const PostTag = new Schema({ - post_id: {type: Schema.Types.CUID, ref: 'Post'}, - tag_id: {type: Schema.Types.CUID, ref: 'Tag'} + const PostTag = new warehouse.Schema({ + post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'}, + tag_id: {type: warehouse.Schema.Types.CUID, ref: 'Tag'} }); return PostTag; diff --git a/lib/models/tag.ts b/lib/models/tag.ts index 12a58bc9a3..14cade6843 100644 --- a/lib/models/tag.ts +++ b/lib/models/tag.ts @@ -1,9 +1,9 @@ -import {Schema} from 'warehouse'; +import warehouse from 'warehouse'; import {slugize, full_url_for} from 'hexo-util'; const { hasOwnProperty: hasOwn } = Object.prototype; export default ctx => { - const Tag = new Schema({ + const Tag = new warehouse.Schema({ name: {type: String, required: true} }); diff --git a/lib/models/types/moment.ts b/lib/models/types/moment.ts index 22a54d3380..8dd0d313c2 100644 --- a/lib/models/types/moment.ts +++ b/lib/models/types/moment.ts @@ -1,7 +1,7 @@ -import {SchemaType} from 'warehouse'; +import warehouse from 'warehouse'; import {moment, toMomentLocale} from '../../plugins/helper/date'; -class SchemaTypeMoment extends SchemaType { +class SchemaTypeMoment extends warehouse.SchemaType { public options: any; constructor(name, options = {}) { @@ -48,7 +48,7 @@ class SchemaTypeMoment extends SchemaType { return 0; } - parse(value, data) { + parse(value) { if (value) return toMoment(value); } diff --git a/test/scripts/models/moment.js b/test/scripts/models/moment.js index 5cc80fb0c0..c952fac95a 100644 --- a/test/scripts/models/moment.js +++ b/test/scripts/models/moment.js @@ -4,7 +4,7 @@ const moment = require('moment-timezone'); describe('SchemaTypeMoment', () => { const SchemaTypeMoment = require('../../../lib/models/types/moment'); - const type = new SchemaTypeMoment('test'); + const type = new warehouse.SchemaTypeMoment('test'); it('cast()', () => { type.cast(1e8).should.eql(moment(1e8)); @@ -14,14 +14,14 @@ describe('SchemaTypeMoment', () => { }); it('cast() - default', () => { - const type = new SchemaTypeMoment('test', {default: moment}); + const type = new warehouse.SchemaTypeMoment('test', {default: moment}); moment.isMoment(type.cast()).should.be.true; }); it('cast() - language', () => { const lang = 'zh-tw'; const format = 'LLLL'; - const type = new SchemaTypeMoment('test', {language: lang}); + const type = new warehouse.SchemaTypeMoment('test', {language: lang}); const now = Date.now(); type.cast(now).format(format).should.eql(moment(now).locale(lang).format(format)); @@ -30,7 +30,7 @@ describe('SchemaTypeMoment', () => { it('cast() - timezone', () => { const timezone = 'Etc/UTC'; const format = 'LLLL'; - const type = new SchemaTypeMoment('test', {timezone}); + const type = new warehouse.SchemaTypeMoment('test', {timezone}); const now = Date.now(); type.cast(now).format(format).should.eql(moment(now).tz(timezone).format(format)); @@ -49,7 +49,7 @@ describe('SchemaTypeMoment', () => { }); it('validate() - required', () => { - const type = new SchemaTypeMoment('test', {required: true}); + const type = new warehouse.SchemaTypeMoment('test', {required: true}); should.throw(() => type.validate(), '`test` is required!'); }); From d50a3ab8fd97aa5846c6ef7e2cfcd6fb0e08d2ab Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 16:51:16 +0800 Subject: [PATCH 13/45] NunjucksError --- lib/extend/tag.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index 2a141415b7..c7282a4174 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -154,6 +154,12 @@ const getContext = (lines, errLine, location, type) => { return message; }; +class NunjucksError extends Error { + line?: number; + location?: string; + type?: string; +} + /** * Provide context for Nunjucks error * @param {Error} err Nunjucks error @@ -171,7 +177,7 @@ const formatNunjucksError = (err, input, source = '') => { // trim useless info from Nunjucks Error const splited = err.message.split('\n'); - const e = new Error(); + const e = new NunjucksError(); e.name = 'Nunjucks Error'; e.line = errLine; e.location = splited[0]; From 1251c28cc67c1f5b9c310d77e44d750df07e25d9 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 19:01:15 +0800 Subject: [PATCH 14/45] declare module --- lib/extend/tag.ts | 2 +- lib/hexo/index.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index c7282a4174..b41eb1c95e 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -235,7 +235,7 @@ class Tag { if (env.hasExtension(name)) env.removeExtension(name); } - render(str, options = {}, callback) { + render(str, options: { source?: string } = {}, callback) { if (!callback && typeof options === 'function') { callback = options; options = {}; diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index 0cd5fa17d1..a20d35bff4 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -119,6 +119,14 @@ interface Query { published?: boolean; } +// Node.js internal APIs +declare module 'module' { + function _nodeModulePaths(path: string): string[]; + function _resolveFilename(request: string, parent: Module, isMain?: any, options?: any): string; + const _extensions: NodeJS.RequireExtensions; + const _cache: any; +} + class Hexo extends EventEmitter { public base_dir: any; public public_dir: any; @@ -345,7 +353,7 @@ class Hexo extends EventEmitter { } } - loadPlugin(path, callback) { + loadPlugin(path: string, callback: Function) { return readFile(path).then(script => { // Based on: https://github.com/joyent/node/blob/v0.10.33/src/node.js#L516 const module = new Module(path); @@ -520,7 +528,7 @@ class Hexo extends EventEmitter { }); } - _generate(options = {}) { + _generate(options: { cache?: boolean } = {}) { if (this._isGenerating) return; const useCache = options.cache; From a1abae6c5cbca39bb8b683c8e52ecf151fd8069f Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 20:25:42 +0800 Subject: [PATCH 15/45] update tests --- test/scripts/box/box.js | 4 ++-- test/scripts/box/file.js | 4 ++-- test/scripts/console/clean.js | 4 ++-- test/scripts/console/config.js | 4 ++-- test/scripts/console/deploy.js | 6 +++--- test/scripts/console/generate.js | 8 ++++---- test/scripts/console/list.js | 6 +++--- test/scripts/console/list_categories.js | 4 ++-- test/scripts/console/list_page.js | 4 ++-- test/scripts/console/list_post.js | 4 ++-- test/scripts/console/list_route.js | 4 ++-- test/scripts/console/list_tags.js | 4 ++-- test/scripts/console/migrate.js | 6 +++--- test/scripts/console/new.js | 4 ++-- test/scripts/console/publish.js | 6 +++--- test/scripts/console/render.js | 6 +++--- test/scripts/extend/console.js | 2 +- test/scripts/extend/deployer.js | 2 +- test/scripts/extend/filter.js | 2 +- test/scripts/extend/generator.js | 2 +- test/scripts/extend/helper.js | 2 +- test/scripts/extend/injector.js | 2 +- test/scripts/extend/migrator.js | 2 +- test/scripts/extend/processor.js | 2 +- test/scripts/extend/renderer.js | 2 +- test/scripts/extend/tag.js | 2 +- test/scripts/extend/tag_errors.js | 2 +- test/scripts/filters/backtick_code_block.js | 8 ++++---- test/scripts/filters/excerpt.js | 4 ++-- test/scripts/filters/external_link.js | 12 ++++++------ test/scripts/filters/i18n_locals.js | 4 ++-- test/scripts/filters/meta_generator.js | 6 +++--- test/scripts/filters/new_post_path.js | 4 ++-- test/scripts/filters/post_permalink.js | 4 ++-- test/scripts/filters/render_post.js | 4 ++-- test/scripts/filters/save_database.js | 4 ++-- test/scripts/filters/titlecase.js | 4 ++-- test/scripts/generators/asset.js | 4 ++-- test/scripts/generators/page.js | 4 ++-- test/scripts/generators/post.js | 4 ++-- test/scripts/helpers/css.js | 4 ++-- test/scripts/helpers/date.js | 4 ++-- test/scripts/helpers/debug.js | 2 +- test/scripts/helpers/escape_html.js | 2 +- test/scripts/helpers/favicon_tag.js | 4 ++-- test/scripts/helpers/feed_tag.js | 2 +- test/scripts/helpers/fragment_cache.js | 4 ++-- test/scripts/helpers/full_url_for.js | 2 +- test/scripts/helpers/gravatar.js | 2 +- test/scripts/helpers/image_tag.js | 4 ++-- test/scripts/helpers/is.js | 4 ++-- test/scripts/helpers/js.js | 4 ++-- test/scripts/helpers/link_to.js | 4 ++-- test/scripts/helpers/list_archives.js | 4 ++-- test/scripts/helpers/list_categories.js | 4 ++-- test/scripts/helpers/list_posts.js | 4 ++-- test/scripts/helpers/list_tags.js | 8 ++++---- test/scripts/helpers/mail_to.js | 4 ++-- test/scripts/helpers/markdown.js | 6 +++--- test/scripts/helpers/meta_generator.js | 4 ++-- test/scripts/helpers/number_format.js | 2 +- test/scripts/helpers/open_graph.js | 8 ++++---- test/scripts/helpers/paginator.js | 4 ++-- test/scripts/helpers/partial.js | 6 +++--- test/scripts/helpers/relative_url.js | 2 +- test/scripts/helpers/render.js | 4 ++-- test/scripts/helpers/search_form.js | 2 +- test/scripts/helpers/tagcloud.js | 6 +++--- test/scripts/helpers/toc.js | 2 +- test/scripts/helpers/url_for.js | 4 ++-- test/scripts/hexo/hexo.js | 4 ++-- test/scripts/hexo/load_config.js | 6 +++--- test/scripts/hexo/load_database.js | 8 ++++---- test/scripts/hexo/load_plugins.js | 4 ++-- test/scripts/hexo/load_theme_config.js | 4 ++-- test/scripts/hexo/locals.js | 2 +- test/scripts/hexo/multi_config_path.js | 4 ++-- test/scripts/hexo/post.js | 2 +- test/scripts/hexo/render.js | 2 +- test/scripts/hexo/router.js | 2 +- test/scripts/hexo/scaffold.js | 2 +- test/scripts/hexo/update_package.js | 4 ++-- test/scripts/hexo/validate_config.js | 6 +++--- test/scripts/models/asset.js | 2 +- test/scripts/models/cache.js | 2 +- test/scripts/models/category.js | 4 ++-- test/scripts/models/moment.js | 2 +- test/scripts/models/page.js | 4 ++-- test/scripts/models/post.js | 2 +- test/scripts/models/post_asset.js | 4 ++-- test/scripts/models/tag.js | 4 ++-- test/scripts/processors/asset.js | 6 +++--- test/scripts/processors/common.js | 2 +- test/scripts/processors/data.js | 4 ++-- test/scripts/processors/post.js | 6 +++--- test/scripts/renderers/json.js | 2 +- test/scripts/renderers/nunjucks.js | 2 +- test/scripts/renderers/plain.js | 2 +- test/scripts/renderers/yaml.js | 2 +- test/scripts/tags/asset_img.js | 4 ++-- test/scripts/tags/asset_link.js | 4 ++-- test/scripts/tags/asset_path.js | 4 ++-- test/scripts/tags/blockquote.js | 4 ++-- test/scripts/tags/code.js | 6 +++--- test/scripts/tags/iframe.js | 2 +- test/scripts/tags/img.js | 4 ++-- test/scripts/tags/include_code.js | 6 +++--- test/scripts/tags/link.js | 2 +- test/scripts/tags/post_link.js | 4 ++-- test/scripts/tags/post_path.js | 4 ++-- test/scripts/tags/pullquote.js | 4 ++-- test/scripts/theme/theme.js | 2 +- test/scripts/theme/view.js | 2 +- test/scripts/theme_processors/config.js | 4 ++-- test/scripts/theme_processors/i18n.js | 4 ++-- test/scripts/theme_processors/source.js | 4 ++-- test/scripts/theme_processors/view.js | 4 ++-- 117 files changed, 225 insertions(+), 225 deletions(-) diff --git a/test/scripts/box/box.js b/test/scripts/box/box.js index 4c9d26cf21..9271a2296b 100644 --- a/test/scripts/box/box.js +++ b/test/scripts/box/box.js @@ -7,9 +7,9 @@ const { hash, Pattern } = require('hexo-util'); const { spy, match, assert: sinonAssert } = require('sinon'); describe('Box', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const baseDir = join(__dirname, 'box_tmp'); - const Box = require('../../../lib/box'); + const Box = require('../../../dist/box'); const newBox = (path, config) => { const hexo = new Hexo(baseDir, { silent: true }); diff --git a/test/scripts/box/file.js b/test/scripts/box/file.js index cf4626ebe5..e019d913cc 100644 --- a/test/scripts/box/file.js +++ b/test/scripts/box/file.js @@ -5,9 +5,9 @@ const { rmdir, stat, statSync, writeFile } = require('hexo-fs'); const { load } = require('js-yaml'); describe('File', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const Box = require('../../../lib/box'); + const Box = require('../../../dist/box'); const box = new Box(hexo, join(hexo.base_dir, 'file_test')); const { File } = box; diff --git a/test/scripts/console/clean.js b/test/scripts/console/clean.js index 8f82672890..f0efb0dcac 100644 --- a/test/scripts/console/clean.js +++ b/test/scripts/console/clean.js @@ -3,12 +3,12 @@ const { exists, mkdirs, unlink, writeFile } = require('hexo-fs'); describe('clean', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); let hexo, clean; beforeEach(() => { hexo = new Hexo(__dirname, {silent: true}); - clean = require('../../../lib/plugins/console/clean').bind(hexo); + clean = require('../../../dist/plugins/console/clean').bind(hexo); }); it('delete database', async () => { diff --git a/test/scripts/console/config.js b/test/scripts/console/config.js index 747ab6f51e..9ed935e19b 100644 --- a/test/scripts/console/config.js +++ b/test/scripts/console/config.js @@ -6,9 +6,9 @@ const { load } = require('js-yaml'); const { stub, assert: sinonAssert } = require('sinon'); describe('config', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); - const config = require('../../../lib/plugins/console/config').bind(hexo); + const config = require('../../../dist/plugins/console/config').bind(hexo); before(async () => { await mkdirs(hexo.base_dir); diff --git a/test/scripts/console/deploy.js b/test/scripts/console/deploy.js index 457e4c3305..86e0c16675 100644 --- a/test/scripts/console/deploy.js +++ b/test/scripts/console/deploy.js @@ -5,9 +5,9 @@ const { join } = require('path'); const { spy, stub, assert: sinonAssert } = require('sinon'); describe('deploy', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'deploy_test'), { silent: true }); - const deploy = require('../../../lib/plugins/console/deploy').bind(hexo); + const deploy = require('../../../dist/plugins/console/deploy').bind(hexo); before(async () => { await mkdirs(hexo.public_dir); @@ -97,7 +97,7 @@ describe('deploy', () => { const hexo = new Hexo(join(__dirname, 'deploy_test')); hexo.log.error = logSpy; - const deploy = require('../../../lib/plugins/console/deploy').bind(hexo); + const deploy = require('../../../dist/plugins/console/deploy').bind(hexo); hexo.extend.deployer.register('baz', () => { }); hexo.config.deploy = { diff --git a/test/scripts/console/generate.js b/test/scripts/console/generate.js index 68c8efaaaa..7ac2bae2d4 100644 --- a/test/scripts/console/generate.js +++ b/test/scripts/console/generate.js @@ -6,8 +6,8 @@ const Promise = require('bluebird'); const { spy } = require('sinon'); describe('generate', () => { - const Hexo = require('../../../lib/hexo'); - const generateConsole = require('../../../lib/plugins/console/generate'); + const Hexo = require('../../../dist/hexo'); + const generateConsole = require('../../../dist/plugins/console/generate'); let hexo, generate; beforeEach(async () => { @@ -290,8 +290,8 @@ describe('generate', () => { // #3975 workaround for Windows describe('generate - watch (delete)', () => { - const Hexo = require('../../../lib/hexo'); - const generateConsole = require('../../../lib/plugins/console/generate'); + const Hexo = require('../../../dist/hexo'); + const generateConsole = require('../../../dist/plugins/console/generate'); const hexo = new Hexo(join(__dirname, 'generate_test'), {silent: true}); const generate = generateConsole.bind(hexo); diff --git a/test/scripts/console/list.js b/test/scripts/console/list.js index 61c3ca2fa2..530a83ffbd 100644 --- a/test/scripts/console/list.js +++ b/test/scripts/console/list.js @@ -3,13 +3,13 @@ const { spy } = require('sinon'); describe('Console list', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); it('no args', () => { hexo.call = spy(); - const list = require('../../../lib/plugins/console/list').bind(hexo); + const list = require('../../../dist/plugins/console/list').bind(hexo); list({ _: [''] }); @@ -21,7 +21,7 @@ describe('Console list', () => { it('list type not found', () => { hexo.call = spy(); - const list = require('../../../lib/plugins/console/list').bind(hexo); + const list = require('../../../dist/plugins/console/list').bind(hexo); list({ _: ['test'] }); diff --git a/test/scripts/console/list_categories.js b/test/scripts/console/list_categories.js index e46324a396..5a67aa93be 100644 --- a/test/scripts/console/list_categories.js +++ b/test/scripts/console/list_categories.js @@ -4,11 +4,11 @@ const Promise = require('bluebird'); const { stub, assert: sinonAssert } = require('sinon'); describe('Console list', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); - const listCategories = require('../../../lib/plugins/console/list/category').bind(hexo); + const listCategories = require('../../../dist/plugins/console/list/category').bind(hexo); let logStub; diff --git a/test/scripts/console/list_page.js b/test/scripts/console/list_page.js index d0bb19c4e1..080a6993b6 100644 --- a/test/scripts/console/list_page.js +++ b/test/scripts/console/list_page.js @@ -3,10 +3,10 @@ const { stub, assert: sinonAssert } = require('sinon'); describe('Console list', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Page = hexo.model('Page'); - const listPages = require('../../../lib/plugins/console/list/page').bind(hexo); + const listPages = require('../../../dist/plugins/console/list/page').bind(hexo); hexo.config.permalink = ':title/'; diff --git a/test/scripts/console/list_post.js b/test/scripts/console/list_post.js index a57e5d538a..23376a2bcc 100644 --- a/test/scripts/console/list_post.js +++ b/test/scripts/console/list_post.js @@ -3,11 +3,11 @@ const { stub, assert: sinonAssert } = require('sinon'); describe('Console list', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); - const listPosts = require('../../../lib/plugins/console/list/post').bind(hexo); + const listPosts = require('../../../dist/plugins/console/list/post').bind(hexo); let logStub; diff --git a/test/scripts/console/list_route.js b/test/scripts/console/list_route.js index ae3892884b..0cbf86996f 100644 --- a/test/scripts/console/list_route.js +++ b/test/scripts/console/list_route.js @@ -3,10 +3,10 @@ const { stub, assert: sinonAssert } = require('sinon'); describe('Console list', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const listRoutes = require('../../../lib/plugins/console/list/route').bind(hexo); + const listRoutes = require('../../../dist/plugins/console/list/route').bind(hexo); const { route } = hexo; let logStub; diff --git a/test/scripts/console/list_tags.js b/test/scripts/console/list_tags.js index 7dd39532cf..01073f7b14 100644 --- a/test/scripts/console/list_tags.js +++ b/test/scripts/console/list_tags.js @@ -4,11 +4,11 @@ const Promise = require('bluebird'); const { stub, assert: sinonAssert } = require('sinon'); describe('Console list', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); - const listTags = require('../../../lib/plugins/console/list/tag').bind(hexo); + const listTags = require('../../../dist/plugins/console/list/tag').bind(hexo); hexo.config.permalink = ':title/'; diff --git a/test/scripts/console/migrate.js b/test/scripts/console/migrate.js index 2de2f77361..a277197d4e 100644 --- a/test/scripts/console/migrate.js +++ b/test/scripts/console/migrate.js @@ -3,9 +3,9 @@ const { spy, assert: sinonAssert, stub } = require('sinon'); describe('migrate', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname, { silent: true }); - const migrate = require('../../../lib/plugins/console/migrate').bind(hexo); + const migrate = require('../../../dist/plugins/console/migrate').bind(hexo); it('default', async () => { const migrator = spy(); @@ -21,7 +21,7 @@ describe('migrate', () => { it('no args', async () => { const hexo = new Hexo(__dirname, { silent: true }); hexo.call = spy(); - const migrate = require('../../../lib/plugins/console/migrate').bind(hexo); + const migrate = require('../../../dist/plugins/console/migrate').bind(hexo); await migrate({ _: [] }); hexo.call.calledOnce.should.be.true; diff --git a/test/scripts/console/new.js b/test/scripts/console/new.js index 8e64429ae0..16e93f4b69 100644 --- a/test/scripts/console/new.js +++ b/test/scripts/console/new.js @@ -7,9 +7,9 @@ const Promise = require('bluebird'); const { useFakeTimers } = require('sinon'); describe('new', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'new_test'), {silent: true}); - const n = require('../../../lib/plugins/console/new').bind(hexo); + const n = require('../../../dist/plugins/console/new').bind(hexo); const post = hexo.post; const now = Date.now(); let clock; diff --git a/test/scripts/console/publish.js b/test/scripts/console/publish.js index e96738f9eb..44069af45e 100644 --- a/test/scripts/console/publish.js +++ b/test/scripts/console/publish.js @@ -7,9 +7,9 @@ const Promise = require('bluebird'); const { useFakeTimers, spy } = require('sinon'); describe('publish', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'publish_test'), {silent: true}); - const publish = require('../../../lib/plugins/console/publish').bind(hexo); + const publish = require('../../../dist/plugins/console/publish').bind(hexo); const post = hexo.post; const now = Date.now(); let clock; @@ -73,7 +73,7 @@ describe('publish', () => { it('no args', async () => { const hexo = new Hexo(join(__dirname, 'publish_test'), {silent: true}); hexo.call = spy(); - const publish = require('../../../lib/plugins/console/publish').bind(hexo); + const publish = require('../../../dist/plugins/console/publish').bind(hexo); await publish({_: []}); diff --git a/test/scripts/console/render.js b/test/scripts/console/render.js index d30217ba1a..1a611766c8 100644 --- a/test/scripts/console/render.js +++ b/test/scripts/console/render.js @@ -6,9 +6,9 @@ const Promise = require('bluebird'); const { spy } = require('sinon'); describe('render', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'render_test'), {silent: true}); - const render = require('../../../lib/plugins/console/render').bind(hexo); + const render = require('../../../dist/plugins/console/render').bind(hexo); before(async () => { await mkdirs(hexo.base_dir); @@ -26,7 +26,7 @@ describe('render', () => { it('no args', async () => { const hexo = new Hexo(join(__dirname, 'render_test'), {silent: true}); hexo.call = spy(); - const render = require('../../../lib/plugins/console/render').bind(hexo); + const render = require('../../../dist/plugins/console/render').bind(hexo); await render({_: []}); diff --git a/test/scripts/extend/console.js b/test/scripts/extend/console.js index 2d3ba48765..479937d687 100644 --- a/test/scripts/extend/console.js +++ b/test/scripts/extend/console.js @@ -1,7 +1,7 @@ 'use strict'; describe('Console', () => { - const Console = require('../../../lib/extend/console'); + const Console = require('../../../dist/extend/console'); it('register()', () => { const c = new Console(); diff --git a/test/scripts/extend/deployer.js b/test/scripts/extend/deployer.js index ddc73193c9..7318cc9777 100644 --- a/test/scripts/extend/deployer.js +++ b/test/scripts/extend/deployer.js @@ -1,7 +1,7 @@ 'use strict'; describe('Deployer', () => { - const Deployer = require('../../../lib/extend/deployer'); + const Deployer = require('../../../dist/extend/deployer'); it('register()', () => { const d = new Deployer(); diff --git a/test/scripts/extend/filter.js b/test/scripts/extend/filter.js index 3f03ee74b6..6010ce5bc6 100644 --- a/test/scripts/extend/filter.js +++ b/test/scripts/extend/filter.js @@ -3,7 +3,7 @@ const { spy } = require('sinon'); describe('Filter', () => { - const Filter = require('../../../lib/extend/filter'); + const Filter = require('../../../dist/extend/filter'); it('register()', () => { const f = new Filter(); diff --git a/test/scripts/extend/generator.js b/test/scripts/extend/generator.js index 154883c579..d90b295fd1 100644 --- a/test/scripts/extend/generator.js +++ b/test/scripts/extend/generator.js @@ -1,7 +1,7 @@ 'use strict'; describe('Generator', () => { - const Generator = require('../../../lib/extend/generator'); + const Generator = require('../../../dist/extend/generator'); it('register()', () => { const g = new Generator(); diff --git a/test/scripts/extend/helper.js b/test/scripts/extend/helper.js index fd5078313d..30054f1a4b 100644 --- a/test/scripts/extend/helper.js +++ b/test/scripts/extend/helper.js @@ -1,7 +1,7 @@ 'use strict'; describe('Helper', () => { - const Helper = require('../../../lib/extend/helper'); + const Helper = require('../../../dist/extend/helper'); it('register()', () => { const h = new Helper(); diff --git a/test/scripts/extend/injector.js b/test/scripts/extend/injector.js index 08ffc8110c..d82c035607 100644 --- a/test/scripts/extend/injector.js +++ b/test/scripts/extend/injector.js @@ -13,7 +13,7 @@ describe('Injector', () => { '' ].join(''); - const Injector = require('../../../lib/extend/injector'); + const Injector = require('../../../dist/extend/injector'); it('register() - entry is required', () => { const i = new Injector(); diff --git a/test/scripts/extend/migrator.js b/test/scripts/extend/migrator.js index 8668c3e94e..fe045b3c28 100644 --- a/test/scripts/extend/migrator.js +++ b/test/scripts/extend/migrator.js @@ -1,7 +1,7 @@ 'use strict'; describe('Migrator', () => { - const Migrator = require('../../../lib/extend/migrator'); + const Migrator = require('../../../dist/extend/migrator'); it('register()', () => { const d = new Migrator(); diff --git a/test/scripts/extend/processor.js b/test/scripts/extend/processor.js index 00894de7f0..eddae6d80b 100644 --- a/test/scripts/extend/processor.js +++ b/test/scripts/extend/processor.js @@ -1,7 +1,7 @@ 'use strict'; describe('Processor', () => { - const Processor = require('../../../lib/extend/processor'); + const Processor = require('../../../dist/extend/processor'); it('register()', () => { const p = new Processor(); diff --git a/test/scripts/extend/renderer.js b/test/scripts/extend/renderer.js index be09798410..44327d0cb7 100644 --- a/test/scripts/extend/renderer.js +++ b/test/scripts/extend/renderer.js @@ -1,7 +1,7 @@ 'use strict'; describe('Renderer', () => { - const Renderer = require('../../../lib/extend/renderer'); + const Renderer = require('../../../dist/extend/renderer'); it('register()', () => { const r = new Renderer(); diff --git a/test/scripts/extend/tag.js b/test/scripts/extend/tag.js index a89f6f7c8b..e46c7a3cb2 100644 --- a/test/scripts/extend/tag.js +++ b/test/scripts/extend/tag.js @@ -3,7 +3,7 @@ const { spy } = require('sinon'); describe('Tag', () => { - const Tag = require('../../../lib/extend/tag'); + const Tag = require('../../../dist/extend/tag'); const tag = new Tag(); it('register()', async () => { diff --git a/test/scripts/extend/tag_errors.js b/test/scripts/extend/tag_errors.js index 6a674430b8..3184d8a09d 100644 --- a/test/scripts/extend/tag_errors.js +++ b/test/scripts/extend/tag_errors.js @@ -1,7 +1,7 @@ 'use strict'; describe('Tag Errors', () => { - const Tag = require('../../../lib/extend/tag'); + const Tag = require('../../../dist/extend/tag'); const assertNunjucksError = (err, line, type) => { err.should.have.property('name', 'Nunjucks Error'); diff --git a/test/scripts/filters/backtick_code_block.js b/test/scripts/filters/backtick_code_block.js index 4b0d75e31b..4b7c932f52 100644 --- a/test/scripts/filters/backtick_code_block.js +++ b/test/scripts/filters/backtick_code_block.js @@ -1,13 +1,13 @@ 'use strict'; const util = require('hexo-util'); -const defaultConfig = require('../../../lib/hexo/default_config'); +const defaultConfig = require('../../../dist/hexo/default_config'); describe('Backtick code block', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - require('../../../lib/plugins/highlight/')(hexo); - const codeBlock = require('../../../lib/plugins/filter/before_post_render/backtick_code_block')(hexo); + require('../../../dist/plugins/highlight/')(hexo); + const codeBlock = require('../../../dist/plugins/filter/before_post_render/backtick_code_block')(hexo); const code = [ 'if (tired && night) {', diff --git a/test/scripts/filters/excerpt.js b/test/scripts/filters/excerpt.js index eb485221f5..c45bd7f757 100644 --- a/test/scripts/filters/excerpt.js +++ b/test/scripts/filters/excerpt.js @@ -1,9 +1,9 @@ 'use strict'; describe('Excerpt', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const excerpt = require('../../../lib/plugins/filter/after_post_render/excerpt').bind(hexo); + const excerpt = require('../../../dist/plugins/filter/after_post_render/excerpt').bind(hexo); it('without ', () => { const content = [ diff --git a/test/scripts/filters/external_link.js b/test/scripts/filters/external_link.js index 46b4ade372..dbec1dbca5 100644 --- a/test/scripts/filters/external_link.js +++ b/test/scripts/filters/external_link.js @@ -3,13 +3,13 @@ const decache = require('decache'); describe('External link', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); let externalLink; beforeEach(() => { - decache('../../../lib/plugins/filter/after_render/external_link'); - externalLink = require('../../../lib/plugins/filter/after_render/external_link').bind(hexo); + decache('../../../dist/plugins/filter/after_render/external_link'); + externalLink = require('../../../dist/plugins/filter/after_render/external_link').bind(hexo); }); hexo.config = { @@ -137,14 +137,14 @@ describe('External link', () => { }); describe('External link - post', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); let externalLink; beforeEach(() => { - decache('../../../lib/plugins/filter/after_post_render/external_link'); - externalLink = require('../../../lib/plugins/filter/after_post_render/external_link').bind(hexo); + decache('../../../dist/plugins/filter/after_post_render/external_link'); + externalLink = require('../../../dist/plugins/filter/after_post_render/external_link').bind(hexo); }); hexo.config = { diff --git a/test/scripts/filters/i18n_locals.js b/test/scripts/filters/i18n_locals.js index 75fe3ed9f0..6ac2f920dc 100644 --- a/test/scripts/filters/i18n_locals.js +++ b/test/scripts/filters/i18n_locals.js @@ -1,9 +1,9 @@ 'use strict'; describe('i18n locals', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const i18nFilter = require('../../../lib/plugins/filter/template_locals/i18n').bind(hexo); + const i18nFilter = require('../../../dist/plugins/filter/template_locals/i18n').bind(hexo); const theme = hexo.theme; const i18n = theme.i18n; diff --git a/test/scripts/filters/meta_generator.js b/test/scripts/filters/meta_generator.js index 7d6078cedf..f87bcc000b 100644 --- a/test/scripts/filters/meta_generator.js +++ b/test/scripts/filters/meta_generator.js @@ -3,14 +3,14 @@ const decache = require('decache'); describe('Meta Generator', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); let metaGenerator; const cheerio = require('cheerio'); beforeEach(() => { - decache('../../../lib/plugins/filter/after_render/meta_generator'); - metaGenerator = require('../../../lib/plugins/filter/after_render/meta_generator').bind(hexo); + decache('../../../dist/plugins/filter/after_render/meta_generator'); + metaGenerator = require('../../../dist/plugins/filter/after_render/meta_generator').bind(hexo); }); it('default', () => { diff --git a/test/scripts/filters/new_post_path.js b/test/scripts/filters/new_post_path.js index c5e2f528e9..006c973538 100644 --- a/test/scripts/filters/new_post_path.js +++ b/test/scripts/filters/new_post_path.js @@ -6,9 +6,9 @@ const { createSha1Hash } = require('hexo-util'); const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); describe('new_post_path', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'new_post_path_test')); - const newPostPath = require('../../../lib/plugins/filter/new_post_path').bind(hexo); + const newPostPath = require('../../../dist/plugins/filter/new_post_path').bind(hexo); const sourceDir = hexo.source_dir; const draftDir = join(sourceDir, '_drafts'); const postDir = join(sourceDir, '_posts'); diff --git a/test/scripts/filters/post_permalink.js b/test/scripts/filters/post_permalink.js index 0098edf065..e01f22a1be 100644 --- a/test/scripts/filters/post_permalink.js +++ b/test/scripts/filters/post_permalink.js @@ -3,9 +3,9 @@ const moment = require('moment'); describe('post_permalink', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const postPermalink = require('../../../lib/plugins/filter/post_permalink').bind(hexo); + const postPermalink = require('../../../dist/plugins/filter/post_permalink').bind(hexo); const Post = hexo.model('Post'); let post; diff --git a/test/scripts/filters/render_post.js b/test/scripts/filters/render_post.js index b74074c831..ab82f405b3 100644 --- a/test/scripts/filters/render_post.js +++ b/test/scripts/filters/render_post.js @@ -3,11 +3,11 @@ const { content, expected } = require('../../fixtures/post_render'); describe('Render post', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Post = hexo.model('Post'); const Page = hexo.model('Page'); - const renderPost = require('../../../lib/plugins/filter/before_generate/render_post').bind(hexo); + const renderPost = require('../../../dist/plugins/filter/before_generate/render_post').bind(hexo); before(async () => { await hexo.init(); diff --git a/test/scripts/filters/save_database.js b/test/scripts/filters/save_database.js index d6a38368c4..f479cdc411 100644 --- a/test/scripts/filters/save_database.js +++ b/test/scripts/filters/save_database.js @@ -4,9 +4,9 @@ const { exists, unlink } = require('hexo-fs'); const Promise = require('bluebird'); describe('Save database', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const saveDatabase = Promise.method(require('../../../lib/plugins/filter/before_exit/save_database')).bind(hexo); + const saveDatabase = Promise.method(require('../../../dist/plugins/filter/before_exit/save_database')).bind(hexo); const dbPath = hexo.database.options.path; it('default', async () => { diff --git a/test/scripts/filters/titlecase.js b/test/scripts/filters/titlecase.js index 126b2a156e..10b979c326 100644 --- a/test/scripts/filters/titlecase.js +++ b/test/scripts/filters/titlecase.js @@ -1,9 +1,9 @@ 'use strict'; describe('Titlecase', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const titlecase = require('../../../lib/plugins/filter/before_post_render/titlecase').bind(hexo); + const titlecase = require('../../../dist/plugins/filter/before_post_render/titlecase').bind(hexo); it('disabled', () => { const title = 'Today is a good day'; diff --git a/test/scripts/generators/asset.js b/test/scripts/generators/asset.js index 43ad30ce67..0486dc0305 100644 --- a/test/scripts/generators/asset.js +++ b/test/scripts/generators/asset.js @@ -5,9 +5,9 @@ const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); const testUtil = require('../../util'); describe('asset', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'asset_test'), {silent: true}); - const generator = require('../../../lib/plugins/generator/asset').bind(hexo); + const generator = require('../../../dist/plugins/generator/asset').bind(hexo); const Asset = hexo.model('Asset'); const checkStream = async (stream, expected) => { diff --git a/test/scripts/generators/page.js b/test/scripts/generators/page.js index 2371566fad..cf0290c640 100644 --- a/test/scripts/generators/page.js +++ b/test/scripts/generators/page.js @@ -3,10 +3,10 @@ const Promise = require('bluebird'); describe('page', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname, {silent: true}); const Page = hexo.model('Page'); - const generator = Promise.method(require('../../../lib/plugins/generator/page').bind(hexo)); + const generator = Promise.method(require('../../../dist/plugins/generator/page').bind(hexo)); const locals = () => { hexo.locals.invalidate(); diff --git a/test/scripts/generators/post.js b/test/scripts/generators/post.js index 7132678015..ace0d2e859 100644 --- a/test/scripts/generators/post.js +++ b/test/scripts/generators/post.js @@ -3,10 +3,10 @@ const Promise = require('bluebird'); describe('post', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname, {silent: true}); const Post = hexo.model('Post'); - const generator = Promise.method(require('../../../lib/plugins/generator/post').bind(hexo)); + const generator = Promise.method(require('../../../dist/plugins/generator/post').bind(hexo)); hexo.config.permalink = ':title/'; diff --git a/test/scripts/helpers/css.js b/test/scripts/helpers/css.js index 4922a1f265..ea68001273 100644 --- a/test/scripts/helpers/css.js +++ b/test/scripts/helpers/css.js @@ -3,14 +3,14 @@ const cheerio = require('cheerio'); describe('css', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { config: hexo.config }; - const css = require('../../../lib/plugins/helper/css').bind(ctx); + const css = require('../../../dist/plugins/helper/css').bind(ctx); function assertResult(result, expected) { const $ = cheerio.load(result); diff --git a/test/scripts/helpers/date.js b/test/scripts/helpers/date.js index 1b33a8528b..80e5cfa510 100644 --- a/test/scripts/helpers/date.js +++ b/test/scripts/helpers/date.js @@ -4,9 +4,9 @@ const moment = require('moment-timezone'); const { useFakeTimers } = require('sinon'); describe('date', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const dateHelper = require('../../../lib/plugins/helper/date'); + const dateHelper = require('../../../dist/plugins/helper/date'); let clock; before(() => { diff --git a/test/scripts/helpers/debug.js b/test/scripts/helpers/debug.js index 409616f3bd..200dc33705 100644 --- a/test/scripts/helpers/debug.js +++ b/test/scripts/helpers/debug.js @@ -3,7 +3,7 @@ const { stub } = require('sinon'); describe('debug', () => { - const debug = require('../../../lib/plugins/helper/debug'); + const debug = require('../../../dist/plugins/helper/debug'); const { inspect } = require('util'); it('inspect simple object', () => { diff --git a/test/scripts/helpers/escape_html.js b/test/scripts/helpers/escape_html.js index 076a27285b..802a85b8b8 100644 --- a/test/scripts/helpers/escape_html.js +++ b/test/scripts/helpers/escape_html.js @@ -1,7 +1,7 @@ 'use strict'; describe('escape_html', () => { - const { escapeHTML } = require('../../../lib/plugins/helper/format'); + const { escapeHTML } = require('../../../dist/plugins/helper/format'); it('default', () => { escapeHTML('

Hello "world".

').should.eql('<p class="foo">Hello "world".</p>'); diff --git a/test/scripts/helpers/favicon_tag.js b/test/scripts/helpers/favicon_tag.js index 81c2dd7e11..2057042510 100644 --- a/test/scripts/helpers/favicon_tag.js +++ b/test/scripts/helpers/favicon_tag.js @@ -1,14 +1,14 @@ 'use strict'; describe('favicon_tag', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { config: hexo.config }; - const favicon = require('../../../lib/plugins/helper/favicon_tag').bind(ctx); + const favicon = require('../../../dist/plugins/helper/favicon_tag').bind(ctx); it('path', () => { favicon('favicon.ico').should.eql(''); diff --git a/test/scripts/helpers/feed_tag.js b/test/scripts/helpers/feed_tag.js index 354752c856..9dd96328f5 100644 --- a/test/scripts/helpers/feed_tag.js +++ b/test/scripts/helpers/feed_tag.js @@ -12,7 +12,7 @@ describe('feed_tag', () => { beforeEach(() => { ctx.config.feed = {}; }); - const feed = require('../../../lib/plugins/helper/feed_tag').bind(ctx); + const feed = require('../../../dist/plugins/helper/feed_tag').bind(ctx); it('path - atom', () => { feed('atom.xml').should.eql(''); diff --git a/test/scripts/helpers/fragment_cache.js b/test/scripts/helpers/fragment_cache.js index 92ff914fe6..f9e391a492 100644 --- a/test/scripts/helpers/fragment_cache.js +++ b/test/scripts/helpers/fragment_cache.js @@ -1,9 +1,9 @@ 'use strict'; describe('fragment_cache', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const fragment_cache = require('../../../lib/plugins/helper/fragment_cache')(hexo); + const fragment_cache = require('../../../dist/plugins/helper/fragment_cache')(hexo); fragment_cache.call({cache: true}, 'foo', () => 123); diff --git a/test/scripts/helpers/full_url_for.js b/test/scripts/helpers/full_url_for.js index 35dc936062..313de00273 100755 --- a/test/scripts/helpers/full_url_for.js +++ b/test/scripts/helpers/full_url_for.js @@ -5,7 +5,7 @@ describe('full_url_for', () => { config: { url: 'https://example.com' } }; - const fullUrlFor = require('../../../lib/plugins/helper/full_url_for').bind(ctx); + const fullUrlFor = require('../../../dist/plugins/helper/full_url_for').bind(ctx); it('no path input', () => { fullUrlFor().should.eql(ctx.config.url + '/'); diff --git a/test/scripts/helpers/gravatar.js b/test/scripts/helpers/gravatar.js index 8b577e97af..7fd79bfdba 100644 --- a/test/scripts/helpers/gravatar.js +++ b/test/scripts/helpers/gravatar.js @@ -3,7 +3,7 @@ const crypto = require('crypto'); describe('gravatar', () => { - const gravatar = require('../../../lib/plugins/helper/gravatar'); + const gravatar = require('../../../dist/plugins/helper/gravatar'); function md5(str) { return crypto.createHash('md5').update(str).digest('hex'); diff --git a/test/scripts/helpers/image_tag.js b/test/scripts/helpers/image_tag.js index 0f7b22af4c..f8a87edbbe 100644 --- a/test/scripts/helpers/image_tag.js +++ b/test/scripts/helpers/image_tag.js @@ -1,14 +1,14 @@ 'use strict'; describe('image_tag', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { config: hexo.config }; - const img = require('../../../lib/plugins/helper/image_tag').bind(ctx); + const img = require('../../../dist/plugins/helper/image_tag').bind(ctx); it('path', () => { img('https://hexo.io/image.jpg').should.eql(''); diff --git a/test/scripts/helpers/is.js b/test/scripts/helpers/is.js index fa8acd9551..cec0990aa9 100644 --- a/test/scripts/helpers/is.js +++ b/test/scripts/helpers/is.js @@ -1,9 +1,9 @@ 'use strict'; describe('is', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const is = require('../../../lib/plugins/helper/is'); + const is = require('../../../dist/plugins/helper/is'); it('is_current', async () => { await is.current.call({path: 'index.html', config: hexo.config}).should.be.true; diff --git a/test/scripts/helpers/js.js b/test/scripts/helpers/js.js index cee95d2c85..5dbc4a16d4 100644 --- a/test/scripts/helpers/js.js +++ b/test/scripts/helpers/js.js @@ -3,14 +3,14 @@ const cheerio = require('cheerio'); describe('js', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { config: hexo.config }; - const js = require('../../../lib/plugins/helper/js').bind(ctx); + const js = require('../../../dist/plugins/helper/js').bind(ctx); function assertResult(result, expected) { const $ = cheerio.load(result); diff --git a/test/scripts/helpers/link_to.js b/test/scripts/helpers/link_to.js index d569eb8f30..528a0ce7b8 100644 --- a/test/scripts/helpers/link_to.js +++ b/test/scripts/helpers/link_to.js @@ -1,14 +1,14 @@ 'use strict'; describe('link_to', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { config: hexo.config }; - const linkTo = require('../../../lib/plugins/helper/link_to').bind(ctx); + const linkTo = require('../../../dist/plugins/helper/link_to').bind(ctx); it('path', () => { linkTo('https://hexo.io/').should.eql('hexo.io'); diff --git a/test/scripts/helpers/list_archives.js b/test/scripts/helpers/list_archives.js index 468b498b04..b733a60c6c 100644 --- a/test/scripts/helpers/list_archives.js +++ b/test/scripts/helpers/list_archives.js @@ -1,7 +1,7 @@ 'use strict'; describe('list_archives', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); @@ -10,7 +10,7 @@ describe('list_archives', () => { page: {} }; - const listArchives = require('../../../lib/plugins/helper/list_archives').bind(ctx); + const listArchives = require('../../../dist/plugins/helper/list_archives').bind(ctx); function resetLocals() { hexo.locals.invalidate(); diff --git a/test/scripts/helpers/list_categories.js b/test/scripts/helpers/list_categories.js index a8c1120112..5cdb46e01f 100644 --- a/test/scripts/helpers/list_categories.js +++ b/test/scripts/helpers/list_categories.js @@ -1,7 +1,7 @@ 'use strict'; describe('list_categories', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); const Category = hexo.model('Category'); @@ -10,7 +10,7 @@ describe('list_categories', () => { config: hexo.config }; - const listCategories = require('../../../lib/plugins/helper/list_categories').bind(ctx); + const listCategories = require('../../../dist/plugins/helper/list_categories').bind(ctx); before(async () => { await hexo.init(); diff --git a/test/scripts/helpers/list_posts.js b/test/scripts/helpers/list_posts.js index 88cd6c4be7..dbb6810331 100644 --- a/test/scripts/helpers/list_posts.js +++ b/test/scripts/helpers/list_posts.js @@ -1,7 +1,7 @@ 'use strict'; describe('list_posts', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); @@ -9,7 +9,7 @@ describe('list_posts', () => { config: hexo.config }; - const listPosts = require('../../../lib/plugins/helper/list_posts').bind(ctx); + const listPosts = require('../../../dist/plugins/helper/list_posts').bind(ctx); hexo.config.permalink = ':title/'; diff --git a/test/scripts/helpers/list_tags.js b/test/scripts/helpers/list_tags.js index 7e07280fb7..c5e196cc91 100644 --- a/test/scripts/helpers/list_tags.js +++ b/test/scripts/helpers/list_tags.js @@ -1,7 +1,7 @@ 'use strict'; describe('list_tags', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); const Tag = hexo.model('Tag'); @@ -10,7 +10,7 @@ describe('list_tags', () => { config: hexo.config }; - const listTags = require('../../../lib/plugins/helper/list_tags').bind(ctx); + const listTags = require('../../../dist/plugins/helper/list_tags').bind(ctx); before(async () => { await hexo.init(); @@ -207,7 +207,7 @@ describe('list_tags', () => { }); describe('list_tags transform', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); @@ -215,7 +215,7 @@ describe('list_tags transform', () => { config: hexo.config }; - const listTags = require('../../../lib/plugins/helper/list_tags').bind(ctx); + const listTags = require('../../../dist/plugins/helper/list_tags').bind(ctx); before(async () => { await hexo.init(); diff --git a/test/scripts/helpers/mail_to.js b/test/scripts/helpers/mail_to.js index bcac9970c7..8dc09ded62 100644 --- a/test/scripts/helpers/mail_to.js +++ b/test/scripts/helpers/mail_to.js @@ -1,14 +1,14 @@ 'use strict'; describe('mail_to', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { config: hexo.config }; - const mailto = require('../../../lib/plugins/helper/mail_to').bind(ctx); + const mailto = require('../../../dist/plugins/helper/mail_to').bind(ctx); it('path', () => { mailto('abc@example.com').should.eql('abc@example.com'); diff --git a/test/scripts/helpers/markdown.js b/test/scripts/helpers/markdown.js index 524c64b7fe..5fd2cd6c38 100644 --- a/test/scripts/helpers/markdown.js +++ b/test/scripts/helpers/markdown.js @@ -1,14 +1,14 @@ 'use strict'; describe('markdown', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { - render: require('../../../lib/plugins/helper/render')(hexo) + render: require('../../../dist/plugins/helper/render')(hexo) }; - const markdown = require('../../../lib/plugins/helper/markdown').bind(ctx); + const markdown = require('../../../dist/plugins/helper/markdown').bind(ctx); before(() => hexo.init().then(() => hexo.loadPlugin(require.resolve('hexo-renderer-marked')))); diff --git a/test/scripts/helpers/meta_generator.js b/test/scripts/helpers/meta_generator.js index c5a180d6f1..972820453e 100755 --- a/test/scripts/helpers/meta_generator.js +++ b/test/scripts/helpers/meta_generator.js @@ -1,10 +1,10 @@ 'use strict'; describe('meta_generator', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const metaGeneratorHelper = require('../../../lib/plugins/helper/meta_generator').bind(hexo); + const metaGeneratorHelper = require('../../../dist/plugins/helper/meta_generator').bind(hexo); it('default', () => { const { version } = hexo; diff --git a/test/scripts/helpers/number_format.js b/test/scripts/helpers/number_format.js index c47c819e62..32390637a5 100644 --- a/test/scripts/helpers/number_format.js +++ b/test/scripts/helpers/number_format.js @@ -1,7 +1,7 @@ 'use strict'; describe('number_format', () => { - const numberFormat = require('../../../lib/plugins/helper/number_format'); + const numberFormat = require('../../../dist/plugins/helper/number_format'); it('default', () => { numberFormat(1234.567).should.eql('1,234.567'); diff --git a/test/scripts/helpers/open_graph.js b/test/scripts/helpers/open_graph.js index ba78dc3bd3..433cddbe24 100644 --- a/test/scripts/helpers/open_graph.js +++ b/test/scripts/helpers/open_graph.js @@ -3,13 +3,13 @@ const moment = require('moment'); const cheerio = require('cheerio'); const { encodeURL } = require('hexo-util'); -const defaultConfig = require('../../../lib/hexo/default_config'); +const defaultConfig = require('../../../dist/hexo/default_config'); describe('open_graph', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const openGraph = require('../../../lib/plugins/helper/open_graph'); - const isPost = require('../../../lib/plugins/helper/is').post; + const openGraph = require('../../../dist/plugins/helper/open_graph'); + const isPost = require('../../../dist/plugins/helper/is').post; const tag = require('hexo-util').htmlTag; const Post = hexo.model('Post'); diff --git a/test/scripts/helpers/paginator.js b/test/scripts/helpers/paginator.js index f1aeb63390..04826e453b 100644 --- a/test/scripts/helpers/paginator.js +++ b/test/scripts/helpers/paginator.js @@ -3,7 +3,7 @@ const { url_for } = require('hexo-util'); describe('paginator', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const ctx = { @@ -15,7 +15,7 @@ describe('paginator', () => { config: hexo.config }; - const paginator = require('../../../lib/plugins/helper/paginator').bind(ctx); + const paginator = require('../../../dist/plugins/helper/paginator').bind(ctx); function link(i) { return url_for.call(ctx, i === 1 ? '' : 'page/' + i + '/'); diff --git a/test/scripts/helpers/partial.js b/test/scripts/helpers/partial.js index 0f7a1015dd..ca4b2133d4 100644 --- a/test/scripts/helpers/partial.js +++ b/test/scripts/helpers/partial.js @@ -5,7 +5,7 @@ const fs = require('hexo-fs'); const Promise = require('bluebird'); describe('partial', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(pathFn.join(__dirname, 'partial_test'), {silent: true}); const themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); const viewDir = pathFn.join(themeDir, 'layout') + pathFn.sep; @@ -20,11 +20,11 @@ describe('partial', () => { cache: true }; - ctx.fragment_cache = require('../../../lib/plugins/helper/fragment_cache')(hexo); + ctx.fragment_cache = require('../../../dist/plugins/helper/fragment_cache')(hexo); hexo.env.init = true; - const partial = require('../../../lib/plugins/helper/partial')(hexo).bind(ctx); + const partial = require('../../../dist/plugins/helper/partial')(hexo).bind(ctx); before(async () => { await Promise.all([ diff --git a/test/scripts/helpers/relative_url.js b/test/scripts/helpers/relative_url.js index 60930788bc..f9f691f602 100644 --- a/test/scripts/helpers/relative_url.js +++ b/test/scripts/helpers/relative_url.js @@ -1,7 +1,7 @@ 'use strict'; describe('relative_url', () => { - const relativeURL = require('../../../lib/plugins/helper/relative_url'); + const relativeURL = require('../../../dist/plugins/helper/relative_url'); it('from root', () => { relativeURL('', 'css/style.css').should.eql('css/style.css'); diff --git a/test/scripts/helpers/render.js b/test/scripts/helpers/render.js index 568af34c0f..04b8c9cc62 100644 --- a/test/scripts/helpers/render.js +++ b/test/scripts/helpers/render.js @@ -1,9 +1,9 @@ 'use strict'; describe('render', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const render = require('../../../lib/plugins/helper/render')(hexo); + const render = require('../../../dist/plugins/helper/render')(hexo); before(() => hexo.init()); diff --git a/test/scripts/helpers/search_form.js b/test/scripts/helpers/search_form.js index 685dbe3eef..6f086008e4 100644 --- a/test/scripts/helpers/search_form.js +++ b/test/scripts/helpers/search_form.js @@ -1,7 +1,7 @@ 'use strict'; describe('search_form', () => { - const searchForm = require('../../../lib/plugins/helper/search_form').bind({ + const searchForm = require('../../../dist/plugins/helper/search_form').bind({ config: {url: 'https://hexo.io'} }); diff --git a/test/scripts/helpers/tagcloud.js b/test/scripts/helpers/tagcloud.js index dba089a256..47ffe87e51 100644 --- a/test/scripts/helpers/tagcloud.js +++ b/test/scripts/helpers/tagcloud.js @@ -3,7 +3,7 @@ const Promise = require('bluebird'); describe('tagcloud', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const Post = hexo.model('Post'); const Tag = hexo.model('Tag'); @@ -12,7 +12,7 @@ describe('tagcloud', () => { config: hexo.config }; - const tagcloud = require('../../../lib/plugins/helper/tagcloud').bind(ctx); + const tagcloud = require('../../../dist/plugins/helper/tagcloud').bind(ctx); before(async () => { await hexo.init(); @@ -50,7 +50,7 @@ describe('tagcloud', () => { await hexo.init(); hexo.locals.invalidate(); hexo.site = hexo.locals.toObject(); - const tagcloud = require('../../../lib/plugins/helper/tagcloud').bind(hexo); + const tagcloud = require('../../../dist/plugins/helper/tagcloud').bind(hexo); const result = tagcloud(); diff --git a/test/scripts/helpers/toc.js b/test/scripts/helpers/toc.js index 47f0014790..b93d7e1d6d 100644 --- a/test/scripts/helpers/toc.js +++ b/test/scripts/helpers/toc.js @@ -3,7 +3,7 @@ const { encodeURL, escapeHTML } = require('hexo-util'); describe('toc', () => { - const toc = require('../../../lib/plugins/helper/toc'); + const toc = require('../../../dist/plugins/helper/toc'); const html = [ '

Title 1

', diff --git a/test/scripts/helpers/url_for.js b/test/scripts/helpers/url_for.js index b0b2187c7c..8f953a7d10 100644 --- a/test/scripts/helpers/url_for.js +++ b/test/scripts/helpers/url_for.js @@ -3,10 +3,10 @@ describe('url_for', () => { const ctx = { config: { url: 'https://example.com' }, - relative_url: require('../../../lib/plugins/helper/relative_url') + relative_url: require('../../../dist/plugins/helper/relative_url') }; - const urlFor = require('../../../lib/plugins/helper/url_for').bind(ctx); + const urlFor = require('../../../dist/plugins/helper/url_for').bind(ctx); it('should encode path', () => { ctx.config.root = '/'; diff --git a/test/scripts/hexo/hexo.js b/test/scripts/hexo/hexo.js index 9c0a33110d..5be487c27d 100644 --- a/test/scripts/hexo/hexo.js +++ b/test/scripts/hexo/hexo.js @@ -9,7 +9,7 @@ const { full_url_for } = require('hexo-util'); describe('Hexo', () => { const base_dir = join(__dirname, 'hexo_test'); - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(base_dir, { silent: true }); const coreDir = join(__dirname, '../../..'); const { version } = require('../../../package.json'); @@ -24,7 +24,7 @@ describe('Hexo', () => { } function loadAssetGenerator() { - hexo.extend.generator.register('asset', require('../../../lib/plugins/generator/asset')); + hexo.extend.generator.register('asset', require('../../../dist/plugins/generator/asset')); } before(async () => { diff --git a/test/scripts/hexo/load_config.js b/test/scripts/hexo/load_config.js index ce9698d068..05150ff1ba 100644 --- a/test/scripts/hexo/load_config.js +++ b/test/scripts/hexo/load_config.js @@ -5,10 +5,10 @@ const { writeFile, unlink, mkdirs, rmdir } = require('hexo-fs'); const { makeRe } = require('micromatch'); describe('Load config', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), { silent: true }); - const loadConfig = require('../../../lib/hexo/load_config'); - const defaultConfig = require('../../../lib/hexo/default_config'); + const loadConfig = require('../../../dist/hexo/load_config'); + const defaultConfig = require('../../../dist/hexo/default_config'); hexo.env.init = true; diff --git a/test/scripts/hexo/load_database.js b/test/scripts/hexo/load_database.js index 8e4de33e17..27c257e9be 100644 --- a/test/scripts/hexo/load_database.js +++ b/test/scripts/hexo/load_database.js @@ -4,9 +4,9 @@ const { join } = require('path'); const { exists, mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); describe('Load database', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'db_test'), {silent: true}); - const loadDatabase = require('../../../lib/hexo/load_database'); + const loadDatabase = require('../../../dist/hexo/load_database'); const dbPath = hexo.database.options.path; const fixture = { @@ -63,9 +63,9 @@ describe('Load database', () => { // Clean-up is not necessary (unlike the above tests), // because the db file is already removed if invalid describe('Load database - load failed', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname), {silent: true}); - const loadDatabase = require('../../../lib/hexo/load_database'); + const loadDatabase = require('../../../dist/hexo/load_database'); const dbPath = hexo.database.options.path; it('database load failed', async () => { diff --git a/test/scripts/hexo/load_plugins.js b/test/scripts/hexo/load_plugins.js index 087d7365f0..f6f7b44b17 100644 --- a/test/scripts/hexo/load_plugins.js +++ b/test/scripts/hexo/load_plugins.js @@ -5,9 +5,9 @@ const { join, dirname } = require('path'); const Promise = require('bluebird'); describe('Load plugins', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'plugin_test'), { silent: true }); - const loadPlugins = require('../../../lib/hexo/load_plugins'); + const loadPlugins = require('../../../dist/hexo/load_plugins'); const script = [ 'hexo._script_test = {', diff --git a/test/scripts/hexo/load_theme_config.js b/test/scripts/hexo/load_theme_config.js index e20e14f3ae..7dc742305b 100644 --- a/test/scripts/hexo/load_theme_config.js +++ b/test/scripts/hexo/load_theme_config.js @@ -4,9 +4,9 @@ const { join } = require('path'); const { mkdirs, unlink, writeFile, rmdir } = require('hexo-fs'); describe('Load alternate theme config', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); - const loadThemeConfig = require('../../../lib/hexo/load_theme_config'); + const loadThemeConfig = require('../../../dist/hexo/load_theme_config'); hexo.env.init = true; diff --git a/test/scripts/hexo/locals.js b/test/scripts/hexo/locals.js index 290d20f99d..9276b5ccaa 100644 --- a/test/scripts/hexo/locals.js +++ b/test/scripts/hexo/locals.js @@ -1,7 +1,7 @@ 'use strict'; describe('Locals', () => { - const Locals = require('../../../lib/hexo/locals'); + const Locals = require('../../../dist/hexo/locals'); const locals = new Locals(); it('get() - name must be a string', () => { diff --git a/test/scripts/hexo/multi_config_path.js b/test/scripts/hexo/multi_config_path.js index 37ba61f160..7cc486657d 100644 --- a/test/scripts/hexo/multi_config_path.js +++ b/test/scripts/hexo/multi_config_path.js @@ -6,10 +6,10 @@ const fs = require('hexo-fs'); const yml = require('js-yaml'); describe('config flag handling', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(pathFn.join(__dirname, 'test_dir')); - const mcp = require('../../../lib/hexo/multi_config_path')(hexo); + const mcp = require('../../../dist/hexo/multi_config_path')(hexo); const base = hexo.base_dir; function ConsoleReader() { diff --git a/test/scripts/hexo/post.js b/test/scripts/hexo/post.js index 23f39c9b1a..d2d3bbaa41 100644 --- a/test/scripts/hexo/post.js +++ b/test/scripts/hexo/post.js @@ -10,7 +10,7 @@ const fixture = require('../../fixtures/post_render'); const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); describe('Post', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'post_test')); require('../../../lib/plugins/highlight/')(hexo); const { post } = hexo; diff --git a/test/scripts/hexo/render.js b/test/scripts/hexo/render.js index ce82338cfb..5dc5a8c6e6 100644 --- a/test/scripts/hexo/render.js +++ b/test/scripts/hexo/render.js @@ -6,7 +6,7 @@ const yaml = require('js-yaml'); const { spy, assert: sinonAssert } = require('sinon'); describe('Render', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'render_test')); hexo.config.meta_generator = false; diff --git a/test/scripts/hexo/router.js b/test/scripts/hexo/router.js index 92c7f39ed2..5e590ee8f3 100644 --- a/test/scripts/hexo/router.js +++ b/test/scripts/hexo/router.js @@ -9,7 +9,7 @@ const { spy, assert: sinonAssert } = require('sinon'); const testUtil = require('../../util'); describe('Router', () => { - const Router = require('../../../lib/hexo/router'); + const Router = require('../../../dist/hexo/router'); const router = new Router(); function checkStream(stream, expected) { diff --git a/test/scripts/hexo/scaffold.js b/test/scripts/hexo/scaffold.js index 0a7ebbdaf4..0f432aad7f 100644 --- a/test/scripts/hexo/scaffold.js +++ b/test/scripts/hexo/scaffold.js @@ -4,7 +4,7 @@ const { join } = require('path'); const { exists, readFile, rmdir, unlink, writeFile } = require('hexo-fs'); describe('Scaffold', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); const scaffold = hexo.scaffold; const scaffoldDir = hexo.scaffold_dir; diff --git a/test/scripts/hexo/update_package.js b/test/scripts/hexo/update_package.js index 3369bc56e6..fac448627f 100644 --- a/test/scripts/hexo/update_package.js +++ b/test/scripts/hexo/update_package.js @@ -4,9 +4,9 @@ const { join } = require('path'); const { readFile, unlink, writeFile } = require('hexo-fs'); describe('Update package.json', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname, {silent: true}); - const updatePkg = require('../../../lib/hexo/update_package'); + const updatePkg = require('../../../dist/hexo/update_package'); const packagePath = join(hexo.base_dir, 'package.json'); beforeEach(() => { diff --git a/test/scripts/hexo/validate_config.js b/test/scripts/hexo/validate_config.js index 3f2b80b903..be5a9bbdb8 100644 --- a/test/scripts/hexo/validate_config.js +++ b/test/scripts/hexo/validate_config.js @@ -3,10 +3,10 @@ const { spy } = require('sinon'); describe('Validate config', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - const validateConfig = require('../../../lib/hexo/validate_config'); - const defaultConfig = require('../../../lib/hexo/default_config'); + const validateConfig = require('../../../dist/hexo/validate_config'); + const defaultConfig = require('../../../dist/hexo/default_config'); let logSpy; beforeEach(() => { diff --git a/test/scripts/models/asset.js b/test/scripts/models/asset.js index 0c3e62a107..889ba9738e 100644 --- a/test/scripts/models/asset.js +++ b/test/scripts/models/asset.js @@ -3,7 +3,7 @@ const { join } = require('path'); describe('Asset', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Asset = hexo.model('Asset'); diff --git a/test/scripts/models/cache.js b/test/scripts/models/cache.js index 32bc5a7efd..de8ad9d7c9 100644 --- a/test/scripts/models/cache.js +++ b/test/scripts/models/cache.js @@ -1,7 +1,7 @@ 'use strict'; describe('Cache', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Cache = hexo.model('Cache'); diff --git a/test/scripts/models/category.js b/test/scripts/models/category.js index 96553e68ca..d1a0da40a1 100644 --- a/test/scripts/models/category.js +++ b/test/scripts/models/category.js @@ -3,12 +3,12 @@ const { deepMerge, full_url_for } = require('hexo-util'); describe('Category', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Category = hexo.model('Category'); const Post = hexo.model('Post'); const PostCategory = hexo.model('PostCategory'); - const defaults = require('../../../lib/hexo/default_config'); + const defaults = require('../../../dist/hexo/default_config'); before(() => hexo.init()); diff --git a/test/scripts/models/moment.js b/test/scripts/models/moment.js index c952fac95a..f457f86fa0 100644 --- a/test/scripts/models/moment.js +++ b/test/scripts/models/moment.js @@ -3,7 +3,7 @@ const moment = require('moment-timezone'); describe('SchemaTypeMoment', () => { - const SchemaTypeMoment = require('../../../lib/models/types/moment'); + const SchemaTypeMoment = require('../../../dist/models/types/moment'); const type = new warehouse.SchemaTypeMoment('test'); it('cast()', () => { diff --git a/test/scripts/models/page.js b/test/scripts/models/page.js index da6a520009..8a6356861e 100644 --- a/test/scripts/models/page.js +++ b/test/scripts/models/page.js @@ -4,10 +4,10 @@ const { join } = require('path'); const { deepMerge, full_url_for } = require('hexo-util'); describe('Page', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Page = hexo.model('Page'); - const defaults = require('../../../lib/hexo/default_config'); + const defaults = require('../../../dist/hexo/default_config'); beforeEach(() => { hexo.config = deepMerge({}, defaults); }); diff --git a/test/scripts/models/post.js b/test/scripts/models/post.js index 1c9887e9cb..e2bf189da0 100644 --- a/test/scripts/models/post.js +++ b/test/scripts/models/post.js @@ -5,7 +5,7 @@ const Promise = require('bluebird'); const { full_url_for } = require('hexo-util'); describe('Post', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Post = hexo.model('Post'); const Tag = hexo.model('Tag'); diff --git a/test/scripts/models/post_asset.js b/test/scripts/models/post_asset.js index 97e5ddde8f..8e6d765304 100644 --- a/test/scripts/models/post_asset.js +++ b/test/scripts/models/post_asset.js @@ -3,12 +3,12 @@ const { join } = require('path'); describe('PostAsset', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const PostAsset = hexo.model('PostAsset'); const Post = hexo.model('Post'); let post; - const defaults = require('../../../lib/hexo/default_config'); + const defaults = require('../../../dist/hexo/default_config'); before(async () => { await hexo.init(); diff --git a/test/scripts/models/tag.js b/test/scripts/models/tag.js index 5e77692da5..7fb86124ca 100644 --- a/test/scripts/models/tag.js +++ b/test/scripts/models/tag.js @@ -3,12 +3,12 @@ const { deepMerge, full_url_for } = require('hexo-util'); describe('Tag', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); const Tag = hexo.model('Tag'); const Post = hexo.model('Post'); const PostTag = hexo.model('PostTag'); - const defaults = require('../../../lib/hexo/default_config'); + const defaults = require('../../../dist/hexo/default_config'); before(() => hexo.init()); diff --git a/test/scripts/processors/asset.js b/test/scripts/processors/asset.js index 882023898f..1b2c1a10b9 100644 --- a/test/scripts/processors/asset.js +++ b/test/scripts/processors/asset.js @@ -6,11 +6,11 @@ const { mkdirs, rmdir, stat, unlink, writeFile } = require('hexo-fs'); const dateFormat = 'YYYY-MM-DD HH:mm:ss'; describe('asset', () => { - const Hexo = require('../../../lib/hexo'); - const defaults = require('../../../lib/hexo/default_config'); + const Hexo = require('../../../dist/hexo'); + const defaults = require('../../../dist/hexo/default_config'); const baseDir = join(__dirname, 'asset_test'); const hexo = new Hexo(baseDir); - const asset = require('../../../lib/plugins/processor/asset')(hexo); + const asset = require('../../../dist/plugins/processor/asset')(hexo); const process = asset.process.bind(hexo); const { pattern } = asset; const { source } = hexo; diff --git a/test/scripts/processors/common.js b/test/scripts/processors/common.js index c0930038ca..1c4a54cd50 100644 --- a/test/scripts/processors/common.js +++ b/test/scripts/processors/common.js @@ -3,7 +3,7 @@ const moment = require('moment'); describe('common', () => { - const common = require('../../../lib/plugins/processor/common'); + const common = require('../../../dist/plugins/processor/common'); it('isTmpFile()', () => { common.isTmpFile('foo').should.be.false; diff --git a/test/scripts/processors/data.js b/test/scripts/processors/data.js index d7dab3e598..d2d1345dc1 100644 --- a/test/scripts/processors/data.js +++ b/test/scripts/processors/data.js @@ -5,10 +5,10 @@ const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); const { join } = require('path'); describe('data', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const baseDir = join(__dirname, 'data_test'); const hexo = new Hexo(baseDir); - const processor = require('../../../lib/plugins/processor/data')(hexo); + const processor = require('../../../dist/plugins/processor/data')(hexo); const process = Promise.method(processor.process).bind(hexo); const { source } = hexo; const { File } = source; diff --git a/test/scripts/processors/post.js b/test/scripts/processors/post.js index 5132f4670e..8d653f61ca 100644 --- a/test/scripts/processors/post.js +++ b/test/scripts/processors/post.js @@ -3,15 +3,15 @@ const { join } = require('path'); const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); const Promise = require('bluebird'); -const defaultConfig = require('../../../lib/hexo/default_config'); +const defaultConfig = require('../../../dist/hexo/default_config'); const dateFormat = 'YYYY-MM-DD HH:mm:ss'; describe('post', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const baseDir = join(__dirname, 'post_test'); const hexo = new Hexo(baseDir); - const post = require('../../../lib/plugins/processor/post')(hexo); + const post = require('../../../dist/plugins/processor/post')(hexo); const process = Promise.method(post.process.bind(hexo)); const { pattern } = post; const { source } = hexo; diff --git a/test/scripts/renderers/json.js b/test/scripts/renderers/json.js index aa7896229b..bdcf516a21 100644 --- a/test/scripts/renderers/json.js +++ b/test/scripts/renderers/json.js @@ -1,7 +1,7 @@ 'use strict'; describe('json', () => { - const r = require('../../../lib/plugins/renderer/json'); + const r = require('../../../dist/plugins/renderer/json'); it('normal', () => { const data = { diff --git a/test/scripts/renderers/nunjucks.js b/test/scripts/renderers/nunjucks.js index bc8717d5b3..a875211caf 100644 --- a/test/scripts/renderers/nunjucks.js +++ b/test/scripts/renderers/nunjucks.js @@ -1,7 +1,7 @@ 'use strict'; require('chai').should(); -const r = require('../../../lib/plugins/renderer/nunjucks'); +const r = require('../../../dist/plugins/renderer/nunjucks'); const { dirname, join } = require('path'); describe('nunjucks', () => { diff --git a/test/scripts/renderers/plain.js b/test/scripts/renderers/plain.js index 18d1ec0382..24982baa14 100644 --- a/test/scripts/renderers/plain.js +++ b/test/scripts/renderers/plain.js @@ -1,7 +1,7 @@ 'use strict'; describe('plain', () => { - const r = require('../../../lib/plugins/renderer/plain'); + const r = require('../../../dist/plugins/renderer/plain'); it('normal', () => { r({text: '123'}).should.eql('123'); diff --git a/test/scripts/renderers/yaml.js b/test/scripts/renderers/yaml.js index 3f734d1766..bf26b6fde0 100644 --- a/test/scripts/renderers/yaml.js +++ b/test/scripts/renderers/yaml.js @@ -1,7 +1,7 @@ 'use strict'; describe('yaml', () => { - const r = require('../../../lib/plugins/renderer/yaml'); + const r = require('../../../dist/plugins/renderer/yaml'); it('normal', () => { r({text: 'foo: 1'}).should.eql({foo: 1}); diff --git a/test/scripts/tags/asset_img.js b/test/scripts/tags/asset_img.js index d8f0709c09..3fa8817087 100644 --- a/test/scripts/tags/asset_img.js +++ b/test/scripts/tags/asset_img.js @@ -3,9 +3,9 @@ const Promise = require('bluebird'); describe('asset_img', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const assetImgTag = require('../../../lib/plugins/tag/asset_img')(hexo); + const assetImgTag = require('../../../dist/plugins/tag/asset_img')(hexo); const Post = hexo.model('Post'); const PostAsset = hexo.model('PostAsset'); let post; diff --git a/test/scripts/tags/asset_link.js b/test/scripts/tags/asset_link.js index 8a1140bc17..a75c8effba 100644 --- a/test/scripts/tags/asset_link.js +++ b/test/scripts/tags/asset_link.js @@ -3,9 +3,9 @@ const Promise = require('bluebird'); describe('asset_link', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const assetLinkTag = require('../../../lib/plugins/tag/asset_link')(hexo); + const assetLinkTag = require('../../../dist/plugins/tag/asset_link')(hexo); const Post = hexo.model('Post'); const PostAsset = hexo.model('PostAsset'); let post; diff --git a/test/scripts/tags/asset_path.js b/test/scripts/tags/asset_path.js index 20d1d4a065..281a015232 100644 --- a/test/scripts/tags/asset_path.js +++ b/test/scripts/tags/asset_path.js @@ -3,9 +3,9 @@ const Promise = require('bluebird'); describe('asset_path', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const assetPathTag = require('../../../lib/plugins/tag/asset_path')(hexo); + const assetPathTag = require('../../../dist/plugins/tag/asset_path')(hexo); const Post = hexo.model('Post'); const PostAsset = hexo.model('PostAsset'); let post; diff --git a/test/scripts/tags/blockquote.js b/test/scripts/tags/blockquote.js index 09be0d9010..d1b1661557 100644 --- a/test/scripts/tags/blockquote.js +++ b/test/scripts/tags/blockquote.js @@ -1,9 +1,9 @@ 'use strict'; describe('blockquote', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const blockquote = require('../../../lib/plugins/tag/blockquote')(hexo); + const blockquote = require('../../../dist/plugins/tag/blockquote')(hexo); before(() => hexo.init().then(() => hexo.loadPlugin(require.resolve('hexo-renderer-marked')))); diff --git a/test/scripts/tags/code.js b/test/scripts/tags/code.js index 406fe69c24..a9c2d5c966 100644 --- a/test/scripts/tags/code.js +++ b/test/scripts/tags/code.js @@ -4,10 +4,10 @@ const util = require('hexo-util'); const cheerio = require('cheerio'); describe('code', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(); - require('../../../lib/plugins/highlight/')(hexo); - const codeTag = require('../../../lib/plugins/tag/code')(hexo); + require('../../../dist/plugins/highlight/')(hexo); + const codeTag = require('../../../dist/plugins/tag/code')(hexo); const { escapeHTML } = util; const fixture = [ diff --git a/test/scripts/tags/iframe.js b/test/scripts/tags/iframe.js index b87806fc31..8f07063ccb 100644 --- a/test/scripts/tags/iframe.js +++ b/test/scripts/tags/iframe.js @@ -3,7 +3,7 @@ const cheerio = require('cheerio'); describe('iframe', () => { - const iframe = require('../../../lib/plugins/tag/iframe'); + const iframe = require('../../../dist/plugins/tag/iframe'); it('url', () => { const $ = cheerio.load(iframe(['https://zespia.tw'])); diff --git a/test/scripts/tags/img.js b/test/scripts/tags/img.js index 7030c92a41..10cd72f549 100644 --- a/test/scripts/tags/img.js +++ b/test/scripts/tags/img.js @@ -4,9 +4,9 @@ const pathFn = require('path'); const cheerio = require('cheerio'); describe('img', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(pathFn.join(__dirname, 'img_test')); - const img = require('../../../lib/plugins/tag/img')(hexo); + const img = require('../../../dist/plugins/tag/img')(hexo); before(() => hexo.init()); diff --git a/test/scripts/tags/include_code.js b/test/scripts/tags/include_code.js index ca8b4c7884..3c18068609 100644 --- a/test/scripts/tags/include_code.js +++ b/test/scripts/tags/include_code.js @@ -6,10 +6,10 @@ const { highlight, prismHighlight } = require('hexo-util'); const Promise = require('bluebird'); describe('include_code', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'include_code_test')); - require('../../../lib/plugins/highlight/')(hexo); - const includeCode = Promise.method(require('../../../lib/plugins/tag/include_code')(hexo)); + require('../../../dist/plugins/highlight/')(hexo); + const includeCode = Promise.method(require('../../../dist/plugins/tag/include_code')(hexo)); const path = join(hexo.source_dir, hexo.config.code_dir, 'test.js'); const defaultCfg = JSON.parse(JSON.stringify(hexo.config)); diff --git a/test/scripts/tags/link.js b/test/scripts/tags/link.js index 4e75d6d146..4adcdcf0cb 100644 --- a/test/scripts/tags/link.js +++ b/test/scripts/tags/link.js @@ -3,7 +3,7 @@ const cheerio = require('cheerio'); describe('link', () => { - const link = require('../../../lib/plugins/tag/link'); + const link = require('../../../dist/plugins/tag/link'); it('text + url', () => { const $ = cheerio.load(link('Click here to Google https://google.com'.split(' '))); diff --git a/test/scripts/tags/post_link.js b/test/scripts/tags/post_link.js index 22696cf553..d476933d0a 100644 --- a/test/scripts/tags/post_link.js +++ b/test/scripts/tags/post_link.js @@ -1,9 +1,9 @@ 'use strict'; describe('post_link', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const postLink = require('../../../lib/plugins/tag/post_link')(hexo); + const postLink = require('../../../dist/plugins/tag/post_link')(hexo); const Post = hexo.model('Post'); hexo.config.permalink = ':title/'; diff --git a/test/scripts/tags/post_path.js b/test/scripts/tags/post_path.js index 2b73c1edc8..5a00ecbf66 100644 --- a/test/scripts/tags/post_path.js +++ b/test/scripts/tags/post_path.js @@ -1,9 +1,9 @@ 'use strict'; describe('post_path', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const postPath = require('../../../lib/plugins/tag/post_path')(hexo); + const postPath = require('../../../dist/plugins/tag/post_path')(hexo); const Post = hexo.model('Post'); hexo.config.permalink = ':title/'; diff --git a/test/scripts/tags/pullquote.js b/test/scripts/tags/pullquote.js index acc0dc9f62..983f2a4a73 100644 --- a/test/scripts/tags/pullquote.js +++ b/test/scripts/tags/pullquote.js @@ -1,9 +1,9 @@ 'use strict'; describe('pullquote', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(__dirname); - const pullquote = require('../../../lib/plugins/tag/pullquote')(hexo); + const pullquote = require('../../../dist/plugins/tag/pullquote')(hexo); before(() => hexo.init().then(() => hexo.loadPlugin(require.resolve('hexo-renderer-marked')))); diff --git a/test/scripts/theme/theme.js b/test/scripts/theme/theme.js index 5ac61bffd1..fc3b498cf7 100644 --- a/test/scripts/theme/theme.js +++ b/test/scripts/theme/theme.js @@ -4,7 +4,7 @@ const { join } = require('path'); const { mkdirs, rmdir, writeFile } = require('hexo-fs'); describe('Theme', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'theme_test'), {silent: true}); const themeDir = join(hexo.base_dir, 'themes', 'test'); diff --git a/test/scripts/theme/view.js b/test/scripts/theme/view.js index 190e2ed98b..20d1a60aa9 100644 --- a/test/scripts/theme/view.js +++ b/test/scripts/theme/view.js @@ -6,7 +6,7 @@ const moment = require('moment'); const { fake, assert: sinonAssert } = require('sinon'); describe('View', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'theme_test')); const themeDir = join(hexo.base_dir, 'themes', 'test'); const { compile } = Object.assign({}, hexo.extend.renderer.store.njk); diff --git a/test/scripts/theme_processors/config.js b/test/scripts/theme_processors/config.js index 5363df0f84..fb750036c4 100644 --- a/test/scripts/theme_processors/config.js +++ b/test/scripts/theme_processors/config.js @@ -6,9 +6,9 @@ const { mkdirs, rmdir, unlink, writeFile} = require('hexo-fs'); const Promise = require('bluebird'); describe('config', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); - const processor = require('../../../lib/theme/processors/config'); + const processor = require('../../../dist/theme/processors/config'); const process = Promise.method(processor.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); diff --git a/test/scripts/theme_processors/i18n.js b/test/scripts/theme_processors/i18n.js index 2e5e9e2671..13b809e33f 100644 --- a/test/scripts/theme_processors/i18n.js +++ b/test/scripts/theme_processors/i18n.js @@ -5,9 +5,9 @@ const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); const Promise = require('bluebird'); describe('i18n', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); - const processor = require('../../../lib/theme/processors/i18n'); + const processor = require('../../../dist/theme/processors/i18n'); const process = Promise.method(processor.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); diff --git a/test/scripts/theme_processors/source.js b/test/scripts/theme_processors/source.js index 4166abe1a1..3596d78bd5 100644 --- a/test/scripts/theme_processors/source.js +++ b/test/scripts/theme_processors/source.js @@ -5,9 +5,9 @@ const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); const Promise = require('bluebird'); describe('source', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'source_test'), {silent: true}); - const processor = require('../../../lib/theme/processors/source'); + const processor = require('../../../dist/theme/processors/source'); const process = Promise.method(processor.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); const Asset = hexo.model('Asset'); diff --git a/test/scripts/theme_processors/view.js b/test/scripts/theme_processors/view.js index f6171e5e33..f2761f597b 100644 --- a/test/scripts/theme_processors/view.js +++ b/test/scripts/theme_processors/view.js @@ -5,9 +5,9 @@ const { mkdirs, rmdir, unlink, writeFile } = require('hexo-fs'); const Promise = require('bluebird'); describe('view', () => { - const Hexo = require('../../../lib/hexo'); + const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'view_test'), {silent: true}); - const processor = require('../../../lib/theme/processors/view'); + const processor = require('../../../dist/theme/processors/view'); const process = Promise.method(processor.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); From a77aebb45b54b3a09d695203128da079d511e36f Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 20:25:52 +0800 Subject: [PATCH 16/45] fix export --- lib/box/file.ts | 2 +- lib/box/index.ts | 2 +- lib/extend/console.ts | 2 +- lib/extend/deployer.ts | 2 +- lib/extend/filter.ts | 2 +- lib/extend/generator.ts | 2 +- lib/extend/helper.ts | 2 +- lib/extend/injector.ts | 2 +- lib/extend/migrator.ts | 2 +- lib/extend/processor.ts | 2 +- lib/extend/renderer.ts | 2 +- lib/extend/tag.ts | 8 ++++---- lib/hexo/default_config.ts | 2 +- lib/hexo/index.ts | 2 +- lib/hexo/load_config.ts | 2 +- lib/hexo/load_database.ts | 2 +- lib/hexo/load_plugins.ts | 4 ++-- lib/hexo/load_theme_config.ts | 2 +- lib/hexo/locals.ts | 2 +- lib/hexo/multi_config_path.ts | 2 +- lib/hexo/post.ts | 2 +- lib/hexo/register_models.ts | 2 +- lib/hexo/render.ts | 2 +- lib/hexo/router.ts | 8 +++++++- lib/hexo/scaffold.ts | 2 +- lib/hexo/source.ts | 2 +- lib/hexo/update_package.ts | 4 ++-- lib/hexo/validate_config.ts | 2 +- lib/models/asset.ts | 2 +- lib/models/cache.ts | 2 +- lib/models/category.ts | 2 +- lib/models/data.ts | 2 +- lib/models/page.ts | 2 +- lib/models/post.ts | 2 +- lib/models/post_asset.ts | 2 +- lib/models/post_category.ts | 2 +- lib/models/post_tag.ts | 2 +- lib/models/tag.ts | 2 +- lib/models/types/moment.ts | 8 +++++++- lib/plugins/console/clean.ts | 2 +- lib/plugins/console/config.ts | 2 +- lib/plugins/console/deploy.ts | 2 +- lib/plugins/console/generate.ts | 2 +- lib/plugins/console/index.ts | 2 +- lib/plugins/console/list/category.ts | 2 +- lib/plugins/console/list/index.ts | 2 +- lib/plugins/console/list/page.ts | 2 +- lib/plugins/console/list/post.ts | 2 +- lib/plugins/console/list/route.ts | 2 +- lib/plugins/console/list/tag.ts | 2 +- lib/plugins/console/migrate.ts | 2 +- lib/plugins/console/new.ts | 2 +- lib/plugins/console/publish.ts | 2 +- lib/plugins/console/render.ts | 2 +- lib/plugins/filter/after_post_render/excerpt.ts | 2 +- lib/plugins/filter/after_post_render/external_link.ts | 2 +- lib/plugins/filter/after_post_render/index.ts | 2 +- lib/plugins/filter/after_render/external_link.ts | 2 +- lib/plugins/filter/after_render/index.ts | 2 +- lib/plugins/filter/after_render/meta_generator.ts | 2 +- lib/plugins/filter/before_exit/index.ts | 2 +- lib/plugins/filter/before_exit/save_database.ts | 2 +- lib/plugins/filter/before_generate/index.ts | 2 +- lib/plugins/filter/before_generate/render_post.ts | 2 +- .../filter/before_post_render/backtick_code_block.ts | 2 +- lib/plugins/filter/before_post_render/index.ts | 2 +- lib/plugins/filter/before_post_render/titlecase.ts | 2 +- lib/plugins/filter/index.ts | 2 +- lib/plugins/filter/new_post_path.ts | 2 +- lib/plugins/filter/post_permalink.ts | 2 +- lib/plugins/filter/template_locals/i18n.ts | 2 +- lib/plugins/filter/template_locals/index.ts | 2 +- lib/plugins/generator/asset.ts | 2 +- lib/plugins/generator/index.ts | 2 +- lib/plugins/generator/page.ts | 2 +- lib/plugins/generator/post.ts | 2 +- lib/plugins/helper/css.ts | 2 +- lib/plugins/helper/date.ts | 6 +++--- lib/plugins/helper/favicon_tag.ts | 2 +- lib/plugins/helper/feed_tag.ts | 2 +- lib/plugins/helper/fragment_cache.ts | 2 +- lib/plugins/helper/full_url_for.ts | 2 +- lib/plugins/helper/gravatar.ts | 2 +- lib/plugins/helper/image_tag.ts | 2 +- lib/plugins/helper/index.ts | 2 +- lib/plugins/helper/js.ts | 2 +- lib/plugins/helper/link_to.ts | 2 +- lib/plugins/helper/list_archives.ts | 2 +- lib/plugins/helper/list_categories.ts | 2 +- lib/plugins/helper/list_posts.ts | 2 +- lib/plugins/helper/list_tags.ts | 2 +- lib/plugins/helper/mail_to.ts | 2 +- lib/plugins/helper/markdown.ts | 2 +- lib/plugins/helper/meta_generator.ts | 2 +- lib/plugins/helper/number_format.ts | 2 +- lib/plugins/helper/open_graph.ts | 2 +- lib/plugins/helper/paginator.ts | 2 +- lib/plugins/helper/partial.ts | 2 +- lib/plugins/helper/relative_url.ts | 2 +- lib/plugins/helper/render.ts | 2 +- lib/plugins/helper/search_form.ts | 2 +- lib/plugins/helper/tagcloud.ts | 2 +- lib/plugins/helper/toc.ts | 2 +- lib/plugins/helper/url_for.ts | 2 +- lib/plugins/injector/index.ts | 2 +- lib/plugins/processor/asset.ts | 2 +- lib/plugins/processor/data.ts | 2 +- lib/plugins/processor/index.ts | 2 +- lib/plugins/processor/post.ts | 2 +- lib/plugins/renderer/index.ts | 2 +- lib/plugins/renderer/json.ts | 2 +- lib/plugins/renderer/nunjucks.ts | 2 +- lib/plugins/renderer/plain.ts | 2 +- lib/plugins/renderer/yaml.ts | 2 +- lib/plugins/tag/asset_img.ts | 2 +- lib/plugins/tag/asset_link.ts | 2 +- lib/plugins/tag/asset_path.ts | 2 +- lib/plugins/tag/blockquote.ts | 2 +- lib/plugins/tag/code.ts | 2 +- lib/plugins/tag/iframe.ts | 2 +- lib/plugins/tag/img.ts | 2 +- lib/plugins/tag/include_code.ts | 2 +- lib/plugins/tag/index.ts | 2 +- lib/plugins/tag/link.ts | 2 +- lib/plugins/tag/post_link.ts | 2 +- lib/plugins/tag/post_path.ts | 2 +- lib/plugins/tag/pullquote.ts | 2 +- lib/theme/index.ts | 2 +- lib/theme/view.ts | 2 +- 129 files changed, 148 insertions(+), 136 deletions(-) diff --git a/lib/box/file.ts b/lib/box/file.ts index 82cfc257c0..e9321355af 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -39,4 +39,4 @@ File.TYPE_UPDATE = 'update'; File.TYPE_SKIP = 'skip'; File.TYPE_DELETE = 'delete'; -export default File; +export = File; diff --git a/lib/box/index.ts b/lib/box/index.ts index 9c65efef72..b3a16687d8 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -292,4 +292,4 @@ function readDirWalker(ctx, base, results, ignore, prefix) { }); } -export default Box; +export = Box; diff --git a/lib/extend/console.ts b/lib/extend/console.ts index 1944f23260..6a977a25a8 100644 --- a/lib/extend/console.ts +++ b/lib/extend/console.ts @@ -83,4 +83,4 @@ class Console { } } -export default Console; +export = Console; diff --git a/lib/extend/deployer.ts b/lib/extend/deployer.ts index 58a78339a3..d26e4187d8 100644 --- a/lib/extend/deployer.ts +++ b/lib/extend/deployer.ts @@ -29,4 +29,4 @@ class Deployer { } } -export default Deployer; +export = Deployer; diff --git a/lib/extend/filter.ts b/lib/extend/filter.ts index deb8b8fa73..eba129cc1b 100644 --- a/lib/extend/filter.ts +++ b/lib/extend/filter.ts @@ -106,4 +106,4 @@ class Filter { } } -export default Filter; +export = Filter; diff --git a/lib/extend/generator.ts b/lib/extend/generator.ts index 10cc6d69d2..e5b3b5a533 100644 --- a/lib/extend/generator.ts +++ b/lib/extend/generator.ts @@ -32,4 +32,4 @@ class Generator { } } -export default Generator; +export = Generator; diff --git a/lib/extend/helper.ts b/lib/extend/helper.ts index 6f8a25a4b4..c3a5ba490d 100644 --- a/lib/extend/helper.ts +++ b/lib/extend/helper.ts @@ -34,4 +34,4 @@ class Helper { } } -export default Helper; +export = Helper; diff --git a/lib/extend/injector.ts b/lib/extend/injector.ts index ec5d8c75f4..cb073fe916 100644 --- a/lib/extend/injector.ts +++ b/lib/extend/injector.ts @@ -101,4 +101,4 @@ class Injector { } } -export default Injector; +export = Injector; diff --git a/lib/extend/migrator.ts b/lib/extend/migrator.ts index b716f0fea4..db0e4eb424 100644 --- a/lib/extend/migrator.ts +++ b/lib/extend/migrator.ts @@ -29,4 +29,4 @@ class Migrator { } } -export default Migrator; +export = Migrator; diff --git a/lib/extend/processor.ts b/lib/extend/processor.ts index 56407a6435..a5a024efc8 100644 --- a/lib/extend/processor.ts +++ b/lib/extend/processor.ts @@ -35,4 +35,4 @@ class Processor { } } -export default Processor; +export = Processor; diff --git a/lib/extend/renderer.ts b/lib/extend/renderer.ts index 34c2ce1111..c4105a910c 100644 --- a/lib/extend/renderer.ts +++ b/lib/extend/renderer.ts @@ -64,4 +64,4 @@ class Renderer { } } -export default Renderer; +export = Renderer; diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index b41eb1c95e..da7844fb7d 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -50,7 +50,7 @@ class NunjucksTag { return node; } - run(context, args, body) { + run(context, args, body, callback) { return this._run(context, args, ''); } @@ -78,7 +78,7 @@ class NunjucksBlock extends NunjucksTag { return body; } - run(context, args, body) { + run(context, args, body, callback) { return this._run(context, args, trimBody(body)); } } @@ -90,7 +90,7 @@ class NunjucksAsyncTag extends NunjucksTag { return new nodes.CallExtensionAsync(this, 'run', node, []); } - run(context, args, callback) { + run(context, args, body, callback) { return this._run(context, args, '').then(result => { callback(null, result); }, callback); @@ -262,4 +262,4 @@ class Tag { } } -export default Tag; +export = Tag; diff --git a/lib/hexo/default_config.ts b/lib/hexo/default_config.ts index 75f6c7810c..379f80737e 100644 --- a/lib/hexo/default_config.ts +++ b/lib/hexo/default_config.ts @@ -1,4 +1,4 @@ -export default { +export = { // Site title: 'Hexo', subtitle: '', diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index a20d35bff4..daca53d648 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -581,4 +581,4 @@ Hexo.prototype.core_dir = Hexo.core_dir; Hexo.version = version; Hexo.prototype.version = Hexo.version; -export default Hexo; +export = Hexo; diff --git a/lib/hexo/load_config.ts b/lib/hexo/load_config.ts index d492b0fdf6..0ca2fb478b 100644 --- a/lib/hexo/load_config.ts +++ b/lib/hexo/load_config.ts @@ -7,7 +7,7 @@ import {magenta} from 'picocolors'; import {deepMerge} from 'hexo-util'; import validateConfig from './validate_config'; -export default async ctx => { +export = async ctx => { if (!ctx.env.init) return; const baseDir = ctx.base_dir; diff --git a/lib/hexo/load_database.ts b/lib/hexo/load_database.ts index 8b625f910a..112afcda17 100644 --- a/lib/hexo/load_database.ts +++ b/lib/hexo/load_database.ts @@ -1,7 +1,7 @@ import fs from 'hexo-fs'; import Promise from 'bluebird'; -export default ctx => { +export = ctx => { if (ctx._dbLoaded) return Promise.resolve(); const db = ctx.database; diff --git a/lib/hexo/load_plugins.ts b/lib/hexo/load_plugins.ts index 4287d1d531..c3daf8814f 100644 --- a/lib/hexo/load_plugins.ts +++ b/lib/hexo/load_plugins.ts @@ -3,7 +3,7 @@ import {exists, readFile, listDir} from 'hexo-fs'; import Promise from 'bluebird'; import {magenta} from 'picocolors'; -export default ctx => { +export = ctx => { if (!ctx.env.init || ctx.env.safe) return; return loadModules(ctx).then(() => loadScripts(ctx)); @@ -18,7 +18,7 @@ function loadModuleList(ctx, basedir) { // Read package.json and find dependencies return readFile(packagePath).then(content => { - const json = JSON.parse(content); + const json = JSON.parse(content as string); const deps = Object.keys(json.dependencies || {}); const devDeps = Object.keys(json.devDependencies || {}); diff --git a/lib/hexo/load_theme_config.ts b/lib/hexo/load_theme_config.ts index e7cdf90556..8377d8bf31 100644 --- a/lib/hexo/load_theme_config.ts +++ b/lib/hexo/load_theme_config.ts @@ -4,7 +4,7 @@ import {exists, readdir} from 'hexo-fs'; import {magenta} from 'picocolors'; import {deepMerge} from 'hexo-util'; -export default ctx => { +export = ctx => { if (!ctx.env.init) return; if (!ctx.config.theme) return; diff --git a/lib/hexo/locals.ts b/lib/hexo/locals.ts index 1d86c95041..bab6240b8b 100644 --- a/lib/hexo/locals.ts +++ b/lib/hexo/locals.ts @@ -62,4 +62,4 @@ class Locals { } } -export default Locals; +export = Locals; diff --git a/lib/hexo/multi_config_path.ts b/lib/hexo/multi_config_path.ts index 0656f60f8a..062610bdf7 100644 --- a/lib/hexo/multi_config_path.ts +++ b/lib/hexo/multi_config_path.ts @@ -3,7 +3,7 @@ import fs from 'hexo-fs'; import yml from 'js-yaml'; import {deepMerge} from 'hexo-util'; -export default ctx => function multiConfigPath(base, configPaths, outputDir) { +export = ctx => function multiConfigPath(base, configPaths, outputDir) { const { log } = ctx; const defaultPath = join(base, '_config.yml'); diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index da70d07a1a..1bbebc11b6 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -466,4 +466,4 @@ class Post { } } -export default Post; +export = Post; diff --git a/lib/hexo/register_models.ts b/lib/hexo/register_models.ts index a30c38bf50..864e4e3631 100644 --- a/lib/hexo/register_models.ts +++ b/lib/hexo/register_models.ts @@ -1,6 +1,6 @@ import * as models from '../models'; -export default ctx => { +export = ctx => { const db = ctx.database; const keys = Object.keys(models); diff --git a/lib/hexo/render.ts b/lib/hexo/render.ts index 384d145c46..b95f7c7ec6 100644 --- a/lib/hexo/render.ts +++ b/lib/hexo/render.ts @@ -132,4 +132,4 @@ class Render { } } -export default Render; +export = Render; diff --git a/lib/hexo/router.ts b/lib/hexo/router.ts index 793e90a462..3b4ae8db20 100644 --- a/lib/hexo/router.ts +++ b/lib/hexo/router.ts @@ -8,6 +8,12 @@ interface Data { modified: boolean; } +declare module 'stream' { + export default class _Stream extends Stream { + readable: boolean; + } +} + class RouteStream extends Readable { public _data: any; public _ended: boolean; @@ -180,4 +186,4 @@ class Router extends EventEmitter { } } -export default Router; +export = Router; diff --git a/lib/hexo/scaffold.ts b/lib/hexo/scaffold.ts index aacb72c918..1ccdb49ecd 100644 --- a/lib/hexo/scaffold.ts +++ b/lib/hexo/scaffold.ts @@ -70,4 +70,4 @@ class Scaffold { } } -export default Scaffold; +export = Scaffold; diff --git a/lib/hexo/source.ts b/lib/hexo/source.ts index 2b5627aa41..ab4d26bc45 100644 --- a/lib/hexo/source.ts +++ b/lib/hexo/source.ts @@ -8,4 +8,4 @@ class Source extends Box { } } -export default Source; +export = Source; diff --git a/lib/hexo/update_package.ts b/lib/hexo/update_package.ts index f7e80e3bec..95c5dfb6dd 100644 --- a/lib/hexo/update_package.ts +++ b/lib/hexo/update_package.ts @@ -1,7 +1,7 @@ import {join} from 'path'; import fs from 'hexo-fs'; -export default ctx => { +export = ctx => { const pkgPath = join(ctx.base_dir, 'package.json'); return readPkg(pkgPath).then(pkg => { @@ -23,7 +23,7 @@ function readPkg(path) { if (!exist) return; return fs.readFile(path).then(content => { - const pkg = JSON.parse(content); + const pkg = JSON.parse(content as string); if (typeof pkg.hexo !== 'object') return; return pkg; diff --git a/lib/hexo/validate_config.ts b/lib/hexo/validate_config.ts index 7482596ad4..8dfcb389e9 100644 --- a/lib/hexo/validate_config.ts +++ b/lib/hexo/validate_config.ts @@ -1,4 +1,4 @@ -module.exports = ctx => { +export = ctx => { const { config, log } = ctx; log.info('Validating config'); diff --git a/lib/models/asset.ts b/lib/models/asset.ts index 04baa35777..4345769a93 100644 --- a/lib/models/asset.ts +++ b/lib/models/asset.ts @@ -1,7 +1,7 @@ import warehouse from 'warehouse'; import {join} from 'path'; -export default ctx => { +export = ctx => { const Asset = new warehouse.Schema({ _id: {type: String, required: true}, path: {type: String, required: true}, diff --git a/lib/models/cache.ts b/lib/models/cache.ts index 66e8900ca8..d4b43f4722 100644 --- a/lib/models/cache.ts +++ b/lib/models/cache.ts @@ -1,7 +1,7 @@ import warehouse from 'warehouse'; import Promise from 'bluebird'; -export default ctx => { +export = ctx => { const Cache = new warehouse.Schema({ _id: {type: String, required: true}, hash: {type: String, default: ''}, diff --git a/lib/models/category.ts b/lib/models/category.ts index 5bfdb0b788..aedd5dd5e9 100644 --- a/lib/models/category.ts +++ b/lib/models/category.ts @@ -1,7 +1,7 @@ import warehouse from 'warehouse'; import {slugize, full_url_for} from 'hexo-util'; -export default ctx => { +export = ctx => { const Category = new warehouse.Schema({ name: {type: String, required: true}, parent: { type: warehouse.Schema.Types.CUID, ref: 'Category'} diff --git a/lib/models/data.ts b/lib/models/data.ts index 63c60c9161..0cdefe318a 100644 --- a/lib/models/data.ts +++ b/lib/models/data.ts @@ -1,6 +1,6 @@ import warehouse from 'warehouse'; -export default ctx => { +export = ctx => { const Data = new warehouse.Schema({ _id: {type: String, required: true}, data: Object diff --git a/lib/models/page.ts b/lib/models/page.ts index dd710f9d05..7bdd77d0d6 100644 --- a/lib/models/page.ts +++ b/lib/models/page.ts @@ -4,7 +4,7 @@ import Moment from './types/moment'; import moment from 'moment'; import {full_url_for} from 'hexo-util'; -export default ctx => { +export = ctx => { const Page = new warehouse.Schema({ title: {type: String, default: ''}, date: { diff --git a/lib/models/post.ts b/lib/models/post.ts index c3919ef240..c1643a06f9 100644 --- a/lib/models/post.ts +++ b/lib/models/post.ts @@ -13,7 +13,7 @@ function removeEmptyTag(tags) { return tags.filter(tag => tag != null && tag !== '').map(tag => `${tag}`); } -export default ctx => { +export = ctx => { const Post = new warehouse.Schema({ id: String, title: {type: String, default: ''}, diff --git a/lib/models/post_asset.ts b/lib/models/post_asset.ts index a14f6676bb..9d6c218f69 100644 --- a/lib/models/post_asset.ts +++ b/lib/models/post_asset.ts @@ -1,7 +1,7 @@ import warehouse from 'warehouse'; import {join} from 'path'; -export default ctx => { +export = ctx => { const PostAsset = new warehouse.Schema({ _id: {type: String, required: true}, slug: {type: String, required: true}, diff --git a/lib/models/post_category.ts b/lib/models/post_category.ts index 6ff44d73ae..f3c813f8be 100644 --- a/lib/models/post_category.ts +++ b/lib/models/post_category.ts @@ -1,6 +1,6 @@ import warehouse from 'warehouse'; -export default ctx => { +export = ctx => { const PostCategory = new warehouse.Schema({ post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'}, category_id: {type: warehouse.Schema.Types.CUID, ref: 'Category'} diff --git a/lib/models/post_tag.ts b/lib/models/post_tag.ts index 20447ce14e..e727ca5e3e 100644 --- a/lib/models/post_tag.ts +++ b/lib/models/post_tag.ts @@ -1,6 +1,6 @@ import warehouse from 'warehouse'; -export default ctx => { +export = ctx => { const PostTag = new warehouse.Schema({ post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'}, tag_id: {type: warehouse.Schema.Types.CUID, ref: 'Tag'} diff --git a/lib/models/tag.ts b/lib/models/tag.ts index 14cade6843..8da4fe35ef 100644 --- a/lib/models/tag.ts +++ b/lib/models/tag.ts @@ -2,7 +2,7 @@ import warehouse from 'warehouse'; import {slugize, full_url_for} from 'hexo-util'; const { hasOwnProperty: hasOwn } = Object.prototype; -export default ctx => { +export = ctx => { const Tag = new warehouse.Schema({ name: {type: String, required: true} }); diff --git a/lib/models/types/moment.ts b/lib/models/types/moment.ts index 8dd0d313c2..b710420a64 100644 --- a/lib/models/types/moment.ts +++ b/lib/models/types/moment.ts @@ -1,6 +1,12 @@ import warehouse from 'warehouse'; import {moment, toMomentLocale} from '../../plugins/helper/date'; +declare module 'moment' { + export default interface Moment extends moment.Moment { + _d: Date; + } +} + class SchemaTypeMoment extends warehouse.SchemaType { public options: any; @@ -87,4 +93,4 @@ function toMoment(value) { return moment(value); } -export default SchemaTypeMoment; +export = SchemaTypeMoment; diff --git a/lib/plugins/console/clean.ts b/lib/plugins/console/clean.ts index 127562b8e0..8016b58ebd 100644 --- a/lib/plugins/console/clean.ts +++ b/lib/plugins/console/clean.ts @@ -33,4 +33,4 @@ function deletePublicDir(ctx) { }); } -export default cleanConsole; +export = cleanConsole; diff --git a/lib/plugins/console/config.ts b/lib/plugins/console/config.ts index c5f859c95f..ac65d22862 100644 --- a/lib/plugins/console/config.ts +++ b/lib/plugins/console/config.ts @@ -81,4 +81,4 @@ function castValue(value) { return value; } -export default configConsole; +export = configConsole; diff --git a/lib/plugins/console/deploy.ts b/lib/plugins/console/deploy.ts index 6f4fa1c5af..1f9504f235 100644 --- a/lib/plugins/console/deploy.ts +++ b/lib/plugins/console/deploy.ts @@ -56,4 +56,4 @@ function deployConsole(args) { }); } -export default deployConsole; +export = deployConsole; diff --git a/lib/plugins/console/generate.ts b/lib/plugins/console/generate.ts index 6ca9175f7c..6014429a0e 100644 --- a/lib/plugins/console/generate.ts +++ b/lib/plugins/console/generate.ts @@ -206,4 +206,4 @@ function generateConsole(args = {}) { }); } -export default generateConsole; +export = generateConsole; diff --git a/lib/plugins/console/index.ts b/lib/plugins/console/index.ts index 600868a922..829f8f0baf 100644 --- a/lib/plugins/console/index.ts +++ b/lib/plugins/console/index.ts @@ -1,4 +1,4 @@ -export default function(ctx) { +export = function(ctx) { const { console } = ctx.extend; console.register('clean', 'Remove generated files and cache.', require('./clean')); diff --git a/lib/plugins/console/list/category.ts b/lib/plugins/console/list/category.ts index 666e5d31b4..82adbf5b4f 100644 --- a/lib/plugins/console/list/category.ts +++ b/lib/plugins/console/list/category.ts @@ -21,4 +21,4 @@ function listCategory() { if (data.length === 1) console.log('No categories.'); } -export default listCategory; +export = listCategory; diff --git a/lib/plugins/console/list/index.ts b/lib/plugins/console/list/index.ts index 6dc2805462..7c3f084138 100644 --- a/lib/plugins/console/list/index.ts +++ b/lib/plugins/console/list/index.ts @@ -22,4 +22,4 @@ function listConsole(args) { return this.load().then(() => Reflect.apply(store[alias[type]], this, [args])); } -export default listConsole; +export = listConsole; diff --git a/lib/plugins/console/list/page.ts b/lib/plugins/console/list/page.ts index 92a3b3ae5b..51ec2665de 100644 --- a/lib/plugins/console/list/page.ts +++ b/lib/plugins/console/list/page.ts @@ -23,4 +23,4 @@ function listPage() { if (data.length === 1) console.log('No pages.'); } -export default listPage; +export = listPage; diff --git a/lib/plugins/console/list/post.ts b/lib/plugins/console/list/post.ts index 366ee6a63c..e361feabb4 100644 --- a/lib/plugins/console/list/post.ts +++ b/lib/plugins/console/list/post.ts @@ -36,4 +36,4 @@ function listPost() { if (data.length === 1) console.log('No posts.'); } -export default listPost; +export = listPost; diff --git a/lib/plugins/console/list/route.ts b/lib/plugins/console/list/route.ts index df26b81c0f..a29e4e4c54 100644 --- a/lib/plugins/console/list/route.ts +++ b/lib/plugins/console/list/route.ts @@ -48,4 +48,4 @@ function buildNodes(tree) { return nodes; } -export default listRoute; +export = listRoute; diff --git a/lib/plugins/console/list/tag.ts b/lib/plugins/console/list/tag.ts index b93bc3d911..040b2c1ee1 100644 --- a/lib/plugins/console/list/tag.ts +++ b/lib/plugins/console/list/tag.ts @@ -21,4 +21,4 @@ function listTag() { if (data.length === 1) console.log('No tags.'); } -export default listTag; +export = listTag; diff --git a/lib/plugins/console/migrate.ts b/lib/plugins/console/migrate.ts index a04436138e..337b48ad65 100644 --- a/lib/plugins/console/migrate.ts +++ b/lib/plugins/console/migrate.ts @@ -24,4 +24,4 @@ function migrateConsole(args) { return Reflect.apply(migrators[type], this, [args]); } -export default migrateConsole; +export = migrateConsole; diff --git a/lib/plugins/console/new.ts b/lib/plugins/console/new.ts index 4abbcb9eb6..aecfd059b1 100644 --- a/lib/plugins/console/new.ts +++ b/lib/plugins/console/new.ts @@ -51,4 +51,4 @@ function newConsole(args) { }); } -export default newConsole; +export = newConsole; diff --git a/lib/plugins/console/publish.ts b/lib/plugins/console/publish.ts index e6f69e59bb..a0945d1a7d 100644 --- a/lib/plugins/console/publish.ts +++ b/lib/plugins/console/publish.ts @@ -15,4 +15,4 @@ function publishConsole(args) { }); } -export default publishConsole; +export = publishConsole; diff --git a/lib/plugins/console/render.ts b/lib/plugins/console/render.ts index ea6c99fa10..dd293f400a 100644 --- a/lib/plugins/console/render.ts +++ b/lib/plugins/console/render.ts @@ -38,4 +38,4 @@ function renderConsole(args) { }); } -export default renderConsole; +export = renderConsole; diff --git a/lib/plugins/filter/after_post_render/excerpt.ts b/lib/plugins/filter/after_post_render/excerpt.ts index e53508c57a..ef1746a352 100644 --- a/lib/plugins/filter/after_post_render/excerpt.ts +++ b/lib/plugins/filter/after_post_render/excerpt.ts @@ -18,4 +18,4 @@ function excerptFilter(data) { } } -export default excerptFilter; +export = excerptFilter; diff --git a/lib/plugins/filter/after_post_render/external_link.ts b/lib/plugins/filter/after_post_render/external_link.ts index c6c7430751..3c2cf66f4d 100644 --- a/lib/plugins/filter/after_post_render/external_link.ts +++ b/lib/plugins/filter/after_post_render/external_link.ts @@ -29,4 +29,4 @@ function externalLinkFilter(data) { }); } -export default externalLinkFilter; +export = externalLinkFilter; diff --git a/lib/plugins/filter/after_post_render/index.ts b/lib/plugins/filter/after_post_render/index.ts index 75be684c60..87bb8b433c 100644 --- a/lib/plugins/filter/after_post_render/index.ts +++ b/lib/plugins/filter/after_post_render/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; filter.register('after_post_render', require('./external_link')); diff --git a/lib/plugins/filter/after_render/external_link.ts b/lib/plugins/filter/after_render/external_link.ts index 35e3f7d95e..82b8d7e405 100644 --- a/lib/plugins/filter/after_render/external_link.ts +++ b/lib/plugins/filter/after_render/external_link.ts @@ -30,4 +30,4 @@ function externalLinkFilter(data) { }); } -export default externalLinkFilter; +export = externalLinkFilter; diff --git a/lib/plugins/filter/after_render/index.ts b/lib/plugins/filter/after_render/index.ts index 7bf9c72644..509e95a0f8 100644 --- a/lib/plugins/filter/after_render/index.ts +++ b/lib/plugins/filter/after_render/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; filter.register('after_render:html', require('./external_link')); diff --git a/lib/plugins/filter/after_render/meta_generator.ts b/lib/plugins/filter/after_render/meta_generator.ts index dc396b1e25..4c04daee3a 100644 --- a/lib/plugins/filter/after_render/meta_generator.ts +++ b/lib/plugins/filter/after_render/meta_generator.ts @@ -15,4 +15,4 @@ function hexoMetaGeneratorInject(data) { return data.replace('', `${META_GENERATOR_TAG}`); } -export default hexoMetaGeneratorInject; +export = hexoMetaGeneratorInject; diff --git a/lib/plugins/filter/before_exit/index.ts b/lib/plugins/filter/before_exit/index.ts index e2670adb48..ba3312749e 100644 --- a/lib/plugins/filter/before_exit/index.ts +++ b/lib/plugins/filter/before_exit/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; filter.register('before_exit', require('./save_database')); diff --git a/lib/plugins/filter/before_exit/save_database.ts b/lib/plugins/filter/before_exit/save_database.ts index ea67d1b5e5..9aadce2ee8 100644 --- a/lib/plugins/filter/before_exit/save_database.ts +++ b/lib/plugins/filter/before_exit/save_database.ts @@ -6,4 +6,4 @@ function saveDatabaseFilter() { }); } -export default saveDatabaseFilter; +export = saveDatabaseFilter; diff --git a/lib/plugins/filter/before_generate/index.ts b/lib/plugins/filter/before_generate/index.ts index 8052c5cc03..288bb1651a 100644 --- a/lib/plugins/filter/before_generate/index.ts +++ b/lib/plugins/filter/before_generate/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; filter.register('before_generate', require('./render_post')); diff --git a/lib/plugins/filter/before_generate/render_post.ts b/lib/plugins/filter/before_generate/render_post.ts index a55f3e4e66..896cfb716b 100644 --- a/lib/plugins/filter/before_generate/render_post.ts +++ b/lib/plugins/filter/before_generate/render_post.ts @@ -18,4 +18,4 @@ function renderPostFilter(data) { ]); } -export default renderPostFilter; +export = renderPostFilter; diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.ts b/lib/plugins/filter/before_post_render/backtick_code_block.ts index 926054be9d..8b77e90649 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.ts +++ b/lib/plugins/filter/before_post_render/backtick_code_block.ts @@ -4,7 +4,7 @@ const rLangCaption = /([^\s]+)\s*(.+)?/; const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); -export default ctx => { +export = ctx => { return function backtickCodeBlock(data) { const dataContent = data.content; diff --git a/lib/plugins/filter/before_post_render/index.ts b/lib/plugins/filter/before_post_render/index.ts index d27d5a6aa8..07bde83da3 100644 --- a/lib/plugins/filter/before_post_render/index.ts +++ b/lib/plugins/filter/before_post_render/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; filter.register('before_post_render', require('./backtick_code_block')(ctx)); diff --git a/lib/plugins/filter/before_post_render/titlecase.ts b/lib/plugins/filter/before_post_render/titlecase.ts index 27baef4074..24e596ace8 100644 --- a/lib/plugins/filter/before_post_render/titlecase.ts +++ b/lib/plugins/filter/before_post_render/titlecase.ts @@ -7,4 +7,4 @@ function titlecaseFilter(data) { data.title = titlecase(data.title); } -export default titlecaseFilter; +export = titlecaseFilter; diff --git a/lib/plugins/filter/index.ts b/lib/plugins/filter/index.ts index b7a6bb246f..612e116ece 100644 --- a/lib/plugins/filter/index.ts +++ b/lib/plugins/filter/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; require('./after_render')(ctx); diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index 047b987267..52c08c5b51 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -95,4 +95,4 @@ function newPostPathFilter(data = {}, replace) { return fs.ensurePath(target); } -export default newPostPathFilter; +export = newPostPathFilter; diff --git a/lib/plugins/filter/post_permalink.ts b/lib/plugins/filter/post_permalink.ts index c2782fdf5d..22e1e86ed4 100644 --- a/lib/plugins/filter/post_permalink.ts +++ b/lib/plugins/filter/post_permalink.ts @@ -65,4 +65,4 @@ function postPermalinkFilter(data) { return permalink.stringify(meta); } -export default postPermalinkFilter; +export = postPermalinkFilter; diff --git a/lib/plugins/filter/template_locals/i18n.ts b/lib/plugins/filter/template_locals/i18n.ts index 58205b03a7..36cad04058 100644 --- a/lib/plugins/filter/template_locals/i18n.ts +++ b/lib/plugins/filter/template_locals/i18n.ts @@ -31,4 +31,4 @@ function i18nLocalsFilter(locals) { locals._p = i18n._p(languages); } -export default i18nLocalsFilter; +export = i18nLocalsFilter; diff --git a/lib/plugins/filter/template_locals/index.ts b/lib/plugins/filter/template_locals/index.ts index f75d6ebbee..663cb8ab3f 100644 --- a/lib/plugins/filter/template_locals/index.ts +++ b/lib/plugins/filter/template_locals/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { filter } = ctx.extend; filter.register('template_locals', require('./i18n')); diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index c44199d955..b9d27f2173 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -40,4 +40,4 @@ function assetGenerator() { ]).then(data => [].concat(...data)); } -export default assetGenerator; +export = assetGenerator; diff --git a/lib/plugins/generator/index.ts b/lib/plugins/generator/index.ts index 46d84380cb..a07031c380 100644 --- a/lib/plugins/generator/index.ts +++ b/lib/plugins/generator/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { generator } = ctx.extend; generator.register('asset', require('./asset')); diff --git a/lib/plugins/generator/page.ts b/lib/plugins/generator/page.ts index 4cdae9f394..8dbbcd817c 100644 --- a/lib/plugins/generator/page.ts +++ b/lib/plugins/generator/page.ts @@ -22,4 +22,4 @@ function pageGenerator(locals) { }); } -export default pageGenerator; +export = pageGenerator; diff --git a/lib/plugins/generator/post.ts b/lib/plugins/generator/post.ts index bd4a04f6ce..4deec563dd 100644 --- a/lib/plugins/generator/post.ts +++ b/lib/plugins/generator/post.ts @@ -28,4 +28,4 @@ function postGenerator(locals) { }); } -export default postGenerator; +export = postGenerator; diff --git a/lib/plugins/helper/css.ts b/lib/plugins/helper/css.ts index 5b42a6a761..db0d4c654c 100644 --- a/lib/plugins/helper/css.ts +++ b/lib/plugins/helper/css.ts @@ -21,7 +21,7 @@ function cssHelper(...args) { return result; } -export default moize(cssHelper, { +export = moize(cssHelper, { maxSize: 10, isDeepEqual: true }); diff --git a/lib/plugins/helper/date.ts b/lib/plugins/helper/date.ts index c160785836..01f3ec356a 100644 --- a/lib/plugins/helper/date.ts +++ b/lib/plugins/helper/date.ts @@ -8,7 +8,7 @@ const isDate = value => function getMoment(date, lang, timezone) { if (date == null) date = moment(); if (!isMoment(date)) date = moment(isDate(date) ? date : new Date(date)); - lang = toMomentLocale(lang); + lang = _toMomentLocale(lang); if (lang) date = date.locale(lang); if (timezone) date = date.tz(timezone); @@ -72,7 +72,7 @@ function getLanguage(ctx) { * * Moment defined locales: https://github.com/moment/moment/tree/master/locale */ -function toMomentLocale(lang) { +function _toMomentLocale(lang) { if (lang === undefined) { return undefined; } @@ -92,4 +92,4 @@ export {fullDateHelper as full_date}; export {relativeDateHelper as relative_date}; export {timeTagHelper as time_tag}; export {moment}; -export var toMomentLocale = moize.shallow(toMomentLocale); +export var toMomentLocale = moize.shallow(_toMomentLocale); diff --git a/lib/plugins/helper/favicon_tag.ts b/lib/plugins/helper/favicon_tag.ts index b8affd6878..212552a497 100644 --- a/lib/plugins/helper/favicon_tag.ts +++ b/lib/plugins/helper/favicon_tag.ts @@ -4,4 +4,4 @@ function faviconTagHelper(path) { return ``; } -export default faviconTagHelper; +export = faviconTagHelper; diff --git a/lib/plugins/helper/feed_tag.ts b/lib/plugins/helper/feed_tag.ts index 81dfdb9daa..83cc18660d 100644 --- a/lib/plugins/helper/feed_tag.ts +++ b/lib/plugins/helper/feed_tag.ts @@ -46,4 +46,4 @@ function feedTagHelper(path, options = {}) { return moize.deep(makeFeedTag.bind(this))(path, options, config.feed, config.title); } -export default feedTagHelper; +export = feedTagHelper; diff --git a/lib/plugins/helper/fragment_cache.ts b/lib/plugins/helper/fragment_cache.ts index 64a0b6abad..84fa85104e 100644 --- a/lib/plugins/helper/fragment_cache.ts +++ b/lib/plugins/helper/fragment_cache.ts @@ -1,7 +1,7 @@ import {Cache} from 'hexo-util'; -export default ctx => { +export = ctx => { const cache = new Cache(); // reset cache for watch mode diff --git a/lib/plugins/helper/full_url_for.ts b/lib/plugins/helper/full_url_for.ts index 454440c6a3..4c9272a848 100644 --- a/lib/plugins/helper/full_url_for.ts +++ b/lib/plugins/helper/full_url_for.ts @@ -1,6 +1,6 @@ import {full_url_for} from 'hexo-util'; -export default function(path) { +export = function(path) { return full_url_for.call(this, path); } diff --git a/lib/plugins/helper/gravatar.ts b/lib/plugins/helper/gravatar.ts index 1146e990f4..235bde9b6e 100644 --- a/lib/plugins/helper/gravatar.ts +++ b/lib/plugins/helper/gravatar.ts @@ -1,2 +1,2 @@ import {gravatar} from 'hexo-util'; -export default gravatar; +export = gravatar; diff --git a/lib/plugins/helper/image_tag.ts b/lib/plugins/helper/image_tag.ts index 009286ba92..1c8d9dd626 100644 --- a/lib/plugins/helper/image_tag.ts +++ b/lib/plugins/helper/image_tag.ts @@ -12,4 +12,4 @@ function imageTagHelper(path, options = {}) { return htmlTag('img', attrs); } -export default imageTagHelper; +export = imageTagHelper; diff --git a/lib/plugins/helper/index.ts b/lib/plugins/helper/index.ts index 7c0bf0773f..79adc27b7d 100644 --- a/lib/plugins/helper/index.ts +++ b/lib/plugins/helper/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { helper } = ctx.extend; const date = require('./date'); diff --git a/lib/plugins/helper/js.ts b/lib/plugins/helper/js.ts index 5362625440..c9ab8a33f5 100644 --- a/lib/plugins/helper/js.ts +++ b/lib/plugins/helper/js.ts @@ -21,7 +21,7 @@ function jsHelper(...args) { return result; } -export default moize(jsHelper, { +export = moize(jsHelper, { maxSize: 10, isDeepEqual: true }); diff --git a/lib/plugins/helper/link_to.ts b/lib/plugins/helper/link_to.ts index 46038d0825..2ebbf58890 100644 --- a/lib/plugins/helper/link_to.ts +++ b/lib/plugins/helper/link_to.ts @@ -23,4 +23,4 @@ function linkToHelper(path, text, options = {}) { return htmlTag('a', attrs, text); } -export default linkToHelper; +export = linkToHelper; diff --git a/lib/plugins/helper/list_archives.ts b/lib/plugins/helper/list_archives.ts index 69c2fe4e79..bf5e04b2c0 100644 --- a/lib/plugins/helper/list_archives.ts +++ b/lib/plugins/helper/list_archives.ts @@ -103,4 +103,4 @@ function listArchivesHelper(options = {}) { return result; } -export default listArchivesHelper; +export = listArchivesHelper; diff --git a/lib/plugins/helper/list_categories.ts b/lib/plugins/helper/list_categories.ts index 74c2bd6dfa..7ecb109aa3 100644 --- a/lib/plugins/helper/list_categories.ts +++ b/lib/plugins/helper/list_categories.ts @@ -105,4 +105,4 @@ function listCategoriesHelper(categories, options) { return flatList(0); } -export default listCategoriesHelper; +export = listCategoriesHelper; diff --git a/lib/plugins/helper/list_posts.ts b/lib/plugins/helper/list_posts.ts index a3de444b77..a15bf9c222 100644 --- a/lib/plugins/helper/list_posts.ts +++ b/lib/plugins/helper/list_posts.ts @@ -53,4 +53,4 @@ function listPostsHelper(posts, options) { return result; } -export default listPostsHelper; +export = listPostsHelper; diff --git a/lib/plugins/helper/list_tags.ts b/lib/plugins/helper/list_tags.ts index 9437bc92cf..1ced1dd53a 100644 --- a/lib/plugins/helper/list_tags.ts +++ b/lib/plugins/helper/list_tags.ts @@ -105,4 +105,4 @@ function listTagsHelperFactory(tags, options) { }).call(this, tags, options); } -export default listTagsHelperFactory; +export = listTagsHelperFactory; diff --git a/lib/plugins/helper/mail_to.ts b/lib/plugins/helper/mail_to.ts index d747edb10a..dbd59ff477 100644 --- a/lib/plugins/helper/mail_to.ts +++ b/lib/plugins/helper/mail_to.ts @@ -31,7 +31,7 @@ function mailToHelper(path, text, options = {}) { return htmlTag('a', attrs, text); } -export default moize(mailToHelper, { +export = moize(mailToHelper, { maxSize: 10, isDeepEqual: true }); diff --git a/lib/plugins/helper/markdown.ts b/lib/plugins/helper/markdown.ts index 4f7731600e..956425f072 100644 --- a/lib/plugins/helper/markdown.ts +++ b/lib/plugins/helper/markdown.ts @@ -2,4 +2,4 @@ function markdownHelper(text, options) { return this.render(text, 'markdown', options); } -export default markdownHelper; +export = markdownHelper; diff --git a/lib/plugins/helper/meta_generator.ts b/lib/plugins/helper/meta_generator.ts index e9513838e1..4b0036c558 100644 --- a/lib/plugins/helper/meta_generator.ts +++ b/lib/plugins/helper/meta_generator.ts @@ -2,4 +2,4 @@ function metaGeneratorHelper() { return ``; } -export default metaGeneratorHelper; +export = metaGeneratorHelper; diff --git a/lib/plugins/helper/number_format.ts b/lib/plugins/helper/number_format.ts index 23c9700124..37aa2c73bb 100644 --- a/lib/plugins/helper/number_format.ts +++ b/lib/plugins/helper/number_format.ts @@ -44,4 +44,4 @@ function numberFormatHelper(num, options = {}) { return before + (after ? separator + after : ''); } -export default numberFormatHelper; +export = numberFormatHelper; diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index 3d916bb7c6..77f77dd004 100644 --- a/lib/plugins/helper/open_graph.ts +++ b/lib/plugins/helper/open_graph.ts @@ -178,4 +178,4 @@ function openGraphHelper(options = {}) { return result.trim(); } -export default openGraphHelper; +export = openGraphHelper; diff --git a/lib/plugins/helper/paginator.ts b/lib/plugins/helper/paginator.ts index 4ff8edff71..7102196c99 100644 --- a/lib/plugins/helper/paginator.ts +++ b/lib/plugins/helper/paginator.ts @@ -148,4 +148,4 @@ function paginatorHelper(options = {}) { return tags.join(''); } -export default paginatorHelper; +export = paginatorHelper; diff --git a/lib/plugins/helper/partial.ts b/lib/plugins/helper/partial.ts index 862f5cf506..83c67c7c9d 100644 --- a/lib/plugins/helper/partial.ts +++ b/lib/plugins/helper/partial.ts @@ -1,6 +1,6 @@ import {dirname, join} from 'path'; -export default ctx => function partial(name, locals, options = {}) { +export = ctx => function partial(name, locals, options = {}) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); const { cache } = options; diff --git a/lib/plugins/helper/relative_url.ts b/lib/plugins/helper/relative_url.ts index 96e7ba0259..55601901c7 100644 --- a/lib/plugins/helper/relative_url.ts +++ b/lib/plugins/helper/relative_url.ts @@ -1,5 +1,5 @@ import {relative_url} from 'hexo-util'; -export default function(from, to) { +export = function(from, to) { return relative_url(from, to); } diff --git a/lib/plugins/helper/render.ts b/lib/plugins/helper/render.ts index ac5e04b962..9f8473efb3 100644 --- a/lib/plugins/helper/render.ts +++ b/lib/plugins/helper/render.ts @@ -1,4 +1,4 @@ -export default ctx => function render(text, engine, options) { +export = ctx => function render(text, engine, options) { return ctx.render.renderSync({ text, engine diff --git a/lib/plugins/helper/search_form.ts b/lib/plugins/helper/search_form.ts index 4f6509a1bb..e55b626c2b 100644 --- a/lib/plugins/helper/search_form.ts +++ b/lib/plugins/helper/search_form.ts @@ -8,4 +8,4 @@ function searchFormHelper(options = {}) { return `
${button ? `` : ''}
`; } -export default moize.deep(searchFormHelper); +export = moize.deep(searchFormHelper); diff --git a/lib/plugins/helper/tagcloud.ts b/lib/plugins/helper/tagcloud.ts index 32f0ec9986..4f57a8a24b 100644 --- a/lib/plugins/helper/tagcloud.ts +++ b/lib/plugins/helper/tagcloud.ts @@ -92,4 +92,4 @@ function tagcloudHelperFactory(tags, options) { }).call(this, tags, options); } -export default tagcloudHelperFactory; +export = tagcloudHelperFactory; diff --git a/lib/plugins/helper/toc.ts b/lib/plugins/helper/toc.ts index 4932a07fe1..21d12490cd 100644 --- a/lib/plugins/helper/toc.ts +++ b/lib/plugins/helper/toc.ts @@ -89,4 +89,4 @@ function tocHelper(str, options = {}) { return result; } -export default tocHelper; +export = tocHelper; diff --git a/lib/plugins/helper/url_for.ts b/lib/plugins/helper/url_for.ts index a69557e49d..6893c10379 100644 --- a/lib/plugins/helper/url_for.ts +++ b/lib/plugins/helper/url_for.ts @@ -1,5 +1,5 @@ import {url_for} from 'hexo-util'; -export default function(path, options) { +export = function(path, options) { return url_for.call(this, path, options); } diff --git a/lib/plugins/injector/index.ts b/lib/plugins/injector/index.ts index 92e3f30837..5c7d54f6ac 100644 --- a/lib/plugins/injector/index.ts +++ b/lib/plugins/injector/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { // eslint-disable-next-line no-unused-vars const { injector } = ctx.extend; }; diff --git a/lib/plugins/processor/asset.ts b/lib/plugins/processor/asset.ts index 451544b76d..370efd0ae6 100644 --- a/lib/plugins/processor/asset.ts +++ b/lib/plugins/processor/asset.ts @@ -5,7 +5,7 @@ import {extname, relative} from 'path'; import {Pattern} from 'hexo-util'; import {magenta} from 'picocolors'; -export default ctx => { +export = ctx => { return { pattern: new Pattern(path => { if (isExcludedFile(path, ctx.config)) return; diff --git a/lib/plugins/processor/data.ts b/lib/plugins/processor/data.ts index 1ed3df1caf..6070c4d8bd 100644 --- a/lib/plugins/processor/data.ts +++ b/lib/plugins/processor/data.ts @@ -1,7 +1,7 @@ import {Pattern} from 'hexo-util'; import {extname} from 'path'; -export default ctx => ({ +export = ctx => ({ pattern: new Pattern('_data/*path'), process: function dataProcessor(file) { diff --git a/lib/plugins/processor/index.ts b/lib/plugins/processor/index.ts index 9342b9a779..1161ff7730 100644 --- a/lib/plugins/processor/index.ts +++ b/lib/plugins/processor/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { processor } = ctx.extend; function register(name) { diff --git a/lib/plugins/processor/post.ts b/lib/plugins/processor/post.ts index f3044a2b08..803bce3cb8 100644 --- a/lib/plugins/processor/post.ts +++ b/lib/plugins/processor/post.ts @@ -20,7 +20,7 @@ const preservedKeys = { hash: true }; -export default ctx => { +export = ctx => { return { pattern: new Pattern(path => { if (isTmpFile(path)) return; diff --git a/lib/plugins/renderer/index.ts b/lib/plugins/renderer/index.ts index 2ca5e36957..c5e6969601 100644 --- a/lib/plugins/renderer/index.ts +++ b/lib/plugins/renderer/index.ts @@ -1,4 +1,4 @@ -export default ctx => { +export = ctx => { const { renderer } = ctx.extend; const plain = require('./plain'); diff --git a/lib/plugins/renderer/json.ts b/lib/plugins/renderer/json.ts index 883785c65b..7c87cf6ecb 100644 --- a/lib/plugins/renderer/json.ts +++ b/lib/plugins/renderer/json.ts @@ -2,4 +2,4 @@ function jsonRenderer(data) { return JSON.parse(data.text); } -export default jsonRenderer; +export = jsonRenderer; diff --git a/lib/plugins/renderer/nunjucks.ts b/lib/plugins/renderer/nunjucks.ts index 008d84d87f..fb46526ead 100644 --- a/lib/plugins/renderer/nunjucks.ts +++ b/lib/plugins/renderer/nunjucks.ts @@ -65,4 +65,4 @@ njkRenderer.compile = data => { return locals => njkCompile(data).render(locals); }; -export default njkRenderer; +export = njkRenderer; diff --git a/lib/plugins/renderer/plain.ts b/lib/plugins/renderer/plain.ts index 666c122705..e1aa47f2df 100644 --- a/lib/plugins/renderer/plain.ts +++ b/lib/plugins/renderer/plain.ts @@ -2,4 +2,4 @@ function plainRenderer(data) { return data.text; } -export default plainRenderer; +export = plainRenderer; diff --git a/lib/plugins/renderer/yaml.ts b/lib/plugins/renderer/yaml.ts index d01c61d1c6..22eab69800 100644 --- a/lib/plugins/renderer/yaml.ts +++ b/lib/plugins/renderer/yaml.ts @@ -18,4 +18,4 @@ function yamlHelper(data) { return yaml.load(escape(data.text), { schema }); } -export default yamlHelper; +export = yamlHelper; diff --git a/lib/plugins/tag/asset_img.ts b/lib/plugins/tag/asset_img.ts index 7398509f2b..7fefcc59a1 100644 --- a/lib/plugins/tag/asset_img.ts +++ b/lib/plugins/tag/asset_img.ts @@ -7,7 +7,7 @@ import {encodeURL} from 'hexo-util'; * Syntax: * {% asset_img [class names] slug [width] [height] [title text [alt text]]%} */ -export default ctx => { +export = ctx => { const PostAsset = ctx.model('PostAsset'); return function assetImgTag(args) { diff --git a/lib/plugins/tag/asset_link.ts b/lib/plugins/tag/asset_link.ts index 4675e440ec..b4c007c73a 100644 --- a/lib/plugins/tag/asset_link.ts +++ b/lib/plugins/tag/asset_link.ts @@ -6,7 +6,7 @@ import {encodeURL, escapeHTML} from 'hexo-util'; * Syntax: * {% asset_link slug [title] [escape] %} */ -export default ctx => { +export = ctx => { const PostAsset = ctx.model('PostAsset'); return function assetLinkTag(args) { diff --git a/lib/plugins/tag/asset_path.ts b/lib/plugins/tag/asset_path.ts index 950cfe3e56..ce68cda497 100644 --- a/lib/plugins/tag/asset_path.ts +++ b/lib/plugins/tag/asset_path.ts @@ -6,7 +6,7 @@ import {encodeURL} from 'hexo-util'; * Syntax: * {% asset_path slug %} */ -export default ctx => { +export = ctx => { const PostAsset = ctx.model('PostAsset'); return function assetPathTag(args) { diff --git a/lib/plugins/tag/blockquote.ts b/lib/plugins/tag/blockquote.ts index 5fb9e6977b..1f99e67c1a 100644 --- a/lib/plugins/tag/blockquote.ts +++ b/lib/plugins/tag/blockquote.ts @@ -55,7 +55,7 @@ const parseFooter = (args, ctx) => { * {% endblockquote %} */ -export default ctx => function blockquoteTag(args, content) { +export = ctx => function blockquoteTag(args, content) { const footer = parseFooter(args, ctx); let result = '
'; diff --git a/lib/plugins/tag/code.ts b/lib/plugins/tag/code.ts index b1de94288e..21e8ebe107 100644 --- a/lib/plugins/tag/code.ts +++ b/lib/plugins/tag/code.ts @@ -114,7 +114,7 @@ function parseArgs(args) { }; } -export default ctx => function codeTag(args, content) { +export = ctx => function codeTag(args, content) { // If neither highlight.js nor prism.js is enabled, return escaped code directly if (!ctx.extend.highlight.query(ctx.config.syntax_highlighter)) { diff --git a/lib/plugins/tag/iframe.ts b/lib/plugins/tag/iframe.ts index fbaefcb16b..83be5b80dd 100644 --- a/lib/plugins/tag/iframe.ts +++ b/lib/plugins/tag/iframe.ts @@ -24,4 +24,4 @@ function iframeTag(args) { return htmlTag('iframe', attrs, ''); } -export default iframeTag; +export = iframeTag; diff --git a/lib/plugins/tag/img.ts b/lib/plugins/tag/img.ts index e631b9aeb6..694f67cf5b 100644 --- a/lib/plugins/tag/img.ts +++ b/lib/plugins/tag/img.ts @@ -10,7 +10,7 @@ const rMetaSingleQuote = /'?([^']+)?'?/; * Syntax: * {% img [class names] /path/to/image [width] [height] [title text [alt text]] %} */ -export default ctx => { +export = ctx => { return function imgTag(args) { const classes = []; diff --git a/lib/plugins/tag/include_code.ts b/lib/plugins/tag/include_code.ts index 600c31f2b8..e03c3fecc8 100644 --- a/lib/plugins/tag/include_code.ts +++ b/lib/plugins/tag/include_code.ts @@ -13,7 +13,7 @@ const rTo = /\s*to:(\d+)/i; * {% include_code [title] [lang:language] path/to/file %} */ -export default ctx => function includeCodeTag(args) { +export = ctx => function includeCodeTag(args) { let codeDir = ctx.config.code_dir; let arg = args.join(' '); diff --git a/lib/plugins/tag/index.ts b/lib/plugins/tag/index.ts index a136ead63f..c0128847cb 100644 --- a/lib/plugins/tag/index.ts +++ b/lib/plugins/tag/index.ts @@ -1,6 +1,6 @@ import moize from 'moize'; -export default ctx => { +export = ctx => { const { tag } = ctx.extend; const blockquote = require('./blockquote')(ctx); diff --git a/lib/plugins/tag/link.ts b/lib/plugins/tag/link.ts index f04dbd9c5b..c383ea3e19 100644 --- a/lib/plugins/tag/link.ts +++ b/lib/plugins/tag/link.ts @@ -54,4 +54,4 @@ function linkTag(args, content) { return htmlTag('a', attrs, text.join(' ')); } -export default linkTag; +export = linkTag; diff --git a/lib/plugins/tag/post_link.ts b/lib/plugins/tag/post_link.ts index c5e04baf20..c90c49505c 100644 --- a/lib/plugins/tag/post_link.ts +++ b/lib/plugins/tag/post_link.ts @@ -7,7 +7,7 @@ import {postFindOneFactory} from './'; * Syntax: * {% post_link slug | title [title] [escape] %} */ -export default ctx => { +export = ctx => { return function postLinkTag(args) { const slug = args.shift(); if (!slug) { diff --git a/lib/plugins/tag/post_path.ts b/lib/plugins/tag/post_path.ts index 93a8c6365e..201c73c1b1 100644 --- a/lib/plugins/tag/post_path.ts +++ b/lib/plugins/tag/post_path.ts @@ -7,7 +7,7 @@ import {postFindOneFactory} from './'; * Syntax: * {% post_path slug | title %} */ -export default ctx => { +export = ctx => { return function postPathTag(args) { const slug = args.shift(); if (!slug) return; diff --git a/lib/plugins/tag/pullquote.ts b/lib/plugins/tag/pullquote.ts index 228d63a775..1235a26d9e 100644 --- a/lib/plugins/tag/pullquote.ts +++ b/lib/plugins/tag/pullquote.ts @@ -6,7 +6,7 @@ * Quote string * {% endpullquote %} */ -export default ctx => function pullquoteTag(args, content) { +export = ctx => function pullquoteTag(args, content) { args.unshift('pullquote'); const result = ctx.render.renderSync({text: content, engine: 'markdown'}); diff --git a/lib/theme/index.ts b/lib/theme/index.ts index 7610b810ef..d8cf042203 100644 --- a/lib/theme/index.ts +++ b/lib/theme/index.ts @@ -79,4 +79,4 @@ class Theme extends Box { } } -export default Theme; +export = Theme; diff --git a/lib/theme/view.ts b/lib/theme/view.ts index 422647ea21..e7cfdd357d 100644 --- a/lib/theme/view.ts +++ b/lib/theme/view.ts @@ -156,4 +156,4 @@ class View { } } -export default View; +export = View; From 71c22ca96d3d950db5f47be8ab9fe173f16bfcf0 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 23:13:57 +0800 Subject: [PATCH 17/45] update --- .../filter/before_generate/render_post.ts | 3 ++- lib/plugins/filter/new_post_path.ts | 9 ++++++- lib/plugins/filter/post_permalink.ts | 5 ++-- lib/plugins/generator/asset.ts | 14 +++++++--- lib/plugins/helper/feed_tag.ts | 7 ++++- lib/plugins/helper/image_tag.ts | 17 +++++++++--- lib/plugins/helper/link_to.ts | 25 +++++++++++++++--- lib/plugins/helper/list_archives.ts | 22 ++++++++++++++-- lib/plugins/helper/list_categories.ts | 6 ++--- lib/plugins/helper/mail_to.ts | 17 ++++++++++-- lib/plugins/helper/number_format.ts | 12 ++++++--- lib/plugins/helper/open_graph.ts | 26 ++++++++++++++++--- tsconfig.json | 2 +- 13 files changed, 135 insertions(+), 30 deletions(-) diff --git a/lib/plugins/filter/before_generate/render_post.ts b/lib/plugins/filter/before_generate/render_post.ts index 896cfb716b..b747e6f287 100644 --- a/lib/plugins/filter/before_generate/render_post.ts +++ b/lib/plugins/filter/before_generate/render_post.ts @@ -1,10 +1,11 @@ import Promise from 'bluebird'; +import warehouse from 'warehouse'; function renderPostFilter(data) { const renderPosts = model => { const posts = model.toArray().filter(post => post.content == null); - return Promise.map(posts, post => { + return Promise.map(posts, (post: warehouse.Schema) => { post.content = post._content; post.site = {data}; diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index 52c08c5b51..c678240758 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -15,7 +15,14 @@ const reservedKeys = { hash: true }; -function newPostPathFilter(data = {}, replace) { +interface Data { + path?: string; + layout?: string; + slug?: string; + date?: Date; +} + +function newPostPathFilter(data: Data = {}, replace) { const sourceDir = this.source_dir; const draftDir = join(sourceDir, '_drafts'); const postDir = join(sourceDir, '_posts'); diff --git a/lib/plugins/filter/post_permalink.ts b/lib/plugins/filter/post_permalink.ts index 22e1e86ed4..cd8381f3fd 100644 --- a/lib/plugins/filter/post_permalink.ts +++ b/lib/plugins/filter/post_permalink.ts @@ -27,7 +27,8 @@ function postPermalinkFilter(data) { second: date.format('ss'), i_month: date.format('M'), i_day: date.format('D'), - hash + hash, + category: config.default_category }; if (!permalink || permalink.rule !== config.permalink) { @@ -38,8 +39,6 @@ function postPermalinkFilter(data) { if (categories.length) { meta.category = categories.last().slug; - } else { - meta.category = config.default_category; } const keys = Object.keys(data); diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index b9d27f2173..76a2da7681 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -1,15 +1,21 @@ import fs from 'hexo-fs'; import Promise from 'bluebird'; import {extname} from 'path'; -import {magenta} from 'picocolors'; +import { magenta } from 'picocolors'; +import warehouse from 'warehouse'; + +interface Data { + modified: boolean; + data?: () => any; +} const process = (name, ctx) => { - return Promise.filter(ctx.model(name).toArray(), asset => fs.exists(asset.source).tap(exist => { + return Promise.filter(ctx.model(name).toArray(), (asset: warehouse.Schema) => fs.exists(asset.source).tap(exist => { if (!exist) return asset.remove(); - })).map(asset => { + })).map((asset: warehouse.Schema) => { const { source } = asset; let { path } = asset; - const data = { + const data: Data = { modified: asset.modified }; diff --git a/lib/plugins/helper/feed_tag.ts b/lib/plugins/helper/feed_tag.ts index 83cc18660d..9d40521138 100644 --- a/lib/plugins/helper/feed_tag.ts +++ b/lib/plugins/helper/feed_tag.ts @@ -6,7 +6,12 @@ const feedFn = (str = '') => { return str; }; -function makeFeedTag(path, options = {}, configFeed?, configTitle?) { +interface Options { + title?: string; + type?: string; +} + +function makeFeedTag(path, options: Options = {}, configFeed?, configTitle?) { const title = options.title || configTitle; if (path) { diff --git a/lib/plugins/helper/image_tag.ts b/lib/plugins/helper/image_tag.ts index 1c8d9dd626..dd07c553e5 100644 --- a/lib/plugins/helper/image_tag.ts +++ b/lib/plugins/helper/image_tag.ts @@ -1,15 +1,26 @@ import {htmlTag, url_for} from 'hexo-util'; -function imageTagHelper(path, options = {}) { +interface Options { + src?: string; + class?: string | string[]; +} + +interface Attrs { + src?: string; + class?: string; + [key: string]: string | undefined; +} + +function imageTagHelper(path: string, options: Options = {}) { const attrs = Object.assign({ - src: url_for.call(this, path) + src: url_for.call(this, path) as string }, options); if (attrs.class && Array.isArray(attrs.class)) { attrs.class = attrs.class.join(' '); } - return htmlTag('img', attrs); + return htmlTag('img', attrs as Attrs); } export = imageTagHelper; diff --git a/lib/plugins/helper/link_to.ts b/lib/plugins/helper/link_to.ts index 2ebbf58890..df0d0e6b9a 100644 --- a/lib/plugins/helper/link_to.ts +++ b/lib/plugins/helper/link_to.ts @@ -1,12 +1,31 @@ import {htmlTag, url_for} from 'hexo-util'; -function linkToHelper(path, text, options = {}) { +interface Options { + href?: string; + title?: string; + external?: boolean | null; + class?: string | string[]; + target?: string; + rel?: string; +} + +interface Attrs { + href: string; + title: string; + external?: boolean | null; + class?: string; + target?: string; + rel?: string; + [key: string]: string | boolean | null | undefined; +} + +function linkToHelper(path: string, text: string, options: Options | boolean = {}) { if (typeof options === 'boolean') options = {external: options}; if (!text) text = path.replace(/^https?:\/\/|\/$/g, ''); const attrs = Object.assign({ - href: url_for.call(this, path), + href: url_for.call(this, path) as string, title: text }, options); @@ -20,7 +39,7 @@ function linkToHelper(path, text, options = {}) { attrs.class = attrs.class.join(' '); } - return htmlTag('a', attrs, text); + return htmlTag('a', attrs as Attrs, text); } export = linkToHelper; diff --git a/lib/plugins/helper/list_archives.ts b/lib/plugins/helper/list_archives.ts index bf5e04b2c0..9b88b1f834 100644 --- a/lib/plugins/helper/list_archives.ts +++ b/lib/plugins/helper/list_archives.ts @@ -1,7 +1,25 @@ import {toMomentLocale} from './date'; import {url_for} from 'hexo-util'; -function listArchivesHelper(options = {}) { +interface Options { + format?: string; + type?: string; + style?: string; + transform?: (name: string) => string; + separator?: string; + show_count?: boolean; + class?: string; + order?: number; +} + +interface Data { + name: string; + year: number; + month: number; + count: number; +} + +function listArchivesHelper(options: Options = {}) { const { config } = this; const archiveDir = config.archive_dir; const { timezone } = config; @@ -25,7 +43,7 @@ function listArchivesHelper(options = {}) { const posts = this.site.posts.sort('date', order); if (!posts.length) return result; - const data = []; + const data: Data[] = []; let length = 0; posts.forEach(post => { diff --git a/lib/plugins/helper/list_categories.ts b/lib/plugins/helper/list_categories.ts index 7ecb109aa3..e0c4630826 100644 --- a/lib/plugins/helper/list_categories.ts +++ b/lib/plugins/helper/list_categories.ts @@ -19,7 +19,7 @@ function listCategoriesHelper(categories, options) { const childrenIndicator = Object.prototype.hasOwnProperty.call(options, 'children_indicator') ? options.children_indicator : false; const prepareQuery = parent => { - const query = {}; + const query: { parent?: any } = {}; if (parent) { query.parent = parent; @@ -30,7 +30,7 @@ function listCategoriesHelper(categories, options) { return categories.find(query).sort(orderby, order); }; - const hierarchicalList = (level, parent) => { + const hierarchicalList = (level: number, parent?: any) => { let result = ''; prepareQuery(parent).forEach((cat, i) => { @@ -75,7 +75,7 @@ function listCategoriesHelper(categories, options) { return result; }; - const flatList = (level, parent) => { + const flatList = (level: number, parent?: any) => { let result = ''; prepareQuery(parent).forEach((cat, i) => { diff --git a/lib/plugins/helper/mail_to.ts b/lib/plugins/helper/mail_to.ts index dbd59ff477..2f71c25b1d 100644 --- a/lib/plugins/helper/mail_to.ts +++ b/lib/plugins/helper/mail_to.ts @@ -1,7 +1,20 @@ import {htmlTag} from 'hexo-util'; import moize from 'moize'; -function mailToHelper(path, text, options = {}) { +interface Options { + href?: string; + title?: string; + class?: string | string[]; +} + +interface Attrs { + href: string; + title: string; + class?: string; + [key: string]: string | boolean | null | undefined; +} + +function mailToHelper(path, text, options: Options = {}) { if (Array.isArray(path)) path = path.join(','); if (!text) text = path; @@ -28,7 +41,7 @@ function mailToHelper(path, text, options = {}) { const querystring = new URLSearchParams(data).toString(); if (querystring) attrs.href += `?${querystring}`; - return htmlTag('a', attrs, text); + return htmlTag('a', attrs as Attrs, text); } export = moize(mailToHelper, { diff --git a/lib/plugins/helper/number_format.ts b/lib/plugins/helper/number_format.ts index 37aa2c73bb..fe78432c48 100644 --- a/lib/plugins/helper/number_format.ts +++ b/lib/plugins/helper/number_format.ts @@ -1,13 +1,19 @@ -function numberFormatHelper(num, options = {}) { +interface Options { + delimiter?: string; + separator?: string; + precision?: number | string; +} + +function numberFormatHelper(num: number, options: Options = {}) { const split = num.toString().split('.'); - let before = split.shift(); + let before = split.shift() as string; let after = split.length ? split[0] : ''; const delimiter = options.delimiter || ','; const separator = options.separator || '.'; const { precision } = options; if (delimiter) { - const beforeArr = []; + const beforeArr: string[] = []; const beforeLength = before.length; const beforeFirst = beforeLength % 3; diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index 77f77dd004..68c880a6ad 100644 --- a/lib/plugins/helper/open_graph.ts +++ b/lib/plugins/helper/open_graph.ts @@ -34,7 +34,7 @@ const localeToTerritory = moize.shallow(str => { } }); -const meta = (name, content, escape) => { +const meta = (name, content, escape?: boolean) => { if (escape !== false && typeof content === 'string') { content = escapeHTML(content); } @@ -43,7 +43,7 @@ const meta = (name, content, escape) => { return `\n`; }; -const og = (name, content, escape) => { +const og = (name, content?: string, escape?: boolean) => { if (escape !== false && typeof content === 'string') { content = escapeHTML(content); } @@ -52,7 +52,27 @@ const og = (name, content, escape) => { return `\n`; }; -function openGraphHelper(options = {}) { +interface Options { + image?: string; + images?: string[]; + description?: string; + title?: string; + type?: string; + url?: string; + site_name?: string; + twitter_card?: string; + date?: boolean; + updated?: boolean; + language?: string; + author?: string; + twitter_image?: string; + twitter_id?: string; + twitter_site?: string; + fb_admins?: string; + fb_app_id?: string; +} + +function openGraphHelper(options: Options = {}) { const { config, page } = this; const { content } = page; let images = options.image || options.images || page.photos || []; diff --git a/tsconfig.json b/tsconfig.json index a212ecebe0..44cec41e42 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,7 @@ ] }, "include": [ - "lib/hexo/index.ts" + "lib/**/*.ts" ], "exclude": [ "node_modules" From 8660df6dcc5942929f90b428680113969af264e2 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 25 Nov 2022 01:02:56 +0800 Subject: [PATCH 18/45] update --- lib/plugins/helper/open_graph.ts | 2 +- lib/plugins/helper/paginator.ts | 23 ++++++++++++++++++++++- lib/plugins/helper/partial.ts | 7 ++++++- lib/plugins/helper/search_form.ts | 8 +++++++- lib/plugins/helper/toc.ts | 15 ++++++++++++++- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index 68c880a6ad..c90fc7f294 100644 --- a/lib/plugins/helper/open_graph.ts +++ b/lib/plugins/helper/open_graph.ts @@ -169,7 +169,7 @@ function openGraphHelper(options: Options = {}) { result += meta('twitter:card', twitterCard); if (options.twitter_image) { - let twitter_image = options.twitter_image; + let twitter_image: string | URL = options.twitter_image; twitter_image = new URL(twitter_image, url || config.url); result += meta('twitter:image', twitter_image, false); } else if (images.length) { diff --git a/lib/plugins/helper/paginator.ts b/lib/plugins/helper/paginator.ts index 7102196c99..a181231386 100644 --- a/lib/plugins/helper/paginator.ts +++ b/lib/plugins/helper/paginator.ts @@ -86,7 +86,28 @@ const pagenasionPartShow = (tags, options, ctx) => { } }; -function paginatorHelper(options = {}) { +interface Options { + base?: string; + current?: number; + format?: string; + total?: number; + end_size?: number; + mid_size?: number; + space?: string; + next_text?: string; + prev_text?: string; + prev_next?: boolean; + escape?: boolean; + page_class?: string; + current_class?: string; + space_class?: string; + prev_class?: string; + next_class?: string; + force_prev_next?: boolean; + show_all?: boolean; +} + +function paginatorHelper(options: Options = {}) { options = Object.assign({ base: this.page.base || '', current: this.page.current || 0, diff --git a/lib/plugins/helper/partial.ts b/lib/plugins/helper/partial.ts index 83c67c7c9d..180615e516 100644 --- a/lib/plugins/helper/partial.ts +++ b/lib/plugins/helper/partial.ts @@ -1,6 +1,11 @@ import {dirname, join} from 'path'; -export = ctx => function partial(name, locals, options = {}) { +interface Options { + cache?: boolean | string; + only?: boolean; +} + +export = ctx => function partial(name, locals, options: Options = {}) { if (typeof name !== 'string') throw new TypeError('name must be a string!'); const { cache } = options; diff --git a/lib/plugins/helper/search_form.ts b/lib/plugins/helper/search_form.ts index e55b626c2b..6414615e82 100644 --- a/lib/plugins/helper/search_form.ts +++ b/lib/plugins/helper/search_form.ts @@ -1,6 +1,12 @@ import moize from 'moize'; -function searchFormHelper(options = {}) { +interface Options { + class?: string; + text?: string; + button?: string | boolean; +} + +function searchFormHelper(options: Options = {}) { const { config } = this; const className = options.class || 'search-form'; const { text = 'Search', button } = options; diff --git a/lib/plugins/helper/toc.ts b/lib/plugins/helper/toc.ts index 21d12490cd..42e5b1dca6 100644 --- a/lib/plugins/helper/toc.ts +++ b/lib/plugins/helper/toc.ts @@ -1,6 +1,19 @@ import {tocObj, escapeHTML, encodeURL} from 'hexo-util'; -function tocHelper(str, options = {}) { +interface Options { + min_depth?: number; + max_depth?: number; + class?: string; + class_item?: string; + class_link?: string; + class_text?: string; + class_child?: string; + class_number?: string; + class_level?: string; + list_number?: boolean; +} + +function tocHelper(str, options: Options = {}) { options = Object.assign({ min_depth: 1, max_depth: 6, From 067de959ccef0a64be21376f77523d6317a42819 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 25 Nov 2022 11:46:05 +0800 Subject: [PATCH 19/45] number_format --- lib/plugins/helper/number_format.ts | 2 +- lib/plugins/tag/include_code.ts | 2 +- lib/theme/processors/source.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/plugins/helper/number_format.ts b/lib/plugins/helper/number_format.ts index fe78432c48..350e1b1129 100644 --- a/lib/plugins/helper/number_format.ts +++ b/lib/plugins/helper/number_format.ts @@ -1,7 +1,7 @@ interface Options { delimiter?: string; separator?: string; - precision?: number | string; + precision?: number; } function numberFormatHelper(num: number, options: Options = {}) { diff --git a/lib/plugins/tag/include_code.ts b/lib/plugins/tag/include_code.ts index e03c3fecc8..f752fa5901 100644 --- a/lib/plugins/tag/include_code.ts +++ b/lib/plugins/tag/include_code.ts @@ -54,7 +54,7 @@ export = ctx => function includeCodeTag(args) { return exists(src).then(exist => { if (exist) return readFile(src); - }).then(code => { + }).then((code: string) => { if (!code) return; const lines = code.split('\n'); diff --git a/lib/theme/processors/source.ts b/lib/theme/processors/source.ts index 4233bac613..97688b7ba7 100644 --- a/lib/theme/processors/source.ts +++ b/lib/theme/processors/source.ts @@ -1,5 +1,5 @@ import {Pattern} from 'hexo-util'; -import common from '../../plugins/processor/common'; +import * as common from '../../plugins/processor/common'; export function process(file) { const Asset = this.model('Asset'); From 4e1f17548eb6950c7648cda5a9faa20527d02fa9 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Fri, 16 Dec 2022 17:46:59 +0800 Subject: [PATCH 20/45] update highlight --- .../{syntax_highlight.js => syntax_highlight.ts} | 13 +++++++++++-- .../before_post_render/backtick_code_block.ts | 9 ++++++++- .../highlight/{highlight.js => highlight.ts} | 0 lib/plugins/highlight/{index.js => index.ts} | 0 lib/plugins/highlight/{prism.js => prism.ts} | 0 5 files changed, 19 insertions(+), 3 deletions(-) rename lib/extend/{syntax_highlight.js => syntax_highlight.ts} (74%) rename lib/plugins/highlight/{highlight.js => highlight.ts} (100%) rename lib/plugins/highlight/{index.js => index.ts} (100%) rename lib/plugins/highlight/{prism.js => prism.ts} (100%) diff --git a/lib/extend/syntax_highlight.js b/lib/extend/syntax_highlight.ts similarity index 74% rename from lib/extend/syntax_highlight.js rename to lib/extend/syntax_highlight.ts index 56d83ba2a8..e0d79a2265 100644 --- a/lib/extend/syntax_highlight.js +++ b/lib/extend/syntax_highlight.ts @@ -1,6 +1,15 @@ -'use strict'; +interface StoreFunction { + (...args: any[]): any; + priority?: number; +} + +interface Store { + [key: string]: StoreFunction[] +} class SyntaxHighlight { + public store: Store; + constructor() { this.store = {}; } @@ -26,4 +35,4 @@ class SyntaxHighlight { } } -module.exports = SyntaxHighlight; +export = SyntaxHighlight; diff --git a/lib/plugins/filter/before_post_render/backtick_code_block.ts b/lib/plugins/filter/before_post_render/backtick_code_block.ts index 8b77e90649..b9df3e60f2 100644 --- a/lib/plugins/filter/before_post_render/backtick_code_block.ts +++ b/lib/plugins/filter/before_post_render/backtick_code_block.ts @@ -4,6 +4,13 @@ const rLangCaption = /([^\s]+)\s*(.+)?/; const escapeSwigTag = str => str.replace(/{/g, '{').replace(/}/g, '}'); +interface Options { + lang: string, + caption: string, + lines_length: number, + firstLineNumber?: string | number +} + export = ctx => { return function backtickCodeBlock(data) { const dataContent = data.content; @@ -44,7 +51,7 @@ export = ctx => { content = content.replace(regexp, ''); } - const options = { + const options: Options = { lang, caption, lines_length: content.split('\n').length diff --git a/lib/plugins/highlight/highlight.js b/lib/plugins/highlight/highlight.ts similarity index 100% rename from lib/plugins/highlight/highlight.js rename to lib/plugins/highlight/highlight.ts diff --git a/lib/plugins/highlight/index.js b/lib/plugins/highlight/index.ts similarity index 100% rename from lib/plugins/highlight/index.js rename to lib/plugins/highlight/index.ts diff --git a/lib/plugins/highlight/prism.js b/lib/plugins/highlight/prism.ts similarity index 100% rename from lib/plugins/highlight/prism.js rename to lib/plugins/highlight/prism.ts From 6f3fdc99f1a679bafac0601ecccb13df6c467d29 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sun, 1 Jan 2023 16:15:26 +0800 Subject: [PATCH 21/45] update --- lib/extend/deployer.ts | 4 ++-- lib/extend/generator.ts | 2 +- lib/extend/helper.ts | 4 ++-- lib/extend/migrator.ts | 4 ++-- lib/extend/syntax_highlight.ts | 13 +++++++++---- lib/hexo/index.ts | 2 +- lib/hexo/post.ts | 1 + lib/plugins/generator/asset.ts | 4 ++-- lib/plugins/tag/code.ts | 14 +++++++++++++- lib/plugins/tag/index.ts | 2 +- 10 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/extend/deployer.ts b/lib/extend/deployer.ts index d26e4187d8..b743071fdb 100644 --- a/lib/extend/deployer.ts +++ b/lib/extend/deployer.ts @@ -11,11 +11,11 @@ class Deployer { return this.store; } - get(name) { + get(name: string) { return this.store[name]; } - register(name, fn) { + register(name: string, fn) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); diff --git a/lib/extend/generator.ts b/lib/extend/generator.ts index e5b3b5a533..41a4a07b12 100644 --- a/lib/extend/generator.ts +++ b/lib/extend/generator.ts @@ -13,7 +13,7 @@ class Generator { return this.store; } - get(name) { + get(name: string) { return this.store[name]; } diff --git a/lib/extend/helper.ts b/lib/extend/helper.ts index c3a5ba490d..fe0500fdd1 100644 --- a/lib/extend/helper.ts +++ b/lib/extend/helper.ts @@ -17,7 +17,7 @@ class Helper { * @param {String} name - The name of the helper plugin * @returns {Function} */ - get(name) { + get(name: string) { return this.store[name]; } @@ -26,7 +26,7 @@ class Helper { * @param {String} name - The name of the helper plugin * @param {Function} fn - The helper plugin function */ - register(name, fn) { + register(name: string, fn) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); diff --git a/lib/extend/migrator.ts b/lib/extend/migrator.ts index db0e4eb424..94e725dc0c 100644 --- a/lib/extend/migrator.ts +++ b/lib/extend/migrator.ts @@ -11,11 +11,11 @@ class Migrator { return this.store; } - get(name) { + get(name: string) { return this.store[name]; } - register(name, fn) { + register(name: string, fn) { if (!name) throw new TypeError('name is required'); if (typeof fn !== 'function') throw new TypeError('fn must be a function'); diff --git a/lib/extend/syntax_highlight.ts b/lib/extend/syntax_highlight.ts index e0d79a2265..22d9371a5e 100644 --- a/lib/extend/syntax_highlight.ts +++ b/lib/extend/syntax_highlight.ts @@ -1,10 +1,15 @@ +interface Options { + context?: any; + args?: any; +} + interface StoreFunction { (...args: any[]): any; priority?: number; } interface Store { - [key: string]: StoreFunction[] + [key: string]: StoreFunction } class SyntaxHighlight { @@ -14,17 +19,17 @@ class SyntaxHighlight { this.store = {}; } - register(name, fn) { + register(name: string, fn: StoreFunction) { if (typeof fn !== 'function') throw new TypeError('fn must be a function'); this.store[name] = fn; } - query(name) { + query(name: string) { return name && this.store[name]; } - exec(name, options) { + exec(name: string, options: Options) { const fn = this.store[name]; if (!fn) throw new TypeError(`syntax highlighter ${name} is not registered`); diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index daca53d648..ae61e38217 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -305,7 +305,7 @@ class Hexo extends EventEmitter { require('../plugins/injector')(this); require('../plugins/processor')(this); require('../plugins/renderer')(this); - require('../plugins/tag')(this); + require('../plugins/tag').default(this); // Load config return Promise.each([ diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 1bbebc11b6..563d3fb524 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -228,6 +228,7 @@ interface Data { content?: string; disableNunjucks?: boolean; markdown?: object; + source?: string; } class Post { diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index 76a2da7681..76c8cbc83a 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -10,9 +10,9 @@ interface Data { } const process = (name, ctx) => { - return Promise.filter(ctx.model(name).toArray(), (asset: warehouse.Schema) => fs.exists(asset.source).tap(exist => { + return Promise.filter(ctx.model(name).toArray(), (asset: warehouse['Schema']) => fs.exists(asset.source).tap(exist => { if (!exist) return asset.remove(); - })).map((asset: warehouse.Schema) => { + })).map((asset: warehouse['Schema']) => { const { source } = asset; let { path } = asset; const data: Data = { diff --git a/lib/plugins/tag/code.ts b/lib/plugins/tag/code.ts index 21e8ebe107..cd7e07bd0e 100644 --- a/lib/plugins/tag/code.ts +++ b/lib/plugins/tag/code.ts @@ -6,6 +6,18 @@ const rCaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+)\s+(.+)/i; const rCaptionUrl = /(\S[\S\s]*)\s+(https?:\/\/\S+)/i; const rCaption = /\S[\S\s]*/; +interface Options { + lang: string; + language_attr: boolean; + firstLine: number; + caption: string; + line_number: boolean; + line_threshold: number; + mark: number[]; + wrap: boolean; + lines_length?: number; +} + /** * Code block tag * Syntax: @@ -25,7 +37,7 @@ const rCaption = /\S[\S\s]*/; * @returns {String} Code snippet with code highlighting */ -function parseArgs(args) { +function parseArgs(args): Options { const _else = []; const len = args.length; let lang, language_attr, diff --git a/lib/plugins/tag/index.ts b/lib/plugins/tag/index.ts index c0128847cb..a136ead63f 100644 --- a/lib/plugins/tag/index.ts +++ b/lib/plugins/tag/index.ts @@ -1,6 +1,6 @@ import moize from 'moize'; -export = ctx => { +export default ctx => { const { tag } = ctx.extend; const blockquote = require('./blockquote')(ctx); From d5eade221bf842d8ddb19c5c20dbe757ede4dff7 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Wed, 15 Feb 2023 22:49:26 +0900 Subject: [PATCH 22/45] add secondary argument when create `Permalink` instance --- lib/plugins/filter/new_post_path.ts | 2 +- lib/plugins/filter/post_permalink.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index c678240758..708e3444dd 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -32,7 +32,7 @@ function newPostPathFilter(data: Data = {}, replace) { const { path, layout, slug } = data; if (!permalink || permalink.rule !== newPostName) { - permalink = new Permalink(newPostName); + permalink = new Permalink(newPostName, {}); } let target = ''; diff --git a/lib/plugins/filter/post_permalink.ts b/lib/plugins/filter/post_permalink.ts index cd8381f3fd..90846ab42b 100644 --- a/lib/plugins/filter/post_permalink.ts +++ b/lib/plugins/filter/post_permalink.ts @@ -32,7 +32,7 @@ function postPermalinkFilter(data) { }; if (!permalink || permalink.rule !== config.permalink) { - permalink = new Permalink(config.permalink); + permalink = new Permalink(config.permalink, {}); } const { categories } = data; From 99a34a7914b5f5312a6a842a25564e106474e538 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Wed, 15 Feb 2023 22:49:56 +0900 Subject: [PATCH 23/45] specify `eslint` target directory --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d633b06d04..1d5eb756f2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "prepublish ": "npm run clean && npm run build", "build": "tsc -b", "clean": "tsc -b --clean", - "eslint": "eslint .", + "eslint": "eslint lib test", "pretest": "npm run clean && npm run build", "test": "mocha test/index.js --require ts-node/register", "test-cov": "c8 --reporter=lcovonly npm test -- --no-parallel", From 030da6904b89a9a31f9113b2fe1f59c2c70c1f30 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Wed, 15 Feb 2023 22:50:29 +0900 Subject: [PATCH 24/45] ignore two rules for testing --- test/.eslintrc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/.eslintrc b/test/.eslintrc index b05fbe4df3..87b9cb6966 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -2,5 +2,9 @@ "extends": "hexo/test", "globals": { "should": true + }, + "rules": { + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/no-empty-function": 0 } } From d222a0ab52133d2091f33b14606a275436badc4b Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Thu, 16 Feb 2023 23:18:12 +0900 Subject: [PATCH 25/45] use `@ts-expect-error` for avoiding compile error --- lib/plugins/generator/asset.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index 76c8cbc83a..4710b238bc 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -10,15 +10,21 @@ interface Data { } const process = (name, ctx) => { + // @ts-expect-error return Promise.filter(ctx.model(name).toArray(), (asset: warehouse['Schema']) => fs.exists(asset.source).tap(exist => { + // @ts-expect-error if (!exist) return asset.remove(); })).map((asset: warehouse['Schema']) => { + // @ts-expect-error const { source } = asset; + // @ts-expect-error let { path } = asset; const data: Data = { + // @ts-expect-error modified: asset.modified }; + // @ts-expect-error if (asset.renderable && ctx.render.isRenderable(path)) { // Replace extension name if the asset is renderable const filename = path.substring(0, path.length - extname(path).length); From ea02b4d361c520adc955f75c4af61e899674fa78 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Thu, 16 Feb 2023 23:18:44 +0900 Subject: [PATCH 26/45] use `any` for avoiding compile error --- lib/extend/tag.ts | 2 +- lib/hexo/index.ts | 2 +- lib/plugins/console/deploy.ts | 2 +- lib/plugins/filter/before_generate/render_post.ts | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index da7844fb7d..8757de6b70 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -54,7 +54,7 @@ class NunjucksTag { return this._run(context, args, ''); } - _run(context, args, body) { + _run(context, args, body): any { return Reflect.apply(this.fn, context.ctx, [args, body]); } } diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index ae61e38217..302747f178 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -327,7 +327,7 @@ class Hexo extends EventEmitter { const c = this.extend.console.get(name); - if (c) return Reflect.apply(c, this, [args]).asCallback(callback); + if (c) return (Reflect.apply(c, this, [args]) as any).asCallback(callback); return Promise.reject(new Error(`Console \`${name}\` has not been registered yet!`)); } diff --git a/lib/plugins/console/deploy.ts b/lib/plugins/console/deploy.ts index 1f9504f235..b443b7c155 100644 --- a/lib/plugins/console/deploy.ts +++ b/lib/plugins/console/deploy.ts @@ -48,7 +48,7 @@ function deployConsole(args) { this.log.info('Deploying: %s', magenta(type)); - return Reflect.apply(deployers[type], this, [{ ...item, ...args }]).then(() => { + return (Reflect.apply(deployers[type], this, [{ ...item, ...args }]) as any).then(() => { this.log.info('Deploy done: %s', magenta(type)); }); }).then(() => { diff --git a/lib/plugins/filter/before_generate/render_post.ts b/lib/plugins/filter/before_generate/render_post.ts index b747e6f287..ae202e9477 100644 --- a/lib/plugins/filter/before_generate/render_post.ts +++ b/lib/plugins/filter/before_generate/render_post.ts @@ -1,11 +1,10 @@ import Promise from 'bluebird'; -import warehouse from 'warehouse'; function renderPostFilter(data) { const renderPosts = model => { const posts = model.toArray().filter(post => post.content == null); - return Promise.map(posts, (post: warehouse.Schema) => { + return Promise.map(posts, (post: any) => { post.content = post._content; post.site = {data}; From 4de2ceca746bb55917735c412871fffa344eb319 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Mon, 20 Feb 2023 01:49:07 +0900 Subject: [PATCH 27/45] chore: add `dist/` to `.gitignore` --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a62e2da0ac..67d6810998 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ package-lock.json coverage/ .tmp* .vscode +dist/ From e8de5978da5411102ec1fe80c819c2d221247007 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Mon, 20 Feb 2023 01:55:27 +0900 Subject: [PATCH 28/45] test(eslint): update `.eslintrc` --- test/.eslintrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/.eslintrc b/test/.eslintrc index 87b9cb6966..6f2a1521e6 100644 --- a/test/.eslintrc +++ b/test/.eslintrc @@ -5,6 +5,8 @@ }, "rules": { "@typescript-eslint/no-var-requires": 0, - "@typescript-eslint/no-empty-function": 0 + "@typescript-eslint/no-empty-function": 0, + "@typescript-eslint/no-unused-vars": 0, + "node/no-missing-require": 0 } } From 4a0520a2c05a98964bb3eb1dd4cb68c9e7d9c710 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Mon, 20 Feb 2023 02:04:28 +0900 Subject: [PATCH 29/45] refactor: `var` to `const` --- lib/plugins/helper/date.ts | 2 +- lib/theme/processors/config.ts | 2 +- lib/theme/processors/i18n.ts | 2 +- lib/theme/processors/source.ts | 2 +- lib/theme/processors/view.ts | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/plugins/helper/date.ts b/lib/plugins/helper/date.ts index 01f3ec356a..b347770dc8 100644 --- a/lib/plugins/helper/date.ts +++ b/lib/plugins/helper/date.ts @@ -92,4 +92,4 @@ export {fullDateHelper as full_date}; export {relativeDateHelper as relative_date}; export {timeTagHelper as time_tag}; export {moment}; -export var toMomentLocale = moize.shallow(_toMomentLocale); +export const toMomentLocale = moize.shallow(_toMomentLocale); diff --git a/lib/theme/processors/config.ts b/lib/theme/processors/config.ts index b2a175b2b0..2da78854d6 100644 --- a/lib/theme/processors/config.ts +++ b/lib/theme/processors/config.ts @@ -15,4 +15,4 @@ export function process(file) { }); } -export var pattern = new Pattern(/^_config\.\w+$/); +export const pattern = new Pattern(/^_config\.\w+$/); diff --git a/lib/theme/processors/i18n.ts b/lib/theme/processors/i18n.ts index 515c6b2e5b..fcdc457aae 100644 --- a/lib/theme/processors/i18n.ts +++ b/lib/theme/processors/i18n.ts @@ -18,4 +18,4 @@ export function process(file) { }); } -export var pattern = new Pattern('languages/*path'); +export const pattern = new Pattern('languages/*path'); diff --git a/lib/theme/processors/source.ts b/lib/theme/processors/source.ts index 97688b7ba7..f7ff6a4a0c 100644 --- a/lib/theme/processors/source.ts +++ b/lib/theme/processors/source.ts @@ -22,7 +22,7 @@ export function process(file) { }); } -export var pattern = new Pattern(path => { +export const pattern = new Pattern(path => { if (!path.startsWith('source/')) return false; path = path.substring(7); diff --git a/lib/theme/processors/view.ts b/lib/theme/processors/view.ts index fe3cf1d04c..bb0d44d1f8 100644 --- a/lib/theme/processors/view.ts +++ b/lib/theme/processors/view.ts @@ -1,4 +1,4 @@ -import {Pattern} from 'hexo-util'; +import { Pattern } from 'hexo-util'; export function process(file) { const { path } = file.params; @@ -13,4 +13,4 @@ export function process(file) { }); } -export var pattern = new Pattern('layout/*path'); +export const pattern = new Pattern('layout/*path'); From 30c4136dc0882558c663196e960d725becd1815e Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Mon, 20 Feb 2023 02:06:11 +0900 Subject: [PATCH 30/45] refactor: delete unnecessary `'use strict';` --- lib/plugins/highlight/highlight.ts | 2 -- lib/plugins/highlight/index.ts | 2 -- lib/plugins/highlight/prism.ts | 2 -- 3 files changed, 6 deletions(-) diff --git a/lib/plugins/highlight/highlight.ts b/lib/plugins/highlight/highlight.ts index c90ccd7994..787017fcf7 100644 --- a/lib/plugins/highlight/highlight.ts +++ b/lib/plugins/highlight/highlight.ts @@ -1,5 +1,3 @@ -'use strict'; - // Lazy require highlight.js let highlight; diff --git a/lib/plugins/highlight/index.ts b/lib/plugins/highlight/index.ts index 9dc22fd7d4..2efad0cbf6 100644 --- a/lib/plugins/highlight/index.ts +++ b/lib/plugins/highlight/index.ts @@ -1,5 +1,3 @@ -'use strict'; - module.exports = ctx => { const { highlight } = ctx.extend; diff --git a/lib/plugins/highlight/prism.ts b/lib/plugins/highlight/prism.ts index 7d46461c96..1e37674fd0 100644 --- a/lib/plugins/highlight/prism.ts +++ b/lib/plugins/highlight/prism.ts @@ -1,5 +1,3 @@ -'use strict'; - // Lazy require prismjs let prismHighlight; From fff9d9a90ec10791141967c6899add2b7d4252ee Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Fri, 24 Feb 2023 01:06:48 +0900 Subject: [PATCH 31/45] test: use `dist/modules/types/moment/SchemaTypeMoment` instead of `warehouse.SchemaTypeMoment` --- test/scripts/models/moment.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/scripts/models/moment.js b/test/scripts/models/moment.js index f457f86fa0..e5054575b8 100644 --- a/test/scripts/models/moment.js +++ b/test/scripts/models/moment.js @@ -1,10 +1,10 @@ 'use strict'; const moment = require('moment-timezone'); +const SchemaTypeMoment = require('../../../dist/models/types/moment'); describe('SchemaTypeMoment', () => { - const SchemaTypeMoment = require('../../../dist/models/types/moment'); - const type = new warehouse.SchemaTypeMoment('test'); + const type = new SchemaTypeMoment('test'); it('cast()', () => { type.cast(1e8).should.eql(moment(1e8)); @@ -14,14 +14,14 @@ describe('SchemaTypeMoment', () => { }); it('cast() - default', () => { - const type = new warehouse.SchemaTypeMoment('test', {default: moment}); + const type = new SchemaTypeMoment('test', {default: moment}); moment.isMoment(type.cast()).should.be.true; }); it('cast() - language', () => { const lang = 'zh-tw'; const format = 'LLLL'; - const type = new warehouse.SchemaTypeMoment('test', {language: lang}); + const type = new SchemaTypeMoment('test', {language: lang}); const now = Date.now(); type.cast(now).format(format).should.eql(moment(now).locale(lang).format(format)); @@ -30,7 +30,7 @@ describe('SchemaTypeMoment', () => { it('cast() - timezone', () => { const timezone = 'Etc/UTC'; const format = 'LLLL'; - const type = new warehouse.SchemaTypeMoment('test', {timezone}); + const type = new SchemaTypeMoment('test', {timezone}); const now = Date.now(); type.cast(now).format(format).should.eql(moment(now).tz(timezone).format(format)); @@ -49,7 +49,7 @@ describe('SchemaTypeMoment', () => { }); it('validate() - required', () => { - const type = new warehouse.SchemaTypeMoment('test', {required: true}); + const type = new SchemaTypeMoment('test', {required: true}); should.throw(() => type.validate(), '`test` is required!'); }); From d1fa0f85653b35a34ab4fca6b33866993768a146 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Fri, 24 Feb 2023 01:07:23 +0900 Subject: [PATCH 32/45] fix: export of processors --- lib/theme/index.ts | 12 ++++++++---- lib/theme/processors/config.ts | 9 +++++++-- lib/theme/processors/i18n.ts | 9 +++++++-- lib/theme/processors/source.ts | 10 ++++++++-- lib/theme/processors/view.ts | 9 +++++++-- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/theme/index.ts b/lib/theme/index.ts index d8cf042203..3d6dfb1259 100644 --- a/lib/theme/index.ts +++ b/lib/theme/index.ts @@ -2,6 +2,10 @@ import {extname} from 'path'; import Box from '../box'; import View from './view'; import I18n from 'hexo-i18n'; +import { config } from './processors/config'; +import { i18n } from './processors/i18n'; +import { source } from './processors/source'; +import { view } from './processors/view'; class Theme extends Box { public config: any; @@ -17,10 +21,10 @@ class Theme extends Box { this.views = {}; this.processors = [ - require('./processors/config'), - require('./processors/i18n'), - require('./processors/source'), - require('./processors/view') + config, + i18n, + source, + view ]; let languages = ctx.config.language; diff --git a/lib/theme/processors/config.ts b/lib/theme/processors/config.ts index 2da78854d6..7d4288eb0f 100644 --- a/lib/theme/processors/config.ts +++ b/lib/theme/processors/config.ts @@ -1,6 +1,6 @@ import {Pattern} from 'hexo-util'; -export function process(file) { +function process(file) { if (file.type === 'delete') { file.box.config = {}; return; @@ -15,4 +15,9 @@ export function process(file) { }); } -export const pattern = new Pattern(/^_config\.\w+$/); +const pattern = new Pattern(/^_config\.\w+$/); + +export const config = { + pattern: pattern, + process: process +} diff --git a/lib/theme/processors/i18n.ts b/lib/theme/processors/i18n.ts index fcdc457aae..f6172f4b4d 100644 --- a/lib/theme/processors/i18n.ts +++ b/lib/theme/processors/i18n.ts @@ -1,7 +1,7 @@ import {Pattern} from 'hexo-util'; import {extname} from 'path'; -export function process(file) { +function process(file) { const { path } = file.params; const ext = extname(path); const name = path.substring(0, path.length - ext.length); @@ -18,4 +18,9 @@ export function process(file) { }); } -export const pattern = new Pattern('languages/*path'); +const pattern = new Pattern('languages/*path'); + +export const i18n = { + pattern: pattern, + process: process +} \ No newline at end of file diff --git a/lib/theme/processors/source.ts b/lib/theme/processors/source.ts index f7ff6a4a0c..52bde14059 100644 --- a/lib/theme/processors/source.ts +++ b/lib/theme/processors/source.ts @@ -1,7 +1,7 @@ import {Pattern} from 'hexo-util'; import * as common from '../../plugins/processor/common'; -export function process(file) { +function process(file) { const Asset = this.model('Asset'); const id = file.source.substring(this.base_dir.length).replace(/\\/g, '/'); const { path } = file.params; @@ -22,7 +22,7 @@ export function process(file) { }); } -export const pattern = new Pattern(path => { +const pattern = new Pattern(path => { if (!path.startsWith('source/')) return false; path = path.substring(7); @@ -30,3 +30,9 @@ export const pattern = new Pattern(path => { return {path}; }); + + +export const source = { + pattern: pattern, + process: process +} \ No newline at end of file diff --git a/lib/theme/processors/view.ts b/lib/theme/processors/view.ts index bb0d44d1f8..600295a8c3 100644 --- a/lib/theme/processors/view.ts +++ b/lib/theme/processors/view.ts @@ -1,6 +1,6 @@ import { Pattern } from 'hexo-util'; -export function process(file) { +function process(file) { const { path } = file.params; if (file.type === 'delete') { @@ -13,4 +13,9 @@ export function process(file) { }); } -export const pattern = new Pattern('layout/*path'); +const pattern = new Pattern('layout/*path'); + +export const view = { + pattern: pattern, + process: process +} \ No newline at end of file From 6d1be46966a5c9d81fa881a294474725e1b94db2 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 28 Feb 2023 22:11:41 +0900 Subject: [PATCH 33/45] test: fix bind --- test/scripts/theme_processors/config.js | 2 +- test/scripts/theme_processors/i18n.js | 2 +- test/scripts/theme_processors/source.js | 2 +- test/scripts/theme_processors/view.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/scripts/theme_processors/config.js b/test/scripts/theme_processors/config.js index fb750036c4..a36e04e8cd 100644 --- a/test/scripts/theme_processors/config.js +++ b/test/scripts/theme_processors/config.js @@ -9,7 +9,7 @@ describe('config', () => { const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); const processor = require('../../../dist/theme/processors/config'); - const process = Promise.method(processor.process.bind(hexo)); + const process = Promise.method(processor.config.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); function newFile(options) { diff --git a/test/scripts/theme_processors/i18n.js b/test/scripts/theme_processors/i18n.js index 13b809e33f..d867cda732 100644 --- a/test/scripts/theme_processors/i18n.js +++ b/test/scripts/theme_processors/i18n.js @@ -8,7 +8,7 @@ describe('i18n', () => { const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); const processor = require('../../../dist/theme/processors/i18n'); - const process = Promise.method(processor.process.bind(hexo)); + const process = Promise.method(processor.i18n.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); function newFile(options) { diff --git a/test/scripts/theme_processors/source.js b/test/scripts/theme_processors/source.js index 3596d78bd5..5dd234bf1b 100644 --- a/test/scripts/theme_processors/source.js +++ b/test/scripts/theme_processors/source.js @@ -8,7 +8,7 @@ describe('source', () => { const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'source_test'), {silent: true}); const processor = require('../../../dist/theme/processors/source'); - const process = Promise.method(processor.process.bind(hexo)); + const process = Promise.method(processor.source.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); const Asset = hexo.model('Asset'); diff --git a/test/scripts/theme_processors/view.js b/test/scripts/theme_processors/view.js index f2761f597b..1642c3a65e 100644 --- a/test/scripts/theme_processors/view.js +++ b/test/scripts/theme_processors/view.js @@ -8,7 +8,7 @@ describe('view', () => { const Hexo = require('../../../dist/hexo'); const hexo = new Hexo(join(__dirname, 'view_test'), {silent: true}); const processor = require('../../../dist/theme/processors/view'); - const process = Promise.method(processor.process.bind(hexo)); + const process = Promise.method(processor.view.process.bind(hexo)); const themeDir = join(hexo.base_dir, 'themes', 'test'); hexo.env.init = true; From 752665afd2d1cb13ed68a3521ee36e03bd2f5071 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 28 Feb 2023 22:19:14 +0900 Subject: [PATCH 34/45] test: fix processer --- test/scripts/theme_processors/config.js | 2 +- test/scripts/theme_processors/i18n.js | 2 +- test/scripts/theme_processors/source.js | 2 +- test/scripts/theme_processors/view.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/scripts/theme_processors/config.js b/test/scripts/theme_processors/config.js index a36e04e8cd..34a61330de 100644 --- a/test/scripts/theme_processors/config.js +++ b/test/scripts/theme_processors/config.js @@ -30,7 +30,7 @@ describe('config', () => { after(() => rmdir(hexo.base_dir)); it('pattern', () => { - const pattern = processor.pattern; + const pattern = processor.config.pattern; pattern.match('_config.yml').should.be.ok; pattern.match('_config.json').should.be.ok; diff --git a/test/scripts/theme_processors/i18n.js b/test/scripts/theme_processors/i18n.js index d867cda732..84088e31af 100644 --- a/test/scripts/theme_processors/i18n.js +++ b/test/scripts/theme_processors/i18n.js @@ -33,7 +33,7 @@ describe('i18n', () => { after(() => rmdir(hexo.base_dir)); it('pattern', () => { - const pattern = processor.pattern; + const pattern = processor.i18n.pattern; pattern.match('languages/default.yml').should.be.ok; pattern.match('languages/zh-TW.yml').should.be.ok; diff --git a/test/scripts/theme_processors/source.js b/test/scripts/theme_processors/source.js index 5dd234bf1b..9cf4387e45 100644 --- a/test/scripts/theme_processors/source.js +++ b/test/scripts/theme_processors/source.js @@ -33,7 +33,7 @@ describe('source', () => { after(() => rmdir(hexo.base_dir)); it('pattern', () => { - const { pattern } = processor; + const { pattern } = processor.source; pattern.match('source/foo.jpg').should.eql({path: 'foo.jpg'}); pattern.match('source/_foo.jpg').should.be.false; diff --git a/test/scripts/theme_processors/view.js b/test/scripts/theme_processors/view.js index 1642c3a65e..145fc85f8e 100644 --- a/test/scripts/theme_processors/view.js +++ b/test/scripts/theme_processors/view.js @@ -34,7 +34,7 @@ describe('view', () => { after(() => rmdir(hexo.base_dir)); it('pattern', () => { - const { pattern } = processor; + const { pattern } = processor.view; pattern.match('layout/index.njk').path.should.eql('index.njk'); should.not.exist(pattern.match('index.njk')); From 254f77205a40e3b790a9e3aa34b011641bc854ec Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 7 Mar 2023 11:03:51 +0800 Subject: [PATCH 35/45] fix fs import --- lib/hexo/load_database.ts | 6 +++--- lib/hexo/multi_config_path.ts | 10 +++++----- lib/hexo/update_package.ts | 8 ++++---- lib/plugins/console/clean.ts | 10 +++++----- lib/plugins/console/config.ts | 6 +++--- lib/plugins/console/render.ts | 4 ++-- lib/plugins/filter/new_post_path.ts | 4 ++-- lib/plugins/generator/asset.ts | 6 +++--- test/scripts/hexo/hexo.js | 2 +- 9 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/hexo/load_database.ts b/lib/hexo/load_database.ts index 112afcda17..c64719c929 100644 --- a/lib/hexo/load_database.ts +++ b/lib/hexo/load_database.ts @@ -1,4 +1,4 @@ -import fs from 'hexo-fs'; +import { exists, unlink } from 'hexo-fs'; import Promise from 'bluebird'; export = ctx => { @@ -8,7 +8,7 @@ export = ctx => { const { path } = db.options; const { log } = ctx; - return fs.exists(path).then(exist => { + return exists(path).then(exist => { if (!exist) return; log.debug('Loading database.'); @@ -17,6 +17,6 @@ export = ctx => { ctx._dbLoaded = true; }).catch(() => { log.error('Database load failed. Deleting database.'); - return fs.unlink(path); + return unlink(path); }); }; diff --git a/lib/hexo/multi_config_path.ts b/lib/hexo/multi_config_path.ts index 062610bdf7..9578c1ed1a 100644 --- a/lib/hexo/multi_config_path.ts +++ b/lib/hexo/multi_config_path.ts @@ -1,5 +1,5 @@ import {isAbsolute, resolve, join, extname} from 'path'; -import fs from 'hexo-fs'; +import { existsSync, readFileSync, writeFileSync } from 'hexo-fs'; import yml from 'js-yaml'; import {deepMerge} from 'hexo-util'; @@ -20,7 +20,7 @@ export = ctx => function multiConfigPath(base, configPaths, outputDir) { // only one config let configPath = isAbsolute(configPaths) ? configPaths : resolve(base, configPaths); - if (!fs.existsSync(configPath)) { + if (!existsSync(configPath)) { log.w(`Config file ${configPaths} not found, using default.`); configPath = defaultPath; } @@ -36,13 +36,13 @@ export = ctx => function multiConfigPath(base, configPaths, outputDir) { for (let i = 0; i < numPaths; i++) { const configPath = isAbsolute(paths[i]) ? paths[i] : join(base, paths[i]); - if (!fs.existsSync(configPath)) { + if (!existsSync(configPath)) { log.w(`Config file ${paths[i]} not found.`); continue; } // files read synchronously to ensure proper overwrite order - const file = fs.readFileSync(configPath); + const file = readFileSync(configPath); const ext = extname(paths[i]).toLowerCase(); if (ext === '.yml') { @@ -68,7 +68,7 @@ export = ctx => function multiConfigPath(base, configPaths, outputDir) { log.d(`Writing _multiconfig.yml to ${outputPath}`); - fs.writeFileSync(outputPath, yml.dump(combinedConfig)); + writeFileSync(outputPath, yml.dump(combinedConfig)); // write file and return path return outputPath; diff --git a/lib/hexo/update_package.ts b/lib/hexo/update_package.ts index 95c5dfb6dd..f57776b626 100644 --- a/lib/hexo/update_package.ts +++ b/lib/hexo/update_package.ts @@ -1,5 +1,5 @@ import {join} from 'path'; -import fs from 'hexo-fs'; +import { writeFile, exists, readFile } from 'hexo-fs'; export = ctx => { const pkgPath = join(ctx.base_dir, 'package.json'); @@ -14,15 +14,15 @@ export = ctx => { pkg.hexo.version = ctx.version; ctx.log.debug('Updating package.json'); - return fs.writeFile(pkgPath, JSON.stringify(pkg, null, ' ')); + return writeFile(pkgPath, JSON.stringify(pkg, null, ' ')); }); }; function readPkg(path) { - return fs.exists(path).then(exist => { + return exists(path).then(exist => { if (!exist) return; - return fs.readFile(path).then(content => { + return readFile(path).then(content => { const pkg = JSON.parse(content as string); if (typeof pkg.hexo !== 'object') return; diff --git a/lib/plugins/console/clean.ts b/lib/plugins/console/clean.ts index 8016b58ebd..fb799039d8 100644 --- a/lib/plugins/console/clean.ts +++ b/lib/plugins/console/clean.ts @@ -1,5 +1,5 @@ import Promise from 'bluebird'; -import fs from 'hexo-fs'; +import { exists, unlink, rmdir } from 'hexo-fs'; function cleanConsole(args) { return Promise.all([ @@ -12,10 +12,10 @@ function cleanConsole(args) { function deleteDatabase(ctx) { const dbPath = ctx.database.options.path; - return fs.exists(dbPath).then(exist => { + return exists(dbPath).then(exist => { if (!exist) return; - return fs.unlink(dbPath).then(() => { + return unlink(dbPath).then(() => { ctx.log.info('Deleted database.'); }); }); @@ -24,10 +24,10 @@ function deleteDatabase(ctx) { function deletePublicDir(ctx) { const publicDir = ctx.public_dir; - return fs.exists(publicDir).then(exist => { + return exists(publicDir).then(exist => { if (!exist) return; - return fs.rmdir(publicDir).then(() => { + return rmdir(publicDir).then(() => { ctx.log.info('Deleted public folder.'); }); }); diff --git a/lib/plugins/console/config.ts b/lib/plugins/console/config.ts index ac65d22862..506a978d36 100644 --- a/lib/plugins/console/config.ts +++ b/lib/plugins/console/config.ts @@ -1,5 +1,5 @@ import yaml from 'js-yaml'; -import fs from 'hexo-fs'; +import { exists, writeFile } from 'hexo-fs'; import {extname} from 'path'; import Promise from 'bluebird'; @@ -21,7 +21,7 @@ function configConsole(args) { const configPath = this.config_path; const ext = extname(configPath); - return fs.exists(configPath).then(exist => { + return exists(configPath).then(exist => { if (!exist) return {}; return this.render.render({path: configPath}); }).then(config => { @@ -31,7 +31,7 @@ function configConsole(args) { const result = ext === '.json' ? JSON.stringify(config) : yaml.dump(config); - return fs.writeFile(configPath, result); + return writeFile(configPath, result); }); } diff --git a/lib/plugins/console/render.ts b/lib/plugins/console/render.ts index dd293f400a..0c3ec979bc 100644 --- a/lib/plugins/console/render.ts +++ b/lib/plugins/console/render.ts @@ -1,7 +1,7 @@ import {resolve} from 'path'; import tildify from 'tildify'; import prettyHrtime from 'pretty-hrtime'; -import fs from 'hexo-fs'; +import { writeFile } from 'hexo-fs'; import {cyan, magenta} from 'picocolors'; function renderConsole(args) { @@ -34,7 +34,7 @@ function renderConsole(args) { const interval = prettyHrtime(process.hrtime(start)); log.info('Rendered in %s: %s -> %s', cyan(interval), magenta(tildify(src)), magenta(tildify(dest))); - return fs.writeFile(dest, result); + return writeFile(dest, result); }); } diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index 708e3444dd..b88681d064 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -2,7 +2,7 @@ import {join, extname} from 'path'; import moment from 'moment'; import Promise from 'bluebird'; import {createSha1Hash, Permalink} from 'hexo-util'; -import fs from 'hexo-fs'; +import { ensurePath } from 'hexo-fs'; let permalink; const reservedKeys = { @@ -99,7 +99,7 @@ function newPostPathFilter(data: Data = {}, replace) { return Promise.resolve(target); } - return fs.ensurePath(target); + return ensurePath(target); } export = newPostPathFilter; diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index 4710b238bc..86ae818d1c 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -1,4 +1,4 @@ -import fs from 'hexo-fs'; +import { exists, createReadStream } from 'hexo-fs'; import Promise from 'bluebird'; import {extname} from 'path'; import { magenta } from 'picocolors'; @@ -11,7 +11,7 @@ interface Data { const process = (name, ctx) => { // @ts-expect-error - return Promise.filter(ctx.model(name).toArray(), (asset: warehouse['Schema']) => fs.exists(asset.source).tap(exist => { + return Promise.filter(ctx.model(name).toArray(), (asset: warehouse['Schema']) => exists(asset.source).tap(exist => { // @ts-expect-error if (!exist) return asset.remove(); })).map((asset: warehouse['Schema']) => { @@ -38,7 +38,7 @@ const process = (name, ctx) => { ctx.log.error({err}, 'Asset render failed: %s', magenta(path)); }); } else { - data.data = () => fs.createReadStream(source); + data.data = () => createReadStream(source); } return { path, data }; diff --git a/test/scripts/hexo/hexo.js b/test/scripts/hexo/hexo.js index 5be487c27d..b039ec1fb0 100644 --- a/test/scripts/hexo/hexo.js +++ b/test/scripts/hexo/hexo.js @@ -48,7 +48,7 @@ describe('Hexo', () => { /* eslint-disable no-path-concat */ hexo.core_dir.should.eql(coreDir + sep); - hexo.lib_dir.should.eql(join(coreDir, 'lib') + sep); + hexo.lib_dir.should.eql(join(coreDir, 'dist') + sep); hexo.version.should.eql(version); hexo.base_dir.should.eql(__dirname + sep); hexo.public_dir.should.eql(join(__dirname, 'public') + sep); From 4d365b18215585a095dcabd4aa8ce8b7a1d578c2 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 7 Mar 2023 11:14:29 +0800 Subject: [PATCH 36/45] fix hexo-i18n and hexo-log --- lib/plugins/renderer/yaml.ts | 4 ++-- lib/theme/index.ts | 2 +- package.json | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/plugins/renderer/yaml.ts b/lib/plugins/renderer/yaml.ts index 22eab69800..43f2eb77e3 100644 --- a/lib/plugins/renderer/yaml.ts +++ b/lib/plugins/renderer/yaml.ts @@ -1,6 +1,6 @@ import yaml from 'js-yaml'; import {escape} from 'hexo-front-matter'; -const log = require('hexo-log')(); +import logger from 'hexo-log'; let schema = {}; // FIXME: workaround for https://github.com/hexojs/hexo/issues/4917 @@ -8,7 +8,7 @@ try { schema = yaml.DEFAULT_SCHEMA.extend(require('js-yaml-js-types').all); } catch (e) { if (e instanceof yaml.YAMLException) { - log.warn('YAMLException: please see https://github.com/hexojs/hexo/issues/4917'); + logger().warn('YAMLException: please see https://github.com/hexojs/hexo/issues/4917'); } else { throw e; } diff --git a/lib/theme/index.ts b/lib/theme/index.ts index 3d6dfb1259..2c9d6233f8 100644 --- a/lib/theme/index.ts +++ b/lib/theme/index.ts @@ -27,7 +27,7 @@ class Theme extends Box { view ]; - let languages = ctx.config.language; + let languages: string | string[] = ctx.config.language; if (!Array.isArray(languages)) languages = [languages]; diff --git a/package.json b/package.json index 1d5eb756f2..ccd1689662 100644 --- a/package.json +++ b/package.json @@ -49,8 +49,8 @@ "hexo-cli": "^4.3.0", "hexo-front-matter": "^4.0.0", "hexo-fs": "^4.1.1", - "hexo-i18n": "^1.0.0", - "hexo-log": "^3.2.0", + "hexo-i18n": "^2.0.0", + "hexo-log": "^4.0.1", "hexo-util": "^3.0.1", "js-yaml": "^4.1.0", "js-yaml-js-types": "^1.0.0", From 755212aadb2492b14c7b0505c3a3cc6fc7d9dc01 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 7 Mar 2023 11:37:29 +0800 Subject: [PATCH 37/45] fix param order --- lib/extend/tag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index 8757de6b70..5eda91ae28 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -90,7 +90,7 @@ class NunjucksAsyncTag extends NunjucksTag { return new nodes.CallExtensionAsync(this, 'run', node, []); } - run(context, args, body, callback) { + run(context, args, callback) { return this._run(context, args, '').then(result => { callback(null, result); }, callback); From 4c717d25cf4be66758733b88cf3598dc5efc6e93 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 7 Mar 2023 23:35:55 +0800 Subject: [PATCH 38/45] build hexo in benchmark --- test/benchmark.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/benchmark.js b/test/benchmark.js index f22a830605..744393d1a2 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -176,6 +176,9 @@ async function init() { if (await exists(resolve(testDir, 'node_modules'))) await rmdir(resolve(testDir, 'node_modules')); await spawnAsync(npmScript, ['install', '--silent'], { cwd: testDir }); + log.info('Build hexo'); + await spawnAsync(npmScript, ['run', 'build'], { cwd: testDir }); + log.info('Replacing hexo'); await rmdir(resolve(testDir, 'node_modules', 'hexo')); From fc1ecf47442d237a782a96c6e97395f4c29edd5c Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Tue, 7 Mar 2023 23:49:31 +0800 Subject: [PATCH 39/45] fix eslint --- .eslintrc.json | 4 +++- lib/plugins/processor/common.ts | 2 +- lib/theme/processors/config.ts | 6 +++--- lib/theme/processors/i18n.ts | 6 +++--- lib/theme/processors/source.ts | 7 +++---- lib/theme/processors/view.ts | 6 +++--- test/benchmark.js | 2 +- 7 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index d82fdaa6b1..98a0b413b2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,6 +6,8 @@ "ecmaVersion": 2020 }, "rules": { - "@typescript-eslint/no-explicit-any": 0 + "@typescript-eslint/no-explicit-any": 0, + "@typescript-eslint/no-var-requires": 0, + "node/no-missing-require": 0 } } diff --git a/lib/plugins/processor/common.ts b/lib/plugins/processor/common.ts index 272b910446..7c8378f5ae 100644 --- a/lib/plugins/processor/common.ts +++ b/lib/plugins/processor/common.ts @@ -25,7 +25,7 @@ function isExcludedFile(path, config) { return false; } -export var ignoreTmpAndHiddenFile = new Pattern(path => { +export const ignoreTmpAndHiddenFile = new Pattern(path => { if (isTmpFile(path) || isHiddenFile(path)) return false; return true; }); diff --git a/lib/theme/processors/config.ts b/lib/theme/processors/config.ts index 7d4288eb0f..77183dc899 100644 --- a/lib/theme/processors/config.ts +++ b/lib/theme/processors/config.ts @@ -18,6 +18,6 @@ function process(file) { const pattern = new Pattern(/^_config\.\w+$/); export const config = { - pattern: pattern, - process: process -} + pattern, + process +}; diff --git a/lib/theme/processors/i18n.ts b/lib/theme/processors/i18n.ts index f6172f4b4d..a222123027 100644 --- a/lib/theme/processors/i18n.ts +++ b/lib/theme/processors/i18n.ts @@ -21,6 +21,6 @@ function process(file) { const pattern = new Pattern('languages/*path'); export const i18n = { - pattern: pattern, - process: process -} \ No newline at end of file + pattern, + process +}; diff --git a/lib/theme/processors/source.ts b/lib/theme/processors/source.ts index 52bde14059..aa3a4a94b8 100644 --- a/lib/theme/processors/source.ts +++ b/lib/theme/processors/source.ts @@ -31,8 +31,7 @@ const pattern = new Pattern(path => { return {path}; }); - export const source = { - pattern: pattern, - process: process -} \ No newline at end of file + pattern, + process +}; diff --git a/lib/theme/processors/view.ts b/lib/theme/processors/view.ts index 600295a8c3..c4011564e2 100644 --- a/lib/theme/processors/view.ts +++ b/lib/theme/processors/view.ts @@ -16,6 +16,6 @@ function process(file) { const pattern = new Pattern('layout/*path'); export const view = { - pattern: pattern, - process: process -} \ No newline at end of file + pattern, + process +}; diff --git a/test/benchmark.js b/test/benchmark.js index 744393d1a2..134fa2449b 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -177,7 +177,7 @@ async function init() { await spawnAsync(npmScript, ['install', '--silent'], { cwd: testDir }); log.info('Build hexo'); - await spawnAsync(npmScript, ['run', 'build'], { cwd: testDir }); + await spawnAsync(npmScript, ['run', 'build']); log.info('Replacing hexo'); await rmdir(resolve(testDir, 'node_modules', 'hexo')); From fd690a5f93453978cb582dff61355e262cf04357 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 8 Mar 2023 00:07:31 +0800 Subject: [PATCH 40/45] fix export & drop travis --- package.json | 8 ++------ test/benchmark.js | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index ccd1689662..f432d1f283 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "hexo", "version": "6.3.0", "description": "A fast, simple & powerful blog framework, powered by Node.js.", - "main": "lib/hexo", + "main": "dist/hexo", "bin": { "hexo": "./bin/hexo" }, @@ -16,12 +16,8 @@ "test-cov": "c8 --reporter=lcovonly npm test -- --no-parallel", "prepare": "husky install" }, - "directories": { - "lib": "./lib", - "bin": "./bin" - }, "files": [ - "lib/", + "dist/", "bin/" ], "repository": "hexojs/hexo", diff --git a/test/benchmark.js b/test/benchmark.js index 134fa2449b..148fd5d71e 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -22,9 +22,7 @@ const isWin32 = require('os').platform() === 'win32'; const npmScript = isWin32 ? 'npm.cmd' : 'npm'; const testDir = resolve('.tmp-hexo-theme-unit-test'); -const zeroEksDir = process.env.TRAVIS_BUILD_DIR - ? join(process.env.TRAVIS_BUILD_DIR, '0x') - : resolve(testDir, '0x'); +const zeroEksDir = resolve(testDir, '0x'); const hexoBin = resolve(testDir, 'node_modules/.bin/hexo'); const isGitHubActions = process.env.GITHUB_ACTIONS; From 87216dbc0f13c732513d13ced83c7d52eec78c26 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 8 Mar 2023 00:11:42 +0800 Subject: [PATCH 41/45] Update .husky/pre-commit --- .husky/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index d5b5fd41c7..36af219892 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -#npx lint-staged +npx lint-staged From 36f3f8bf199278dd8e6999f451364414855dd8a8 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Wed, 8 Mar 2023 00:15:08 +0800 Subject: [PATCH 42/45] add spaces --- lib/box/file.ts | 2 +- lib/box/index.ts | 12 ++++++------ lib/extend/injector.ts | 2 +- lib/extend/processor.ts | 2 +- lib/extend/renderer.ts | 2 +- lib/extend/tag.ts | 6 +++--- lib/hexo/index.ts | 12 ++++++------ lib/hexo/load_config.ts | 8 ++++---- lib/hexo/load_plugins.ts | 6 +++--- lib/hexo/load_theme_config.ts | 8 ++++---- lib/hexo/locals.ts | 2 +- lib/hexo/multi_config_path.ts | 4 ++-- lib/hexo/post.ts | 12 ++++++------ lib/hexo/render.ts | 4 ++-- lib/hexo/router.ts | 2 +- lib/hexo/scaffold.ts | 4 ++-- lib/hexo/update_package.ts | 2 +- lib/models/asset.ts | 2 +- lib/models/category.ts | 2 +- lib/models/page.ts | 4 ++-- lib/models/post.ts | 4 ++-- lib/models/post_asset.ts | 2 +- lib/models/tag.ts | 2 +- lib/models/types/moment.ts | 2 +- lib/plugins/console/config.ts | 2 +- lib/plugins/console/deploy.ts | 4 ++-- lib/plugins/console/generate.ts | 10 +++++----- lib/plugins/console/list/category.ts | 4 ++-- lib/plugins/console/list/page.ts | 4 ++-- lib/plugins/console/list/post.ts | 4 ++-- lib/plugins/console/list/tag.ts | 4 ++-- lib/plugins/console/migrate.ts | 2 +- lib/plugins/console/new.ts | 2 +- lib/plugins/console/publish.ts | 2 +- lib/plugins/console/render.ts | 4 ++-- .../filter/after_post_render/external_link.ts | 2 +- lib/plugins/filter/after_render/external_link.ts | 2 +- lib/plugins/filter/new_post_path.ts | 4 ++-- lib/plugins/filter/post_permalink.ts | 4 ++-- lib/plugins/filter/template_locals/i18n.ts | 2 +- lib/plugins/generator/asset.ts | 2 +- lib/plugins/helper/css.ts | 2 +- lib/plugins/helper/debug.ts | 2 +- lib/plugins/helper/favicon_tag.ts | 2 +- lib/plugins/helper/feed_tag.ts | 2 +- lib/plugins/helper/format.ts | 2 +- lib/plugins/helper/fragment_cache.ts | 2 +- lib/plugins/helper/full_url_for.ts | 2 +- lib/plugins/helper/gravatar.ts | 2 +- lib/plugins/helper/image_tag.ts | 2 +- lib/plugins/helper/js.ts | 2 +- lib/plugins/helper/link_to.ts | 2 +- lib/plugins/helper/list_archives.ts | 4 ++-- lib/plugins/helper/list_categories.ts | 2 +- lib/plugins/helper/list_posts.ts | 2 +- lib/plugins/helper/list_tags.ts | 2 +- lib/plugins/helper/mail_to.ts | 2 +- lib/plugins/helper/open_graph.ts | 4 ++-- lib/plugins/helper/paginator.ts | 2 +- lib/plugins/helper/partial.ts | 2 +- lib/plugins/helper/relative_url.ts | 2 +- lib/plugins/helper/tagcloud.ts | 2 +- lib/plugins/helper/toc.ts | 2 +- lib/plugins/helper/url_for.ts | 2 +- lib/plugins/processor/asset.ts | 10 +++++----- lib/plugins/processor/common.ts | 2 +- lib/plugins/processor/data.ts | 4 ++-- lib/plugins/processor/post.ts | 12 ++++++------ lib/plugins/renderer/nunjucks.ts | 4 ++-- lib/plugins/renderer/yaml.ts | 2 +- lib/plugins/tag/asset_img.ts | 2 +- lib/plugins/tag/asset_link.ts | 2 +- lib/plugins/tag/asset_path.ts | 2 +- lib/plugins/tag/code.ts | 2 +- lib/plugins/tag/iframe.ts | 2 +- lib/plugins/tag/img.ts | 2 +- lib/plugins/tag/include_code.ts | 4 ++-- lib/plugins/tag/link.ts | 2 +- lib/plugins/tag/post_link.ts | 4 ++-- lib/plugins/tag/post_path.ts | 4 ++-- lib/theme/index.ts | 2 +- lib/theme/processors/config.ts | 2 +- lib/theme/processors/i18n.ts | 4 ++-- lib/theme/processors/source.ts | 2 +- lib/theme/view.ts | 4 ++-- 85 files changed, 145 insertions(+), 145 deletions(-) diff --git a/lib/box/file.ts b/lib/box/file.ts index e9321355af..6171e430d6 100644 --- a/lib/box/file.ts +++ b/lib/box/file.ts @@ -1,4 +1,4 @@ -import {readFile, readFileSync, stat, statSync} from 'hexo-fs'; +import { readFile, readFileSync, stat, statSync } from 'hexo-fs'; class File { public source: any; diff --git a/lib/box/index.ts b/lib/box/index.ts index b3a16687d8..5dceb37784 100644 --- a/lib/box/index.ts +++ b/lib/box/index.ts @@ -1,11 +1,11 @@ -import {join, sep} from 'path'; +import { join, sep } from 'path'; import BlueBirdPromise from 'bluebird'; import File from './file'; -import {Pattern, createSha1Hash} from 'hexo-util'; -import {createReadStream, readdir, stat, watch} from 'hexo-fs'; -import {magenta} from 'picocolors'; -import {EventEmitter} from 'events'; -import {isMatch, makeRe} from 'micromatch'; +import { Pattern, createSha1Hash } from 'hexo-util'; +import { createReadStream, readdir, stat, watch } from 'hexo-fs'; +import { magenta } from 'picocolors'; +import { EventEmitter } from 'events'; +import { isMatch, makeRe } from 'micromatch'; const defaultPattern = new Pattern(() => ({})); diff --git a/lib/extend/injector.ts b/lib/extend/injector.ts index cb073fe916..7802152efd 100644 --- a/lib/extend/injector.ts +++ b/lib/extend/injector.ts @@ -1,4 +1,4 @@ -import {Cache} from 'hexo-util'; +import { Cache } from 'hexo-util'; class Injector { public store: any; diff --git a/lib/extend/processor.ts b/lib/extend/processor.ts index a5a024efc8..b3bcb8e544 100644 --- a/lib/extend/processor.ts +++ b/lib/extend/processor.ts @@ -1,5 +1,5 @@ import Promise from 'bluebird'; -import {Pattern} from 'hexo-util'; +import { Pattern } from 'hexo-util'; class Processor { public store: any; diff --git a/lib/extend/renderer.ts b/lib/extend/renderer.ts index c4105a910c..e2782dfdba 100644 --- a/lib/extend/renderer.ts +++ b/lib/extend/renderer.ts @@ -1,4 +1,4 @@ -import {extname} from 'path'; +import { extname } from 'path'; import Promise from 'bluebird'; const getExtname = str => { diff --git a/lib/extend/tag.ts b/lib/extend/tag.ts index 5eda91ae28..b2bcd2fcfd 100644 --- a/lib/extend/tag.ts +++ b/lib/extend/tag.ts @@ -1,6 +1,6 @@ -import {stripIndent} from 'hexo-util'; -import {cyan, magenta, red, bold} from 'picocolors'; -import {Environment} from 'nunjucks'; +import { stripIndent } from 'hexo-util'; +import { cyan, magenta, red, bold } from 'picocolors'; +import { Environment } from 'nunjucks'; import Promise from 'bluebird'; const rSwigRawFullBlock = /{% *raw *%}/; const rCodeTag = /]*>[\s\S]+?<\/code>/g; diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index 302747f178..eb041289e2 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -1,12 +1,12 @@ import Promise from 'bluebird'; -import {sep, join, dirname} from 'path'; +import { sep, join, dirname } from 'path'; import tildify from 'tildify'; import Database from 'warehouse'; -import {magenta, underline} from 'picocolors'; -import {EventEmitter} from 'events'; -import {readFile} from 'hexo-fs'; +import { magenta, underline } from 'picocolors'; +import { EventEmitter } from 'events'; +import { readFile } from 'hexo-fs'; import Module from 'module'; -import {runInThisContext} from 'vm'; +import { runInThisContext } from 'vm'; const {version} = require('../../package.json'); import logger from 'hexo-log'; @@ -35,7 +35,7 @@ import Locals from './locals'; import defaultConfig from './default_config'; import loadDatabase from './load_database'; import multiConfigPath from './multi_config_path'; -import {deepMerge, full_url_for} from 'hexo-util'; +import { deepMerge, full_url_for } from 'hexo-util'; let resolveSync; // = require('resolve'); const libDir = dirname(__dirname); diff --git a/lib/hexo/load_config.ts b/lib/hexo/load_config.ts index 0ca2fb478b..231e285f02 100644 --- a/lib/hexo/load_config.ts +++ b/lib/hexo/load_config.ts @@ -1,10 +1,10 @@ -import {sep, resolve, join, parse} from 'path'; +import { sep, resolve, join, parse } from 'path'; import tildify from 'tildify'; import Theme from '../theme'; import Source from './source'; -import {exists, readdir} from 'hexo-fs'; -import {magenta} from 'picocolors'; -import {deepMerge} from 'hexo-util'; +import { exists, readdir } from 'hexo-fs'; +import { magenta } from 'picocolors'; +import { deepMerge } from 'hexo-util'; import validateConfig from './validate_config'; export = async ctx => { diff --git a/lib/hexo/load_plugins.ts b/lib/hexo/load_plugins.ts index c3daf8814f..c1dcb29067 100644 --- a/lib/hexo/load_plugins.ts +++ b/lib/hexo/load_plugins.ts @@ -1,7 +1,7 @@ -import {join} from 'path'; -import {exists, readFile, listDir} from 'hexo-fs'; +import { join } from 'path'; +import { exists, readFile, listDir } from 'hexo-fs'; import Promise from 'bluebird'; -import {magenta} from 'picocolors'; +import { magenta } from 'picocolors'; export = ctx => { if (!ctx.env.init || ctx.env.safe) return; diff --git a/lib/hexo/load_theme_config.ts b/lib/hexo/load_theme_config.ts index 8377d8bf31..57a28adb41 100644 --- a/lib/hexo/load_theme_config.ts +++ b/lib/hexo/load_theme_config.ts @@ -1,8 +1,8 @@ -import {join, parse} from 'path'; +import { join, parse } from 'path'; import tildify from 'tildify'; -import {exists, readdir} from 'hexo-fs'; -import {magenta} from 'picocolors'; -import {deepMerge} from 'hexo-util'; +import { exists, readdir } from 'hexo-fs'; +import { magenta } from 'picocolors'; +import { deepMerge } from 'hexo-util'; export = ctx => { if (!ctx.env.init) return; diff --git a/lib/hexo/locals.ts b/lib/hexo/locals.ts index bab6240b8b..468dabe26f 100644 --- a/lib/hexo/locals.ts +++ b/lib/hexo/locals.ts @@ -1,4 +1,4 @@ -import {Cache} from 'hexo-util'; +import { Cache } from 'hexo-util'; class Locals { public cache: any; diff --git a/lib/hexo/multi_config_path.ts b/lib/hexo/multi_config_path.ts index 9578c1ed1a..8d140d3569 100644 --- a/lib/hexo/multi_config_path.ts +++ b/lib/hexo/multi_config_path.ts @@ -1,7 +1,7 @@ -import {isAbsolute, resolve, join, extname} from 'path'; +import { isAbsolute, resolve, join, extname } from 'path'; import { existsSync, readFileSync, writeFileSync } from 'hexo-fs'; import yml from 'js-yaml'; -import {deepMerge} from 'hexo-util'; +import { deepMerge } from 'hexo-util'; export = ctx => function multiConfigPath(base, configPaths, outputDir) { const { log } = ctx; diff --git a/lib/hexo/post.ts b/lib/hexo/post.ts index 563d3fb524..6eda66cc90 100644 --- a/lib/hexo/post.ts +++ b/lib/hexo/post.ts @@ -1,12 +1,12 @@ import assert from 'assert'; import moment from 'moment'; import Promise from 'bluebird'; -import {join, extname, basename} from 'path'; -import {magenta} from 'picocolors'; -import {load} from 'js-yaml'; -import {slugize, escapeRegExp} from 'hexo-util'; -import {copyDir, exists, listDir, mkdirs, readFile, rmdir, unlink, writeFile} from 'hexo-fs'; -import {parse as yfmParse, split as yfmSplit, stringify as yfmStringify} from 'hexo-front-matter'; +import { join, extname, basename } from 'path'; +import { magenta } from 'picocolors'; +import { load } from 'js-yaml'; +import { slugize, escapeRegExp } from 'hexo-util'; +import { copyDir, exists, listDir, mkdirs, readFile, rmdir, unlink, writeFile } from 'hexo-fs'; +import { parse as yfmParse, split as yfmSplit, stringify as yfmStringify } from 'hexo-front-matter'; const preservedKeys = ['title', 'slug', 'path', 'layout', 'date', 'content']; const rHexoPostRenderEscape = /([\s\S]+?)<\/hexoPostRenderCodeBlock>/g; diff --git a/lib/hexo/render.ts b/lib/hexo/render.ts index b95f7c7ec6..a25d152314 100644 --- a/lib/hexo/render.ts +++ b/lib/hexo/render.ts @@ -1,6 +1,6 @@ -import {extname} from 'path'; +import { extname } from 'path'; import Promise from 'bluebird'; -import {readFile, readFileSync} from 'hexo-fs'; +import { readFile, readFileSync } from 'hexo-fs'; const getExtname = str => { if (typeof str !== 'string') return ''; diff --git a/lib/hexo/router.ts b/lib/hexo/router.ts index 3b4ae8db20..f00824d381 100644 --- a/lib/hexo/router.ts +++ b/lib/hexo/router.ts @@ -1,4 +1,4 @@ -import {EventEmitter} from 'events'; +import { EventEmitter } from 'events'; import Promise from 'bluebird'; import Stream from 'stream'; const { Readable } = Stream; diff --git a/lib/hexo/scaffold.ts b/lib/hexo/scaffold.ts index 1ccdb49ecd..18a1a5ff41 100644 --- a/lib/hexo/scaffold.ts +++ b/lib/hexo/scaffold.ts @@ -1,5 +1,5 @@ -import {extname, join} from 'path'; -import {exists, listDir, readFile, unlink, writeFile} from 'hexo-fs'; +import { extname, join } from 'path'; +import { exists, listDir, readFile, unlink, writeFile } from 'hexo-fs'; class Scaffold { public context: any; diff --git a/lib/hexo/update_package.ts b/lib/hexo/update_package.ts index f57776b626..03319913e6 100644 --- a/lib/hexo/update_package.ts +++ b/lib/hexo/update_package.ts @@ -1,4 +1,4 @@ -import {join} from 'path'; +import { join } from 'path'; import { writeFile, exists, readFile } from 'hexo-fs'; export = ctx => { diff --git a/lib/models/asset.ts b/lib/models/asset.ts index 4345769a93..006391d3b5 100644 --- a/lib/models/asset.ts +++ b/lib/models/asset.ts @@ -1,5 +1,5 @@ import warehouse from 'warehouse'; -import {join} from 'path'; +import { join } from 'path'; export = ctx => { const Asset = new warehouse.Schema({ diff --git a/lib/models/category.ts b/lib/models/category.ts index aedd5dd5e9..740bc67015 100644 --- a/lib/models/category.ts +++ b/lib/models/category.ts @@ -1,5 +1,5 @@ import warehouse from 'warehouse'; -import {slugize, full_url_for} from 'hexo-util'; +import { slugize, full_url_for } from 'hexo-util'; export = ctx => { const Category = new warehouse.Schema({ diff --git a/lib/models/page.ts b/lib/models/page.ts index 7bdd77d0d6..bbaa606422 100644 --- a/lib/models/page.ts +++ b/lib/models/page.ts @@ -1,8 +1,8 @@ import warehouse from 'warehouse'; -import {join} from 'path'; +import { join } from 'path'; import Moment from './types/moment'; import moment from 'moment'; -import {full_url_for} from 'hexo-util'; +import { full_url_for } from 'hexo-util'; export = ctx => { const Page = new warehouse.Schema({ diff --git a/lib/models/post.ts b/lib/models/post.ts index c1643a06f9..60695323ec 100644 --- a/lib/models/post.ts +++ b/lib/models/post.ts @@ -1,9 +1,9 @@ import warehouse from 'warehouse'; import moment from 'moment'; -import {extname, join, sep} from 'path'; +import { extname, join, sep } from 'path'; import Promise from 'bluebird'; import Moment from './types/moment'; -import {full_url_for} from 'hexo-util'; +import { full_url_for } from 'hexo-util'; function pickID(data) { return data._id; diff --git a/lib/models/post_asset.ts b/lib/models/post_asset.ts index 9d6c218f69..72ec5f90f1 100644 --- a/lib/models/post_asset.ts +++ b/lib/models/post_asset.ts @@ -1,5 +1,5 @@ import warehouse from 'warehouse'; -import {join} from 'path'; +import { join } from 'path'; export = ctx => { const PostAsset = new warehouse.Schema({ diff --git a/lib/models/tag.ts b/lib/models/tag.ts index 8da4fe35ef..9c5b10a55e 100644 --- a/lib/models/tag.ts +++ b/lib/models/tag.ts @@ -1,5 +1,5 @@ import warehouse from 'warehouse'; -import {slugize, full_url_for} from 'hexo-util'; +import { slugize, full_url_for } from 'hexo-util'; const { hasOwnProperty: hasOwn } = Object.prototype; export = ctx => { diff --git a/lib/models/types/moment.ts b/lib/models/types/moment.ts index b710420a64..c8402806d5 100644 --- a/lib/models/types/moment.ts +++ b/lib/models/types/moment.ts @@ -1,5 +1,5 @@ import warehouse from 'warehouse'; -import {moment, toMomentLocale} from '../../plugins/helper/date'; +import { moment, toMomentLocale } from '../../plugins/helper/date'; declare module 'moment' { export default interface Moment extends moment.Moment { diff --git a/lib/plugins/console/config.ts b/lib/plugins/console/config.ts index 506a978d36..841c241c23 100644 --- a/lib/plugins/console/config.ts +++ b/lib/plugins/console/config.ts @@ -1,6 +1,6 @@ import yaml from 'js-yaml'; import { exists, writeFile } from 'hexo-fs'; -import {extname} from 'path'; +import { extname } from 'path'; import Promise from 'bluebird'; function configConsole(args) { diff --git a/lib/plugins/console/deploy.ts b/lib/plugins/console/deploy.ts index b443b7c155..c6483790d0 100644 --- a/lib/plugins/console/deploy.ts +++ b/lib/plugins/console/deploy.ts @@ -1,5 +1,5 @@ -import {exists} from 'hexo-fs'; -import {underline, magenta} from 'picocolors'; +import { exists } from 'hexo-fs'; +import { underline, magenta } from 'picocolors'; function deployConsole(args) { let config = this.config.deploy; diff --git a/lib/plugins/console/generate.ts b/lib/plugins/console/generate.ts index 6014429a0e..ccae2b3d94 100644 --- a/lib/plugins/console/generate.ts +++ b/lib/plugins/console/generate.ts @@ -1,11 +1,11 @@ -import {exists, writeFile, unlink, stat, mkdirs} from 'hexo-fs'; -import {join} from 'path'; +import { exists, writeFile, unlink, stat, mkdirs } from 'hexo-fs'; +import { join } from 'path'; import Promise from 'bluebird'; import prettyHrtime from 'pretty-hrtime'; -import {cyan, magenta} from 'picocolors'; +import { cyan, magenta } from 'picocolors'; import tildify from 'tildify'; -import {PassThrough} from 'stream'; -import {createSha1Hash} from 'hexo-util'; +import { PassThrough } from 'stream'; +import { createSha1Hash } from 'hexo-util'; class Generater { public context: any; diff --git a/lib/plugins/console/list/category.ts b/lib/plugins/console/list/category.ts index 82adbf5b4f..0044ec3a0e 100644 --- a/lib/plugins/console/list/category.ts +++ b/lib/plugins/console/list/category.ts @@ -1,6 +1,6 @@ -import {underline} from 'picocolors'; +import { underline } from 'picocolors'; import table from 'text-table'; -import {stringLength} from './common'; +import { stringLength } from './common'; function listCategory() { const categories = this.model('Category'); diff --git a/lib/plugins/console/list/page.ts b/lib/plugins/console/list/page.ts index 51ec2665de..d132231450 100644 --- a/lib/plugins/console/list/page.ts +++ b/lib/plugins/console/list/page.ts @@ -1,6 +1,6 @@ -import {magenta, underline, gray} from 'picocolors'; +import { magenta, underline, gray } from 'picocolors'; import table from 'text-table'; -import {stringLength} from './common'; +import { stringLength } from './common'; function listPage() { const Page = this.model('Page'); diff --git a/lib/plugins/console/list/post.ts b/lib/plugins/console/list/post.ts index e361feabb4..e4dca1a578 100644 --- a/lib/plugins/console/list/post.ts +++ b/lib/plugins/console/list/post.ts @@ -1,6 +1,6 @@ -import {gray, magenta, underline} from 'picocolors'; +import { gray, magenta, underline } from 'picocolors'; import table from 'text-table'; -import {stringLength} from './common'; +import { stringLength } from './common'; function mapName(item) { return item.name; diff --git a/lib/plugins/console/list/tag.ts b/lib/plugins/console/list/tag.ts index 040b2c1ee1..09c0a148df 100644 --- a/lib/plugins/console/list/tag.ts +++ b/lib/plugins/console/list/tag.ts @@ -1,6 +1,6 @@ -import {magenta, underline} from 'picocolors'; +import { magenta, underline } from 'picocolors'; import table from 'text-table'; -import {stringLength} from './common'; +import { stringLength } from './common'; function listTag() { const Tag = this.model('Tag'); diff --git a/lib/plugins/console/migrate.ts b/lib/plugins/console/migrate.ts index 337b48ad65..df341f6ed4 100644 --- a/lib/plugins/console/migrate.ts +++ b/lib/plugins/console/migrate.ts @@ -1,4 +1,4 @@ -import {underline, magenta} from 'picocolors'; +import { underline, magenta } from 'picocolors'; function migrateConsole(args) { // Display help message if user didn't input any arguments diff --git a/lib/plugins/console/new.ts b/lib/plugins/console/new.ts index aecfd059b1..becbe1c625 100644 --- a/lib/plugins/console/new.ts +++ b/lib/plugins/console/new.ts @@ -1,5 +1,5 @@ import tildify from 'tildify'; -import {magenta} from 'picocolors'; +import { magenta } from 'picocolors'; import { basename } from 'path'; const reservedKeys = { diff --git a/lib/plugins/console/publish.ts b/lib/plugins/console/publish.ts index a0945d1a7d..f73d87ec55 100644 --- a/lib/plugins/console/publish.ts +++ b/lib/plugins/console/publish.ts @@ -1,5 +1,5 @@ import tildify from 'tildify'; -import {magenta} from 'picocolors'; +import { magenta } from 'picocolors'; function publishConsole(args) { // Display help message if user didn't input any arguments diff --git a/lib/plugins/console/render.ts b/lib/plugins/console/render.ts index 0c3ec979bc..01cb57c581 100644 --- a/lib/plugins/console/render.ts +++ b/lib/plugins/console/render.ts @@ -1,8 +1,8 @@ -import {resolve} from 'path'; +import { resolve } from 'path'; import tildify from 'tildify'; import prettyHrtime from 'pretty-hrtime'; import { writeFile } from 'hexo-fs'; -import {cyan, magenta} from 'picocolors'; +import { cyan, magenta } from 'picocolors'; function renderConsole(args) { // Display help message if user didn't input any arguments diff --git a/lib/plugins/filter/after_post_render/external_link.ts b/lib/plugins/filter/after_post_render/external_link.ts index 3c2cf66f4d..0b116de8b4 100644 --- a/lib/plugins/filter/after_post_render/external_link.ts +++ b/lib/plugins/filter/after_post_render/external_link.ts @@ -1,4 +1,4 @@ -import {isExternalLink} from 'hexo-util'; +import { isExternalLink } from 'hexo-util'; let EXTERNAL_LINK_POST_ENABLED = true; const rATag = /]+?\s+?)href=["']((?:https?:|\/\/)[^<>"']+)["'][^<>]*>/gi; const rTargetAttr = /target=/i; diff --git a/lib/plugins/filter/after_render/external_link.ts b/lib/plugins/filter/after_render/external_link.ts index 82b8d7e405..a5d7218133 100644 --- a/lib/plugins/filter/after_render/external_link.ts +++ b/lib/plugins/filter/after_render/external_link.ts @@ -1,4 +1,4 @@ -import {isExternalLink} from 'hexo-util'; +import { isExternalLink } from 'hexo-util'; let EXTERNAL_LINK_SITE_ENABLED = true; const rATag = /]+?\s+?)href=["']((?:https?:|\/\/)[^<>"']+)["'][^<>]*>/gi; diff --git a/lib/plugins/filter/new_post_path.ts b/lib/plugins/filter/new_post_path.ts index b88681d064..c06b946230 100644 --- a/lib/plugins/filter/new_post_path.ts +++ b/lib/plugins/filter/new_post_path.ts @@ -1,7 +1,7 @@ -import {join, extname} from 'path'; +import { join, extname } from 'path'; import moment from 'moment'; import Promise from 'bluebird'; -import {createSha1Hash, Permalink} from 'hexo-util'; +import { createSha1Hash, Permalink } from 'hexo-util'; import { ensurePath } from 'hexo-fs'; let permalink; diff --git a/lib/plugins/filter/post_permalink.ts b/lib/plugins/filter/post_permalink.ts index 90846ab42b..c715e67b5d 100644 --- a/lib/plugins/filter/post_permalink.ts +++ b/lib/plugins/filter/post_permalink.ts @@ -1,5 +1,5 @@ -import {createSha1Hash, Permalink, slugize} from 'hexo-util'; -import {basename} from 'path'; +import { createSha1Hash, Permalink, slugize } from 'hexo-util'; +import { basename } from 'path'; let permalink; function postPermalinkFilter(data) { diff --git a/lib/plugins/filter/template_locals/i18n.ts b/lib/plugins/filter/template_locals/i18n.ts index 36cad04058..73367d8df0 100644 --- a/lib/plugins/filter/template_locals/i18n.ts +++ b/lib/plugins/filter/template_locals/i18n.ts @@ -1,4 +1,4 @@ -import {Pattern} from 'hexo-util'; +import { Pattern } from 'hexo-util'; function i18nLocalsFilter(locals) { const { i18n } = this.theme; diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index 86ae818d1c..eed0951814 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -1,6 +1,6 @@ import { exists, createReadStream } from 'hexo-fs'; import Promise from 'bluebird'; -import {extname} from 'path'; +import { extname } from 'path'; import { magenta } from 'picocolors'; import warehouse from 'warehouse'; diff --git a/lib/plugins/helper/css.ts b/lib/plugins/helper/css.ts index db0d4c654c..b7a86f5524 100644 --- a/lib/plugins/helper/css.ts +++ b/lib/plugins/helper/css.ts @@ -1,4 +1,4 @@ -import {htmlTag, url_for} from 'hexo-util'; +import { htmlTag, url_for } from 'hexo-util'; import moize from 'moize'; function cssHelper(...args) { diff --git a/lib/plugins/helper/debug.ts b/lib/plugins/helper/debug.ts index 59cda3d42a..ba4a96983f 100644 --- a/lib/plugins/helper/debug.ts +++ b/lib/plugins/helper/debug.ts @@ -1,4 +1,4 @@ -import {inspect} from 'util'; +import { inspect } from 'util'; // this format object as string, resolves circular reference function inspectObject(object, options) { diff --git a/lib/plugins/helper/favicon_tag.ts b/lib/plugins/helper/favicon_tag.ts index 212552a497..579c04379a 100644 --- a/lib/plugins/helper/favicon_tag.ts +++ b/lib/plugins/helper/favicon_tag.ts @@ -1,4 +1,4 @@ -import {url_for} from 'hexo-util'; +import { url_for } from 'hexo-util'; function faviconTagHelper(path) { return ``; diff --git a/lib/plugins/helper/feed_tag.ts b/lib/plugins/helper/feed_tag.ts index 9d40521138..8fccfc7738 100644 --- a/lib/plugins/helper/feed_tag.ts +++ b/lib/plugins/helper/feed_tag.ts @@ -1,4 +1,4 @@ -import {url_for} from 'hexo-util'; +import { url_for } from 'hexo-util'; import moize from 'moize'; const feedFn = (str = '') => { diff --git a/lib/plugins/helper/format.ts b/lib/plugins/helper/format.ts index a66a848526..c9372b507e 100644 --- a/lib/plugins/helper/format.ts +++ b/lib/plugins/helper/format.ts @@ -1,4 +1,4 @@ -import {stripHTML, wordWrap, truncate, escapeHTML} from 'hexo-util'; +import { stripHTML, wordWrap, truncate, escapeHTML } from 'hexo-util'; import titlecase from 'titlecase'; export {stripHTML as strip_html}; export {stripHTML}; diff --git a/lib/plugins/helper/fragment_cache.ts b/lib/plugins/helper/fragment_cache.ts index 84fa85104e..1c38229e0c 100644 --- a/lib/plugins/helper/fragment_cache.ts +++ b/lib/plugins/helper/fragment_cache.ts @@ -1,5 +1,5 @@ -import {Cache} from 'hexo-util'; +import { Cache } from 'hexo-util'; export = ctx => { const cache = new Cache(); diff --git a/lib/plugins/helper/full_url_for.ts b/lib/plugins/helper/full_url_for.ts index 4c9272a848..4e77338082 100644 --- a/lib/plugins/helper/full_url_for.ts +++ b/lib/plugins/helper/full_url_for.ts @@ -1,5 +1,5 @@ -import {full_url_for} from 'hexo-util'; +import { full_url_for } from 'hexo-util'; export = function(path) { return full_url_for.call(this, path); diff --git a/lib/plugins/helper/gravatar.ts b/lib/plugins/helper/gravatar.ts index 235bde9b6e..5500335216 100644 --- a/lib/plugins/helper/gravatar.ts +++ b/lib/plugins/helper/gravatar.ts @@ -1,2 +1,2 @@ -import {gravatar} from 'hexo-util'; +import { gravatar } from 'hexo-util'; export = gravatar; diff --git a/lib/plugins/helper/image_tag.ts b/lib/plugins/helper/image_tag.ts index dd07c553e5..402c6e3714 100644 --- a/lib/plugins/helper/image_tag.ts +++ b/lib/plugins/helper/image_tag.ts @@ -1,4 +1,4 @@ -import {htmlTag, url_for} from 'hexo-util'; +import { htmlTag, url_for } from 'hexo-util'; interface Options { src?: string; diff --git a/lib/plugins/helper/js.ts b/lib/plugins/helper/js.ts index c9ab8a33f5..120d1738bb 100644 --- a/lib/plugins/helper/js.ts +++ b/lib/plugins/helper/js.ts @@ -1,4 +1,4 @@ -import {htmlTag, url_for} from 'hexo-util'; +import { htmlTag, url_for } from 'hexo-util'; import moize from 'moize'; function jsHelper(...args) { diff --git a/lib/plugins/helper/link_to.ts b/lib/plugins/helper/link_to.ts index df0d0e6b9a..cb0792d172 100644 --- a/lib/plugins/helper/link_to.ts +++ b/lib/plugins/helper/link_to.ts @@ -1,4 +1,4 @@ -import {htmlTag, url_for} from 'hexo-util'; +import { htmlTag, url_for } from 'hexo-util'; interface Options { href?: string; diff --git a/lib/plugins/helper/list_archives.ts b/lib/plugins/helper/list_archives.ts index 9b88b1f834..2572a25cb7 100644 --- a/lib/plugins/helper/list_archives.ts +++ b/lib/plugins/helper/list_archives.ts @@ -1,5 +1,5 @@ -import {toMomentLocale} from './date'; -import {url_for} from 'hexo-util'; +import { toMomentLocale } from './date'; +import { url_for } from 'hexo-util'; interface Options { format?: string; diff --git a/lib/plugins/helper/list_categories.ts b/lib/plugins/helper/list_categories.ts index e0c4630826..ff248d6bf3 100644 --- a/lib/plugins/helper/list_categories.ts +++ b/lib/plugins/helper/list_categories.ts @@ -1,4 +1,4 @@ -import {url_for} from 'hexo-util'; +import { url_for } from 'hexo-util'; function listCategoriesHelper(categories, options) { if (!options && (!categories || !Object.prototype.hasOwnProperty.call(categories, 'length'))) { diff --git a/lib/plugins/helper/list_posts.ts b/lib/plugins/helper/list_posts.ts index a15bf9c222..a3d9b9b5ca 100644 --- a/lib/plugins/helper/list_posts.ts +++ b/lib/plugins/helper/list_posts.ts @@ -1,4 +1,4 @@ -import {url_for} from 'hexo-util'; +import { url_for } from 'hexo-util'; function listPostsHelper(posts, options) { if (!options && (!posts || !Object.prototype.hasOwnProperty.call(posts, 'length'))) { diff --git a/lib/plugins/helper/list_tags.ts b/lib/plugins/helper/list_tags.ts index 1ced1dd53a..b7b0d0b523 100644 --- a/lib/plugins/helper/list_tags.ts +++ b/lib/plugins/helper/list_tags.ts @@ -1,4 +1,4 @@ -import {url_for, escapeHTML} from 'hexo-util'; +import { url_for, escapeHTML } from 'hexo-util'; import moize from 'moize'; function listTagsHelper(tags, options?) { diff --git a/lib/plugins/helper/mail_to.ts b/lib/plugins/helper/mail_to.ts index 2f71c25b1d..90f9ef88c9 100644 --- a/lib/plugins/helper/mail_to.ts +++ b/lib/plugins/helper/mail_to.ts @@ -1,4 +1,4 @@ -import {htmlTag} from 'hexo-util'; +import { htmlTag } from 'hexo-util'; import moize from 'moize'; interface Options { diff --git a/lib/plugins/helper/open_graph.ts b/lib/plugins/helper/open_graph.ts index c90fc7f294..9209eeda63 100644 --- a/lib/plugins/helper/open_graph.ts +++ b/lib/plugins/helper/open_graph.ts @@ -1,5 +1,5 @@ -import {isMoment, isDate} from 'moment'; -import {encodeURL, prettyUrls, stripHTML, escapeHTML} from 'hexo-util'; +import { isMoment, isDate } from 'moment'; +import { encodeURL, prettyUrls, stripHTML, escapeHTML } from 'hexo-util'; import moize from 'moize'; const localeMap = { diff --git a/lib/plugins/helper/paginator.ts b/lib/plugins/helper/paginator.ts index a181231386..83a12ff2c1 100644 --- a/lib/plugins/helper/paginator.ts +++ b/lib/plugins/helper/paginator.ts @@ -1,4 +1,4 @@ -import {htmlTag, url_for} from 'hexo-util'; +import { htmlTag, url_for } from 'hexo-util'; const createLink = (options, ctx) => { const { base, format } = options; diff --git a/lib/plugins/helper/partial.ts b/lib/plugins/helper/partial.ts index 180615e516..d548a58ba9 100644 --- a/lib/plugins/helper/partial.ts +++ b/lib/plugins/helper/partial.ts @@ -1,4 +1,4 @@ -import {dirname, join} from 'path'; +import { dirname, join } from 'path'; interface Options { cache?: boolean | string; diff --git a/lib/plugins/helper/relative_url.ts b/lib/plugins/helper/relative_url.ts index 55601901c7..631a9946fd 100644 --- a/lib/plugins/helper/relative_url.ts +++ b/lib/plugins/helper/relative_url.ts @@ -1,4 +1,4 @@ -import {relative_url} from 'hexo-util'; +import { relative_url } from 'hexo-util'; export = function(from, to) { return relative_url(from, to); diff --git a/lib/plugins/helper/tagcloud.ts b/lib/plugins/helper/tagcloud.ts index 4f57a8a24b..0b9a58d0b0 100644 --- a/lib/plugins/helper/tagcloud.ts +++ b/lib/plugins/helper/tagcloud.ts @@ -1,4 +1,4 @@ -import {Color, url_for} from 'hexo-util'; +import { Color, url_for } from 'hexo-util'; import moize from 'moize'; function tagcloudHelper(tags, options?) { diff --git a/lib/plugins/helper/toc.ts b/lib/plugins/helper/toc.ts index 42e5b1dca6..4abec4d30b 100644 --- a/lib/plugins/helper/toc.ts +++ b/lib/plugins/helper/toc.ts @@ -1,4 +1,4 @@ -import {tocObj, escapeHTML, encodeURL} from 'hexo-util'; +import { tocObj, escapeHTML, encodeURL } from 'hexo-util'; interface Options { min_depth?: number; diff --git a/lib/plugins/helper/url_for.ts b/lib/plugins/helper/url_for.ts index 6893c10379..49e7a5f124 100644 --- a/lib/plugins/helper/url_for.ts +++ b/lib/plugins/helper/url_for.ts @@ -1,4 +1,4 @@ -import {url_for} from 'hexo-util'; +import { url_for } from 'hexo-util'; export = function(path, options) { return url_for.call(this, path, options); diff --git a/lib/plugins/processor/asset.ts b/lib/plugins/processor/asset.ts index 370efd0ae6..9693bbaeb5 100644 --- a/lib/plugins/processor/asset.ts +++ b/lib/plugins/processor/asset.ts @@ -1,9 +1,9 @@ -import {timezone, toDate, isExcludedFile, isMatch} from './common'; +import { timezone, toDate, isExcludedFile, isMatch } from './common'; import Promise from 'bluebird'; -import {parse as yfm} from 'hexo-front-matter'; -import {extname, relative} from 'path'; -import {Pattern} from 'hexo-util'; -import {magenta} from 'picocolors'; +import { parse as yfm } from 'hexo-front-matter'; +import { extname, relative } from 'path'; +import { Pattern } from 'hexo-util'; +import { magenta } from 'picocolors'; export = ctx => { return { diff --git a/lib/plugins/processor/common.ts b/lib/plugins/processor/common.ts index 7c8378f5ae..c981536598 100644 --- a/lib/plugins/processor/common.ts +++ b/lib/plugins/processor/common.ts @@ -1,4 +1,4 @@ -import {Pattern} from 'hexo-util'; +import { Pattern } from 'hexo-util'; import moment from 'moment-timezone'; import micromatch from 'micromatch'; diff --git a/lib/plugins/processor/data.ts b/lib/plugins/processor/data.ts index 6070c4d8bd..7757e7c99c 100644 --- a/lib/plugins/processor/data.ts +++ b/lib/plugins/processor/data.ts @@ -1,5 +1,5 @@ -import {Pattern} from 'hexo-util'; -import {extname} from 'path'; +import { Pattern } from 'hexo-util'; +import { extname } from 'path'; export = ctx => ({ pattern: new Pattern('_data/*path'), diff --git a/lib/plugins/processor/post.ts b/lib/plugins/processor/post.ts index 803bce3cb8..dca6306e62 100644 --- a/lib/plugins/processor/post.ts +++ b/lib/plugins/processor/post.ts @@ -1,10 +1,10 @@ -import {toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch} from './common'; +import { toDate, timezone, isExcludedFile, isTmpFile, isHiddenFile, isMatch } from './common'; import Promise from 'bluebird'; -import {parse as yfm} from 'hexo-front-matter'; -import {extname, join} from 'path'; -import {stat, listDir} from 'hexo-fs'; -import {slugize, Pattern, Permalink} from 'hexo-util'; -import {magenta} from 'picocolors'; +import { parse as yfm } from 'hexo-front-matter'; +import { extname, join } from 'path'; +import { stat, listDir } from 'hexo-fs'; +import { slugize, Pattern, Permalink } from 'hexo-util'; +import { magenta } from 'picocolors'; const postDir = '_posts/'; const draftDir = '_drafts/'; diff --git a/lib/plugins/renderer/nunjucks.ts b/lib/plugins/renderer/nunjucks.ts index fb46526ead..be6cfc1781 100644 --- a/lib/plugins/renderer/nunjucks.ts +++ b/lib/plugins/renderer/nunjucks.ts @@ -1,7 +1,7 @@ import nunjucks from 'nunjucks'; -import {readFileSync} from 'hexo-fs'; -import {dirname} from 'path'; +import { readFileSync } from 'hexo-fs'; +import { dirname } from 'path'; function toArray(value) { if (Array.isArray(value)) { diff --git a/lib/plugins/renderer/yaml.ts b/lib/plugins/renderer/yaml.ts index 43f2eb77e3..a8f0af4a34 100644 --- a/lib/plugins/renderer/yaml.ts +++ b/lib/plugins/renderer/yaml.ts @@ -1,5 +1,5 @@ import yaml from 'js-yaml'; -import {escape} from 'hexo-front-matter'; +import { escape } from 'hexo-front-matter'; import logger from 'hexo-log'; let schema = {}; diff --git a/lib/plugins/tag/asset_img.ts b/lib/plugins/tag/asset_img.ts index 7fefcc59a1..e608b499ff 100644 --- a/lib/plugins/tag/asset_img.ts +++ b/lib/plugins/tag/asset_img.ts @@ -1,5 +1,5 @@ import img from './img'; -import {encodeURL} from 'hexo-util'; +import { encodeURL } from 'hexo-util'; /** * Asset image tag diff --git a/lib/plugins/tag/asset_link.ts b/lib/plugins/tag/asset_link.ts index b4c007c73a..eb07087625 100644 --- a/lib/plugins/tag/asset_link.ts +++ b/lib/plugins/tag/asset_link.ts @@ -1,4 +1,4 @@ -import {encodeURL, escapeHTML} from 'hexo-util'; +import { encodeURL, escapeHTML } from 'hexo-util'; /** * Asset link tag diff --git a/lib/plugins/tag/asset_path.ts b/lib/plugins/tag/asset_path.ts index ce68cda497..7242e3ce73 100644 --- a/lib/plugins/tag/asset_path.ts +++ b/lib/plugins/tag/asset_path.ts @@ -1,4 +1,4 @@ -import {encodeURL} from 'hexo-util'; +import { encodeURL } from 'hexo-util'; /** * Asset path tag diff --git a/lib/plugins/tag/code.ts b/lib/plugins/tag/code.ts index cd7e07bd0e..266bda70e2 100644 --- a/lib/plugins/tag/code.ts +++ b/lib/plugins/tag/code.ts @@ -1,6 +1,6 @@ // Based on: https://raw.github.com/imathis/octopress/master/plugins/code_block.rb -import {escapeHTML} from 'hexo-util'; +import { escapeHTML } from 'hexo-util'; const rCaptionUrlTitle = /(\S[\S\s]*)\s+(https?:\/\/\S+)\s+(.+)/i; const rCaptionUrl = /(\S[\S\s]*)\s+(https?:\/\/\S+)/i; diff --git a/lib/plugins/tag/iframe.ts b/lib/plugins/tag/iframe.ts index 83be5b80dd..f1e6b2663d 100644 --- a/lib/plugins/tag/iframe.ts +++ b/lib/plugins/tag/iframe.ts @@ -1,4 +1,4 @@ -import {htmlTag} from 'hexo-util'; +import { htmlTag } from 'hexo-util'; /** * Iframe tag diff --git a/lib/plugins/tag/img.ts b/lib/plugins/tag/img.ts index 694f67cf5b..22e4970020 100644 --- a/lib/plugins/tag/img.ts +++ b/lib/plugins/tag/img.ts @@ -1,4 +1,4 @@ -import {htmlTag, url_for} from 'hexo-util'; +import { htmlTag, url_for } from 'hexo-util'; const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/; const rMetaDoubleQuote = /"?([^"]+)?"?/; diff --git a/lib/plugins/tag/include_code.ts b/lib/plugins/tag/include_code.ts index f752fa5901..8457c75294 100644 --- a/lib/plugins/tag/include_code.ts +++ b/lib/plugins/tag/include_code.ts @@ -1,5 +1,5 @@ -import {exists, readFile} from 'hexo-fs'; -import {basename, extname, join, posix} from 'path'; +import { exists, readFile } from 'hexo-fs'; +import { basename, extname, join, posix } from 'path'; const rCaptionTitleFile = /(.*)?(?:\s+|^)(\/*\S+)/; const rLang = /\s*lang:(\w+)/i; diff --git a/lib/plugins/tag/link.ts b/lib/plugins/tag/link.ts index c383ea3e19..0df202b574 100644 --- a/lib/plugins/tag/link.ts +++ b/lib/plugins/tag/link.ts @@ -1,4 +1,4 @@ -import {htmlTag} from 'hexo-util'; +import { htmlTag } from 'hexo-util'; const rUrl = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=+$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[+~%/.\w-_]*)?\??(?:[-+=&;%@.\w_]*)#?(?:[.!/\\w]*))?)/; diff --git a/lib/plugins/tag/post_link.ts b/lib/plugins/tag/post_link.ts index c90c49505c..4460cef8fe 100644 --- a/lib/plugins/tag/post_link.ts +++ b/lib/plugins/tag/post_link.ts @@ -1,5 +1,5 @@ -import {encodeURL, escapeHTML} from 'hexo-util'; -import {postFindOneFactory} from './'; +import { encodeURL, escapeHTML } from 'hexo-util'; +import { postFindOneFactory } from './'; /** * Post link tag diff --git a/lib/plugins/tag/post_path.ts b/lib/plugins/tag/post_path.ts index 201c73c1b1..e9aec212f2 100644 --- a/lib/plugins/tag/post_path.ts +++ b/lib/plugins/tag/post_path.ts @@ -1,5 +1,5 @@ -import {encodeURL} from 'hexo-util'; -import {postFindOneFactory} from './'; +import { encodeURL } from 'hexo-util'; +import { postFindOneFactory } from './'; /** * Post path tag diff --git a/lib/theme/index.ts b/lib/theme/index.ts index 2c9d6233f8..d37cd281b5 100644 --- a/lib/theme/index.ts +++ b/lib/theme/index.ts @@ -1,4 +1,4 @@ -import {extname} from 'path'; +import { extname } from 'path'; import Box from '../box'; import View from './view'; import I18n from 'hexo-i18n'; diff --git a/lib/theme/processors/config.ts b/lib/theme/processors/config.ts index 77183dc899..64f65e2c28 100644 --- a/lib/theme/processors/config.ts +++ b/lib/theme/processors/config.ts @@ -1,4 +1,4 @@ -import {Pattern} from 'hexo-util'; +import { Pattern } from 'hexo-util'; function process(file) { if (file.type === 'delete') { diff --git a/lib/theme/processors/i18n.ts b/lib/theme/processors/i18n.ts index a222123027..ce955eb8a4 100644 --- a/lib/theme/processors/i18n.ts +++ b/lib/theme/processors/i18n.ts @@ -1,5 +1,5 @@ -import {Pattern} from 'hexo-util'; -import {extname} from 'path'; +import { Pattern } from 'hexo-util'; +import { extname } from 'path'; function process(file) { const { path } = file.params; diff --git a/lib/theme/processors/source.ts b/lib/theme/processors/source.ts index aa3a4a94b8..40915fae47 100644 --- a/lib/theme/processors/source.ts +++ b/lib/theme/processors/source.ts @@ -1,4 +1,4 @@ -import {Pattern} from 'hexo-util'; +import { Pattern } from 'hexo-util'; import * as common from '../../plugins/processor/common'; function process(file) { diff --git a/lib/theme/view.ts b/lib/theme/view.ts index e7cfdd357d..241005f871 100644 --- a/lib/theme/view.ts +++ b/lib/theme/view.ts @@ -1,5 +1,5 @@ -import {dirname, extname, join} from 'path'; -import {parse as yfm} from 'hexo-front-matter'; +import { dirname, extname, join } from 'path'; +import { parse as yfm } from 'hexo-front-matter'; import Promise from 'bluebird'; const assignIn = (target, ...sources) => { From 1d54103012f4d85cb397d0510f1cf2ed3dbdbc51 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Mar 2023 06:48:52 +0800 Subject: [PATCH 43/45] refactor: ts debounce fn --- lib/hexo/index.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index eb041289e2..63d3a77070 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -93,14 +93,12 @@ const createLoadThemeRoute = function(generatorResult, locals, ctx) { }; }; -function debounce(func, wait) { - let timeout; +function debounce(func: () => void, wait: number) { + let timeout: NodeJS.Timeout; return function() { - const context = this; - const args = arguments; clearTimeout(timeout); timeout = setTimeout(() => { - func.apply(context, args); + func.apply(this); }, wait); }; } From a7d0eb6c402fa033633d780385815913726e31e7 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Mar 2023 06:59:58 +0800 Subject: [PATCH 44/45] fix: lint errors --- lib/hexo/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index 63d3a77070..f1d11e99d4 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -121,8 +121,8 @@ interface Query { declare module 'module' { function _nodeModulePaths(path: string): string[]; function _resolveFilename(request: string, parent: Module, isMain?: any, options?: any): string; - const _extensions: NodeJS.RequireExtensions; - const _cache: any; + const _extensions: NodeJS.RequireExtensions, + _cache: any; } class Hexo extends EventEmitter { @@ -351,7 +351,7 @@ class Hexo extends EventEmitter { } } - loadPlugin(path: string, callback: Function) { + loadPlugin(path: string, callback: (...args: any[]) => any) { return readFile(path).then(script => { // Based on: https://github.com/joyent/node/blob/v0.10.33/src/node.js#L516 const module = new Module(path); From 2749b23406d47c5a8d13cb3e95991e3440dbb435 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Sat, 11 Mar 2023 16:41:08 +0800 Subject: [PATCH 45/45] fix: lint errors --- lib/hexo/index.ts | 3 ++- lib/models/types/moment.ts | 1 + lib/plugins/console/deploy.ts | 1 + lib/plugins/generator/asset.ts | 1 + lib/theme/view.ts | 2 ++ test/benchmark.js | 2 +- 6 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/hexo/index.ts b/lib/hexo/index.ts index f1d11e99d4..023f78f81d 100644 --- a/lib/hexo/index.ts +++ b/lib/hexo/index.ts @@ -122,7 +122,7 @@ declare module 'module' { function _nodeModulePaths(path: string): string[]; function _resolveFilename(request: string, parent: Module, isMain?: any, options?: any): string; const _extensions: NodeJS.RequireExtensions, - _cache: any; + _cache: any; } class Hexo extends EventEmitter { @@ -325,6 +325,7 @@ class Hexo extends EventEmitter { const c = this.extend.console.get(name); + // eslint-disable-next-line no-extra-parens if (c) return (Reflect.apply(c, this, [args]) as any).asCallback(callback); return Promise.reject(new Error(`Console \`${name}\` has not been registered yet!`)); } diff --git a/lib/models/types/moment.ts b/lib/models/types/moment.ts index c8402806d5..59a86e1479 100644 --- a/lib/models/types/moment.ts +++ b/lib/models/types/moment.ts @@ -4,6 +4,7 @@ import { moment, toMomentLocale } from '../../plugins/helper/date'; declare module 'moment' { export default interface Moment extends moment.Moment { _d: Date; + // eslint-disable-next-line semi } } diff --git a/lib/plugins/console/deploy.ts b/lib/plugins/console/deploy.ts index c6483790d0..6da32c2e76 100644 --- a/lib/plugins/console/deploy.ts +++ b/lib/plugins/console/deploy.ts @@ -48,6 +48,7 @@ function deployConsole(args) { this.log.info('Deploying: %s', magenta(type)); + // eslint-disable-next-line no-extra-parens return (Reflect.apply(deployers[type], this, [{ ...item, ...args }]) as any).then(() => { this.log.info('Deploy done: %s', magenta(type)); }); diff --git a/lib/plugins/generator/asset.ts b/lib/plugins/generator/asset.ts index eed0951814..b7dcb47a83 100644 --- a/lib/plugins/generator/asset.ts +++ b/lib/plugins/generator/asset.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ import { exists, createReadStream } from 'hexo-fs'; import Promise from 'bluebird'; import { extname } from 'path'; diff --git a/lib/theme/view.ts b/lib/theme/view.ts index 241005f871..f2b2234d4f 100644 --- a/lib/theme/view.ts +++ b/lib/theme/view.ts @@ -40,12 +40,14 @@ class View { this._precompile(); } + // eslint-disable-next-line @typescript-eslint/ban-types render(options: Options | Function = {}, callback) { if (!callback && typeof options === 'function') { callback = options; options = {}; } const { data } = this; + // eslint-disable-next-line no-extra-parens const { layout = (options as Options).layout } = data; const locals = this._buildLocals(options); diff --git a/test/benchmark.js b/test/benchmark.js index 148fd5d71e..e377b140b6 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -5,7 +5,7 @@ const { spawn } = require('child_process'); const { spawn: spawnAsync } = require('hexo-util'); const { rmdir, exists } = require('hexo-fs'); const { appendFileSync: appendFile } = require('fs'); -const { join, resolve } = require('path'); +const { resolve } = require('path'); const log = require('hexo-log').default(); const { red } = require('picocolors'); const hooks = [