diff --git a/src/cli.ts b/src/cli.ts index e506fb16..9683588e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -17,8 +17,6 @@ import * as meow from 'meow'; import * as updateNotifier from 'update-notifier'; import {init} from './init'; -import {lint} from './lint'; -import {format} from './format'; import {clean} from './clean'; export interface Logger { @@ -35,6 +33,9 @@ export interface Options { logger: Logger; } +export type VerbFunction = (options: Options, fix?: boolean) => + Promise; + const logger: Logger = console; const cli = meow(` @@ -74,9 +75,15 @@ async function run(verb: string): Promise { yes: cli.flags.yes || cli.flags.y || false, logger: logger }; + // Linting/formatting depend on typescript. We don't want to load the + // typescript module during init, since it might not exist. + // See: https://github.com/google/ts-style/issues/48 + if (verb === 'init') { + return await init(options); + } + const lint: VerbFunction = require('./lint'); + const format: VerbFunction = require('./format'); switch (verb) { - case 'init': - return await init(options); case 'check': return (await lint(options) && await format(options)); case 'fix':