Skip to content

Commit e22b9eb

Browse files
committed
Various cleanup. Changed output format to MarkDown.
1 parent 4d702c2 commit e22b9eb

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

src/extension.ts

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,24 @@ import * as vscode from 'vscode';
44
import * as fs from 'fs';
55
import * as path from 'path';
66

7-
// this method is called when your extension is activated
8-
// your extension is activated the very first time the command is executed
97
export function activate(context: vscode.ExtensionContext) {
108

11-
// Use the console to output diagnostic information (console.log) and errors (console.error)
12-
// This line of code will only be executed once when your extension is activated
13-
console.log('Congratulations, your extension "angulartools" is now active!');
14-
15-
// The command has been defined in the package.json file
16-
// Now provide the implementation of the command with registerCommand
17-
// The commandId parameter must match the command field in package.json
9+
// Implementation of the commands that has been defined in the package.json file
1810
const listAllImportsDisposable = vscode.commands.registerCommand('angulartools.listAllImports', () => {
1911
// The code you place here will be executed every time your command is executed
2012
var directoryPath: string = getWorkspaceFolder();
2113
const excludeDirectories = ['bin', 'obj', 'node_modules', 'dist', 'packages', '.git', '.vs', '.github'];
2214
const isTypescriptFile = (filename: string): boolean => filename.endsWith('.ts') && !filename.endsWith('index.ts');
2315
const files = listFiles(directoryPath, excludeDirectories, isTypescriptFile);
24-
console.log('files:' + files.length);
25-
writeResult('imports.txt', files);
26-
// Display a message box to the user
27-
//vscode.window.showInformationMessage('Hello World from AngularTools!\n' + directoryPath + '\n');
16+
writeResult('ReadMe-Imports.md', files);
2817
});
2918
context.subscriptions.push(listAllImportsDisposable);
3019

3120
const projectDirectoryStructureDisposable = vscode.commands.registerCommand('angulartools.projectDirectoryStructure', () => {
32-
var directoryPath: string = getWorkspaceFolder();
21+
var workspaceDirectory: string = getWorkspaceFolder();
3322
const excludeDirectories = ['bin', 'obj', 'node_modules', 'dist', 'packages', '.git', '.vs', '.github'];
34-
const gDirectories: string[] = listDirectories(directoryPath, excludeDirectories);
35-
writeDirectoryStructure(directoryPath, 'projectDirectoryStructure.txt', gDirectories);
36-
vscode.window.showInformationMessage('Hello World from AngularTools!\n');
23+
const directories: string[] = listDirectories(workspaceDirectory, excludeDirectories);
24+
writeDirectoryStructure(workspaceDirectory, 'ReadMe-ProjectDirectoryStructure.md', directories);
3725
});
3826
context.subscriptions.push(projectDirectoryStructureDisposable);
3927
}
@@ -67,14 +55,17 @@ function writeResult(filename: string, results: string[]) {
6755
}
6856
});
6957
}
70-
var directoryPath: string = getWorkspaceFolder();
71-
var output = `Imports for files in workspace: ${directoryPath}\n`;
58+
var workspaceDirectory: string = getWorkspaceFolder();
59+
var output = `# Imports for files in workspace: ${workspaceDirectory}\n\n`+
60+
'The number following each import in the list is the number of occurrences of the package import.\n\n' +
61+
"```text\n";
7262
for (const key of Object.keys(imports).sort()) {
7363
console.log(`${key}: ${imports[key]}`);
7464
output = output + `${key}: ${imports[key]}\n`;
7565
}
76-
console.log('open file ' + path.join(directoryPath, filename));
77-
writeFileAndOpen(path.join(directoryPath, filename), output);
66+
output = output + "```\n";
67+
console.log('open file ' + path.join(workspaceDirectory, filename));
68+
writeFileAndOpen(path.join(workspaceDirectory, filename), output);
7869
};
7970

8071
function listFiles(
@@ -95,11 +86,12 @@ function listFiles(
9586
}
9687

9788
function writeDirectoryStructure(workSpaceDirectory: string, filename: string, directories: string[]) {
98-
var output: string = `Workspace directory: ${workSpaceDirectory}\nDirectories:\n`;
89+
var output: string = `# Project Directory Structure\n\nWorkspace directory: ${workSpaceDirectory}\n\n## Directories\n\n` + "```text\n";
9990
directories?.forEach(directoryFullPath => {
10091
var directoryName = directoryFullPath.replace(workSpaceDirectory, '.');
10192
output = output + directoryName + '\n';
10293
});
94+
output = output + "```\n";
10395
var directoryPath: string = getWorkspaceFolder();
10496
writeFileAndOpen(path.join(directoryPath, filename), output);
10597
}

0 commit comments

Comments
 (0)