Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Johnston committed Jun 2, 2015
1 parent 13cbde2 commit 7957f94
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 20 deletions.
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,75 @@
# tsconfig-glob
A lightweight npm package + cli that allows you to specify glob patterns for tsconfig files
A lightweight npm package + cli that allows you to specify glob patterns for tsconfig files. Most of the credit is due to glob/minimatch, this is a very thin layer on top of those libraries.

## Install

Use `npm` to install this package.

Locally:

```shell
npm install tsconfig-glob --save-dev
```

or, Globally:

```shell
npm install -g tsconfig-glob --save-dev
```

## Usage

You can use this library as either a CLI or in a node script. It follows a similar format to the [atom-typescript](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md) plugin:

0. You provide a path to a directory containing a tsconfig.json
0. You specify a `filesGlob` pattern in your tsconfig.json
0. The library will find the files matching the `filesGlob` patterns and put them in the `files` property

### Using the CLI
```shell
tsconfig .
```

#### Options

```shell
-i, --indent <number> The number of spaces to indent the tsconfig.json file (defaults to 4)
```

### Using with Node

```ts
import * as tsconfig from 'tsconfig-glob';
tsconfig();
```

#### Options

```ts
{
/**
* A relative path from cwd to the directory containing a tsconfig.json. If not specified, the '.' is used.
*/
configPath?: string;

/**
* The current working directory, defaults to `process.cwd()`
*/
cwd?: string;

/**
* The number of spaces to indent the tsconfig.json
*/
indent?: number;
}
```
#### Realistic Node Usage

```ts
import * as tsconfig from 'tsconfig-glob';
tsconfig({
configPath: '.',
cwd: process.cwd(),
indent: 2
});
```
20 changes: 18 additions & 2 deletions cli
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@ resolve('tsconfig-glob', {
cli = require(localCli);
}

var args = process.argv.slice(2),
indentOptionIndex = args.indexOf('-i'),
indent = 4;

if(indentOptionIndex === -1) {
indentOptionIndex = args.indexOf('--indent');
}

if(indentOptionIndex > -1) {
indent = Number(args.splice(indentOptionIndex, 2)[1])
}

var cwd = process.cwd();

try {
cli({
args: process.argv.slice(2),
cwd: process.cwd()
args: args,
indent: indent,
configPath: args[0] || '.',
cwd: cwd
});
exit(0);
} catch(e) {
Expand Down
20 changes: 4 additions & 16 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,9 @@ function sort(a: string, b: string) {
return 0;
}

export = function(options: { args: Array<string>; cwd: string; }) {
var args = options.args,
root = options.cwd,
indentOptionIndex = args.indexOf('-i'),
indent = 4;

if(indentOptionIndex === -1) {
indentOptionIndex = args.indexOf('--indent');
}

if(indentOptionIndex > -1) {
indent = Number(args.splice(indentOptionIndex, 2)[1])
}

var configDir = path.resolve(root, args[0] || '.'),
export = function(options: { args?: Array<string>; configPath?: string; cwd?: string; indent?: number; }) {
var root = options.cwd || process.cwd(),
configDir = path.resolve(root, options.configPath || '.'),
filePath = path.resolve(configDir, 'tsconfig.json'),
configFile: { filesGlob: Array<string>; files: Array<string>; } = require(filePath),
filesGlob: Array<string> = configFile.filesGlob || [],
Expand All @@ -81,5 +69,5 @@ export = function(options: { args: Array<string>; cwd: string; }) {
})));
}, []).sort(sort);

fs.writeFileSync(filePath, JSON.stringify(configFile, null, indent));
fs.writeFileSync(filePath, JSON.stringify(configFile, null, options.indent || 4));
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"prepublish": "npm run build",
"build": "tsc -p .",
"cli": "node cli -i 4",
"cli": "node cli",
"test": "echo \"Error: no test specified\" && exit 1"
}
}

0 comments on commit 7957f94

Please sign in to comment.