Skip to content

Commit

Permalink
Merge 228525d into 8c29937
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Oct 31, 2022
2 parents 8c29937 + 228525d commit 46ee88a
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
coverage/
tmp/
tmp/
dist/
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"extends": "hexo",
"root": true
"root": true,
"extends": "hexo/ts.js",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2020
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules/
tmp/
*.log
.idea/
coverage
coverage
dist
package-lock.json
13 changes: 9 additions & 4 deletions lib/i18n.js → lib/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
'use strict';
import { vsprintf } from 'sprintf-js';

const { vsprintf } = require('sprintf-js');
interface Options {
languages?: string[];
}

class i18n {
constructor(options = {}) {
data: object;
languages: string[];

constructor(options: Options = {}) {
this.data = {};
this.languages = options.languages || ['default'];

Expand Down Expand Up @@ -110,4 +115,4 @@ function flattenObject(data, obj = {}, parent = '') {
return obj;
}

module.exports = i18n;
export = i18n;
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
"name": "hexo-i18n",
"version": "1.0.0",
"description": "i18n module for Hexo.",
"main": "lib/i18n.js",
"main": "dist/i18n.js",
"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 run test"
},
"directories": {
"lib": "./lib"
},
"files": [
"lib/"
"dist/**"
],
"types": "./dist/front_matter.d.ts",
"engines": {
"node": ">=14"
},
Expand All @@ -30,10 +35,16 @@
"sprintf-js": "^1.1.2"
},
"devDependencies": {
"@types/node": "^18.11.8",
"@types/sprintf-js": "^1.1.2",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"c8": "^7.12.0",
"chai": "^4.3.4",
"eslint": "^8.6.0",
"chai": "^4.3.6",
"eslint": "^8.26.0",
"eslint-config-hexo": "^5.0.0",
"mocha": "^10.1.0"
"mocha": "^10.1.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
}
}
5 changes: 4 additions & 1 deletion test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "hexo/test"
"extends": "hexo/test",
"rules": {
"@typescript-eslint/no-var-requires": 0
}
}
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const should = require('chai').should();

describe('i18n', () => {
const Ctor = require('../lib/i18n');
const Ctor = require('../dist/i18n');

const i18n = new Ctor({
languages: ['zh-TW', 'en']
Expand Down
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"outDir": "dist",
"declaration": true,
"esModuleInterop": true,
"types": [
"node"
]
},
"include": [
"lib/i18n.ts"
],
"exclude": [
"node_modules"
]
}

0 comments on commit 46ee88a

Please sign in to comment.