filecafe 0.4.1 → 0.4.3

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 CHANGED
@@ -19,6 +19,10 @@ npm i -g filecafe
19
19
  filecafe --help
20
20
  ```
21
21
 
22
+ Run `filecafe upgrade` to update a global install to the latest version. It uses the package manager that installed filecafe (npm, pnpm, Yarn, or Bun).
23
+
24
+ A global install also adds `cafe` as a shorter name for the same command, so `cafe upload report.pdf` works too. With npx, use `npx filecafe`: the `cafe` package on npm is unrelated.
25
+
22
26
  Requires Node.js 20 or newer.
23
27
 
24
28
  When you run filecafe in a terminal and a new version is out, it tells you and offers to upgrade it with the package manager you installed it with. It checks npm in the background once a day (retrying on the next run if npm can't be reached), mentions an update at most every three days, and never shows this in CI or when its output is piped (scripts and AI agents). Set `FILECAFE_NO_UPDATE_CHECK=1` or `NO_UPDATE_NOTIFIER=1` to turn it off.
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { a as updateCachePath, c as configPath, d as readConfig, f as resolveSettings, l as deleteConfig, m as VERSION, n as fetchLatestVersion, o as updateUpdateCache, p as writeConfig, r as readUpdateCache, t as CHECK_INTERVAL_MS, u as normalizeBaseUrl } from "./update-cache-INu00cnB.js";
2
+ import { a as updateCachePath, c as configPath, d as readConfig, f as resolveSettings, l as deleteConfig, m as VERSION, n as fetchLatestVersion, o as updateUpdateCache, p as writeConfig, r as readUpdateCache, t as CHECK_INTERVAL_MS, u as normalizeBaseUrl } from "./update-cache-BhWuFo-r.js";
3
3
  import { Command } from "commander";
4
4
  import { execFile, spawn } from "node:child_process";
5
5
  import { realpath, stat } from "node:fs/promises";
@@ -1171,28 +1171,6 @@ async function logoutCommand(context) {
1171
1171
  if (context.env.FILECAFE_TOKEN?.trim()) context.stderr.write(`${err.yellow("Note:")} FILECAFE_TOKEN is still set in your environment; unset it to stop using that token.\n`);
1172
1172
  return 0;
1173
1173
  }
1174
- // src/commands/whoami.ts
1175
- async function whoamiCommand(options, globals, context) {
1176
- const { client, settings } = await requireSession(context, globals);
1177
- let me;
1178
- try {
1179
- me = await fetchMe(client);
1180
- } catch (error) {
1181
- throw new CliError(error.message);
1182
- }
1183
- if (options.json) context.stdout.write(`${JSON.stringify({
1184
- name: me.name,
1185
- email: me.email,
1186
- url: settings.baseUrl,
1187
- token_source: settings.tokenSource
1188
- })}\n`);
1189
- else {
1190
- const out = colorsFor(context.stdout, context.env);
1191
- context.stdout.write(`Logged in to ${settings.baseUrl} as ${out.bold(me.name)} (${me.email})\n`);
1192
- if (settings.tokenSource === "env") context.stderr.write(`${colorsFor(context.stderr, context.env).gray("(using FILECAFE_TOKEN)")}\n`);
1193
- }
1194
- return 0;
1195
- }
1196
1174
  // src/update-check.ts
1197
1175
  const RELEASES_URL = "https://github.com/filecafe/cli/releases/tag";
1198
1176
  /** Mention an update at most every three days, like the Vercel CLI. */
@@ -1250,7 +1228,7 @@ async function offerUpdate(context, version) {
1250
1228
  const color = colorsFor(context.stderr, context.env);
1251
1229
  const run = (command) => color.cyan(command);
1252
1230
  context.stderr.write(version ? `\nUpdate available for filecafe (${color.gray(`v${VERSION}`)} → ${color.green(`v${version}`)})\nChangelog: ${styledUrl(context.stderr, context.env, `${RELEASES_URL}/v${version}`)}\n` : "\nA newer version of filecafe may be available.\n");
1253
- if (context.env.npm_command === "exec" || context.scriptPath.replaceAll("\\", "/").includes("/_npx/")) {
1231
+ if (isNpx(context)) {
1254
1232
  context.stderr.write(`Run: ${run("npx filecafe@latest")}\n`);
1255
1233
  return;
1256
1234
  }
@@ -1271,6 +1249,10 @@ async function offerUpdate(context, version) {
1271
1249
  const exitCode = await context.run(command, args);
1272
1250
  context.stderr.write(exitCode === 0 ? `${color.green("Updated filecafe.")}\n` : `${color.red("The update failed.")} Run it yourself: ${run(installer.join(" "))}\n`);
1273
1251
  }
1252
+ /** Whether this copy is running through npx, so there is nothing installed to upgrade. */
1253
+ function isNpx(context) {
1254
+ return context.env.npm_command === "exec" || context.scriptPath.replaceAll("\\", "/").includes("/_npx/");
1255
+ }
1274
1256
  const PACKAGE_MANAGERS = [
1275
1257
  {
1276
1258
  install: [
@@ -1389,6 +1371,54 @@ function isNewer(candidate, current) {
1389
1371
  for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i];
1390
1372
  return false;
1391
1373
  }
1374
+ // src/commands/upgrade.ts
1375
+ const LATEST_TIMEOUT_MS = 1e4;
1376
+ /**
1377
+ * Upgrade a global install to the latest release with the package manager that installed it.
1378
+ * npx runs and installs it can't place get the command to run instead.
1379
+ */
1380
+ async function upgradeCommand(context) {
1381
+ const color = colorsFor(context.stderr, context.env);
1382
+ const latest = await fetchLatestVersion(context.fetch, context.userAgent, LATEST_TIMEOUT_MS);
1383
+ if (latest && !isNewer(latest, VERSION)) {
1384
+ context.stdout.write(`filecafe v${VERSION} is already the latest version.\n`);
1385
+ return 0;
1386
+ }
1387
+ if (isNpx(context)) {
1388
+ context.stdout.write(`You are running filecafe with npx, so there is nothing to upgrade. Run: npx filecafe@latest\n`);
1389
+ return 0;
1390
+ }
1391
+ const installer = await detectInstaller(context);
1392
+ if (!installer) throw new CliError("Could not tell whether npm, pnpm, Yarn, or Bun installed filecafe. Upgrade it with the package manager that installed it, for example: npm i -g filecafe@latest");
1393
+ const [command, ...args] = installer;
1394
+ context.stderr.write(latest ? `Upgrading filecafe v${VERSION} → v${latest}\n` : `Upgrading filecafe v${VERSION}\n`);
1395
+ context.stderr.write(`${color.gray(`> ${installer.join(" ")}`)}\n`);
1396
+ if (await context.run(command, args) !== 0) throw new CliError(`The upgrade failed. Run it yourself: ${installer.join(" ")}`);
1397
+ context.stdout.write(latest ? `Upgraded filecafe to v${latest}.\n` : "Upgraded filecafe to the latest version.\n");
1398
+ return 0;
1399
+ }
1400
+ // src/commands/whoami.ts
1401
+ async function whoamiCommand(options, globals, context) {
1402
+ const { client, settings } = await requireSession(context, globals);
1403
+ let me;
1404
+ try {
1405
+ me = await fetchMe(client);
1406
+ } catch (error) {
1407
+ throw new CliError(error.message);
1408
+ }
1409
+ if (options.json) context.stdout.write(`${JSON.stringify({
1410
+ name: me.name,
1411
+ email: me.email,
1412
+ url: settings.baseUrl,
1413
+ token_source: settings.tokenSource
1414
+ })}\n`);
1415
+ else {
1416
+ const out = colorsFor(context.stdout, context.env);
1417
+ context.stdout.write(`Logged in to ${settings.baseUrl} as ${out.bold(me.name)} (${me.email})\n`);
1418
+ if (settings.tokenSource === "env") context.stderr.write(`${colorsFor(context.stderr, context.env).gray("(using FILECAFE_TOKEN)")}\n`);
1419
+ }
1420
+ return 0;
1421
+ }
1392
1422
  // src/cli.ts
1393
1423
  const MAIN_EXAMPLES = `
