Skip to content

Commit

Permalink
refactor: migrate typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Mar 11, 2023
1 parent 8bf2b69 commit 0913097
Show file tree
Hide file tree
Showing 140 changed files with 150 additions and 9 deletions.
5 changes: 5 additions & 0 deletions lib/box/file.js → lib/box/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 14 additions & 1 deletion lib/box/index.js → lib/box/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -100,7 +113,7 @@ class Box extends EventEmitter {
}));
}

process(callback) {
process(callback?) {
const { base, Cache, context: ctx } = this;

return stat(base).then(stats => {
Expand Down
3 changes: 3 additions & 0 deletions lib/extend/console.js → lib/extend/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import abbrev from 'abbrev';
*/

class Console {
public store: any;
public alias: any;

constructor() {
this.store = {};
this.alias = {};
Expand Down
2 changes: 2 additions & 0 deletions lib/extend/deployer.js → lib/extend/deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import Promise from 'bluebird';

class Deployer {
public store: any;

constructor() {
this.store = {};
}
Expand Down
2 changes: 2 additions & 0 deletions lib/extend/filter.js → lib/extend/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const typeAlias = {
};

class Filter {
public store: any;

constructor() {
this.store = {};
}
Expand Down
3 changes: 3 additions & 0 deletions lib/extend/generator.js → lib/extend/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import Promise from 'bluebird';

class Generator {
public id: any;
public store: any;

constructor() {
this.id = 0;
this.store = {};
Expand Down
2 changes: 2 additions & 0 deletions lib/extend/helper.js → lib/extend/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

class Helper {
public store: any;

constructor() {
this.store = {};
}
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions lib/extend/injector.js → lib/extend/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
2 changes: 2 additions & 0 deletions lib/extend/migrator.js → lib/extend/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import Promise from 'bluebird';

class Migrator {
public store: any;

constructor() {
this.store = {};
}
Expand Down
2 changes: 2 additions & 0 deletions lib/extend/processor.js → lib/extend/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Promise from 'bluebird';
import {Pattern} from 'hexo-util';

class Processor {
public store: any;

constructor() {
this.store = [];
}
Expand Down
5 changes: 4 additions & 1 deletion lib/extend/renderer.js → lib/extend/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const getExtname = str => {
};

class Renderer {
public store: any;
public storeSync: any;

constructor() {
this.store = {};
this.storeSync = {};
Expand All @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions lib/extend/tag.js → lib/extend/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const rCodeTag = /<code[^<>]*>[\s\S]+?<\/code>/g;
const escapeSwigTag = str => str.replace(/{/g, '&#123;').replace(/}/g, '&#125;');

class NunjucksTag {
public tags: any;
public fn: any;

constructor(name, fn) {
this.tags = [name];
this.fn = fn;
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions lib/hexo/index.js → lib/hexo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions lib/hexo/locals.js → lib/hexo/locals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import {Cache} from 'hexo-util';

class Locals {
public cache: any;
public getters: any;

constructor() {
this.cache = new Cache();
this.getters = {};
Expand Down
File renamed without changes.
10 changes: 9 additions & 1 deletion lib/hexo/post.js → lib/hexo/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const isNonWhiteSpaceChar = char => char !== '\r'
&& char !== ' ';

class PostRenderEscape {
public stored: any;
public length: any;

constructor() {
this.stored = [];
}
Expand Down Expand Up @@ -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;
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion lib/hexo/render.js → lib/hexo/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +46,7 @@ class Render {
return this.renderer.getOutput(path);
}

getRenderer(ext, sync) {
getRenderer(ext, sync?) {
return this.renderer.get(ext, sync);
}

Expand Down
9 changes: 9 additions & 0 deletions lib/hexo/router.js → lib/hexo/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -89,6 +95,9 @@ const _format = path => {
};

class Router extends EventEmitter {
public routes: any;
public emit: any;

constructor() {
super();

Expand Down
4 changes: 4 additions & 0 deletions lib/hexo/scaffold.js → lib/hexo/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions lib/models/types/moment.js → lib/models/types/moment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion lib/theme/index.js → lib/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions lib/theme/view.js → lib/theme/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0913097

Please sign in to comment.