Skip to content

Commit bf931b5

Browse files
committed
exclude node_modules
1 parent 51c28a0 commit bf931b5

File tree

5 files changed

+33
-23
lines changed

5 files changed

+33
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tcg
1919
It will remind you how to use the CLI: you need to provide specific files, or globs (wildcard paths):
2020

2121
```sh
22-
tcg myFile.ts folder/*.ts anotherFolder/**/*.ts
22+
tcg myFile.ts folder/* anotherFolder/**/*
2323
```
2424

2525
## Developing

bin/extract.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function extractFunctionCalls(node, sourceFile, indentLevel) {
3737
updateCalledFunctions(calledFunction);
3838
}
3939
}
40-
logThings(node, sourceFile, indentLevel);
40+
// logNode(node, sourceFile, indentLevel);
4141
node.forEachChild(function (child) { return extractFunctionCalls(child, sourceFile, indentLevel + 1); });
4242
}
4343
/**
@@ -46,7 +46,7 @@ function extractFunctionCalls(node, sourceFile, indentLevel) {
4646
* @param sourceFile
4747
* @param indentLevel
4848
*/
49-
function logThings(node, sourceFile, indentLevel) {
49+
function logNode(node, sourceFile, indentLevel) {
5050
var indentation = "-".repeat(indentLevel);
5151
var syntaxKind = ts.SyntaxKind[node.kind];
5252
var nodeText = node.getText(sourceFile).split('\n')[0];
@@ -81,7 +81,7 @@ function processFiles(filenames) {
8181
// instead of: extractFunctionCalls(sourceFile, 0, sourceFile);
8282
// grab all the root nodes first
8383
// then do recursion for each
84-
filenames.filter(function (file) { return file.endsWith('ts'); }).forEach(function (filename) {
84+
filenames.forEach(function (filename) {
8585
var rootNodes = [];
8686
var codeAsString = fs.readFileSync(filename).toString();
8787
var sourceFile = ts.createSourceFile(filename, codeAsString, ts.ScriptTarget.Latest);

bin/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ exports.__esModule = true;
44
var extract_1 = require("./extract");
55
var _a = require('kleur'), green = _a.green, bold = _a.bold;
66
var myArgs = process.argv.slice(2);
7-
if (myArgs.length) {
8-
console.log(myArgs);
7+
var onlyTypescript = myArgs.filter(function (file) { return file.endsWith('ts'); });
8+
var withoutNodeModules = onlyTypescript.filter(function (file) { return !file.includes('node_modules'); });
9+
if (withoutNodeModules.length) {
10+
console.log(withoutNodeModules);
911
var inquirer = require('inquirer');
1012
inquirer
1113
.prompt([{
@@ -32,11 +34,14 @@ function showHelpMessage() {
3234
console.log('Please provide a list of input files and/or folders');
3335
console.log('e.g. `'
3436
+ green('myFile.ts') + '`, `'
35-
+ green('*.ts`') + ', `'
36-
+ green('**/*.ts`') + ', `'
37-
+ green('myFolder/*.ts') + '`');
38-
console.log('or any combination of the above, like `' + green('myFile.ts myFolder/*.ts') + '`');
37+
+ green('*') + '`, `'
38+
+ green('**/*') + '`, `'
39+
+ green('myFolder/*') + '`');
40+
console.log('or any combination of the above, like `' + green('myFile.ts myFolder/*') + '`');
3941
}
42+
/**
43+
* If user confirms the files they want to analyze, proceed
44+
*/
4045
function proceed() {
41-
extract_1.processFiles(myArgs);
46+
extract_1.processFiles(withoutNodeModules);
4247
}

extract.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function extractFunctionCalls(node: ts.Node, sourceFile: ts.SourceFile, indentLe
4242
}
4343
}
4444

45-
// logThings(node, sourceFile, indentLevel);
45+
// logNode(node, sourceFile, indentLevel);
4646

4747
node.forEachChild(child => extractFunctionCalls(child, sourceFile, indentLevel + 1));
4848
}
@@ -53,14 +53,13 @@ function extractFunctionCalls(node: ts.Node, sourceFile: ts.SourceFile, indentLe
5353
* @param sourceFile
5454
* @param indentLevel
5555
*/
56-
function logThings(node: ts.Node, sourceFile: ts.SourceFile, indentLevel: number) {
56+
function logNode(node: ts.Node, sourceFile: ts.SourceFile, indentLevel: number) {
5757
const indentation = "-".repeat(indentLevel);
5858
const syntaxKind = ts.SyntaxKind[node.kind];
5959
const nodeText = node.getText(sourceFile).split('\n')[0];
6060
console.log(`${indentation}${syntaxKind}: ${nodeText}`);
6161
}
6262

63-
6463
/**
6564
* Update `allFunctions` and `currentFunction`
6665
* @param declaredFunction
@@ -87,14 +86,13 @@ function updateCalledFunctions(calledFunction: string): void {
8786
}
8887
}
8988

90-
9189
export function processFiles(filenames: string[]) {
9290

9391
// =================================================================================================
9492
// instead of: extractFunctionCalls(sourceFile, 0, sourceFile);
9593
// grab all the root nodes first
9694
// then do recursion for each
97-
filenames.filter(file => file.endsWith('ts')).forEach((filename) => {
95+
filenames.forEach((filename) => {
9896

9997
const rootNodes: ts.Node[] = [];
10098

index.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ const { green, bold } = require('kleur');
66

77
const myArgs = process.argv.slice(2);
88

9-
if (myArgs.length) {
9+
const onlyTypescript: string[] = myArgs.filter(file => file.endsWith('ts'));
1010

11-
console.log(myArgs);
11+
const withoutNodeModules: string[] = onlyTypescript.filter(file => !file.includes('node_modules'));
12+
13+
if (withoutNodeModules.length) {
14+
15+
console.log(withoutNodeModules);
1216

1317
var inquirer = require('inquirer');
1418

@@ -39,12 +43,15 @@ function showHelpMessage(): void {
3943
console.log('Please provide a list of input files and/or folders');
4044
console.log('e.g. `'
4145
+ green('myFile.ts') + '`, `'
42-
+ green('*.ts`') + ', `'
43-
+ green('**/*.ts`') + ', `'
44-
+ green('myFolder/*.ts') + '`');
45-
console.log('or any combination of the above, like `' + green('myFile.ts myFolder/*.ts') + '`');
46+
+ green('*') + '`, `'
47+
+ green('**/*') + '`, `'
48+
+ green('myFolder/*') + '`');
49+
console.log('or any combination of the above, like `' + green('myFile.ts myFolder/*') + '`');
4650
}
4751

52+
/**
53+
* If user confirms the files they want to analyze, proceed
54+
*/
4855
function proceed(): void {
49-
processFiles(myArgs);
56+
processFiles(withoutNodeModules);
5057
}

0 commit comments

Comments
 (0)