ts2famix 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
@@ -29,17 +30,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
30
  const fs = __importStar(require("fs"));
30
31
  const yargs_1 = __importDefault(require("yargs"));
31
32
  const analyze_1 = require("./analyze");
32
- const importer = new analyze_1.Importer();
33
+ const ts_morph_1 = require("ts-morph");
33
34
  const argv = yargs_1.default
34
- .example(`ts-node src/ts2famix-cli.ts -i "../path/to/project/**/*.ts" -o JSONModels/projectName.json`, 'creates a JSON-format model of a typescript project')
35
+ .example(`ts2famix -i "path/to/project/**/*.ts" -o JSONModels/projectName.json`, 'Creates a JSON-format Famix model of typescript files.')
36
+ .example(`ts2famix -i path/to/tsconfig.json -o JSONModels/projectName.json`, 'Creates a JSON-format model of a typescript project.')
35
37
  .alias('i', 'input')
36
38
  .nargs('i', 1)
37
39
  .alias('o', 'output')
38
40
  .nargs('o', 1)
39
41
  .demandOption('input').demandOption('output').parseSync();
40
- const paths = new Array();
41
- paths.push(argv.input);
42
- const famixRep = importer.famixRepFromPaths(paths);
42
+ const importer = new analyze_1.Importer();
43
+ let famixRep;
44
+ if (argv.input.endsWith('tsconfig.json')) {
45
+ const tsConfigFilePath = argv.input;
46
+ const project = new ts_morph_1.Project({
47
+ tsConfigFilePath
48
+ });
49
+ famixRep = importer.famixRepFromProject(project);
50
+ }
51
+ else {
52
+ const paths = new Array();
53
+ paths.push(argv.input);
54
+ famixRep = importer.famixRepFromPaths(paths);
55
+ }
43
56
  const jsonOutput = famixRep.getJSON();
44
57
  const jsonFilePath = argv.output;
45
58
  fs.writeFile(jsonFilePath, jsonOutput, (err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts2famix",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Examples of the TypeScript compiler API usage",
5
5
  "main": "dist/ts2famix-cli.js",
6
6
  "scripts": {
@@ -1,21 +1,34 @@
1
+ #!/usr/bin/env node
1
2
  import * as fs from "fs";
2
3
  import yargs from "yargs";
3
4
  import { Importer } from './analyze';
4
-
5
- const importer = new Importer();
5
+ import { FamixRepository } from "./lib/famix/src/famix_repository";
6
+ import { Project } from "ts-morph";
6
7
 
7
8
  const argv = yargs
8
- .example(`ts-node src/ts2famix-cli.ts -i "../path/to/project/**/*.ts" -o JSONModels/projectName.json`, 'creates a JSON-format model of a typescript project')
9
+ .example(`ts2famix -i "path/to/project/**/*.ts" -o JSONModels/projectName.json`, 'Creates a JSON-format Famix model of typescript files.')
10
+ .example(`ts2famix -i path/to/tsconfig.json -o JSONModels/projectName.json`, 'Creates a JSON-format model of a typescript project.')
9
11
  .alias('i', 'input')
10
12
  .nargs('i', 1)
11
13
  .alias('o', 'output')
12
14
  .nargs('o', 1)
13
15
  .demandOption('input').demandOption('output').parseSync();
14
16
 
15
- const paths = new Array<string>();
16
- paths.push(argv.input as string);
17
+ const importer = new Importer();
18
+ let famixRep: FamixRepository;
19
+
20
+ if ((argv.input as string).endsWith('tsconfig.json')) {
21
+ const tsConfigFilePath = argv.input as string;
22
+ const project = new Project({
23
+ tsConfigFilePath
24
+ });
25
+ famixRep = importer.famixRepFromProject(project);
26
+ } else {
27
+ const paths = new Array<string>();
28
+ paths.push(argv.input as string);
29
+ famixRep = importer.famixRepFromPaths(paths);
30
+ }
17
31
 
18
- const famixRep = importer.famixRepFromPaths(paths);
19
32
  const jsonOutput = famixRep.getJSON();
20
33
  const jsonFilePath = argv.output as string;
21
34