stdin-glob 1.0.1 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,8 @@ name: NPM Package
5
5
 
6
6
  on:
7
7
  push:
8
- branches: [main]
8
+ tags:
9
+ - 'v*'
9
10
 
10
11
  permissions:
11
12
  id-token: write # Required for OIDC
package/README.md CHANGED
@@ -25,6 +25,7 @@ This pipes all relevant TypeScript/TSX files directly into my clipboard, ready t
25
25
 
26
26
  - Expand glob patterns to find matching files
27
27
  - Output file contents with syntax highlighting markers
28
+ - Copy output directly to clipboard with `--copy` flag
28
29
  - Support for absolute or relative paths
29
30
  - Option to show only file paths without content
30
31
  - Written in TypeScript
@@ -43,12 +44,13 @@ stdin-glob [options] [patterns...]
43
44
 
44
45
  ### Options
45
46
 
46
- | Option | Description |
47
- | --------------- | --------------------------------------------------- |
48
- | `--no-content` | Do not show file contents, only list matching paths |
49
- | `--absolute` | Show absolute paths for entries |
50
- | `-V, --version` | Output the version number |
51
- | `-h, --help` | Display help information |
47
+ | Option | Description |
48
+ | --------------- | ----------------------------------------------------------- |
49
+ | `--no-content` | Do not show file contents, only list matching paths |
50
+ | `--absolute` | Show absolute paths for entries |
51
+ | `-c, --copy` | Copy the output to clipboard instead of printing to console |
52
+ | `-V, --version` | Output the version number |
53
+ | `-h, --help` | Display help information |
52
54
 
53
55
  ### Arguments
54
56
 
@@ -90,6 +92,22 @@ function add(a, b) {
90
92
  ```
91
93
  ````
92
94
 
95
+ ### Copy to clipboard
96
+
97
+ Copy all TypeScript file contents directly to clipboard:
98
+
99
+ ```bash
100
+ stdin-glob "src/**/*.ts" --copy
101
+ ```
102
+
103
+ This will copy the formatted output to your clipboard without printing to console. You'll see a confirmation message:
104
+
105
+ ```
106
+ -> Output copied to clipboard successfully!
107
+ ```
108
+
109
+ Now you can paste (Ctrl+V or Cmd+V) anywhere - perfect for sharing code in pull requests, documentation, or with LLMs.
110
+
93
111
  ### Only list files
94
112
 
95
113
  List all TypeScript files in the src directory without content:
@@ -137,3 +155,14 @@ Use with grep to search for specific content:
137
155
  ```bash
138
156
  stdin-glob "src/**/*.ts" | grep "function"
139
157
  ```
158
+
159
+ Or combine with other clipboard tools for maximum flexibility:
160
+
161
+ ```bash
162
+ # Copy without the confirmation message
163
+ stdin-glob "src/**/*.ts" --no-content | pbcopy
164
+
165
+ # Preview first, then copy if it looks good
166
+ stdin-glob "src/**/*.ts" --content
167
+ stdin-glob "src/**/*.ts" --copy
168
+ ```
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const package_json_1 = require("../package.json");
8
8
  const promises_1 = require("fs/promises");
9
9
  const fast_glob_1 = __importDefault(require("fast-glob"));
10
10
  const path_1 = __importDefault(require("path"));
11
+ const clipboardy_1 = __importDefault(require("clipboardy"));
11
12
  const program = new commander_1.Command();
12
13
  program
13
14
  .name('stdin-glob')
@@ -15,6 +16,7 @@ program
15
16
  .version(package_json_1.version)
16
17
  .option('--no-content', 'Do not show file contents, only list matching paths')
17
18
  .option('--absolute', 'Show the absolute path for entries')
19
+ .option('-c, --copy', 'Copy the output to clipboard instead of printing to console')
18
20
  .argument('[patterns...]', 'Glob patterns to match files')
19
21
  .action(async (patterns, options) => {
20
22
  if (patterns.length === 0) {
@@ -30,29 +32,61 @@ program
30
32
  console.error('No files matched the given patterns.');
31
33
  process.exit(1);
32
34
  }
35
+ let output = '';
33
36
  for (const file of files) {
34
- if (options.content)
35
- await printFileWithFormat(file);
36
- else
37
- console.log(file);
37
+ if (options.content) {
38
+ const fileOutput = await getFileContent(file);
39
+ output += fileOutput;
40
+ }
41
+ else {
42
+ output += file + '\n';
43
+ }
44
+ }
45
+ if (options.copy) {
46
+ try {
47
+ await clipboardy_1.default.write(output.trim());
48
+ console.log('-> Output copied to clipboard successfully!');
49
+ }
50
+ catch (error) {
51
+ console.error('-X Error copying to clipboard:', error);
52
+ process.exit(1);
53
+ }
54
+ }
55
+ else {
56
+ console.log(output.trim());
38
57
  }
39
58
  });
40
59
  program.parse(process.argv);
41
60
  /**
42
- * Print files with format markdown
61
+ * Find the maximum number of consecutive backticks in a string
62
+ */
63
+ const findMaxConsecutiveBackticks = (str) => {
64
+ const matches = str.match(/`+/g);
65
+ if (!matches)
66
+ return 0;
67
+ return Math.max(...matches.map((m) => m.length));
68
+ };
69
+ /**
70
+ * Get file content with markdown format
43
71
  */
