structify-project 1.0.0 → 1.1.1

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.
Files changed (3) hide show
  1. package/dist/cli.js +32 -18
  2. package/dist/index.js +43 -38
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -4,14 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ console.log("🔥 Structify CLI started");
7
8
  const inquirer_1 = __importDefault(require("inquirer"));
8
9
  const index_1 = require("./index");
9
- // CLI args
10
10
  const args = process.argv.slice(2);
11
11
  const projectPath = args[0] || ".";
12
12
  const outputBase = args[1] || "structure";
13
- // Interactive prompts
14
- (async () => {
13
+ const specialDirs = [
14
+ "node_modules",
15
+ ".git",
16
+ ".angular",
17
+ ".vscode",
18
+ "dist"
19
+ ];
20
+ async function run() {
15
21
  const { format } = await inquirer_1.default.prompt([
16
22
  {
17
23
  type: "list",
@@ -21,18 +27,26 @@ const outputBase = args[1] || "structure";
21
27
  default: "txt"
22
28
  }
23
29
  ]);
24
- const { nodeModules } = await inquirer_1.default.prompt([
25
- {
26
- type: "list",
27
- name: "nodeModules",
28
- message: "How should node_modules be handled?",
29
- choices: [
30
- { name: "Skip (ignore completely)", value: "skip" },
31
- { name: "Name only (show folder but no contents)", value: "name" },
32
- { name: "Full (expand everything inside)", value: "full" }
33
- ],
34
- default: "name"
35
- }
36
- ]);
37
- (0, index_1.generateStructure)(projectPath, outputBase, format, nodeModules);
38
- })();
30
+ const config = {};
31
+ for (const dir of specialDirs) {
32
+ const { mode } = await inquirer_1.default.prompt([
33
+ {
34
+ type: "list",
35
+ name: "mode",
36
+ message: `How should "${dir}" be handled? (if present)`,
37
+ choices: [
38
+ { name: "Skip", value: "skip" },
39
+ { name: "Name only", value: "name" },
40
+ { name: "Full", value: "full" }
41
+ ],
42
+ default: dir === "node_modules" ? "name" : "skip"
43
+ }
44
+ ]);
45
+ config[dir] = mode;
46
+ }
47
+ (0, index_1.generateStructure)(projectPath, outputBase, format, config);
48
+ }
49
+ run().catch(err => {
50
+ console.error("❌ CLI crashed:", err);
51
+ process.exit(1);
52
+ });
package/dist/index.js CHANGED
@@ -41,30 +41,35 @@ const fs = __importStar(require("fs"));
41
41
  const path = __importStar(require("path"));
42
42
  const yaml_1 = __importDefault(require("yaml"));
43
43
  /**
44
- * Recursively builds a tree structure object for directories and files.
44
+ * Build directory tree object recursively
45
45
  */
