johankit 0.0.7 → 0.0.9

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.
@@ -17,7 +17,13 @@ async function copy(input) {
17
17
  else {
18
18
  snapshot = (0, scan_1.scanDir)(input);
19
19
  }
20
- const clipboardJSON = JSON.stringify(snapshot, null, 2); // <- garante JSON válido
21
- await (0, clipboard_1.copyToClipboard)(clipboardJSON);
20
+ const clipboardJSON = JSON.stringify(snapshot, null, 2);
21
+ try {
22
+ await (0, clipboard_1.copyToClipboard)(clipboardJSON);
23
+ }
24
+ catch (err) {
25
+ console.warn("Clipboard unavailable:", err);
26
+ }
27
+ return clipboardJSON;
22
28
  }
23
29
  exports.copy = copy;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.three = void 0;
6
+ exports.tree = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const ts_morph_1 = require("ts-morph");
9
9
  /**
@@ -20,7 +20,7 @@ function detectFileKind(filePath, exportsCount) {
20
20
  return "domain";
21
21
  return "unknown";
22
22
  }
23
- async function three(dir) {
23
+ async function tree(dir) {
24
24
  const project = new ts_morph_1.Project({});
25
25
  project.addSourceFilesAtPaths([
26
26
  `${dir}/**/*.{ts,tsx,js,jsx}`,
@@ -95,7 +95,7 @@ async function three(dir) {
95
95
  }
96
96
  return tree;
97
97
  }
98
- exports.three = three;
98
+ exports.tree = tree;
99
99
  function safeType(fn) {
100
100
  try {
101
101
  return fn();
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tree = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const ts_morph_1 = require("ts-morph");
9
+ /**
10
+ * Heurística simples para classificar arquivos
11
+ */
12
+ function detectFileKind(filePath, exportsCount) {
13
+ if (filePath.includes("/cli/"))
14
+ return "cli";
15
+ if (filePath.endsWith("index.ts") || filePath.endsWith("main.ts"))
16
+ return "entry";
17
+ if (exportsCount === 0)
18
+ return "util";
19
+ if (exportsCount > 3)
20
+ return "domain";
21
+ return "unknown";
22
+ }
23
+ async function tree(dir) {
24
+ const project = new ts_morph_1.Project({});
25
+ project.addSourceFilesAtPaths([
26
+ `${dir}/**/*.{ts,tsx,js,jsx}`,
27
+ `!${dir}/**/node_modules/**/*`,
28
+ `!${dir}/**/dist/**/*`,
29
+ ]);
30
+ const tree = [];
31
+ for (const file of project.getSourceFiles()) {
32
+ const absolutePath = file.getFilePath();
33
+ const filePath = path_1.default.relative(dir, absolutePath);
34
+ if (filePath.includes("node_modules") || filePath.includes("/dist/")) {
35
+ continue;
36
+ }
37
+ /* ---------------- IMPORTS ---------------- */
38
+ const imports = file
39
+ .getImportDeclarations()
40
+ .map(i => i.getModuleSpecifierValue());
41
+ /* ---------------- CLASSES ---------------- */
42
+ const classes = file.getClasses().map(cls => ({
43
+ name: cls.getName() || "<anonymous>",
44
+ methods: cls.getMethods().map(m => ({
45
+ name: m.getName(),
46
+ params: m.getParameters().map(p => p.getName()),
47
+ returnType: safeType(() => m.getReturnType().getText()),
48
+ scope: "class",
49
+ }))
50
+ }));
51
+ /* ---------------- FUNCTIONS ---------------- */
52
+ const functions = file.getFunctions().map(fn => ({
53
+ name: fn.getName() || "<anonymous>",
54
+ params: fn.getParameters().map(p => p.getName()),
55
+ returnType: safeType(() => fn.getReturnType().getText()),
56
+ scope: "global",
57
+ }));
58
+ /* ---------------- VARIABLES ---------------- */
59
+ const variables = file.getVariableDeclarations().map(v => ({
60
+ name: v.getName(),
61
+ type: safeType(() => v.getType().getText()),
62
+ scope: v.getParent() instanceof ts_morph_1.SourceFile ? "global" : "local",
63
+ }));
64
+ /* ---------------- EXPORTS ---------------- */
65
+ const exports = [];
66
+ let mainExport;
67
+ file.getExportedDeclarations().forEach((decls, name) => {
68
+ decls.forEach(d => {
69
+ let kind = "unknown";
70
+ if (d.getKind() === ts_morph_1.SyntaxKind.ClassDeclaration)
71
+ kind = "class";
72
+ if (d.getKind() === ts_morph_1.SyntaxKind.FunctionDeclaration)
73
+ kind = "function";
74
+ if (d.getKind() === ts_morph_1.SyntaxKind.VariableDeclaration)
75
+ kind = "variable";
76
+ if (d.getKind() === ts_morph_1.SyntaxKind.TypeAliasDeclaration)
77
+ kind = "type";
78
+ exports.push({ name, kind });
79
+ });
80
+ });
81
+ if (exports.length === 1) {
82
+ mainExport = exports[0].name;
83
+ }
84
+ const kind = detectFileKind(filePath, exports.length);
85
+ tree.push({
86
+ path: filePath,
87
+ kind,
88
+ imports,
89
+ classes,
90
+ functions,
91
+ variables,
92
+ exports,
93
+ mainExport,
94
+ });
95
+ }
96
+ return tree;
97
+ }
98
+ exports.tree = tree;
99
+ function safeType(fn) {
100
+ try {
101
+ return fn();
102
+ }
103
+ catch {
104
+ return "unknown";
105
+ }
106
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readClipboard = exports.copyToClipboard = void 0;
3
+ exports.copyToClipboard = void 0;
4
4
  // src/core/clipboard.ts
5
5
  const child_process_1 = require("child_process");
6
6
  function copyToClipboard(text) {
@@ -15,40 +15,21 @@ function copyToClipboard(text) {
15
15
  command = "clip";
16
16
  args = [];
17
17
  }
18
- const child = (0, child_process_1.spawn)(command, args, { stdio: ["pipe", "ignore", "ignore"] });
19
- child.on("error", (err) => reject(err));
20
- child.on("close", () => resolve());
21
- child.stdin.write(text);
22
- child.stdin.end();
23
- });
24
- }
25
- exports.copyToClipboard = copyToClipboard;
26
- function readClipboard() {
27
- return new Promise((resolve, reject) => {
28
- let command = "xclip";
29
- let args = ["-selection", "clipboard", "-o"];
30
- if (process.platform === "darwin") {
31
- command = "pbpaste";
32
- args = [];
33
- }
34
- else if (process.platform === "win32") {
35
- command = "powershell";
36
- args = ["-command", "Get-Clipboard"];
37
- }
38
- const child = (0, child_process_1.spawn)(command, args, { stdio: ["ignore", "pipe", "pipe"] });
39
- let output = "";
40
- let error = "";
41
- child.stdout.on("data", (d) => (output += d.toString()));
42
- child.stderr.on("data", (d) => (error += d.toString()));
43
- child.on("error", (err) => reject(err));
44
- child.on("close", (code) => {
45
- if (code !== 0 && error && !output) {
46
- reject(new Error(error || "Clipboard read failed"));
18
+ const child = (0, child_process_1.spawn)(command, args, {
19
+ stdio: ["pipe", "ignore", "ignore"]
20
+ });
21
+ child.on("error", reject);
22
+ child.stdin.on("error", (err) => {
23
+ if (err.code === "EPIPE") {
24
+ resolve();
47
25
  }
48
26
  else {
49
- resolve(output.trim().replace(/^\uFEFF/, ""));
27
+ reject(err);
50
28
  }
51
29
  });
30
+ child.stdin.write(text);
31
+ child.stdin.end();
32
+ child.on("close", () => resolve());
52
33
  });
53
34
  }
54
- exports.readClipboard = readClipboard;
35
+ exports.copyToClipboard = copyToClipboard;
package/dist/index.js CHANGED
@@ -31,9 +31,9 @@ async function main() {
31
31
  await service.sync(dir);
32
32
  break;
33
33
  }
34
- case "three": {
34
+ case "tree": {
35
35
  const dir = args[0] ?? ".";
36
- const output = await service.three(dir);
36
+ const output = await service.tree(dir);
37
37
  console.log(output);
38
38
  break;
39
39
  }
@@ -59,14 +59,14 @@ Usage:
59
59
  johankit paste <dir>
60
60
  johankit prompt <dir> "<user request>" [--diff]
61
61
  johankit sync <dir>
62
- johankit three <dir>
62
+ johankit tree <dir>
63
63
 
64
64
  Examples:
65
65
  johankit copy src
66
66
  johankit paste src
67
67
  johankit prompt src "refactor to async/await"
68
68
  johankit sync src
69
- johankit three src
69
+ johankit tree src
70
70
  `);
