Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/shopq.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env bun

import "../src/commands/config";
import "../src/commands/gql";
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shopq",
"version": "0.3.8",
"version": "0.3.9",
"description": "A zero-dependency Shopify Admin CLI built on Bun",
"type": "module",
"license": "MIT",
Expand All @@ -12,7 +12,7 @@
"skills"
],
"scripts": {
"build": "bun build bin/shopq.ts --target=node --outfile dist/shopq.js && chmod +x dist/shopq.js",
"build": "bun build bin/shopq.ts --target=bun --outfile dist/shopq.js && chmod +x dist/shopq.js",
"prepublishOnly": "bun run build",
"test": "bun test",
"check": "bunx --bun biome check --write .",
Expand Down
38 changes: 1 addition & 37 deletions src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,48 +47,12 @@ export class ConfigError extends Error {
constructor(public missing: string[]) {
super(
`Missing required environment variables: ${missing.join(", ")}\n` +
`Set them in ~/.config/shopq/.env, a local .env file, or as environment variables.`,
`Set them in a .env file or as environment variables.`,
);
this.name = "ConfigError";
}
}

/**
* Load env vars from ~/.config/shopq/.env (XDG base dir convention),
* then let CWD .env and actual env vars override.
* This follows the pattern used by gh, vercel, railway, etc.
*/
function loadConfigEnv(): void {
const xdgConfig =
process.env.XDG_CONFIG_HOME ||
`${process.env.HOME || require("os").homedir()}/.config`;
const configPath = `${xdgConfig}/shopq/.env`;

try {
const content = require("fs").readFileSync(configPath, "utf-8") as string;
for (const line of content.split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const eqIdx = trimmed.indexOf("=");
if (eqIdx === -1) continue;
const key = trimmed.slice(0, eqIdx).trim();
const value = trimmed
.slice(eqIdx + 1)
.trim()
.replace(/^["']|["']$/g, "");
// Don't override existing env vars (CWD .env or real env take precedence)
if (!process.env[key]) {
process.env[key] = value;
}
}
} catch {
// Config file doesn't exist — that's fine
}
}

// Load on module init
loadConfigEnv();

export function resolveConfig(storeFlag?: string): {
store: string;
clientId: string;
Expand Down
Loading