catco 2.0.0 → 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/dist/index.cjs +104 -0
- package/dist/index.js +102 -0
- package/dist/index.mjs +102 -0
- package/package.json +1 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var path = require('node:path');
|
|
5
|
+
var sade = require('sade');
|
|
6
|
+
var clipboard = require('clipboardy');
|
|
7
|
+
var fs = require('node:fs');
|
|
8
|
+
var globby = require('globby');
|
|
9
|
+
|
|
10
|
+
const minify = (content) => {
|
|
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();
|
|
12
|
+
if (!minified) return "(EMPTY FILE)";
|
|
13
|
+
return minified;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const DEFAULT_ANTI_PATTERNS = [
|
|
17
|
+
"node_modules",
|
|
18
|
+
"node_modules/**",
|
|
19
|
+
".git",
|
|
20
|
+
".git/**",
|
|
21
|
+
".github",
|
|
22
|
+
".github/**",
|
|
23
|
+
"dist",
|
|
24
|
+
"dist/**",
|
|
25
|
+
"build",
|
|
26
|
+
"build/**",
|
|
27
|
+
"coverage",
|
|
28
|
+
"coverage/**",
|
|
29
|
+
".next",
|
|
30
|
+
".next/**",
|
|
31
|
+
".vercel",
|
|
32
|
+
".vercel/**",
|
|
33
|
+
".turbo",
|
|
34
|
+
".turbo/**",
|
|
35
|
+
".DS_Store",
|
|
36
|
+
"*.log",
|
|
37
|
+
"npm-debug.log",
|
|
38
|
+
"yarn-error.log",
|
|
39
|
+
"pnpm-debug.log",
|
|
40
|
+
".env",
|
|
41
|
+
".env.*"
|
|
42
|
+
];
|
|
43
|
+
|
|
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 });
|
|
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 = [];
|
|
53
|
+
for (const filePath of filePaths) {
|
|
54
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
55
|
+
blocks.push(createFileBlock(filePath, content));
|
|
56
|
+
}
|
|
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;
|
|
71
|
+
}
|
|
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}`);
|
|
83
|
+
}
|
|
84
|
+
console.log(`[catco parse] done. files written to ${outputDir}`);
|
|
85
|
+
};
|
|
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
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import sade from 'sade';
|
|
4
|
+
import clipboard from 'clipboardy';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { globby } from 'globby';
|
|
7
|
+
|
|
8
|
+
const minify = (content) => {
|
|
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();
|
|
10
|
+
if (!minified) return "(EMPTY FILE)";
|
|
11
|
+
return minified;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const DEFAULT_ANTI_PATTERNS = [
|
|
15
|
+
"node_modules",
|
|
16
|
+
"node_modules/**",
|
|
17
|
+
".git",
|
|
18
|
+
".git/**",
|
|
19
|
+
".github",
|
|
20
|
+
".github/**",
|
|
21
|
+
"dist",
|
|
22
|
+
"dist/**",
|
|
23
|
+
"build",
|
|
24
|
+
"build/**",
|
|
25
|
+
"coverage",
|
|
26
|
+
"coverage/**",
|
|
27
|
+
".next",
|
|
28
|
+
".next/**",
|
|
29
|
+
".vercel",
|
|
30
|
+
".vercel/**",
|
|
31
|
+
".turbo",
|
|
32
|
+
".turbo/**",
|
|
33
|
+
".DS_Store",
|
|
34
|
+
"*.log",
|
|
35
|
+
"npm-debug.log",
|
|
36
|
+
"yarn-error.log",
|
|
37
|
+
"pnpm-debug.log",
|
|
38
|
+
".env",
|
|
39
|
+
".env.*"
|
|
40
|
+
];
|
|
41
|
+
|
|
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 });
|
|
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 = [];
|
|
51
|
+
for (const filePath of filePaths) {
|
|
52
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
53
|
+
blocks.push(createFileBlock(filePath, content));
|
|
54
|
+
}
|
|
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;
|
|
69
|
+
}
|
|
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}`);
|
|
81
|
+
}
|
|
82
|
+
console.log(`[catco parse] done. files written to ${outputDir}`);
|
|
83
|
+
};
|
|
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
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import sade from 'sade';
|
|
4
|
+
import clipboard from 'clipboardy';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import { globby } from 'globby';
|
|
7
|
+
|
|
8
|
+
const minify = (content) => {
|
|
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();
|
|
10
|
+
if (!minified) return "(EMPTY FILE)";
|
|
11
|
+
return minified;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const DEFAULT_ANTI_PATTERNS = [
|
|
15
|
+
"node_modules",
|
|
16
|
+
"node_modules/**",
|
|
17
|
+
".git",
|
|
18
|
+
".git/**",
|
|
19
|
+
".github",
|
|
20
|
+
".github/**",
|
|
21
|
+
"dist",
|
|
22
|
+
"dist/**",
|
|
23
|
+
"build",
|
|
24
|
+
"build/**",
|
|
25
|
+
"coverage",
|
|
26
|
+
"coverage/**",
|
|
27
|
+
".next",
|
|
28
|
+
".next/**",
|
|
29
|
+
".vercel",
|
|
30
|
+
".vercel/**",
|
|
31
|
+
".turbo",
|
|
32
|
+
".turbo/**",
|
|
33
|
+
".DS_Store",
|
|
34
|
+
"*.log",
|
|
35
|
+
"npm-debug.log",
|
|
36
|
+
"yarn-error.log",
|
|
37
|
+
"pnpm-debug.log",
|
|
38
|
+
".env",
|
|
39
|
+
".env.*"
|
|
40
|
+
];
|
|
41
|
+
|
|
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 });
|
|
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 = [];
|
|
51
|
+
for (const filePath of filePaths) {
|
|
52
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
53
|
+
blocks.push(createFileBlock(filePath, content));
|
|
54
|
+
}
|
|
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;
|
|
69
|
+
}
|
|
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}`);
|
|
81
|
+
}
|
|
82
|
+
console.log(`[catco parse] done. files written to ${outputDir}`);
|
|
83
|
+
};
|
|
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);
|