44
- const printFileWithFormat = async (filePath) => {
72
+ const getFileContent = async (filePath) => {
45
73
  try {
46
74
  const content = await (0, promises_1.readFile)(filePath, 'utf-8');
47
- console.log('```' + path_1.default.extname(filePath).replace('.', ''));
48
- console.log(`// ${filePath}`);
49
- console.log();
50
- console.log(content);
51
- console.log('```');
52
- console.log();
75
+ const extension = path_1.default.extname(filePath).replace('.', '');
76
+ const maxBackticks = findMaxConsecutiveBackticks(content);
77
+ const wrapper = '`'.repeat(Math.max(3, maxBackticks + 1));
78
+ return (wrapper +
79
+ extension +
80
+ '\n' +
81
+ `// ${filePath}\n\n` +
82
+ content +
83
+ '\n' +
84
+ wrapper +
85
+ '\n\n');
53
86
  }
54
87
  catch (e) {
55
88
  console.error(`Error reading file ${filePath}:`, e);
89
+ return '';
56
90
  }
57
91
  };
58
92
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,yCAAoC;AACpC,kDAA0C;AAC1C,0CAAuC;AACvC,0DAA6B;AAC7B,gDAAwB;AAOxB,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,YAAY,CAAC;KAClB,WAAW,CAAC,yDAAyD,CAAC;KACtE,OAAO,CAAC,sBAAO,CAAC;KAChB,MAAM,CAAC,cAAc,EAAE,qDAAqD,CAAC;KAC7E,MAAM,CAAC,YAAY,EAAE,oCAAoC,CAAC;KAC1D,QAAQ,CAAC,eAAe,EAAE,8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,MAAM,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,cAAc,GAAG,KAAK,EAAE,QAAgB,EAAmB,EAAE;IACjE,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1D,MAAM,YAAY,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC;QAE1D,OAAO,CACL,OAAO;YACP,SAAS;YACT,IAAI;YACJ,MAAM,QAAQ,MAAM;YACpB,OAAO;YACP,IAAI;YACJ,OAAO;YACP,MAAM,CACP,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,sBAAsB,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;QACpD,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stdin-glob",
3
- "version": "1.0.1",
3
+ "version": "1.0.7",
4
4
  "description": "Expand glob patterns and output file contents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -30,6 +30,7 @@
30
30
  },
31
31
  "homepage": "https://github.com/rodnye/stdin-glob#readme",
32
32
  "dependencies": {
33
+ "clipboardy": "^5.3.1",
33
34
  "commander": "^11.1.0",
34
35
  "fast-glob": "^3.3.3"
35
36
  },
package/src/index.ts CHANGED
@@ -3,10 +3,12 @@ import { version } from '../package.json';
3
3
  import { readFile } from 'fs/promises';
4
4
  import glob from 'fast-glob';
5
5
  import path from 'path';
6
+ import clipboard from 'clipboardy';
6
7
 
7
8
  interface Options {
8
9
  content?: boolean;
9
10
  absolute?: boolean;
11
+ copy?: boolean;
10
12
  }
11
13
 
12
14
  const program = new Command();
@@ -17,6 +19,10 @@ program
17
19
  .version(version)
18
20
  .option('--no-content', 'Do not show file contents, only list matching paths')
19
21
  .option('--absolute', 'Show the absolute path for entries')
22
+ .option(
23
+ '-c, --copy',
24
+ 'Copy the output to clipboard instead of printing to console',
25
+ )
20
26
  .argument('[patterns...]', 'Glob patterns to match files')
21
27
  .action(async (patterns: string[], options: Options) => {
22
28
  if (patterns.length === 0) {
@@ -35,27 +41,63 @@ program
35
41
  process.exit(1);
36
42
  }
37
43
 
44
+ let output = '';
45
+
38
46
  for (const file of files) {
39
- if (options.content) await printFileWithFormat(file);
40
- else console.log(file);
47
+ if (options.content) {
48
+ const fileOutput = await getFileContent(file);
49
+ output += fileOutput;
50
+ } else {
51
+ output += file + '\n';
52
+ }
53
+ }
54
+
55
+ if (options.copy) {
56
+ try {
57
+ await clipboard.write(output.trim());
58
+ console.log('-> Output copied to clipboard successfully!');
59
+ } catch (error) {
60
+ console.error('-X Error copying to clipboard:', error);
61
+ process.exit(1);
62
+ }
63
+ } else {
64
+ console.log(output.trim());
41
65
  }
42
66
  });
43
67
 
44
68
  program.parse(process.argv);
45
69
 
46
70
  /**
47
- * Print files with format markdown
71
+ * Find the maximum number of consecutive backticks in a string
72
+ */
73
+ const findMaxConsecutiveBackticks = (str: string): number => {
74
+ const matches = str.match(/`+/g);
75
+ if (!matches) return 0;
76
+ return Math.max(...matches.map((m) => m.length));
77
+ };
78
+
79
+ /**
80
+ * Get file content with markdown format
48
81
  */
49
- const printFileWithFormat = async (filePath: string) => {
82
+ const getFileContent = async (filePath: string): Promise<string> => {
50
83
  try {
51
84
  const content = await readFile(filePath, 'utf-8');
52
- console.log('```' + path.extname(filePath).replace('.', ''));
53
- console.log(`// ${filePath}`);
54
- console.log();
55
- console.log(content);
56
- console.log('```');
57
- console.log();
85
+ const extension = path.extname(filePath).replace('.', '');
86
+ const maxBackticks = findMaxConsecutiveBackticks(content);
87
+ const wrapper = '`'.repeat(Math.max(3, maxBackticks + 1));
88
+
89
+ return (
90
+ wrapper +
91
+ extension +
92
+ '\n' +
93
+ `// ${filePath}\n\n` +
94
+ content +
95
+ '\n' +
96
+ wrapper +
97
+ '\n\n'
98
+ );
58
99
  } catch (e) {
59
100
  console.error(`Error reading file ${filePath}:`, e);
101
+ return '';
60
102
  }
61
103
  };