@@ -4,36 +4,24 @@ import * as vscode from 'vscode';
4
4
import * as fs from 'fs' ;
5
5
import * as path from 'path' ;
6
6
7
- // this method is called when your extension is activated
8
- // your extension is activated the very first time the command is executed
9
7
export function activate ( context : vscode . ExtensionContext ) {
10
8
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
18
10
const listAllImportsDisposable = vscode . commands . registerCommand ( 'angulartools.listAllImports' , ( ) => {
19
11
// The code you place here will be executed every time your command is executed
20
12
var directoryPath : string = getWorkspaceFolder ( ) ;
21
13
const excludeDirectories = [ 'bin' , 'obj' , 'node_modules' , 'dist' , 'packages' , '.git' , '.vs' , '.github' ] ;
22
14
const isTypescriptFile = ( filename : string ) : boolean => filename . endsWith ( '.ts' ) && ! filename . endsWith ( 'index.ts' ) ;
23
15
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 ) ;
28
17
} ) ;
29
18
context . subscriptions . push ( listAllImportsDisposable ) ;
30
19
31
20
const projectDirectoryStructureDisposable = vscode . commands . registerCommand ( 'angulartools.projectDirectoryStructure' , ( ) => {
32
- var directoryPath : string = getWorkspaceFolder ( ) ;
21
+ var workspaceDirectory : string = getWorkspaceFolder ( ) ;
33
22
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 ) ;
37
25
} ) ;
38
26
context . subscriptions . push ( projectDirectoryStructureDisposable ) ;
39
27
}
@@ -67,14 +55,17 @@ function writeResult(filename: string, results: string[]) {
67
55
}
68
56
} ) ;
69
57
}
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" ;
72
62
for ( const key of Object . keys ( imports ) . sort ( ) ) {
73
63
console . log ( `${ key } : ${ imports [ key ] } ` ) ;
74
64
output = output + `${ key } : ${ imports [ key ] } \n` ;
75
65
}
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 ) ;
78
69
} ;
79
70
80
71
function listFiles (
@@ -95,11 +86,12 @@ function listFiles(
95
86
}
96
87
97
88
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" ;
99
90
directories ?. forEach ( directoryFullPath => {
100
91
var directoryName = directoryFullPath . replace ( workSpaceDirectory , '.' ) ;
101
92
output = output + directoryName + '\n' ;
102
93
} ) ;
94
+ output = output + "```\n" ;
103
95
var directoryPath : string = getWorkspaceFolder ( ) ;
104
96
writeFileAndOpen ( path . join ( directoryPath , filename ) , output ) ;
105
97
}
0 commit comments