1394
1424
  Examples:
@@ -1400,6 +1430,7 @@ Examples:
1400
1430
  $ filecafe collections # list your collections and their IDs
1401
1431
  $ filecafe collections create "Inbox" # an empty collection to upload into with --collection
1402
1432
  $ FILECAFE_TOKEN=... npx filecafe upload notes.txt --json # CI / headless
1433
+ $ filecafe upgrade # install the latest version
1403
1434
 
1404
1435
  Environment:
1405
1436
  FILECAFE_TOKEN API token; takes precedence over the saved login
@@ -1464,6 +1495,7 @@ function createProgram(context) {
1464
1495
  const collections = program.command("collections").description("List or create collections (upload --collection <id> adds files to one)");
1465
1496
  collections.command("list", { isDefault: true }).description("List your collections, newest first").option("--json", "print a JSON array of collections on stdout").addHelpText("after", "\nOutput:\n Terminal: name, file count, URL and ID per collection.\n Piped: one \"id<TAB>name<TAB>url\" line per collection.\n --json: [{\"id\", \"name\", \"url\", \"files_count\", \"password_protected\", \"accepts_uploads\", \"created_at\", \"expires_at\"}]\n\nExamples:\n $ filecafe collections\n $ filecafe collections --json\n").action((options, command) => execute(context, () => collectionsCommand(options, globals(command), context)));
1466
1497
  collections.command("create").description("Create an empty collection to upload into with upload --collection").argument("<name>", "the collection name (at most 120 characters)").option("--json", "print the new collection as JSON on stdout").addHelpText("after", "\nOutput:\n Terminal: the collection URL and ID.\n Piped: one \"id<TAB>name<TAB>url\" line.\n --json: {\"id\", \"name\", \"url\", \"files_count\", \"password_protected\", \"accepts_uploads\", \"created_at\", \"expires_at\"}\n\nExamples:\n $ filecafe collections create \"Inbox\"\n $ id=$(filecafe collections create \"Builds\" | cut -f1)\n $ filecafe upload build.zip --collection \"$id\"\n").action((name, options, command) => execute(context, () => createCollectionCommand(name, options, globals(command), context)));
1498
+ program.command("upgrade").description("Upgrade filecafe to the latest version with the package manager that installed it").action(() => execute(context, () => upgradeCommand(context), { quiet: true }));
1467
1499
  return program;
1468
1500
  }
