stow-cli 2.1.0 → 2.2.0

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.
@@ -0,0 +1,135 @@
1
+ import {
2
+ isJsonOutput,
3
+ output
4
+ } from "./chunk-P2BKGBQE.js";
5
+ import {
6
+ formatBytes,
7
+ formatTable
8
+ } from "./chunk-FZGOTXTE.js";
9
+ import {
10
+ createStow
11
+ } from "./chunk-5LU25QZK.js";
12
+ import "./chunk-TOADDO2F.js";
13
+
14
+ // src/commands/search.ts
15
+ async function textSearch(query, options) {
16
+ const stow = createStow();
17
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
18
+ const data = await stow.search.text({
19
+ query,
20
+ ...options.bucket ? { bucket: options.bucket } : {},
21
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
22
+ });
23
+ if (data.results.length === 0) {
24
+ if (isJsonOutput() || options.json) {
25
+ output(data);
26
+ } else {
27
+ console.log("No results found.");
28
+ }
29
+ return;
30
+ }
31
+ output(
32
+ data,
33
+ () => {
34
+ const rows = data.results.map((r) => [
35
+ r.key,
36
+ formatBytes(r.size),
37
+ r.similarity.toFixed(3)
38
+ ]);
39
+ return formatTable(["Key", "Size", "Similarity"], rows);
40
+ },
41
+ { json: options.json }
42
+ );
43
+ }
44
+ async function similarSearch(options) {
45
+ const stow = createStow();
46
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
47
+ const data = await stow.search.similar({
48
+ fileKey: options.file,
49
+ ...options.bucket ? { bucket: options.bucket } : {},
50
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
51
+ });
52
+ if (data.results.length === 0) {
53
+ if (isJsonOutput() || options.json) {
54
+ output(data);
55
+ } else {
56
+ console.log("No similar files found.");
57
+ }
58
+ return;
59
+ }
60
+ output(
61
+ data,
62
+ () => {
63
+ const rows = data.results.map((r) => [
64
+ r.key,
65
+ formatBytes(r.size),
66
+ r.similarity.toFixed(3)
67
+ ]);
68
+ return formatTable(["Key", "Size", "Similarity"], rows);
69
+ },
70
+ { json: options.json }
71
+ );
72
+ }
73
+ async function colorSearch(options) {
74
+ const stow = createStow();
75
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
76
+ const data = await stow.search.color({
77
+ hex: options.hex,
78
+ ...options.bucket ? { bucket: options.bucket } : {},
79
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
80
+ });
81
+ if (data.results.length === 0) {
82
+ if (isJsonOutput() || options.json) {
83
+ output(data);
84
+ } else {
85
+ console.log("No results found.");
86
+ }
87
+ return;
88
+ }
89
+ output(
90
+ data,
91
+ () => {
92
+ const rows = data.results.map((r) => [
93
+ r.key,
94
+ r.contentType,
95
+ r.colorDistance.toFixed(3)
96
+ ]);
97
+ return formatTable(["Key", "Type", "Distance"], rows);
98
+ },
99
+ { json: options.json }
100
+ );
101
+ }
102
+ async function diverseSearch(options) {
103
+ const stow = createStow();
104
+ const parsedLimit = options.limit ? Number.parseInt(options.limit, 10) : null;
105
+ const data = await stow.search.diverse({
106
+ ...options.bucket ? { bucket: options.bucket } : {},
107
+ ...parsedLimit && parsedLimit > 0 ? { limit: parsedLimit } : {}
108
+ });
109
+ if (data.results.length === 0) {
110
+ if (isJsonOutput() || options.json) {
111
+ output(data);
112
+ } else {
113
+ console.log("No results found.");
114
+ }
115
+ return;
116
+ }
117
+ output(
118
+ data,
119
+ () => {
120
+ const rows = data.results.map((r) => [
121
+ r.key,
122
+ formatBytes(r.size),
123
+ r.similarity.toFixed(3)
124
+ ]);
125
+ return formatTable(["Key", "Size", "Similarity"], rows);
126
+ },
127
+ { json: options.json }
128
+ );
129
+ }
130
+ export {
131
+ colorSearch,
132
+ diverseSearch,
133
+ similarSearch,
134
+ textSearch
135
+ };
@@ -0,0 +1,90 @@
1
+ import {
2
+ parseJsonInput
3
+ } from "./chunk-3BLL5SQJ.js";
4
+ import {
5
+ validateInput
6
+ } from "./chunk-PLZFHPLC.js";
7
+ import {
8
+ isJsonOutput,
9
+ output
10
+ } from "./chunk-P2BKGBQE.js";
11
+ import {
12
+ formatTable
13
+ } from "./chunk-FZGOTXTE.js";
14
+ import {
15
+ createStow
16
+ } from "./chunk-5LU25QZK.js";
17
+ import "./chunk-TOADDO2F.js";
18
+
19
+ // src/commands/tags.ts
20
+ async function listTags(options) {
21
+ const stow = createStow();
22
+ const data = await stow.tags.list();
23
+ if (data.tags.length === 0) {
24
+ if (isJsonOutput() || options.json) {
25
+ output(data);
26
+ } else {
27
+ console.log("No tags yet. Create one with: stow tags create <name>");
28
+ }
29
+ return;
30
+ }
31
+ output(data, () => {
32
+ const rows = data.tags.map((t) => [t.name, t.slug, t.color ?? "\u2014", t.id]);
33
+ return formatTable(["Name", "Slug", "Color", "ID"], rows);
34
+ });
35
+ }
36
+ async function createTag(name, options) {
37
+ const input = parseJsonInput(
38
+ options.inputJson,
39
+ { name, color: options.color }
40
+ );
41
+ validateInput(input.name, "tag name");
42
+ if (options.dryRun) {
43
+ console.log(
44
+ JSON.stringify(
45
+ {
46
+ dryRun: true,
47
+ action: "createTag",
48
+ details: {
49
+ name: input.name,
50
+ color: input.color ?? null
51
+ }
52
+ },
53
+ null,
54
+ 2
55
+ )
56
+ );
57
+ return;
58
+ }
59
+ const stow = createStow();
60
+ const tag = await stow.tags.create({
61
+ name: input.name,
62
+ ...input.color ? { color: input.color } : {}
63
+ });
64
+ output(tag, () => `Created tag: ${tag.name}`);
65
+ }
66
+ async function deleteTag(id, options = {}) {
67
+ validateInput(id, "tag id");
68
+ if (options.dryRun) {
69
+ console.log(
70
+ JSON.stringify(
71
+ {
72
+ dryRun: true,
73
+ action: "deleteTag",
74
+ details: { id }
75
+ },
76
+ null,
77
+ 2
78
+ )
79
+ );
80
+ return;
81
+ }
82
+ const stow = createStow();
83
+ await stow.tags.delete(id);
84
+ console.log(`Deleted tag: ${id}`);
85
+ }
86
+ export {
87
+ createTag,
88
+ deleteTag,
89
+ listTags
90
+ };
@@ -0,0 +1,126 @@
1
+ import {
2
+ validateBucketName
3
+ } from "./chunk-PLZFHPLC.js";
4
+ import {
5
+ formatBytes
6
+ } from "./chunk-FZGOTXTE.js";
7
+ import {
8
+ createStow
9
+ } from "./chunk-5LU25QZK.js";
10
+ import "./chunk-TOADDO2F.js";
11
+
12
+ // src/commands/upload.ts
13
+ import { existsSync, readFileSync, statSync } from "fs";
14
+ import { basename, resolve } from "path";
15
+ var CONTENT_TYPES = {
16
+ png: "image/png",
17
+ jpg: "image/jpeg",
18
+ jpeg: "image/jpeg",
19
+ gif: "image/gif",
20
+ webp: "image/webp",
21
+ svg: "image/svg+xml",
22
+ ico: "image/x-icon",
23
+ avif: "image/avif",
24
+ pdf: "application/pdf",
25
+ mp4: "video/mp4",
26
+ webm: "video/webm",
27
+ mov: "video/quicktime",
28
+ mp3: "audio/mpeg",
29
+ wav: "audio/wav",
30
+ ogg: "audio/ogg",
31
+ zip: "application/zip",
32
+ tar: "application/x-tar",
33
+ gz: "application/gzip",
34
+ txt: "text/plain",
35
+ json: "application/json",
36
+ xml: "application/xml",
37
+ html: "text/html",
38
+ css: "text/css",
39
+ js: "application/javascript"
40
+ };
41
+ function getContentType(filename) {
42
+ const ext = filename.toLowerCase().split(".").pop();
43
+ return CONTENT_TYPES[ext || ""] || "application/octet-stream";
44
+ }
45
+ function readFile(filePath) {
46
+ const resolvedPath = resolve(filePath);
47
+ if (!existsSync(resolvedPath)) {
48
+ console.error(`Error: File not found: ${filePath}`);
49
+ process.exit(1);
50
+ }
51
+ const buffer = readFileSync(resolvedPath);
52
+ const filename = basename(resolvedPath);
53
+ const contentType = getContentType(filename);
54
+ return { buffer, filename, contentType };
55
+ }
56
+ function printUploadResult(url, options, opts) {
57
+ if (options.quiet) {
58
+ console.log(url);
59
+ return;
60
+ }
61
+ console.error(opts?.deduped ? "Done! (deduped)" : "Done!");
62
+ console.log("");
63
+ console.log(url);
64
+ }
65
+ async function uploadDrop(filePath, options) {
66
+ const { buffer, filename, contentType } = readFile(filePath);
67
+ if (!options.quiet) {
68
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
69
+ }
70
+ const stow = createStow();
71
+ const result = await stow.drop(buffer, {
72
+ filename,
73
+ contentType
74
+ });
75
+ printUploadResult(result.url, options);
76
+ }
77
+ async function uploadFile(filePath, options) {
78
+ if (options.bucket) {
79
+ validateBucketName(options.bucket);
80
+ }
81
+ const resolvedPath = resolve(filePath);
82
+ if (!existsSync(resolvedPath)) {
83
+ console.error(`Error: File not found: ${filePath}`);
84
+ process.exit(1);
85
+ }
86
+ const filename = basename(resolvedPath);
87
+ const contentType = getContentType(filename);
88
+ const size = statSync(resolvedPath).size;
89
+ if (options.dryRun) {
90
+ console.log(
91
+ JSON.stringify(
92
+ {
93
+ dryRun: true,
94
+ action: "upload",
95
+ details: {
96
+ file: resolvedPath,
97
+ filename,
98
+ contentType,
99
+ size,
100
+ bucket: options.bucket ?? null
101
+ }
102
+ },
103
+ null,
104
+ 2
105
+ )
106
+ );
107
+ return;
108
+ }
109
+ const buffer = readFileSync(resolvedPath);
110
+ if (!options.quiet) {
111
+ console.error(`Uploading ${filename} (${formatBytes(buffer.length)})...`);
112
+ }
113
+ const stow = createStow();
114
+ const result = await stow.uploadFile(buffer, {
115
+ ...options.bucket ? { bucket: options.bucket } : {},
116
+ filename,
117
+ contentType
118
+ });
119
+ printUploadResult(result.url ?? result.key, options, {
120
+ deduped: result.deduped
121
+ });
122
+ }
123
+ export {
124
+ uploadDrop,
125
+ uploadFile
126
+ };
@@ -0,0 +1,28 @@
1
+ import {
2
+ formatBytes
3
+ } from "./chunk-FZGOTXTE.js";
4
+ import {
5
+ createStow
6
+ } from "./chunk-5LU25QZK.js";
7
+ import "./chunk-TOADDO2F.js";
8
+
9
+ // src/commands/whoami.ts
10
+ async function whoami() {
11
+ const stow = createStow();
12
+ const data = await stow.whoami();
13
+ console.log(`Account: ${data.user.email}`);
14
+ console.log("");
15
+ console.log(`Buckets: ${data.stats.bucketCount}`);
16
+ console.log(`Files: ${data.stats.totalFiles}`);
17
+ console.log(`Storage: ${formatBytes(data.stats.totalBytes)}`);
18
+ if (data.key) {
19
+ console.log("");
20
+ console.log(`API Key: ${data.key.name}`);
21
+ console.log(`Scope: ${data.key.scope}`);
22
+ const perms = Object.entries(data.key.permissions).filter(([, v]) => v).map(([k]) => k);
23
+ console.log(`Perms: ${perms.join(", ")}`);
24
+ }
25
+ }
26
+ export {
27
+ whoami
28
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stow-cli",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "description": "CLI for Stow file storage",
6
6
  "license": "MIT",
@@ -22,14 +22,7 @@
22
22
  "files": [
23
23
  "dist"
24
24
  ],
25
- "scripts": {
26
- "build": "tsup src/cli.ts --format esm --shims",
27
- "dev": "tsup src/cli.ts --format esm --shims --watch",
28
- "test": "vitest run",
29
- "test:watch": "vitest"
30
- },
31
25
  "dependencies": {
32
- "@howells/stow-server": "workspace:*",
33
26
  "@modelcontextprotocol/sdk": "^1.27.1",
34
27
  "clipboardy": "^5.3.1",
35
28
  "commander": "^14.0.3",
@@ -39,14 +32,21 @@
39
32
  "ink-text-input": "^6.0.0",
40
33
  "open": "^11.0.0",
41
34
  "react": "^19.2.4",
42
- "zod": "^4.3.6"
35
+ "zod": "^4.3.6",
36
+ "@howells/stow-server": "2.2.0"
43
37
  },
44
38
  "devDependencies": {
45
- "@stow/typescript-config": "workspace:*",
46
39
  "@types/node": "^25.5.0",
47
40
  "@types/react": "19.2.14",
48
41
  "tsup": "^8.5.1",
49
42
  "typescript": "^5.9.3",
50
- "vitest": "^4.1.0"
43
+ "vitest": "^4.1.0",
44
+ "@stow/typescript-config": "0.0.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsup src/cli.ts --format esm --shims",
48
+ "dev": "tsup src/cli.ts --format esm --shims --watch",
49
+ "test": "vitest run",
50
+ "test:watch": "vitest"
51
51
  }
52
- }
52
+ }