Skip to content

Commit 48801b8

Browse files
committed
+Update readme
1 parent 62cdb6a commit 48801b8

File tree

6 files changed

+87
-33
lines changed

6 files changed

+87
-33
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,42 @@ Dart & Flutter Packages by dev-cetera.com & contributors.
1313

1414
<!-- BEGIN _README_CONTENT -->
1515

16-
## Summary
17-
1816
This tool automatically adds standardized comment headers to your source files, enhancing protection, consistency, and authenticity across your codebase.
1917

18+
## How to Use
19+
20+
### With Visual Studio Code
21+
22+
1. Install the extension here: https://marketplace.visualstudio.com/items?itemName=Dev-Cetera.dev-cetera-df-support-commands
23+
2. Create a template file in your project's directory and call it `header_template.md`:
24+
25+
````md
26+
```dart
27+
// The use of this source code is governed by the LICENSE file located in this
28+
// project's root directory.
29+
```
30+
````
31+
32+
3. Back up your source code!
33+
4. Right-click on any folder in your project and select `🔹 Generate Header Comments`.
34+
5. Alternatively, right-click a folder and select `"Open in Integrated Terminal"` then run `--headers -t path/to/header_template.md` in the terminal.
35+
6. This will modify source files in the folder and add the header comments.
36+
37+
### Without Visual Studio Code
38+
39+
1. Install this tool by running: `dart pub global activate df_generate_header_comments`.
40+
2. Back up your source code!
41+
3. Create a template file and call it something like `header_template.md`:
42+
43+
````md
44+
```dart
45+
// The use of this source code is governed by the LICENSE file located in this
46+
// project's root directory.
47+
```
48+
````
49+
50+
4. Open a terminal at a desired folder then run `--headers -t path/to/header_template.md` in the terminal. This will modify source files in the folder and add the header comments.
51+
2052
<!-- END _README_CONTENT -->
2153

2254
---

_README_CONTENT.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1-
## Summary
1+
This tool automatically adds standardized comment headers to your source files, enhancing protection, consistency, and authenticity across your codebase.
22

3-
This tool automatically adds standardized comment headers to your source files, enhancing protection, consistency, and authenticity across your codebase.
3+
## How to Use
4+
5+
### With Visual Studio Code
6+
7+
1. Install the extension here: https://marketplace.visualstudio.com/items?itemName=Dev-Cetera.dev-cetera-df-support-commands
8+
2. Create a template file in your project's directory and call it `header_template.md`:
9+
10+
````md
11+
```dart
12+
// The use of this source code is governed by the LICENSE file located in this
13+
// project's root directory.
14+
```
15+
````
16+
17+
3. Back up your source code!
18+
4. Right-click on any folder in your project and select `🔹 Generate Header Comments`.
19+
5. Alternatively, right-click a folder and select `"Open in Integrated Terminal"` then run `--headers -t path/to/header_template.md` in the terminal.
20+
6. This will modify source files in the folder and add the header comments.
21+
22+
### Without Visual Studio Code
23+
24+
1. Install this tool by running: `dart pub global activate df_generate_header_comments`.
25+
2. Back up your source code!
26+
3. Create a template file and call it something like `header_template.md`:
27+
28+
````md
29+
```dart
30+
// The use of this source code is governed by the LICENSE file located in this
31+
// project's root directory.
32+
```
33+
````
34+
35+
4. Open a terminal at a desired folder then run `--headers -t path/to/header_template.md` in the terminal. This will modify source files in the folder and add the header comments.

lib/df_generate_header_comments.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
/// A tool to generate header comments for your source files.
1414
library;
1515

16-
export 'src/_index.g.dart';
16+
export 'src/_src.dart';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
88
//.title~
99

10-
export 'generate_header_comments.dart';
10+
export './generate_header_comments.dart';

lib/src/generate_header_comments.dart

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Future<void> generateHeaderComments(
4545

4646
final help = argResults.flag(DefaultFlags.HELP.name);
4747
if (help) {
48-
_print(Log.printCyan, parser.getInfo(argParser));
48+
Log.printCyan(parser.getInfo(argParser));
4949
exit(ExitCodes.SUCCESS.code);
5050
}
5151

@@ -59,16 +59,13 @@ Future<void> generateHeaderComments(
5959
DefaultOptionParams.TEMPLATE_PATH_OR_URL.name,
6060
)!;
6161
} catch (_) {
62-
_print(
63-
Log.printRed,
64-
'Missing required args! Use --help flag for more information.',
65-
);
62+
Log.printRed('Missing required args! Use --help flag for more information.');
6663
exit(ExitCodes.FAILURE.code);
6764
}
6865