1469
1501
  await createProgram(createDefaultContext()).parseAsync(process.argv);
@@ -3,7 +3,7 @@ import "node:os";
3
3
  import { basename, dirname, join } from "node:path";
4
4
  import { randomUUID } from "node:crypto";
5
5
  // src/version.ts
6
- const VERSION = "0.4.1";
6
+ const VERSION = "0.4.3";
7
7
  // src/config.ts
8
8
  const DEFAULT_BASE_URL = "https://file.cafe";
9
9
  /**
@@ -1,4 +1,4 @@
1
- import { i as refreshUpdateCache, m as VERSION } from "./update-cache-INu00cnB.js";
1
+ import { i as refreshUpdateCache, m as VERSION } from "./update-cache-BhWuFo-r.js";
2
2
  // src/update-worker.ts
3
3
  /**
4
4
  * Spawned detached by the CLI to refresh the update cache, so no command ever waits on npm.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "filecafe",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Upload files to file.cafe from the command line. Built for AI coding agents, humans, and CI.",
5
5
  "keywords": [
6
6
  "file.cafe",
@@ -12,7 +12,8 @@
12
12
  "homepage": "https://file.cafe",
13
13
  "type": "module",
14
14
  "bin": {
15
- "filecafe": "dist/cli.js"
15
+ "filecafe": "dist/cli.js",
16
+ "cafe": "dist/cli.js"
16
17
  },
17
18
  "files": [
18
19
  "dist"