diff --git a/src/utils/download.ts b/src/utils/download.ts index 94f6fd6..767f2e7 100644 --- a/src/utils/download.ts +++ b/src/utils/download.ts @@ -1,8 +1,8 @@ import GitlyOptions from '../interfaces/options' -import fetch from './fetch' import execute from './execute' import exists from './exists' +import fetch from './fetch' import { isOffline } from './offline' import parse from './parse' import { getFile, getUrl } from './tar' @@ -11,7 +11,6 @@ import { getFile, getUrl } from './tar' * Download the tar file from the repository * and store it in a temporary directory * @param repository The repository to download - * @param options * * @example * ```js @@ -23,7 +22,7 @@ import { getFile, getUrl } from './tar' export default async function download( repository: string, options: GitlyOptions = {} -) { +): Promise { const info = parse(repository, options) const file = getFile(info, options) const url = getUrl(info, options) diff --git a/src/utils/exists.ts b/src/utils/exists.ts index 93afde6..52310f0 100644 --- a/src/utils/exists.ts +++ b/src/utils/exists.ts @@ -6,13 +6,17 @@ import GitlyOptions from '../interfaces/options' import parse from './parse' import { getFile } from './tar' -export default async (path: string, options: GitlyOptions = {}) => { +export default async function exists( + path: string, + options: GitlyOptions = {} +): Promise { if (!isAbsolute(path)) { path = getFile(parse(path), options) } try { await fs.access(path, constants.F_OK) return true - } catch (_) { } + // eslint-disable-next-line no-empty + } catch (_) {} return false } diff --git a/src/utils/extract.ts b/src/utils/extract.ts index 0972fed..3873ecc 100644 --- a/src/utils/extract.ts +++ b/src/utils/extract.ts @@ -1,6 +1,5 @@ import { promises as fs } from 'fs' import { resolve } from 'path' -import { FileStat } from 'tar' import GitlyOptions from '../interfaces/options' @@ -16,16 +15,23 @@ const { mkdir } = fs * @param options * */ -export default async (source: string, destination: string, options: GitlyOptions = {}) => { +export default async ( + source: string, + destination: string, + options: GitlyOptions = {} +): Promise => { destination = resolve(destination) if (await exists(source, options)) { try { - let filter = (options.extract && options.extract.filter) ? options.extract.filter : - (_path: string, _stat: FileStat) => true + const filter = + options.extract && options.extract.filter + ? options.extract.filter + : () => true await mkdir(destination, { recursive: true }) await extract({ strip: 1, filter, file: source, cwd: destination }) return destination - } catch (_) { } + // eslint-disable-next-line no-empty + } catch (_) {} } return '' } diff --git a/src/utils/gitly.ts b/src/utils/gitly.ts index 825a4dc..4446c90 100644 --- a/src/utils/gitly.ts +++ b/src/utils/gitly.ts @@ -1,4 +1,5 @@ import GitlyOptions from '../interfaces/options' + import download from './download' import extract from './extract' @@ -6,7 +7,6 @@ import extract from './extract' * Downloads and extracts the repository * @param repository The repository to download * @param destination The destination to extract - * @param options * @returns A tuple with the source and destination respectively */ export default async function gitly( diff --git a/src/utils/offline.ts b/src/utils/offline.ts index 42cb2eb..d2eed70 100644 --- a/src/utils/offline.ts +++ b/src/utils/offline.ts @@ -4,6 +4,7 @@ export async function isOffline(): Promise { try { await lookup('google.com') return false - } catch (_) { } + // eslint-disable-next-line no-empty + } catch (_) {} return true } diff --git a/src/utils/parse.ts b/src/utils/parse.ts index f086ae8..0bc7a77 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -18,15 +18,15 @@ import URLInfo from '../interfaces/url' * ``` */ export default (url: string, options: GitlyOptions = {}): URLInfo => { - let { url: normalized, host } = normalizeURL(url, options) + const { url: normalized, host } = normalizeURL(url, options) // Parse the url const result = parse(normalized) - const paths = (result.path || '').split('/').filter(p => !!p) + const paths = (result.path || '').split('/').filter((p) => !!p) const owner = paths.shift() || '' const repository = paths.shift() || '' return { - protocol: (result.protocol || 'https').replace(/\:/g, ''), + protocol: (result.protocol || 'https').replace(/:/g, ''), host: result.host || host || 'github.com', hostname: (result.hostname || host || 'github').replace(/\.(\S+)/, ''), hash: result.hash || '', @@ -34,23 +34,23 @@ export default (url: string, options: GitlyOptions = {}): URLInfo => { path: result.path || '', repository, owner, - type: (result.hash || '#master').substr(1) + type: (result.hash || '#master').substr(1), } } -function normalizeURL(url: string, options: any) { +function normalizeURL(url: string, options: GitlyOptions) { // Remove 'www.' url = url.replace('www.', '') // Remove '.git' url = url.replace('.git', '') - const httpRegex = /http(s)?\:\/\// + const httpRegex = /http(s)?:\/\// const tldRegex = /[\S]+\.([\D]+)/ let host = options.host || '' - if (/([\S]+)\:.+/.test(url) && !httpRegex.test(url)) { + if (/([\S]+):.+/.test(url) && !httpRegex.test(url)) { /** * Matches host:owner/repo */ - const matches = url.match(/([\S]+)\:.+/) + const matches = url.match(/([\S]+):.+/) // Get the host host = matches ? matches[1] : '' // Remove the host from the url @@ -68,10 +68,10 @@ function normalizeURL(url: string, options: any) { */ // Get the TLD if any - const matches = (options.host as string || '').match(tldRegex) + const matches = ((options.host as string) || '').match(tldRegex) let match = 'com' if (matches) match = matches[1] - let domain = (options.host || 'github') + let domain = options.host || 'github' domain = domain.replace(`.${match}`, '') url = `https://${domain}.${match}/${url}` diff --git a/src/utils/tar.ts b/src/utils/tar.ts index 248dfe4..b8ed6aa 100644 --- a/src/utils/tar.ts +++ b/src/utils/tar.ts @@ -5,7 +5,7 @@ import tar = require('tar') import GitlyOptions from '../interfaces/options' import URLInfo from '../interfaces/url' -export function getUrl(info: URLInfo, options: GitlyOptions = {}) { +export function getUrl(info: URLInfo, options: GitlyOptions = {}): string { const { path: repo, type } = info if (options.url && options.url.filter) { @@ -22,9 +22,14 @@ export function getUrl(info: URLInfo, options: GitlyOptions = {}) { } } -export function getFile(info: URLInfo, options: GitlyOptions = {}) { +export function getFile(info: URLInfo, options: GitlyOptions = {}): string { const { path, type, hostname: site } = info - return join(options.temp || join(os.homedir(), '.gitly'), site, path, `${type}.tar.gz`) + return join( + options.temp || join(os.homedir(), '.gitly'), + site, + path, + `${type}.tar.gz` + ) } export const extract = tar.extract diff --git a/src/utils/write.ts b/src/utils/write.ts index dd7eb7b..8351fd0 100644 --- a/src/utils/write.ts +++ b/src/utils/write.ts @@ -1,3 +1,4 @@ +import { WriteStream } from 'fs' import { createWriteStream, promises as fs } from 'fs' import { dirname, normalize } from 'path' @@ -6,7 +7,7 @@ const { mkdir } = fs * Create a folder and return a writable stream. * @param path The path to write a file */ -export default async (path: string) => { +export default async function write(path: string): Promise { path = normalize(path) await mkdir(dirname(path), { recursive: true }) return createWriteStream(path)