Skip to content

Commit 6a972c8

Browse files
authored
Merge pull request #4 from ioncakephper:feature/allow-multiple-filenames
* chore(CHANGELOG.md): update changelog for version 1.1.0
2 parents c762191 + a008bf1 commit 6a972c8

File tree

6 files changed

+462
-47
lines changed

6 files changed

+462
-47
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
*Changelog created using the [Simple Changelog](https://marketplace.visualstudio.com/items?itemName=tobiaswaelde.vscode-simple-changelog) extension for VS Code.*
44

5+
## [1.1.0] - 2024-12-17
6+
### Added
7+
- Extended action scope: use pattern(s) to indicate folders and filenames
8+
9+
### Changed
10+
- Changed the argument to represent a filename pattern
11+
12+
513
## [1.0.3] - 2024-12-17
614
### Changed
715
- Commented out test in processSourceCode.test.js

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ The `insert-file-tag` package is a Node.js utility that simplifies the process o
99
The package works by parsing your document, looking for special HTML-style comment tags that indicate the path to the file you want to insert. For example:
1010

1111
```html
12-
<!-- Error processing file: path/to/code.js -->
13-
14-
12+
<!-- ::insert file="path/to/code.js" -->
13+
Content of path/to/code.js file will be inserted here.
14+
<!-- ::/insert -->
1515
```
1616

1717
The content of path/to/code.js will be inserted between these tags when the utility is run. This keeps your main document clean and maintainable while allowing you to include dynamic content from other sources. insert-file-tag supports various file types and can be easily integrated into your build process.
1818

1919
## Table of Contents <!-- omit in toc -->
2020

2121
- [Getting Started](#getting-started)
22-
- [Installing](#installing)
22+
- [Installing](#installing)
2323
- [Usage](#usage)
2424
- [Author](#author)
2525
- [License](#license)
@@ -28,21 +28,52 @@ The content of path/to/code.js will be inserted between these tags when the util
2828

2929
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See [deployment](#deployment) for notes on how to deploy the project on a live system.
3030

31-
### Installing
31+
## Installing
32+
33+
```bash
34+
$ npm i insert-file-tag
35+
```
36+
37+
Or,
38+
39+
```bash
40+
$ npm i insert-file-tag -g
41+
```
42+
43+
This will install the package globally, making it available from the command line. After installing, you can run the `instags` command.
44+
45+
```bash
46+
$ instags -h
47+
```
48+
49+
Or,
50+
51+
You can skip installing it the package globally, and use the `npx instags` command.
3252

3353
```bash
34-
$ npm install insert-file-tag
54+
$ npx insert-file-tag -h
3555
```
3656

3757
## Usage
3858

3959
**Basic Usage:**
4060

4161
```bash
42-
npx insert-file-tag input.md output.md
62+
npx instags -h
63+
```
64+
65+
This will display the help message, showing available options like `-V` (version) -o (output folder, and others. It explains how to use the command.
66+
67+
```
68+
npx instags -V
69+
```
70+
This will display the version number of the installed insert-file-tag package.
71+
72+
```bash
73+
$ npx instags README.md
4374
```
4475

45-
This will process `input.md`, insert the content specified by the tags, and write the result to `output.md`.
76+
This command will process the README.md file. It will search for any <!-- ::insert ... --> tags within README.md. If any are found, the specified file content will be inserted in place of the tag, and the updated content will be written back to README.md. If no insert tags are present, the file will remain unchanged.
4677

4778
## Author
4879

cli.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,36 @@ const { Command } = require('commander');
44
const { processAndSaveFileWithTags } = require('./src/source-processor');
55
const packageJson = require('./package.json');
66
const path = require('path');
7+
const { globSync } = require('glob');
78

89
const program = new Command();
910

1011
program
1112
.name(packageJson.name)
1213
.version(packageJson.version)
1314
.description(packageJson.description)
14-
.argument('<filename>', 'file to process for insert tags')
15-
.option('-o, --output <output>', 'output filename', '')
16-
.action((filename, options) => {
17-
const outputFilename = options.output || filename;
18-
try {
19-
processAndSaveFileWithTags(filename, outputFilename);
20-
} catch (error) {
21-
console.error(error);
22-
process.exit(1);
23-
}
15+
.argument('[pattern...]', 'filename pattern(s) to process for insert tags', ['README.md'])
16+
.option('-o, --output <path>', 'output directory for processed files', '')
17+
.option('-v, --verbose', 'verbose output', false)
18+
.action((pattern, options) => {
19+
pattern = Array.isArray(pattern) ? pattern : [pattern];
20+
const filenames = globSync(pattern);
21+
filenames.forEach((filename) => {
22+
const outputFilename = path.join(options.output, filename);
23+
try {
24+
processAndSaveFileWithTags(filename, outputFilename);
25+
} catch (error) {
26+
console.error(error);
27+
process.exit(1);
28+
}
29+
})
30+
31+
})
32+
.configureHelp({
33+
sortOptions: true,
34+
sortSubcommands: true,
35+
subcommandTerm: '<command>',
36+
helpWidth: 80
2437
});
2538

2639
program.parse(process.argv);

0 commit comments

Comments
 (0)