structify-project 1.0.0 → 1.1.0
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.
- package/dist/cli.js +28 -16
- package/dist/index.js +43 -38
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
1
|
"use strict";
|
|
3
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -10,8 +9,16 @@ const index_1 = require("./index");
|
|
|
10
9
|
const args = process.argv.slice(2);
|
|
11
10
|
const projectPath = args[0] || ".";
|
|
12
11
|
const outputBase = args[1] || "structure";
|
|
13
|
-
//
|
|
12
|
+
// Directories to control
|
|
13
|
+
const specialDirs = [
|
|
14
|
+
"node_modules",
|
|
15
|
+
".git",
|
|
16
|
+
".angular",
|
|
17
|
+
".vscode",
|
|
18
|
+
"dist"
|
|
19
|
+
];
|
|
14
20
|
(async () => {
|
|
21
|
+
// Output format
|
|
15
22
|
const { format } = await inquirer_1.default.prompt([
|
|
16
23
|
{
|
|
17
24
|
type: "list",
|
|
@@ -21,18 +28,23 @@ const outputBase = args[1] || "structure";
|
|
|
21
28
|
default: "txt"
|
|
22
29
|
}
|
|
23
30
|
]);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
// Directory handling
|
|
32
|
+
const config = {};
|
|
33
|
+
for (const dir of specialDirs) {
|
|
34
|
+
const { mode } = await inquirer_1.default.prompt([
|
|
35
|
+
{
|
|
36
|
+
type: "list",
|
|
37
|
+
name: "mode",
|
|
38
|
+
message: `How should "${dir}" be handled?`,
|
|
39
|
+
choices: [
|
|
40
|
+
{ name: "Skip (exclude completely)", value: "skip" },
|
|
41
|
+
{ name: "Name only (show folder name)", value: "name" },
|
|
42
|
+
{ name: "Full (include everything)", value: "full" }
|
|
43
|
+
],
|
|
44
|
+
default: dir === "node_modules" ? "name" : "skip"
|
|
45
|
+
}
|
|
46
|
+
]);
|
|
47
|
+
config[dir] = mode;
|
|
48
|
+
}
|
|
49
|
+
(0, index_1.generateStructure)(projectPath, outputBase, format, config);
|
|
38
50
|
})();
|
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
|
-
*
|
|
44
|
+
* Build directory tree object recursively
|
|
45
45
|
*/
|
|
46
|
-
function buildTreeObject(dir,
|
|
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
|
-
|
|
53
|
-
|
|
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 (
|
|
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(
|
|
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(
|
|
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
|
|
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
|
-
*
|
|
96
|
+
* Convert tree to markdown
|
|
92
97
|
*/
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
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 += `${
|
|
102
|
+
md += `${indent}- ${node.name}\n`;
|
|
115
103
|
if (node.type === "directory" && node.children) {
|
|
116
|
-
md +=
|
|
104
|
+
md += toMarkdown("", node.children, depth + 1);
|
|
117
105
|
}
|
|
118
106
|
});
|
|
119
107
|
return md;
|
|
120
108
|
}
|
|
121
109
|
/**
|
|
122
|
-
*
|
|
110
|
+
* Generate output file
|
|
123
111
|
*/
|
|
124
|
-
function generateStructure(projectPath,
|
|
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,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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