catco 1.0.1 → 2.0.1
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.
- package/README.md +31 -32
- package/dist/index.cjs +58 -57
- package/dist/index.js +57 -57
- package/dist/index.mjs +58 -57
- package/package.json +63 -60
- package/dist/index.d.cts +0 -1
- package/dist/index.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# catco
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
catco does two things.
|
|
4
|
+
|
|
5
|
+
1. It creates a single string of text from the contents of all files that match a glob.
|
|
6
|
+
2. It can take a file of combined file contents and scaffold directories/files from it.
|
|
4
7
|
|
|
5
8
|
## Install
|
|
6
9
|
|
|
@@ -8,44 +11,40 @@ Glob copy file contents to ya clipboard. Use it to quickly share many files with
|
|
|
8
11
|
npm i -g catco
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Copying files to your clipboard
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
You give catco a glob pattern, it reads every matching file, wraps each one in a little `/* FILE: ./path/to/file */` comment, minifies the whole thing into a single string, and puts it in your clipboard.
|
|
14
19
|
|
|
20
|
+
```sh
|
|
21
|
+
catco "./src/**/*.ts"
|
|
15
22
|
```
|
|
16
|
-
catco src/components/**/*.ts
|
|
17
23
|
|
|
18
|
-
|
|
24
|
+
Multiple patterns work too. Just keep adding them.
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
```sh
|
|
27
|
+
catco "./src/**/*.ts" "./src/**/*.css"
|
|
21
28
|
```
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
If you want to skip certain files, pass `--ignore` with a space-separated list of patterns.
|
|
24
31
|
|
|
32
|
+
```sh
|
|
33
|
+
catco "./src/**/*.ts" --ignore "**/*.test.ts **/*.spec.ts"
|
|
25
34
|
```
|
|
26
|
-
|
|
27
|
-
node_modules
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
build/**
|
|
36
|
-
coverage
|
|
37
|
-
coverage/**
|
|
38
|
-
.next
|
|
39
|
-
.next/**
|
|
40
|
-
.vercel
|
|
41
|
-
.vercel/**
|
|
42
|
-
.turbo
|
|
43
|
-
.turbo/**
|
|
44
|
-
.DS_Store
|
|
45
|
-
*.log
|
|
46
|
-
npm-debug.log
|
|
47
|
-
yarn-error.log
|
|
48
|
-
pnpm-debug.log
|
|
49
|
-
.env
|
|
50
|
-
.env.*
|
|
35
|
+
|
|
36
|
+
Without `--ignore`, catco already skips the usual suspects — `node_modules`, `dist`, `build`, `.git`, `.env`, log files, and framework cache folders like `.next`, `.vercel`, and `.turbo`.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Parsing a string of combined files into files/directories.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
catco parse ./output.txt ./my-project
|
|
51
44
|
```
|
|
45
|
+
|
|
46
|
+
That reads `output.txt`, finds every `/* FILE: ./some/path */` section, creates whatever folders are needed, and writes each file.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
The output format catco uses is plain enough you can give it to AI if you need to. The `/* FILE: */` markers are just comments, so syntax highlighting still works and nothing breaks if you drop it into a code block.
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
|
-
var fs = require('node:fs');
|
|
4
4
|
var path = require('node:path');
|
|
5
|
-
var
|
|
5
|
+
var sade = require('sade');
|
|
6
6
|
var clipboard = require('clipboardy');
|
|
7
|
+
var fs = require('node:fs');
|
|
8
|
+
var globby = require('globby');
|
|
7
9
|
|
|
8
10
|
const minify = (content) => {
|
|
9
11
|
const minified = content.replace(/\s+/g, " ").replace(/\s*([\{\}\[\]\(\),;:])\s*/g, "$1").replace(/\s*=\s*/g, "=").replace(/\s*>\s*/g, ">").replace(/;\s*/g, ";").replace(/"\s+/g, '"').replace(/\s+"/g, '"').replace(/'\s+/g, "'").replace(/\s+'/g, "'").trim();
|
|
@@ -39,65 +41,64 @@ const DEFAULT_ANTI_PATTERNS = [
|
|
|
39
41
|
".env.*"
|
|
40
42
|
];
|
|
41
43
|
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const patterns = [];
|
|
46
|
-
const ignorePatterns = [];
|
|
47
|
-
for (const value of argv) {
|
|
48
|
-
if (value === "--ignore") {
|
|
49
|
-
hasIgnorePassed = true;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (hasIgnorePassed) ignorePatterns.push(value);
|
|
53
|
-
if (!hasIgnorePassed) patterns.push(value);
|
|
54
|
-
}
|
|
55
|
-
const ignore = ignorePatterns.length ? ignorePatterns : DEFAULT_ANTI_PATTERNS;
|
|
56
|
-
return { patterns, ignore };
|
|
57
|
-
};
|
|
58
|
-
const input = getInput();
|
|
59
|
-
|
|
60
|
-
if (input.patterns.length === 0) {
|
|
61
|
-
console.log("[catco] usage: catco [...patterns]");
|
|
62
|
-
console.log("");
|
|
63
|
-
console.log("Examples:");
|
|
64
|
-
console.log(" catco ./");
|
|
65
|
-
console.log(' catco "./src/**/*.ts"');
|
|
66
|
-
console.log(' catco "./src/**/*.{js,ts}"');
|
|
67
|
-
console.log(' catco "./*.js"');
|
|
68
|
-
console.log(' catco "./src/**/index.ts"');
|
|
69
|
-
console.log(' catco "./src/**/*.test.ts"');
|
|
70
|
-
console.log(' catco "./**/*.md"');
|
|
71
|
-
console.log(' catco "./src/utils/*.ts" "./src/components/*.ts"');
|
|
72
|
-
console.log(' catco "./**/*" "!./node_modules"');
|
|
73
|
-
console.log(' catco "./src/**/*" --exclude="./src/**/*.spec.ts"');
|
|
74
|
-
console.log("");
|
|
75
|
-
console.log("Supports multiple patterns and globs. Use quotes for complex patterns.");
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
const createOutputContents = (filePath, content) => {
|
|
79
|
-
return `/* FILE: ${path.resolve(filePath)} */ ${content} `;
|
|
80
|
-
};
|
|
81
|
-
const catco = async () => {
|
|
82
|
-
const fileContentsList = [];
|
|
83
|
-
const options = { ignore: input.ignore };
|
|
84
|
-
const filePaths = await globby.globby(input.patterns, options);
|
|
44
|
+
const createFileBlock = (filePath, content) => `/* FILE: ./${path.relative(process.cwd(), path.resolve(filePath)).replace(/\\/g, "/")} */ ${content} `;
|
|
45
|
+
const copy = async (patterns, ignore = DEFAULT_ANTI_PATTERNS) => {
|
|
46
|
+
const filePaths = await globby.globby(patterns, { ignore });
|
|
85
47
|
console.log(`[catco] found ${filePaths.length} files.`);
|
|
48
|
+
if (!filePaths.length) {
|
|
49
|
+
console.warn(`[catco] no matching files found for patterns: ${patterns.join(", ")}`);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const blocks = [];
|
|
86
53
|
for (const filePath of filePaths) {
|
|
87
54
|
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
88
|
-
|
|
89
|
-
fileContentsList.push(final);
|
|
55
|
+
blocks.push(createFileBlock(filePath, content));
|
|
90
56
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
57
|
+
const joined = blocks.join("\n");
|
|
58
|
+
const minified = minify(joined);
|
|
59
|
+
console.log(`[catco] pre-minified length: ${joined.length}`);
|
|
60
|
+
console.log(`[catco] post-minified length: ${minified.length}`);
|
|
61
|
+
return minified;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const FILE_MARKER_REGEX = /\/\* FILE: (\.\/[^\s*][^*]*?) \*\//g;
|
|
65
|
+
const parse = async (inputFile, outputDir) => {
|
|
66
|
+
const content = await fs.promises.readFile(inputFile, "utf-8");
|
|
67
|
+
const matches = [...content.matchAll(FILE_MARKER_REGEX)];
|
|
68
|
+
if (matches.length === 0) {
|
|
69
|
+
console.warn("[catco parse] no FILE markers found in input.");
|
|
70
|
+
return;
|
|
98
71
|
}
|
|
99
|
-
|
|
100
|
-
|
|
72
|
+
console.log(`[catco parse] found ${matches.length} file(s).`);
|
|
73
|
+
for (let i = 0; i < matches.length; i++) {
|
|
74
|
+
const match = matches[i];
|
|
75
|
+
const relativePath = match[1];
|
|
76
|
+
const markerEnd = (match.index ?? 0) + match[0].length;
|
|
77
|
+
const nextMarkerStart = matches[i + 1]?.index ?? content.length;
|
|
78
|
+
const fileContent = content.slice(markerEnd, nextMarkerStart).trim();
|
|
79
|
+
const absolutePath = path.resolve(outputDir, relativePath);
|
|
80
|
+
await fs.promises.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
81
|
+
await fs.promises.writeFile(absolutePath, fileContent, "utf-8");
|
|
82
|
+
console.log(`[catco parse] wrote ${relativePath}`);
|
|
101
83
|
}
|
|
84
|
+
console.log(`[catco parse] done. files written to ${outputDir}`);
|
|
102
85
|
};
|
|
103
|
-
|
|
86
|
+
|
|
87
|
+
var version = "2.0.0";
|
|
88
|
+
var pkg = {
|
|
89
|
+
version: version};
|
|
90
|
+
|
|
91
|
+
const prog = sade("catco");
|
|
92
|
+
prog.version(pkg.version).command("copy <patterns...>", "Copy file contents to clipboard", { default: true }).describe("Glob one or more patterns and copy all matched file contents to clipboard.").option("--ignore", "Glob patterns to ignore (space-separated)", "").example('copy "./"').example('copy "./src/**/*.ts"').example('copy "./src/**/*.{js,ts}"').example('copy "./**/*" --ignore "node_modules dist"').action(async (patterns, opts) => {
|
|
93
|
+
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
94
|
+
const ignore = opts.ignore ? opts.ignore.split(/\s+/).filter(Boolean) : DEFAULT_ANTI_PATTERNS;
|
|
95
|
+
const minified = await copy(patternList, ignore);
|
|
96
|
+
if (minified) {
|
|
97
|
+
await clipboard.write(minified);
|
|
98
|
+
console.log(`[catco] all files contents copied to clipboard!`);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
prog.command("parse <input> <output>", "Parse a catco file into a directory structure").describe("Read a catco-formatted file and write each /* FILE: */ section to the output directory.").example("parse ./output.txt ./my-project").action(async (input, output) => {
|
|
102
|
+
await parse(path.resolve(input), path.resolve(output));
|
|
103
|
+
});
|
|
104
|
+
prog.parse(process.argv);
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
4
|
-
import
|
|
3
|
+
import sade from 'sade';
|
|
5
4
|
import clipboard from 'clipboardy';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { globby } from 'globby';
|
|
6
7
|
|
|
7
8
|
const minify = (content) => {
|
|
8
9
|
const minified = content.replace(/\s+/g, " ").replace(/\s*([\{\}\[\]\(\),;:])\s*/g, "$1").replace(/\s*=\s*/g, "=").replace(/\s*>\s*/g, ">").replace(/;\s*/g, ";").replace(/"\s+/g, '"').replace(/\s+"/g, '"').replace(/'\s+/g, "'").replace(/\s+'/g, "'").trim();
|
|
@@ -38,65 +39,64 @@ const DEFAULT_ANTI_PATTERNS = [
|
|
|
38
39
|
".env.*"
|
|
39
40
|
];
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const patterns = [];
|
|
45
|
-
const ignorePatterns = [];
|
|
46
|
-
for (const value of argv) {
|
|
47
|
-
if (value === "--ignore") {
|
|
48
|
-
hasIgnorePassed = true;
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (hasIgnorePassed) ignorePatterns.push(value);
|
|
52
|
-
if (!hasIgnorePassed) patterns.push(value);
|
|
53
|
-
}
|
|
54
|
-
const ignore = ignorePatterns.length ? ignorePatterns : DEFAULT_ANTI_PATTERNS;
|
|
55
|
-
return { patterns, ignore };
|
|
56
|
-
};
|
|
57
|
-
const input = getInput();
|
|
58
|
-
|
|
59
|
-
if (input.patterns.length === 0) {
|
|
60
|
-
console.log("[catco] usage: catco [...patterns]");
|
|
61
|
-
console.log("");
|
|
62
|
-
console.log("Examples:");
|
|
63
|
-
console.log(" catco ./");
|
|
64
|
-
console.log(' catco "./src/**/*.ts"');
|
|
65
|
-
console.log(' catco "./src/**/*.{js,ts}"');
|
|
66
|
-
console.log(' catco "./*.js"');
|
|
67
|
-
console.log(' catco "./src/**/index.ts"');
|
|
68
|
-
console.log(' catco "./src/**/*.test.ts"');
|
|
69
|
-
console.log(' catco "./**/*.md"');
|
|
70
|
-
console.log(' catco "./src/utils/*.ts" "./src/components/*.ts"');
|
|
71
|
-
console.log(' catco "./**/*" "!./node_modules"');
|
|
72
|
-
console.log(' catco "./src/**/*" --exclude="./src/**/*.spec.ts"');
|
|
73
|
-
console.log("");
|
|
74
|
-
console.log("Supports multiple patterns and globs. Use quotes for complex patterns.");
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
77
|
-
const createOutputContents = (filePath, content) => {
|
|
78
|
-
return `/* FILE: ${path.resolve(filePath)} */ ${content} `;
|
|
79
|
-
};
|
|
80
|
-
const catco = async () => {
|
|
81
|
-
const fileContentsList = [];
|
|
82
|
-
const options = { ignore: input.ignore };
|
|
83
|
-
const filePaths = await globby(input.patterns, options);
|
|
42
|
+
const createFileBlock = (filePath, content) => `/* FILE: ./${path.relative(process.cwd(), path.resolve(filePath)).replace(/\\/g, "/")} */ ${content} `;
|
|
43
|
+
const copy = async (patterns, ignore = DEFAULT_ANTI_PATTERNS) => {
|
|
44
|
+
const filePaths = await globby(patterns, { ignore });
|
|
84
45
|
console.log(`[catco] found ${filePaths.length} files.`);
|
|
46
|
+
if (!filePaths.length) {
|
|
47
|
+
console.warn(`[catco] no matching files found for patterns: ${patterns.join(", ")}`);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const blocks = [];
|
|
85
51
|
for (const filePath of filePaths) {
|
|
86
52
|
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
87
|
-
|
|
88
|
-
fileContentsList.push(final);
|
|
53
|
+
blocks.push(createFileBlock(filePath, content));
|
|
89
54
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
55
|
+
const joined = blocks.join("\n");
|
|
56
|
+
const minified = minify(joined);
|
|
57
|
+
console.log(`[catco] pre-minified length: ${joined.length}`);
|
|
58
|
+
console.log(`[catco] post-minified length: ${minified.length}`);
|
|
59
|
+
return minified;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const FILE_MARKER_REGEX = /\/\* FILE: (\.\/[^\s*][^*]*?) \*\//g;
|
|
63
|
+
const parse = async (inputFile, outputDir) => {
|
|
64
|
+
const content = await fs.promises.readFile(inputFile, "utf-8");
|
|
65
|
+
const matches = [...content.matchAll(FILE_MARKER_REGEX)];
|
|
66
|
+
if (matches.length === 0) {
|
|
67
|
+
console.warn("[catco parse] no FILE markers found in input.");
|
|
68
|
+
return;
|
|
97
69
|
}
|
|
98
|
-
|
|
99
|
-
|
|
70
|
+
console.log(`[catco parse] found ${matches.length} file(s).`);
|
|
71
|
+
for (let i = 0; i < matches.length; i++) {
|
|
72
|
+
const match = matches[i];
|
|
73
|
+
const relativePath = match[1];
|
|
74
|
+
const markerEnd = (match.index ?? 0) + match[0].length;
|
|
75
|
+
const nextMarkerStart = matches[i + 1]?.index ?? content.length;
|
|
76
|
+
const fileContent = content.slice(markerEnd, nextMarkerStart).trim();
|
|
77
|
+
const absolutePath = path.resolve(outputDir, relativePath);
|
|
78
|
+
await fs.promises.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
79
|
+
await fs.promises.writeFile(absolutePath, fileContent, "utf-8");
|
|
80
|
+
console.log(`[catco parse] wrote ${relativePath}`);
|
|
100
81
|
}
|
|
82
|
+
console.log(`[catco parse] done. files written to ${outputDir}`);
|
|
101
83
|
};
|
|
102
|
-
|
|
84
|
+
|
|
85
|
+
var version = "2.0.0";
|
|
86
|
+
var pkg = {
|
|
87
|
+
version: version};
|
|
88
|
+
|
|
89
|
+
const prog = sade("catco");
|
|
90
|
+
prog.version(pkg.version).command("copy <patterns...>", "Copy file contents to clipboard", { default: true }).describe("Glob one or more patterns and copy all matched file contents to clipboard.").option("--ignore", "Glob patterns to ignore (space-separated)", "").example('copy "./"').example('copy "./src/**/*.ts"').example('copy "./src/**/*.{js,ts}"').example('copy "./**/*" --ignore "node_modules dist"').action(async (patterns, opts) => {
|
|
91
|
+
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
92
|
+
const ignore = opts.ignore ? opts.ignore.split(/\s+/).filter(Boolean) : DEFAULT_ANTI_PATTERNS;
|
|
93
|
+
const minified = await copy(patternList, ignore);
|
|
94
|
+
if (minified) {
|
|
95
|
+
await clipboard.write(minified);
|
|
96
|
+
console.log(`[catco] all files contents copied to clipboard!`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
prog.command("parse <input> <output>", "Parse a catco file into a directory structure").describe("Read a catco-formatted file and write each /* FILE: */ section to the output directory.").example("parse ./output.txt ./my-project").action(async (input, output) => {
|
|
100
|
+
await parse(path.resolve(input), path.resolve(output));
|
|
101
|
+
});
|
|
102
|
+
prog.parse(process.argv);
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import
|
|
3
|
+
import sade from 'sade';
|
|
4
4
|
import clipboard from 'clipboardy';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { globby } from 'globby';
|
|
5
7
|
|
|
6
8
|
const minify = (content) => {
|
|
7
9
|
const minified = content.replace(/\s+/g, " ").replace(/\s*([\{\}\[\]\(\),;:])\s*/g, "$1").replace(/\s*=\s*/g, "=").replace(/\s*>\s*/g, ">").replace(/;\s*/g, ";").replace(/"\s+/g, '"').replace(/\s+"/g, '"').replace(/'\s+/g, "'").replace(/\s+'/g, "'").trim();
|
|
@@ -37,65 +39,64 @@ const DEFAULT_ANTI_PATTERNS = [
|
|
|
37
39
|
".env.*"
|
|
38
40
|
];
|
|
39
41
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const patterns = [];
|
|
44
|
-
const ignorePatterns = [];
|
|
45
|
-
for (const value of argv) {
|
|
46
|
-
if (value === "--ignore") {
|
|
47
|
-
hasIgnorePassed = true;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (hasIgnorePassed) ignorePatterns.push(value);
|
|
51
|
-
if (!hasIgnorePassed) patterns.push(value);
|
|
52
|
-
}
|
|
53
|
-
const ignore = ignorePatterns.length ? ignorePatterns : DEFAULT_ANTI_PATTERNS;
|
|
54
|
-
return { patterns, ignore };
|
|
55
|
-
};
|
|
56
|
-
const input = getInput();
|
|
57
|
-
|
|
58
|
-
if (input.patterns.length === 0) {
|
|
59
|
-
console.log("[catco] usage: catco [...patterns]");
|
|
60
|
-
console.log("");
|
|
61
|
-
console.log("Examples:");
|
|
62
|
-
console.log(" catco ./");
|
|
63
|
-
console.log(' catco "./src/**/*.ts"');
|
|
64
|
-
console.log(' catco "./src/**/*.{js,ts}"');
|
|
65
|
-
console.log(' catco "./*.js"');
|
|
66
|
-
console.log(' catco "./src/**/index.ts"');
|
|
67
|
-
console.log(' catco "./src/**/*.test.ts"');
|
|
68
|
-
console.log(' catco "./**/*.md"');
|
|
69
|
-
console.log(' catco "./src/utils/*.ts" "./src/components/*.ts"');
|
|
70
|
-
console.log(' catco "./**/*" "!./node_modules"');
|
|
71
|
-
console.log(' catco "./src/**/*" --exclude="./src/**/*.spec.ts"');
|
|
72
|
-
console.log("");
|
|
73
|
-
console.log("Supports multiple patterns and globs. Use quotes for complex patterns.");
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
const createOutputContents = (filePath, content) => {
|
|
77
|
-
return `/* FILE: ${path.resolve(filePath)} */ ${content} `;
|
|
78
|
-
};
|
|
79
|
-
const catco = async () => {
|
|
80
|
-
const fileContentsList = [];
|
|
81
|
-
const options = { ignore: input.ignore };
|
|
82
|
-
const filePaths = await globby(input.patterns, options);
|
|
42
|
+
const createFileBlock = (filePath, content) => `/* FILE: ./${path.relative(process.cwd(), path.resolve(filePath)).replace(/\\/g, "/")} */ ${content} `;
|
|
43
|
+
const copy = async (patterns, ignore = DEFAULT_ANTI_PATTERNS) => {
|
|
44
|
+
const filePaths = await globby(patterns, { ignore });
|
|
83
45
|
console.log(`[catco] found ${filePaths.length} files.`);
|
|
46
|
+
if (!filePaths.length) {
|
|
47
|
+
console.warn(`[catco] no matching files found for patterns: ${patterns.join(", ")}`);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const blocks = [];
|
|
84
51
|
for (const filePath of filePaths) {
|
|
85
52
|
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
86
|
-
|
|
87
|
-
fileContentsList.push(final);
|
|
53
|
+
blocks.push(createFileBlock(filePath, content));
|
|
88
54
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
55
|
+
const joined = blocks.join("\n");
|
|
56
|
+
const minified = minify(joined);
|
|
57
|
+
console.log(`[catco] pre-minified length: ${joined.length}`);
|
|
58
|
+
console.log(`[catco] post-minified length: ${minified.length}`);
|
|
59
|
+
return minified;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const FILE_MARKER_REGEX = /\/\* FILE: (\.\/[^\s*][^*]*?) \*\//g;
|
|
63
|
+
const parse = async (inputFile, outputDir) => {
|
|
64
|
+
const content = await fs.promises.readFile(inputFile, "utf-8");
|
|
65
|
+
const matches = [...content.matchAll(FILE_MARKER_REGEX)];
|
|
66
|
+
if (matches.length === 0) {
|
|
67
|
+
console.warn("[catco parse] no FILE markers found in input.");
|
|
68
|
+
return;
|
|
96
69
|
}
|
|
97
|
-
|
|
98
|
-
|
|
70
|
+
console.log(`[catco parse] found ${matches.length} file(s).`);
|
|
71
|
+
for (let i = 0; i < matches.length; i++) {
|
|
72
|
+
const match = matches[i];
|
|
73
|
+
const relativePath = match[1];
|
|
74
|
+
const markerEnd = (match.index ?? 0) + match[0].length;
|
|
75
|
+
const nextMarkerStart = matches[i + 1]?.index ?? content.length;
|
|
76
|
+
const fileContent = content.slice(markerEnd, nextMarkerStart).trim();
|
|
77
|
+
const absolutePath = path.resolve(outputDir, relativePath);
|
|
78
|
+
await fs.promises.mkdir(path.dirname(absolutePath), { recursive: true });
|
|
79
|
+
await fs.promises.writeFile(absolutePath, fileContent, "utf-8");
|
|
80
|
+
console.log(`[catco parse] wrote ${relativePath}`);
|
|
99
81
|
}
|
|
82
|
+
console.log(`[catco parse] done. files written to ${outputDir}`);
|
|
100
83
|
};
|
|
101
|
-
|
|
84
|
+
|
|
85
|
+
var version = "2.0.0";
|
|
86
|
+
var pkg = {
|
|
87
|
+
version: version};
|
|
88
|
+
|
|
89
|
+
const prog = sade("catco");
|
|
90
|
+
prog.version(pkg.version).command("copy <patterns...>", "Copy file contents to clipboard", { default: true }).describe("Glob one or more patterns and copy all matched file contents to clipboard.").option("--ignore", "Glob patterns to ignore (space-separated)", "").example('copy "./"').example('copy "./src/**/*.ts"').example('copy "./src/**/*.{js,ts}"').example('copy "./**/*" --ignore "node_modules dist"').action(async (patterns, opts) => {
|
|
91
|
+
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
92
|
+
const ignore = opts.ignore ? opts.ignore.split(/\s+/).filter(Boolean) : DEFAULT_ANTI_PATTERNS;
|
|
93
|
+
const minified = await copy(patternList, ignore);
|
|
94
|
+
if (minified) {
|
|
95
|
+
await clipboard.write(minified);
|
|
96
|
+
console.log(`[catco] all files contents copied to clipboard!`);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
prog.command("parse <input> <output>", "Parse a catco file into a directory structure").describe("Read a catco-formatted file and write each /* FILE: */ section to the output directory.").example("parse ./output.txt ./my-project").action(async (input, output) => {
|
|
100
|
+
await parse(path.resolve(input), path.resolve(output));
|
|
101
|
+
});
|
|
102
|
+
prog.parse(process.argv);
|
package/package.json
CHANGED
|
@@ -1,60 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "catco",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
5
|
-
"description": "Glob copy file contents to ya clipboard.",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "pkgroll",
|
|
8
|
-
"start": "tsx src/index.ts ./src/**/*.ts"
|
|
9
|
-
},
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
|
-
"main": "./dist/index.cjs",
|
|
14
|
-
"module": "./dist/index.mjs",
|
|
15
|
-
"exports": {
|
|
16
|
-
"import": {
|
|
17
|
-
"default": "./dist/index.mjs"
|
|
18
|
-
},
|
|
19
|
-
"require": {
|
|
20
|
-
"default": "./dist/index.cjs"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"bin": {
|
|
24
|
-
"catco": "./dist/index.js"
|
|
25
|
-
},
|
|
26
|
-
"license": "MIT",
|
|
27
|
-
"homepage": "https://github.com/tasteee/catco",
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/tasteee/catco.git"
|
|
31
|
-
},
|
|
32
|
-
"bugs": "https://github.com/tasteee/catco/issues",
|
|
33
|
-
"author": "tasteink <rocolcleasure@gmail.com>",
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "catco",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Glob copy file contents to ya clipboard.",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "pkgroll",
|
|
8
|
+
"start": "tsx src/index.ts ./src/**/*.ts"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"main": "./dist/index.cjs",
|
|
14
|
+
"module": "./dist/index.mjs",
|
|
15
|
+
"exports": {
|
|
16
|
+
"import": {
|
|
17
|
+
"default": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"default": "./dist/index.cjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"bin": {
|
|
24
|
+
"catco": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://github.com/tasteee/catco",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/tasteee/catco.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": "https://github.com/tasteee/catco/issues",
|
|
33
|
+
"author": "tasteink <rocolcleasure@gmail.com>",
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^25.5.2",
|
|
36
|
+
"@types/sade": "^1.8.0",
|
|
37
|
+
"pkgroll": "^2.12.2",
|
|
38
|
+
"prettier": "^3.5.3",
|
|
39
|
+
"tsx": "^4.19.2",
|
|
40
|
+
"typescript": "^5.6.3",
|
|
41
|
+
"vitest": "^2.1.3"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"clipboardy": "^4.0.0",
|
|
45
|
+
"globby": "^14.0.2",
|
|
46
|
+
"sade": "^1.8.1"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"ai",
|
|
53
|
+
"ai-assistant",
|
|
54
|
+
"ai-tools",
|
|
55
|
+
"gpt",
|
|
56
|
+
"copy",
|
|
57
|
+
"clipboard",
|
|
58
|
+
"claude",
|
|
59
|
+
"chatgpt",
|
|
60
|
+
"chatgpt4o",
|
|
61
|
+
"chatgpt4o-mini"
|
|
62
|
+
]
|
|
63
|
+
}
|
package/dist/index.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|