@farthershore/cli 0.3.5 → 0.3.7

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/config.js DELETED
@@ -1,76 +0,0 @@
1
- // ~/.farthershore/ config management
2
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { join } from "node:path";
5
- import { BUILD_API_URL } from "./build-info.js";
6
- const CONFIG_DIR = join(homedir(), ".farthershore");
7
- const CONFIG_FILE = join(CONFIG_DIR, "config.json");
8
- const CREDENTIALS_FILE = join(CONFIG_DIR, "credentials.json");
9
- const CONFIGS_DIR = join(CONFIG_DIR, "configs");
10
- function ensureDir(dir) {
11
- if (!existsSync(dir))
12
- mkdirSync(dir, { recursive: true, mode: 0o700 });
13
- }
14
- // --- Config ---
15
- const DEFAULT_CONFIG = {
16
- apiUrl: BUILD_API_URL,
17
- defaultFormat: "table",
18
- };
19
- export function loadConfig() {
20
- ensureDir(CONFIG_DIR);
21
- if (!existsSync(CONFIG_FILE))
22
- return DEFAULT_CONFIG;
23
- try {
24
- return {
25
- ...DEFAULT_CONFIG,
26
- ...JSON.parse(readFileSync(CONFIG_FILE, "utf-8")),
27
- };
28
- }
29
- catch {
30
- return DEFAULT_CONFIG;
31
- }
32
- }
33
- export function saveConfig(config) {
34
- ensureDir(CONFIG_DIR);
35
- const current = loadConfig();
36
- writeFileSync(CONFIG_FILE, JSON.stringify({ ...current, ...config }, null, 2) + "\n");
37
- }
38
- // --- Credentials ---
39
- export function loadCredentials() {
40
- if (!existsSync(CREDENTIALS_FILE))
41
- return null;
42
- try {
43
- return JSON.parse(readFileSync(CREDENTIALS_FILE, "utf-8"));
44
- }
45
- catch {
46
- return null;
47
- }
48
- }
49
- export function saveCredentials(creds) {
50
- ensureDir(CONFIG_DIR);
51
- writeFileSync(CREDENTIALS_FILE, JSON.stringify(creds, null, 2) + "\n", {
52
- mode: 0o600,
53
- });
54
- }
55
- export function clearCredentials() {
56
- if (existsSync(CREDENTIALS_FILE)) {
57
- writeFileSync(CREDENTIALS_FILE, "{}");
58
- }
59
- }
60
- // --- Plan configs ---
61
- export function getConfigPath(productSlug) {
62
- const dir = join(CONFIGS_DIR, productSlug);
63
- ensureDir(dir);
64
- return join(dir, "plans.yaml");
65
- }
66
- export function writeConfigFile(productSlug, content) {
67
- const path = getConfigPath(productSlug);
68
- writeFileSync(path, content);
69
- return path;
70
- }
71
- export function readConfigFile(productSlug) {
72
- const path = getConfigPath(productSlug);
73
- if (!existsSync(path))
74
- return null;
75
- return readFileSync(path, "utf-8");
76
- }
package/dist/output.js DELETED
@@ -1,47 +0,0 @@
1
- // Output formatting: tables, JSON, colors
2
- import chalk from "chalk";
3
- export function table(headers, rows) {
4
- const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
5
- const header = headers.map((h, i) => h.padEnd(widths[i])).join(" ");
6
- const separator = widths.map((w) => "─".repeat(w)).join("──");
7
- const body = rows
8
- .map((row) => row.map((cell, i) => (cell ?? "").padEnd(widths[i])).join(" "))
9
- .join("\n");
10
- return `${chalk.bold(header)}\n${chalk.dim(separator)}\n${body}`;
11
- }
12
- export function json(data) {
13
- return JSON.stringify(data, null, 2);
14
- }
15
- export function success(msg) {
16
- console.log(chalk.green(`✓ ${msg}`));
17
- }
18
- export function error(msg) {
19
- console.error(chalk.red(`✗ ${msg}`));
20
- }
21
- export function warn(msg) {
22
- console.warn(chalk.yellow(`⚠ ${msg}`));
23
- }
24
- export function info(msg) {
25
- console.log(chalk.dim(msg));
26
- }
27
- export function heading(msg) {
28
- console.log(chalk.bold(msg));
29
- }
30
- export function formatPrice(cents) {
31
- return `$${(cents / 100).toFixed(2)}`;
32
- }
33
- export function formatDate(iso) {
34
- return new Date(iso).toLocaleDateString("en-US", {
35
- year: "numeric",
36
- month: "short",
37
- day: "numeric",
38
- });
39
- }
40
- export function isTTY() {
41
- return process.stdout.isTTY === true;
42
- }
43
- export function outputFormat(flagFormat) {
44
- if (flagFormat === "json" || flagFormat === "yaml" || flagFormat === "table")
45
- return flagFormat;
46
- return isTTY() ? "table" : "json";
47
- }
package/dist/types.js DELETED
@@ -1,9 +0,0 @@
1
- // Shared types for the FartherShore CLI
2
- export class CliError extends Error {
3
- status;
4
- constructor(message, status) {
5
- super(message);
6
- this.status = status;
7
- this.name = "CliError";
8
- }
9
- }