Skip to content

Commit

Permalink
fix: conditionally require lint, format (#49)
Browse files Browse the repository at this point in the history
PR-URL: #49
  • Loading branch information
kjin authored Aug 31, 2017
1 parent 5e3c3f2 commit ce4246c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,6 +33,9 @@ export interface Options {
logger: Logger;
}

export type VerbFunction = (options: Options, fix?: boolean) =>
Promise<boolean>;

const logger: Logger = console;

const cli = meow(`
Expand Down Expand Up @@ -74,9 +75,15 @@ async function run(verb: string): Promise<boolean> {
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':
Expand Down

0 comments on commit ce4246c

Please sign in to comment.