bod-cli 0.5.1 → 0.5.4

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/cli.js CHANGED
@@ -19073,7 +19073,7 @@ var deploy_default = defineCommand2({
19073
19073
  const { url, apiKey, name: instanceName, instance } = getResolvedInstance(loadConfig(), readInstanceFromYaml());
19074
19074
  console.log(source_default.dim(`Using instance "${instanceName}"`));
19075
19075
  const client = new BodClient(url, apiKey);
19076
- const isLocal = url.startsWith("http://localhost");
19076
+ const isLocal = !url.startsWith("https://");
19077
19077
  let localConfig = null;
19078
19078
  if (isLocal) {
19079
19079
  try {
@@ -19284,7 +19284,7 @@ var env_default = defineCommand2({
19284
19284
  });
19285
19285
 
19286
19286
  // src/commands/init/init.ts
19287
- import { existsSync as existsSync3, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3, readdirSync } from "fs";
19287
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3, readdirSync, readFileSync as readFileSync4 } from "fs";
19288
19288
  import { basename, join as join3 } from "path";
19289
19289
 
19290
19290
  // src/commands/init/templates.ts
@@ -19642,12 +19642,35 @@ var init_default = defineCommand2({
19642
19642
  const proc = Bun.spawnSync(["git", "remote", "get-url", "origin"], { cwd });
19643
19643
  repo = proc.stdout.toString().trim();
19644
19644
  } catch {}
19645
- if (existsSync3(join3(cwd, "bodify.yaml"))) {
19646
- console.log(source_default.dim("bodify.yaml already exists, skipping"));
19647
- } else {
19645
+ const yamlPath = join3(cwd, "bodify.yaml");
19646
+ let yamlData = {};
19647
+ let yamlExisted = false;
19648
+ if (existsSync3(yamlPath)) {
19649
+ yamlExisted = true;
19650
+ yamlData = $parse(readFileSync4(yamlPath, "utf8")) ?? {};
19651
+ }
19652
+ let yamlDirty = false;
19653
+ if (!yamlData.name) {
19654
+ yamlData.name = appName;
19655
+ yamlDirty = true;
19656
+ }
19657
+ if (!yamlExisted) {
19648
19658
  const useDb = detected === "caab" && await esm_default5({ message: "Enable database?", default: false });
19649
- writeFileSync3(join3(cwd, "bodify.yaml"), generateBodifyYaml(appName, { database: useDb, repo }));
19650
- console.log(source_default.green("✓ Created bodify.yaml"));
19659
+ if (useDb) {
19660
+ yamlData.database = true;
19661
+ yamlDirty = true;
19662
+ }
19663
+ if (repo) {
19664
+ yamlData.repo = repo;
19665
+ yamlDirty = true;
19666
+ }
19667
+ yamlDirty = true;
19668
+ }
19669
+ if (yamlDirty) {
19670
+ writeFileSync3(yamlPath, $stringify(yamlData));
19671
+ console.log(source_default.green(yamlExisted ? "✓ Updated bodify.yaml" : "✓ Created bodify.yaml"));
19672
+ } else {
19673
+ console.log(source_default.dim("bodify.yaml already up to date"));
19651
19674
  }
19652
19675
  console.log(source_default.dim("Registering app with Bodify..."));
19653
19676
  try {
@@ -19659,6 +19682,17 @@ var init_default = defineCommand2({
19659
19682
  console.log(source_default.green(`✓ App registered (id: ${app.id})`));
19660
19683
  if (app.domain)
19661
19684
  console.log(source_default.dim(` Domain: ${app.domain}`));
19685
+ let changed = false;
19686
+ if (app.id && !yamlData.appId) {
19687
+ yamlData.appId = app.id;
19688
+ changed = true;
19689
+ }
19690
+ if (app.domain && !yamlData.domain) {
19691
+ yamlData.domain = app.domain;
19692
+ changed = true;
19693
+ }
19694
+ if (changed)
19695
+ writeFileSync3(yamlPath, $stringify(yamlData));
19662
19696
  } catch (e2) {
19663
19697
  console.warn(source_default.yellow(`Warning: Could not register: ${e2.message}`));
19664
19698
  }
@@ -19786,7 +19820,11 @@ var open_default = defineCommand2({
19786
19820
  import { join as join4 } from "path";
19787
19821
  import { existsSync as existsSync4 } from "fs";
19788
19822
  function resolveBodifyServe() {
19789
- const sibling = join4(import.meta.dir, "../../../bodify/src/serve.ts");
19823
+ const candidates = [
19824
+ join4(import.meta.dir, "../../../bodify/src/serve.ts"),
19825
+ join4(import.meta.dir, "../../bodify/src/serve.ts")
19826
+ ];
19827
+ const sibling = candidates.find(existsSync4) ?? candidates[0];
19790
19828
  if (existsSync4(sibling))
19791
19829
  return sibling;
19792
19830
  const envDir = process.env.BODIFY_DIR;
@@ -19865,7 +19903,7 @@ var ssh_default = defineCommand2({
19865
19903
  });
19866
19904
 
19867
19905
  // src/commands/publish.ts
19868
- import { readFileSync as readFileSync4 } from "fs";
19906
+ import { readFileSync as readFileSync5 } from "fs";
19869
19907
  var publish_default = defineCommand2({
19870
19908
  meta: { name: "publish", description: "Publish a package to Bodify registry" },
19871
19909
  args: {
@@ -19874,7 +19912,7 @@ var publish_default = defineCommand2({
19874
19912
  async run({ args }) {
19875
19913
  let pkg;
19876
19914
  try {
19877
- pkg = JSON.parse(readFileSync4("package.json", "utf-8"));
19915
+ pkg = JSON.parse(readFileSync5("package.json", "utf-8"));
19878
19916
  } catch {
19879
19917
  console.error(source_default.red("No package.json found in current directory"));
19880
19918
  process.exit(1);
@@ -19896,7 +19934,7 @@ var publish_default = defineCommand2({
19896
19934
  }
19897
19935
  const tarballPath = pack.stdout.toString().trim().split(`
19898
19936
  `).pop();
19899
- const tarballData = readFileSync4(tarballPath);
19937
+ const tarballData = readFileSync5(tarballPath);
19900
19938
  const tarballBase64 = tarballData.toString("base64");
19901
19939
  const distTag = args.tag || "latest";
19902
19940
  const safeName = pkg.name.replace("/", "%2f");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bod-cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "bod": "./dist/cli.js"
@@ -138,7 +138,7 @@ export default defineCommand({
138
138
  console.log(chalk.dim(`Using instance "${instanceName}"`))
139
139
  const client = new BodClient(url, apiKey)
140
140
  // Fetch local config for URL generation
141
- const isLocal = url.startsWith('http://localhost')
141
+ const isLocal = !url.startsWith('https://')
142
142
  let localConfig: { localDomain?: string; caddyPort?: number } | null = null
143
143
  if (isLocal) {
144
144
  try { localConfig = await client.get<any>('/config/public') } catch {}
@@ -1,11 +1,12 @@
1
1
  import { defineCommand } from 'citty'
2
2
  import { select, input, confirm } from '@inquirer/prompts'
3
3
  import chalk from 'chalk'
4
- import { existsSync, mkdirSync, writeFileSync, readdirSync } from 'fs'
4
+ import { existsSync, mkdirSync, writeFileSync, readdirSync, readFileSync } from 'fs'
5
5
  import { basename, join } from 'path'
6
6
  import { loadConfig, getResolvedInstance, configExists } from '../../config'
7
7
  import { BodClient } from '../../client'
8
8
  import { TEMPLATES, type TemplateId } from './templates'
9
+ import { parse as parseYaml, stringify as stringifyYaml } from 'yaml'
9
10
 
10
11
  type AppType = 'caab' | 'static' | 'server' | 'mixed' | 'unknown'
11
12
 
@@ -232,13 +233,27 @@ export default defineCommand({
232
233
  repo = proc.stdout.toString().trim()
233
234
  } catch { /* no git remote */ }
234
235
 
235
- // bodify.yaml
236
- if (existsSync(join(cwd, 'bodify.yaml'))) {
237
- console.log(chalk.dim('bodify.yaml already exists, skipping'))
238
- } else {
236
+ // bodify.yaml — create or merge missing fields
237
+ const yamlPath = join(cwd, 'bodify.yaml')
238
+ let yamlData: Record<string, any> = {}
239
+ let yamlExisted = false
240
+ if (existsSync(yamlPath)) {
241
+ yamlExisted = true
242
+ yamlData = parseYaml(readFileSync(yamlPath, 'utf8')) ?? {}
243
+ }
244
+ let yamlDirty = false
245
+ if (!yamlData.name) { yamlData.name = appName; yamlDirty = true }
246
+ if (!yamlExisted) {
239
247
  const useDb = detected === 'caab' && await confirm({ message: 'Enable database?', default: false })
240
- writeFileSync(join(cwd, 'bodify.yaml'), generateBodifyYaml(appName, { database: useDb, repo }))
241
- console.log(chalk.green('✓ Created bodify.yaml'))
248
+ if (useDb) { yamlData.database = true; yamlDirty = true }
249
+ if (repo) { yamlData.repo = repo; yamlDirty = true }
250
+ yamlDirty = true
251
+ }
252
+ if (yamlDirty) {
253
+ writeFileSync(yamlPath, stringifyYaml(yamlData))
254
+ console.log(chalk.green(yamlExisted ? '✓ Updated bodify.yaml' : '✓ Created bodify.yaml'))
255
+ } else {
256
+ console.log(chalk.dim('bodify.yaml already up to date'))
242
257
  }
243
258
 
244
259
  // Register
@@ -251,6 +266,11 @@ export default defineCommand({
251
266
  })
252
267
  console.log(chalk.green(`✓ App registered (id: ${app.id})`))
253
268
  if (app.domain) console.log(chalk.dim(` Domain: ${app.domain}`))
269
+ // Persist appId + domain into bodify.yaml
270
+ let changed = false
271
+ if (app.id && !yamlData.appId) { yamlData.appId = app.id; changed = true }
272
+ if (app.domain && !yamlData.domain) { yamlData.domain = app.domain; changed = true }
273
+ if (changed) writeFileSync(yamlPath, stringifyYaml(yamlData))
254
274
  } catch (e) {
255
275
  console.warn(chalk.yellow(`Warning: Could not register: ${(e as Error).message}`))
256
276
  }
@@ -4,7 +4,12 @@ import { existsSync } from 'fs'
4
4
 
5
5
  function resolveBodifyServe(): string {
6
6
  // Sibling directory convention: bod-cli and bodify live side by side
7
- const sibling = join(import.meta.dir, '../../../bodify/src/serve.ts')
7
+ // Try both source (src/commands/) and dist (dist/) layouts
8
+ const candidates = [
9
+ join(import.meta.dir, '../../../bodify/src/serve.ts'), // from src/commands/
10
+ join(import.meta.dir, '../../bodify/src/serve.ts'), // from dist/
11
+ ]
12
+ const sibling = candidates.find(existsSync) ?? candidates[0]
8
13
  if (existsSync(sibling)) return sibling
9
14
  // Fallback: try global BODIFY_DIR env
10
15
  const envDir = process.env.BODIFY_DIR