stdin-glob 1.0.1 → 1.0.5

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.
@@ -6,6 +6,8 @@ name: NPM Package
6
6
  on:
7
7
  push:
8
8
  branches: [main]
9
+ tags:
10
+ - 'v*'
9
11
 
10
12
  permissions:
11
13
  id-token: write # Required for OIDC
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,49 @@ 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
+ * Get file content with markdown format
43
62
  */
44
- const printFileWithFormat = async (filePath) => {
63
+ const getFileContent = async (filePath) => {
45
64
  try {
46
65
  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();
66
+ const extension = path_1.default.extname(filePath).replace('.', '');
67
+ return ('```' +
68
+ extension +
69
+ '\n' +
70
+ `// ${filePath}\n\n` +
71
+ content +
72
+ '\n' +
73
+ '```\n\n');
53
74
  }
54
75
  catch (e) {
55
76
  console.error(`Error reading file ${filePath}:`, e);
77
+ return '';
56
78
  }
57
79
  };
58
80
  //# 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,8BAA8B,CAAC;KACzD,MAAM,CAAC,KAAK,EAAE,QAAkB,EAAE,OAAgB,EAAE,EAAE;IACrD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,aAAa;IACb,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAI,EAAC,QAAQ,EAAE;QACjC,SAAS,EAAE,IAAI;QACf,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"version": "1.0.1",
3
+ "version": "1.0.5",
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,50 @@ 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
+ * Get file content with markdown format
48
72
  */
49
- const printFileWithFormat = async (filePath: string) => {
73
+ const getFileContent = async (filePath: string): Promise<string> => {
50
74
  try {
51
75
  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();
76
+ const extension = path.extname(filePath).replace('.', '');
77
+ return (
78
+ '```' +
79
+ extension +
80
+ '\n' +
81
+ `// ${filePath}\n\n` +
82
+ content +
83
+ '\n' +
84
+ '```\n\n'
85
+ );
58
86
  } catch (e) {
59
87
  console.error(`Error reading file ${filePath}:`, e);
88
+ return '';
60
89
  }
61
90
  };