71
71
  }
72
72
  main();
@@ -8,7 +8,7 @@ const createAsciiTree_1 = __importDefault(require("../utils/createAsciiTree"));
8
8
  const copy_1 = require("../cli/commands/copy");
9
9
  const paste_1 = require("../cli/commands/paste");
10
10
  const prompt_1 = require("../cli/commands/prompt");
11
- const three_1 = require("../cli/commands/three");
11
+ const tree_1 = require("../cli/commands/tree");
12
12
  const scan_1 = require("../core/scan");
13
13
  const diff_1 = require("../core/diff");
14
14
  const validation_1 = require("../core/validation");
@@ -51,9 +51,9 @@ class JohankitService {
51
51
  const snapshotAfter = (0, scan_1.scanDir)(dir);
52
52
  return { before: snapshotBefore, after: snapshotAfter };
53
53
  }
54
- async three(dir = ".") {
55
- const tree = await (0, three_1.three)(dir);
56
- return (0, createAsciiTree_1.default)(tree);
54
+ async tree(dir = ".") {
55
+ const _tree = await (0, tree_1.tree)(dir);
56
+ return (0, createAsciiTree_1.default)(_tree);
57
57
  }
58
58
  }
59
59
  exports.JohankitService = JohankitService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "johankit",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -16,8 +16,13 @@ export async function copy(input: string | string[]) {
16
16
  snapshot = scanDir(input);
17
17
  }
