-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproject_structure.txt
217 lines (175 loc) · 5.74 KB
/
project_structure.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
--- Folder Structure ---
.gitignore
extension.js
jsconfig.json
package.json
--- File Contents ---
--- File: .gitignore ---
node_modules
.vscode-test/
*.vsix
--- File: extension.js ---
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const fs = require('fs');
const path = require('path');
// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "vscode-project-structure" is now active!');
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
// let disposable = vscode.commands.registerCommand('vscode-project-structure.helloWorld', function () {
// // The code you place here will be executed every time your command is executed
// // Display a message box to the user
// vscode.window.showInformationMessage('Hello World from vscode-project-structure!');
// });
let disposable = vscode.commands.registerCommand('extension.generateProjectStructure', () => {
generateProjectStructure();
})
context.subscriptions.push(disposable);
}
function generateProjectStructure() {
const rootPath = vscode.workspace.workspaceFolders
? vscode.workspace.workspaceFolders[0].uri.fsPath
: undefined;
if (!rootPath) {
vscode.window.showErrorMessage('No workspace folder is open');
return;
}
const ignoreFilePath = path.join(rootPath, '.project_structure_ignore');
let ignoreFiles = [];
if (fs.existsSync(ignoreFilePath)) {
const ignoreFileContent = fs.readFileSync(ignoreFilePath, 'utf-8');
ignoreFiles = ignoreFileContent.split('\n').filter(line => line.trim() !== '');
}
let output = '';
output += '--- Folder Structure ---\n';
output += getFolderStructure(rootPath, ignoreFiles, 0);
output += '\n--- File Contents ---\n';
output += getFileContents(rootPath, ignoreFiles);
const outputPath = path.join(rootPath, 'project_structure.txt');
fs.writeFileSync(outputPath, output);
vscode.window.showInformationMessage('Project structure generated successfully');
}
function getFolderStructure(dir, ignoreFiles, level) {
let output = '';
if (fs.existsSync(dir)) {
const files = fs.readdirSync(dir);
files.forEach((file, index) => {
const fullPath = path.join(dir, file);
if (ignoreFiles.includes(file)) {
return;
}
const isLastFile = index === files.length - 1;
const prefix = level === 0 ? '' : isLastFile ? '└── ' : '├── ';
const indent = ' '.repeat(level * 4) + (level > 0 ? prefix : '');
if (fs.lstatSync(fullPath).isDirectory()) {
output += indent + `[${file}]\n`;
output += getFolderStructure(fullPath, ignoreFiles, level + 1);
} else {
output += indent + file + '\n';
}
});
}
return output;
}
function getFileContents(dir, ignoreFiles) {
let output = '';
const readDirectory = (directory) => {
let results = [];
const files = fs.readdirSync(directory);
files.forEach(file => {
const fullPath = path.join(directory, file);
if (ignoreFiles.includes(file)) {
return;
}
if (fs.lstatSync(fullPath).isDirectory()) {
results = results.concat(readDirectory(fullPath));
} else {
results.push(fullPath);
}
});
return results;
};
const filePaths = readDirectory(dir);
filePaths.forEach(filePath => {
const relativePath = path.relative(dir, filePath);
output += `\n--- File: ${relativePath} ---\n`;
output += fs.readFileSync(filePath, 'utf-8') + '\n';
});
return output;
}
// This method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}
--- File: jsconfig.json ---
{
"compilerOptions": {
"module": "commonjs",
"target": "ES2020",
"checkJs": false, /* Typecheck .js files. */
"lib": [
"ES2020"
]
},
"exclude": [
"node_modules"
]
}
--- File: package.json ---
{
"name": "vscode-project-structure",
"displayName": "vscode-project-structure",
"description": "Print the project folder structure, file name and file contents into a txt file",
"version": "0.0.2",
"icon": "images/logo.jpeg",
"engines": {
"vscode": "^1.76.0"
},
"categories": [
"Other"
],
"publisher": "Austin-Lin",
"repository": {
"type": "git",
"url": "https://github.com/l02162010/VSCode-Project-Structure"
},
"license": "MIT",
"activationEvents": [],
"main": "./extension.js",
"contributes": {
"commands": [
{
"command": "extension.generateProjectStructure",
"title": "Generate Project Structure"
}
]
},
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "node ./test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.76.0",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "16.x",
"eslint": "^8.34.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"typescript": "^4.9.5",
"@vscode/test-electron": "^2.2.3"
}
}