6966
// ---------------------------------------------------------------------------
7067

71-
_print(Log.printWhite, 'Looking for files..');
68+
Log.printWhite('Looking for files..');
7269
final filePathStream0 = PathExplorer(inputPath).exploreFiles();
7370
final filePathStream1 = filePathStream0.where((e) {
7471
final path = p.relative(e.path, from: inputPath);
@@ -78,55 +75,51 @@ Future<void> generateHeaderComments(
7875
try {
7976
findings = await filePathStream1.toList();
8077
} catch (e) {
81-
_print(Log.printRed, 'Failed to read file tree!');
78+
Log.printRed('Failed to read file tree!');
8279
exit(ExitCodes.FAILURE.code);
8380
}
8481
if (findings.isEmpty) {
85-
_print(Log.printYellow, 'No files found in $inputPath!');
82+
Log.printYellow('No files found in $inputPath!');
8683
exit(ExitCodes.SUCCESS.code);
8784
}
8885

8986
// ---------------------------------------------------------------------------
9087

9188
String templateData;
92-
_print(Log.printWhite, 'Reading template at: $template...');
89+
Log.printWhite('Reading template at: $template...');
9390

94-
final result = (await MdTemplateUtility.i
95-
.readTemplateFromPathOrUrl(template)
96-
.value);
91+
final result = (await MdTemplateUtility.i.readTemplateFromPathOrUrl(template).value);
9792

9893
if (result.isErr()) {
99-
_print(Log.printRed, ' Failed to read template!');
94+
Log.printRed(' Failed to read template!');
10095
exit(ExitCodes.FAILURE.code);
10196
}
10297
templateData = result.unwrap();
10398

10499
// ---------------------------------------------------------------------------
105100

106-
_print(Log.printWhite, 'Generating...');
101+
Log.printWhite('Generating...');
107102

108103
for (final finding in findings) {
109104
final filePath = finding.path;
110105
try {
111106
await _generateForFile(filePath, templateData);
112107
} catch (_) {
113-
_print(Log.printRed, 'Failed to write at: $filePath');
108+
Log.printRed('Failed to write at: $filePath');
114109
}
115110
}
116111

117112
// ---------------------------------------------------------------------------
118113

119-
_print(Log.printGreen, 'Done!');
114+
Log.printGreen('Done!');
120115
}
121116

122117
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
123118

124119
Future<void> _generateForFile(String filePath, String template) async {
125-
final commentStarter =
126-
langFileCommentStarters[p.extension(filePath).toLowerCase()] ?? '//';
120+
final commentStarter = langFileCommentStarters[p.extension(filePath).toLowerCase()] ?? '//';
127121
var templateLines = template.split('\n');
128-
final sourceLines =
129-
(await FileSystemUtility.i.readLocalFileAsLinesOrNull(filePath)) ?? [];
122+
final sourceLines = (await FileSystemUtility.i.readLocalFileAsLinesOrNull(filePath)) ?? [];
130123
if (sourceLines.isNotEmpty) {
131124
// Replace leading '//' in all template lines with the comment starter
132125
templateLines = templateLines.map((line) {
@@ -140,19 +133,14 @@ Future<void> _generateForFile(String filePath, String template) async {
140133
final line = sourceLines[n].trim();
141134
if (line.isEmpty || !line.startsWith(commentStarter)) {
142135
final withoutHeader = sourceLines.sublist(n).join('\n');
143-
final withHeader =
144-
'${templateLines.join('\n')}\n\n${withoutHeader.trimLeft()}\n';
136+
final withHeader = '${templateLines.join('\n')}\n\n${withoutHeader.trimLeft()}\n';
145137
await FileSystemUtility.i.writeLocalFile(filePath, withHeader);
146138
break;
147139
}
148140
}
149141
}
150142
}
151143

152-
void _print(void Function(String) print, String message) {
153-
print('[gen-header-comments] $message');
154-
}
155-
156144
bool _isAllowedFileName(String e) {
157145
final lc = e.toLowerCase();
158146
return !lc.startsWith('_') &&

pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ homepage: https://dev-cetera.com/
1515
repository: https://github.com/robmllze/df_generate_comment_headers
1616
funding:
1717
- https://www.buymeacoffee.com/dev_cetera
18+
- https://www.patreon.com/c/RobertMollentze
19+
- https://github.com/sponsors/robmllze
1820
description: A tool to generate header comments for your source files.
19-
version: 0.5.1
21+
version: 0.6.0
2022
topics:
2123
- source-gen
2224
- build-runner

0 commit comments

Comments
 (0)