Skip to content

Commit

Permalink
refactor: add prettier-plugin-organize-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhaenisch committed Feb 29, 2020
1 parent dae3cf8 commit 82e1834
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 30 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"husky": "4.2.1",
"nyc": "15.0.0",
"prettier": "1.19.1",
"prettier-plugin-organize-imports": "1.0.0",
"tap-xunit": "2.4.1",
"ts-node": "8.6.2",
"typescript": "3.7.5",
Expand Down
15 changes: 7 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
// --
// Packages

import path from 'path';
import arg from 'arg';
import chalk from 'chalk';
import Listr from 'listr';
import getStdin from 'get-stdin';
import getPort from 'get-port';
import { watch } from 'chokidar';

import getPort from 'get-port';
import getStdin from 'get-stdin';
import Listr from 'listr';
import path from 'path';
import { Config, defaultConfig } from './lib/config';
import { help } from './lib/help';
import { serveDirectory, closeServer } from './lib/serve-dir';
import { defaultConfig, Config } from './lib/config';
import { convertMdToPdf } from './lib/md-to-pdf';
import { setProcessAndTermTitle } from './lib/helpers';
import { convertMdToPdf } from './lib/md-to-pdf';
import { closeServer, serveDirectory } from './lib/serve-dir';

// --
// Configure CLI Arguments
Expand Down
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node

import getPort from 'get-port';

import { defaultConfig, Config } from './lib/config';
import { serveDirectory } from './lib/serve-dir';
import { convertMdToPdf } from './lib/md-to-pdf';
import { Config, defaultConfig } from './lib/config';
import { getDir } from './lib/helpers';
import { convertMdToPdf } from './lib/md-to-pdf';
import { serveDirectory } from './lib/serve-dir';

/**
* Convert a markdown file to PDF.
Expand Down
4 changes: 2 additions & 2 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolve } from 'path';
import { MarkedOptions } from 'marked';
import { PDFOptions, LaunchOptions } from 'puppeteer';
import { resolve } from 'path';
import { LaunchOptions, PDFOptions } from 'puppeteer';

export const defaultConfig: Config = {
basedir: process.cwd(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-html.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getMarked } from './get-marked-with-highlighter';
import { Config } from './config';
import { getMarked } from './get-marked-with-highlighter';

/**
* Generates a HTML document from a markdown string and returns it as a string.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-marked-with-highlighter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import marked, { MarkedOptions } from 'marked';
import { getLanguage, highlight } from 'highlight.js';
import marked, { MarkedOptions } from 'marked';

export const getMarked = (options: MarkedOptions) => {
const renderer = options.renderer || new marked.Renderer();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-output-file-path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse, join } from 'path';
import { join, parse } from 'path';

/**
* Derive the output file path from a source file.
Expand Down
9 changes: 3 additions & 6 deletions src/lib/read-file.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { promisify } from 'util';
import { readFile as fsReadFile } from 'fs';
import { promises as fs } from 'fs';
import iconv from 'iconv-lite';

const readFileAsync = promisify(fsReadFile);

/**
* Read a file synchronously with the given encoding, and return its content as a string.
* Read a file with the given encoding, and return its content as a string.
*
* Uses iconv-lite to solve some issues with Windows encodings.
*/
export const readFile = async (file: string, encoding: string = 'utf-8') =>
/utf-?8/i.test(encoding) ? readFileAsync(file, { encoding }) : iconv.decode(await readFileAsync(file), encoding);
/utf-?8/i.test(encoding) ? fs.readFile(file, { encoding }) : iconv.decode(await fs.readFile(file), encoding);
2 changes: 1 addition & 1 deletion src/test/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import test, { before } from 'ava';
import { execSync } from 'child_process';
import { readFileSync, unlinkSync } from 'fs';
import { join, resolve } from 'path';
import test, { before } from 'ava';

before(() => {
const filesToDelete = [
Expand Down
11 changes: 5 additions & 6 deletions src/test/lib.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { EOL } from 'os';
import { posix, sep, resolve } from 'path';
import test from 'ava';
import { Renderer } from 'marked';

import { setProcessAndTermTitle, getDir, getMarginObject } from '../lib/helpers';
import { EOL } from 'os';
import { posix, resolve, sep } from 'path';
import { defaultConfig } from '../lib/config';
import { getHtml } from '../lib/get-html';
import { getMarked } from '../lib/get-marked-with-highlighter';
import { getOutputFilePath } from '../lib/get-output-file-path';
import { readFile } from '../lib/read-file';
import { isMdFile } from '../lib/is-md-file';
import { getDir, getMarginObject, setProcessAndTermTitle } from '../lib/helpers';
import { isHttpUrl } from '../lib/is-http-url';
import { isMdFile } from '../lib/is-md-file';
import { readFile } from '../lib/read-file';

// --
// helpers
Expand Down

0 comments on commit 82e1834

Please sign in to comment.