Skip to content

Commit

Permalink
Better enforcement of typescript/linting rules + cleanup for compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrrrl committed Jul 1, 2021
1 parent 20a9f22 commit 928ef4e
Show file tree
Hide file tree
Showing 25 changed files with 564 additions and 253 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "./node_modules/gts/"
"extends": "./node_modules/gts/",
"rules": {
"@typescript-eslint/ban-ts-comment": 0
}
}
141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"scripts": {
"clean": "gts clean",
"compile": "babel --extensions '.ts,.js' --source-maps both -d lib/ src/",
"compile": "tsc && babel --extensions '.ts,.js' --source-maps both -d lib/ src/",
"prepublish": "npm run compile",
"exec": "npm run compile && node bin/md2gslides.js",
"test": "mocha --require ./test/register --timeout 5000 \"test/**/*.spec.ts\"",
Expand Down Expand Up @@ -87,17 +87,26 @@
"@babel/preset-env": "7.14.7",
"@babel/preset-typescript": "7.14.5",
"@babel/register": "7.14.5",
"@types/chai": "^4.2.19",
"@types/chai-as-promised": "^7.1.4",
"@types/chai-subset": "^1.3.3",
"@types/debug": "^4.1.5",
"@types/extend": "^3.0.1",
"@types/jsonfile": "^6.0.0",
"@types/lowdb": "1.0.10",
"@types/lowlight": "^0.0.2",
"@types/markdown-it": "12.0.2",
"@types/mkdirp": "^1.0.1",
"@types/mocha": "^8.2.2",
"@types/mock-fs": "^4.13.0",
"@types/node": "15.12.4",
"@types/parse-color": "^1.0.0",
"@types/parse5": "^6.0.0",
"@types/probe-image-size": "^7.0.0",
"@types/promise-retry": "^1.1.3",
"@types/request-promise-native": "^1.0.17",
"@types/sharp": "0.28.3",
"@types/tmp": "^0.2.0",
"@types/uuid": "^8.3.0",
"chai": "4.3.4",
"chai-as-promised": "7.1.1",
Expand Down
9 changes: 3 additions & 6 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,10 @@ export default class UserAuthorizer {
*
* This may block briefly to ensure the token file exists.
*
* @param {String} clientId Client ID
* @param {String} clientSecret Client secret
* @param {String} filePath Path to file where tokens are saved
* @param {UserAuthorizer~promptCallback} prompt Function to acquire the authorization code
* @param options
*/
public constructor(options: AuthOptions) {
this.db = this.initDbSync(options.filePath);
this.db = UserAuthorizer.initDbSync(options?.filePath);
this.clientId = options.clientId;
this.clientSecret = options.clientSecret;
this.prompt = options.prompt;
Expand Down Expand Up @@ -127,7 +124,7 @@ export default class UserAuthorizer {
* @returns {lowdb} database instance
* @private
*/
private initDbSync<T>(filePath: string): lowdb.LowdbSync<T> {
private static initDbSync<T>(filePath?: string): lowdb.LowdbSync<T> {
let adapter: lowdb.AdapterSync;
if (filePath) {
const parentDir = path.dirname(filePath);
Expand Down
5 changes: 4 additions & 1 deletion src/images/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import Debug from 'debug';
import renderSVG from './svg';
import renderMathJax from './/mathjax';
import {ImageDefinition} from '../slides';
import assert from 'assert';

const debug = Debug('md2gslides');

const renderers = {
const renderers: {[key: string]: (img: ImageDefinition) => Promise<String>} = {
svg: renderSVG,
math: renderMathJax,
};
Expand All @@ -37,6 +38,8 @@ async function maybeGenerateImage(
return image;
}

assert(image.type);

const imageType = image.type.trim().toLowerCase();

const renderer = renderers[imageType];
Expand Down
3 changes: 3 additions & 0 deletions src/images/mathjax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
// limitations under the License.

import Debug from 'debug';
// @ts-ignore
import mathJax from 'mathjax-node';
import renderSVG from './svg';
import {ImageDefinition} from '../slides';
import assert from 'assert';

const debug = Debug('md2gslides');
let mathJaxInitialized = false;
Expand Down Expand Up @@ -58,6 +60,7 @@ function addOrMergeStyles(svg: string, style?: string): string {

async function renderMathJax(image: ImageDefinition): Promise<string> {
debug('Generating math image: %O', image);
assert(image.source);
lazyInitMathJax();
const out = await mathJax.typeset({
math: image.source,
Expand Down
Loading

0 comments on commit 928ef4e

Please sign in to comment.