18
18
 
19
- const clipboardJSON = JSON.stringify(snapshot, null, 2); // <- garante JSON válido
20
- await copyToClipboard(clipboardJSON);
19
+ const clipboardJSON = JSON.stringify(snapshot, null, 2);
20
+
21
+ try {
22
+ await copyToClipboard(clipboardJSON);
23
+ } catch (err) {
24
+ console.warn("Clipboard unavailable:", err);
25
+ }
21
26
 
22
27
  return clipboardJSON;
23
28
  }
@@ -20,7 +20,7 @@ function detectFileKind(filePath: string, exportsCount: number): FileKind {
20
20
  return "unknown";
21
21
  }
22
22
 
23
- export async function three(dir: string): Promise<FileTree[]> {
23
+ export async function tree(dir: string): Promise<FileTree[]> {
24
24
  const project = new Project({});
25
25
 
26
26
  project.addSourceFilesAtPaths([
@@ -35,6 +35,8 @@ export async function three(dir: string): Promise<FileTree[]> {
35
35
  const absolutePath = file.getFilePath();
36
36
  const filePath = path.relative(dir, absolutePath);
37
37
 
38
+ console.log(filePath);
39
+
38
40
  if (filePath.includes("node_modules") || filePath.includes("/dist/")) {
39
41
  continue;
40
42
  }
package/src/index.ts CHANGED
@@ -34,9 +34,9 @@ async function main() {
34
34
  break;
35
35
  }
36
36
 
37
- case "three": {
37
+ case "tree": {
38
38
  const dir = args[0] ?? ".";
39
- const output = await service.three(dir);
39
+ const output = await service.tree(dir);
40
40
  console.log(output);
41
41
  break;
42
42
  }
@@ -62,14 +62,14 @@ Usage:
62
62
  johankit paste <dir>
63
63
  johankit prompt <dir> "<user request>" [--diff]
64
64
  johankit sync <dir>
65
- johankit three <dir>
65
+ johankit tree <dir>
66
66
 
67
67
  Examples:
68
68
  johankit copy src
69
69
  johankit paste src
70
70
  johankit prompt src "refactor to async/await"
71
71
  johankit sync src
72
- johankit three src
72
+ johankit tree src
73
73
  `);
74
74
  }
75
75
 
@@ -2,7 +2,7 @@ import createAsciiTree from "../utils/createAsciiTree";
2
2
  import { copy } from "../cli/commands/copy";
3
3
  import { paste } from "../cli/commands/paste";
4
4
  import { prompt } from "../cli/commands/prompt";
5
- import { three } from "../cli/commands/three";
5
+ import { tree } from "../cli/commands/tree";
6
6
  import { scanDir } from "../core/scan";
7
7
  import { applyDiff, DiffPatch } from "../core/diff";
8
8
  import { validatePatches } from "../core/validation";
@@ -63,8 +63,8 @@ export class JohankitService {
63
63
  return { before: snapshotBefore, after: snapshotAfter };
64
64
  }
65
65
 
66
- async three(dir: string = ".") {
67
- const tree = await three(dir);
68
- return createAsciiTree(tree);
66
+ async tree(dir: string = ".") {
67
+ const _tree = await tree(dir);
68
+ return createAsciiTree(_tree);
69
69
  }
70
70
  }