Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: conditionally require lint, format #49

Merged
merged 6 commits into from
Aug 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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