Skip to content

Commit

Permalink
feat(api): print tsc version when exec --version
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Mar 2, 2017
1 parent 64ac10f commit 17a16ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ try {
console.error("typescript is required. please try 'npm install -g typescript'\n");
}

import * as ts from "typescript";

import * as fs from "fs";
import * as path from "path";
import * as commandpost from "commandpost";

import * as lib from "./";
import { getConfigFileName, readFilesFromTsconfig } from "./utils";

let packageJson = JSON.parse(fs.readFileSync(__dirname + "/../package.json").toString());
const packageJson = JSON.parse(fs.readFileSync(path.join( __dirname, "../package.json")).toString());

interface RootOptions {
replace: boolean;
Expand All @@ -27,6 +29,7 @@ interface RootOptions {
useTslint: string[];
useTsfmt: string[];
verbose: boolean;
version: boolean;
}

interface RootArguments {
Expand All @@ -35,7 +38,6 @@ interface RootArguments {

let root = commandpost
.create<RootOptions, RootArguments>("tsfmt [files...]")
.version(packageJson.version, "-v, --version")
.option("-r, --replace", "replace .ts file")
.option("--verify", "checking file format")
.option("--baseDir <path>", "config file lookup from <path>")
Expand All @@ -49,6 +51,7 @@ let root = commandpost
.option("--useTslint <path>", "using specified config file insteaf of tslint.json")
.option("--useTsfmt <path>", "using specified config file insteaf of tsfmt.json")
.option("--verbose", "makes output more verbose")
.option("-v, --version", "output the version number")
.action((opts, args) => {
let replace = !!opts.replace;
let verify = !!opts.verify;
Expand All @@ -63,6 +66,13 @@ let root = commandpost
let tslintFile = opts.useTslint[0] ? path.join(process.cwd(), opts.useTslint[0]) : null;
let tsfmtFile = opts.useTsfmt[0] ? path.join(process.cwd(), opts.useTsfmt[0]) : null;
let verbose = !!opts.verbose;
let version = !!opts.version;

if (version) {
console.log(`tsfmt : ${packageJson.version}`);
console.log(`tsc : ${ts.version}`);
return;
}

let files = args.files;
let useTsconfig = false;
Expand Down
4 changes: 4 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { createDefaultFormatCodeSettings, parseJSON } from "./utils";
export { parseJSON };

import * as fs from "fs";
import * as path from "path";

import base from "./provider/base";
import tsconfigjson from "./provider/tsconfigjson";
import editorconfig, { postProcess as editorconfigPostProcess } from "./provider/editorconfig";
import tslintjson, { postProcess as tslintPostProcess } from "./provider/tslintjson";
import vscodesettings from "./provider/vscodesettings";

const packageJson = JSON.parse(fs.readFileSync(path.join( __dirname, "../package.json")).toString());
export const version = packageJson.version;

export interface Options {
dryRun?: boolean;
verbose?: boolean;
Expand Down

0 comments on commit 17a16ac

Please sign in to comment.