46
- function buildTreeObject(dir, nodeModulesMode = "name") {
46
+ function buildTreeObject(dir, config) {
47
47
  const items = fs
48
48
  .readdirSync(dir, { withFileTypes: true })
49
49
  .sort((a, b) => Number(b.isDirectory()) - Number(a.isDirectory()));
50
50
  return items
51
51
  .map(item => {
52
- if (item.name === "node_modules") {
53
- if (nodeModulesMode === "skip")
52
+ const fullPath = path.join(dir, item.name);
53
+ const mode = config[item.name];
54
+ // Handle special directories
55
+ if (mode) {
56
+ if (mode === "skip")
54
57
  return null;
55
- if (nodeModulesMode === "name")
58
+ if (mode === "name") {
56
59
  return { name: item.name, type: "directory" };
60
+ }
61
+ // full
57
62
  return {
58
63
  name: item.name,
59
64
  type: "directory",
60
- children: buildTreeObject(path.join(dir, item.name), nodeModulesMode),
65
+ children: buildTreeObject(fullPath, config)
61
66
  };
62
67
  }
63
68
  if (item.isDirectory()) {
64
69
  return {
65
70
  name: item.name,
66
71
  type: "directory",
67
- children: buildTreeObject(path.join(dir, item.name), nodeModulesMode),
72
+ children: buildTreeObject(fullPath, config)
68
73
  };
69
74
  }
70
75
  return { name: item.name, type: "file" };
@@ -72,7 +77,7 @@ function buildTreeObject(dir, nodeModulesMode = "name") {
72
77
  .filter(Boolean);
73
78
  }
74
79
  /**
75
- * Convert tree object to a text tree string
80
+ * Convert tree object to text tree
76
81
  */
77
82
  function toTextTree(tree, prefix = "") {
78
83
  let result = "";
@@ -88,49 +93,49 @@ function toTextTree(tree, prefix = "") {
88
93
  return result;
89
94
  }
90
95
  /**
91
- * Export tree in different formats
96
+ * Convert tree to markdown
92
97
  */
93
- function formatTree(projectName, tree, format) {
94
- switch (format) {
95
- case "txt":
96
- return `${projectName}/\n${toTextTree(tree)}`;
97
- case "json":
98
- return JSON.stringify({ name: projectName, type: "directory", children: tree }, null, 2);
99
- case "yaml":
100
- return yaml_1.default.stringify({ name: projectName, type: "directory", children: tree });
101
- case "md":
102
- return treeToMarkdown(projectName, tree);
103
- default:
104
- return "";
105
- }
106
- }
107
- /**
108
- * Markdown conversion
109
- */
110
- function treeToMarkdown(projectName, tree, depth = 0) {
111
- let md = depth === 0 ? `# Project Structure\n\n- ${projectName}/\n` : "";
112
- const prefix = " ".repeat(depth + 1);
98
+ function toMarkdown(name, tree, depth = 0) {
99
+ let md = depth === 0 ? `# Project Structure\n\n- ${name}/\n` : "";
100
+ const indent = " ".repeat(depth + 1);
113
101
  tree.forEach(node => {
114
- md += `${prefix}- ${node.name}\n`;
102
+ md += `${indent}- ${node.name}\n`;
115
103
  if (node.type === "directory" && node.children) {
116
- md += treeToMarkdown("", node.children, depth + 1);
104
+ md += toMarkdown("", node.children, depth + 1);
117
105
  }
118
106
  });
119
107
  return md;
120
108
  }
121
109
  /**
122
- * Generates a project structure file.
110
+ * Generate output file
123
111
  */
124
- function generateStructure(projectPath, outputFileBase, format, nodeModulesMode) {
112
+ function generateStructure(projectPath, outputBase, format, config) {
125
113
  const absPath = path.resolve(projectPath);
126
114
  if (!fs.existsSync(absPath)) {
127
115
  console.error(`❌ Path not found: ${absPath}`);
128
116
  process.exit(1);
129
117
  }
130
118
  const projectName = path.basename(absPath);
131
- const tree = buildTreeObject(absPath, nodeModulesMode);
132
- const output = formatTree(projectName, tree, format);
133
- const outputFile = `${outputFileBase}.${format}`;
134
- fs.writeFileSync(outputFile, output, "utf-8");
135
- console.log(`✅ Project structure written to ${outputFile}`);
119
+ const tree = buildTreeObject(absPath, config);
120
+ let output = "";
121
+ switch (format) {
122
+ case "txt":
123
+ output = `${projectName}/\n${toTextTree(tree)}`;
124
+ break;
125
+ case "json":
126
+ output = JSON.stringify({ name: projectName, type: "directory", children: tree }, null, 2);
127
+ break;
128
+ case "yaml":
129
+ output = yaml_1.default.stringify({
130
+ name: projectName,
131
+ type: "directory",
132
+ children: tree
133
+ });
134
+ break;
135
+ case "md":
136
+ output = toMarkdown(projectName, tree);
137
+ break;
138
+ }
139
+ fs.writeFileSync(`${outputBase}.${format}`, output, "utf-8");
140
+ console.log(`✅ Project structure written to ${outputBase}.${format}`);
136
141
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "structify-project",
3
3
  "author": "Yashwanth Byalla",
4
- "version": "1.0.0",
4
+ "version": "1.1.1",
5
5
  "description": "Interactive CLI to visualize and export project structure as text, JSON, Markdown, or YAML",
6
6
  "main": "index.js",
7
7
  "scripts": {