Skip to content

Commit 5a1a697

Browse files
committed
#16 - New setting + message implementation
1 parent e2e57e1 commit 5a1a697

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [2.5.0] 11-07-2022
4+
5+
- [#16](https://github.com/estruyf/vscode-typescript-exportallmodules/issues/16): New `exportall.config.message` setting to specify a message that will be added at the top of the generated barrel file.
6+
37
## [2.4.1] 20-06-2022
48

59
- Changed activation to `onStartupFinished`

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ The extension makes use of the following settings:
9696
| `exportall.config.relExclusion` | Specify the relative folder/file paths to exclude from the export. | string[] | `[]` |
9797
| `exportall.config.semis` | Specify if you want to enable/disable the usage of semis in the barrel file. | boolean | `true` |
9898
| `exportall.config.quote` | Specify the character that you want to use as the quoting character; typically `'` or `"`. | string | `'` |
99+
| `exportall.config.message` | Specify the message that you want to use in the generated barrel file. The message will be added at the top. | string | |
99100

100101
<p align="center">
101102
<img src="./assets/config.png" alt="Config settings example" style="display: inline-block" />

Diff for: package.json

+4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@
159159
"Double quote"
160160
],
161161
"description": "Specify the character that you want to use as the quoting character; typically ' or \""
162+
},
163+
"exportall.config.message": {
164+
"type": "string",
165+
"description": "Specify the message that you want to use in the generated barrel file. The message will be added at the top."
162166
}
163167
}
164168
}

Diff for: src/commands/ExportAll.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
33
import * as fs from 'fs';
4-
import { getSettingName, CONFIG_EXCLUDE, CONFIG_INCLUDE_FOLDERS, CONFIG_RELATIVE_EXCLUDE, CONFIG_SEMIS, CONFIG_QUOTE, EXTENSION_NAME } from '../constants';
4+
import { getSettingName, CONFIG_EXCLUDE, CONFIG_INCLUDE_FOLDERS, CONFIG_RELATIVE_EXCLUDE, CONFIG_SEMIS, CONFIG_QUOTE, EXTENSION_NAME, CONFIG_MESSAGE, EXTENSION_KEY } from '../constants';
55
import { getRelativeFolderPath } from '../helpers';
66
import { Logger } from '../helpers/logger';
77

@@ -15,11 +15,13 @@ export class ExportAll {
1515

1616
public static async start(uri: vscode.Uri, runSilent: boolean = true) {
1717
try {
18-
const excludeFiles: string | undefined = vscode.workspace.getConfiguration().get(getSettingName(CONFIG_EXCLUDE));
19-
const excludeRel: string | undefined = vscode.workspace.getConfiguration().get(getSettingName(CONFIG_RELATIVE_EXCLUDE));
20-
const includeFolders: boolean | undefined = vscode.workspace.getConfiguration().get(getSettingName(CONFIG_INCLUDE_FOLDERS));
21-
const semis: boolean | undefined = vscode.workspace.getConfiguration().get(getSettingName(CONFIG_SEMIS));
22-
const quote: "\"" | "'" = vscode.workspace.getConfiguration().get(getSettingName(CONFIG_QUOTE)) ?? "'";
18+
const config = vscode.workspace.getConfiguration(EXTENSION_KEY);
19+
const excludeFiles: string | undefined = config.get(CONFIG_EXCLUDE);
20+
const excludeRel: string | undefined = config.get(CONFIG_RELATIVE_EXCLUDE);
21+
const includeFolders: boolean | undefined = config.get(CONFIG_INCLUDE_FOLDERS);
22+
const semis: boolean | undefined = config.get(CONFIG_SEMIS);
23+
const quote: "\"" | "'" = config.get(CONFIG_QUOTE) ?? "'";
24+
const message: string | string[] | undefined = config.get<string | string[]>(CONFIG_MESSAGE);
2325

2426
const folderPath = uri.fsPath;
2527
const files = fs.readdirSync(folderPath);
@@ -109,6 +111,12 @@ export class ExportAll {
109111
const fileUri = vscode.Uri.file(filePath);
110112
const document = await vscode.workspace.openTextDocument(fileUri);
111113

114+
// Check if the banner message needs to be added
115+
if (message) {
116+
output.unshift(`\n`);
117+
output.unshift(`// ${message}\n`);
118+
}
119+
112120
let fileContents = document.getText();
113121
let updatedFileContents = output.join("");
114122

Diff for: src/constants/Extension.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const CONFIG_RELATIVE_EXCLUDE = 'config.relExclusion';
55
export const CONFIG_INCLUDE_FOLDERS = 'config.includeFoldersToExport';
66
export const CONFIG_SEMIS = 'config.semis';
77
export const CONFIG_QUOTE = 'config.quote';
8+
export const CONFIG_MESSAGE = 'config.message';
89

910
export const EXTENSION_NAME = "Barrel Generator";
1011

0 commit comments

Comments
 (0)