everything-dev 0.0.2 → 0.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "everything-dev",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "bos": "./src/cli.ts"
@@ -15,6 +15,7 @@
15
15
  "@effect/platform": "^0.82.8",
16
16
  "@effect/platform-bun": "^0.58.1",
17
17
  "@inquirer/prompts": "^8.2.0",
18
+ "@libsql/client": "^0.17.0",
18
19
  "borsh": "^2.0.0",
19
20
  "boxen": "^8.0.1",
20
21
  "chalk": "^5.6.2",
package/src/config.ts CHANGED
@@ -55,6 +55,7 @@ export interface BosConfig {
55
55
 
56
56
  let cachedConfig: BosConfig | null = null;
57
57
  let configDir: string | null = null;
58
+ let configLoaded = false;
58
59
 
59
60
  export function findConfigPath(startDir: string): string | null {
60
61
  let dir = startDir;
@@ -86,25 +87,33 @@ function findConfigPathSync(startDir: string): string | null {
86
87
  return null;
87
88
  }
88
89
 
89
- export function loadConfig(cwd?: string): BosConfig {
90
- if (cachedConfig) return cachedConfig;
90
+ export function loadConfig(cwd?: string): BosConfig | null {
91
+ if (configLoaded) return cachedConfig;
91
92
 
92
93
  const startDir = cwd ?? process.cwd();
93
94
  const configPath = findConfigPathSync(startDir);
94
95
 
95
96
  if (!configPath) {
96
- throw new Error("Could not find bos.config.json in current directory or parents");
97
+ configLoaded = true;
98
+ configDir = startDir;
99
+ return null;
97
100
  }
98
101
 
99
102
  configDir = dirname(configPath);
100
- const file = Bun.file(configPath);
101
103
  const content = require(configPath);
102
104
  cachedConfig = content as BosConfig;
105
+ configLoaded = true;
103
106
  return cachedConfig;
104
107
  }
105
108
 
109
+ export function setConfig(config: BosConfig, dir?: string): void {
110
+ cachedConfig = config;
111
+ configDir = dir ?? process.cwd();
112
+ configLoaded = true;
113
+ }
114
+
106
115
  export function getConfigDir(): string {
107
- if (!configDir) {
116
+ if (!configLoaded) {
108
117
  loadConfig();
109
118
  }
110
119
  return configDir!;
@@ -112,16 +121,19 @@ export function getConfigDir(): string {
112
121
 
113
122
  export function getRemotes(): string[] {
114
123
  const config = loadConfig();
124
+ if (!config) return [];
115
125
  return Object.keys(config.app).filter((k) => k !== "host");
116
126
  }
117
127
 
118
128
  export function getPackages(): string[] {
119
129
  const config = loadConfig();
130
+ if (!config) return [];
120
131
  return Object.keys(config.app);
121
132
  }
122
133
 
123
134
  export function getRemote(name: string): RemoteConfig | undefined {
124
135
  const config = loadConfig();
136
+ if (!config) return undefined;
125
137
  const remote = config.app[name];
126
138
  if (remote && "name" in remote) {
127
139
  return remote as RemoteConfig;
@@ -131,6 +143,9 @@ export function getRemote(name: string): RemoteConfig | undefined {
131
143
 
132
144
  export function getHost(): HostConfig {
133
145
  const config = loadConfig();
146
+ if (!config) {
147
+ throw new Error("No bos.config.json found");
148
+ }
134
149
  return config.app.host;
135
150
  }
136
151
 
@@ -139,6 +154,7 @@ export function getUrl(
139
154
  env: "development" | "production" = "development"
140
155
  ): string | undefined {
141
156
  const config = loadConfig();
157
+ if (!config) return undefined;
142
158
  const pkg = config.app[packageName];
143
159
  if (!pkg) return undefined;
144
160
  return pkg[env];
@@ -146,11 +162,17 @@ export function getUrl(
146
162
 
147
163
  export function getAccount(): string {
148
164
  const config = loadConfig();
165
+ if (!config) {
166
+ throw new Error("No bos.config.json found");
167
+ }
149
168
  return config.account;
150
169
  }
151
170
 
152
171
  export function getTitle(): string {
153
172
  const config = loadConfig();
173
+ if (!config) {
174
+ throw new Error("No bos.config.json found");
175
+ }
154
176
  return config.app.host.title;
155
177
  }
156
178
 
@@ -159,6 +181,9 @@ export function getComponentUrl(
159
181
  source: SourceMode
160
182
  ): string {
161
183
  const config = loadConfig();
184
+ if (!config) {
185
+ throw new Error("No bos.config.json found");
186
+ }
162
187
 
163
188
  if (component === "host") {
164
189
  return source === "remote" ? config.app.host.production : config.app.host.development;
@@ -189,6 +214,9 @@ export interface PortConfig {
189
214
 
190
215
  export function getPortsFromConfig(): PortConfig {
191
216
  const config = loadConfig();
217
+ if (!config) {
218
+ return { host: 3000, ui: 3002, api: 3014 };
219
+ }
192
220
  return {
193
221
  host: parsePort(config.app.host.development),
194
222
  ui: config.app.ui ? parsePort((config.app.ui as RemoteConfig).development) : 3002,
@@ -205,10 +233,14 @@ export function getConfigPath(): string {
205
233
 
206
234
  export function getHostRemoteUrl(): string | undefined {
207
235
  const config = loadConfig();
236
+ if (!config) return undefined;
208
237
  return config.app.host.production || undefined;
209
238
  }
210
239
 
211
240
  export function getGatewayUrl(env: "development" | "production" = "development"): string {
212
241
  const config = loadConfig();
242
+ if (!config) {
243
+ throw new Error("No bos.config.json found");
244
+ }
213
245
  return config.gateway[env];
214
246
  }
package/src/plugin.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  getPortsFromConfig,
15
15
  getRemotes,
16
16
  loadConfig,
17
+ setConfig,
17
18
  type SourceMode
18
19
  } from "./config";
19
20
  import { bosContract } from "./contract";
@@ -37,7 +38,7 @@ import { run } from "./utils/run";
37
38
  import { colors, icons } from "./utils/theme";
38
39
 
39
40
  interface BosDeps {
40
- bosConfig: BosConfigType;
41
+ bosConfig: BosConfigType | null;
41
42
  configDir: string;
42
43
  nearPrivateKey?: string;
43
44
  }
@@ -164,7 +165,7 @@ export default createPlugin({
164
165
  bosConfig,
165
166
  configDir,
166
167
  nearPrivateKey: config.secrets.nearPrivateKey
167
- };
168
+ } as BosDeps;
168
169
  }),
169
170
 
170
171
  shutdown: () => Effect.void,
@@ -233,6 +234,7 @@ export default createPlugin({
233
234
  }
234
235
  if (typeof current === "string") {
235
236
  remoteConfig = JSON.parse(current) as BosConfigType;
237
+ setConfig(remoteConfig);
236
238
  }
237
239
  }
238
240
  } catch (error) {
@@ -253,6 +255,15 @@ export default createPlugin({
253
255
  }
254
256
 
255
257
  const config = remoteConfig || deps.bosConfig;
258
+
259
+ if (!config) {
260
+ console.error("No configuration available. Provide --account and --domain, or run from a BOS project directory.");
261
+ return {
262
+ status: "error" as const,
263
+ url: "",
264
+ };
265
+ }
266
+
256
267
  const port = input.port ?? 3000;
257
268
 
258
269
  const env: Record<string, string> = {
@@ -361,6 +372,15 @@ export default createPlugin({
361
372
  publish: builder.publish.handler(async ({ input: publishInput }) => {
362
373
  const { bosConfig, nearPrivateKey } = deps;
363
374
 
375
+ if (!bosConfig) {
376
+ return {
377
+ status: "error" as const,
378
+ txHash: "",
379
+ registryUrl: "",
380
+ error: "No bos.config.json found. Run from a BOS project directory.",
381
+ };
382
+ }
383
+
364
384
  const gatewayDomain = getGatewayDomain(bosConfig);
365
385
  const socialPath = `${bosConfig.account}/bos/gateways/${gatewayDomain}/bos.config.json`;
366
386
 
@@ -425,7 +445,7 @@ export default createPlugin({
425
445
  gateway: "near-everything/every-plugin/demo/gateway",
426
446
  };
427
447
 
428
- const template = input.template || deps.bosConfig.create?.[input.type] || DEFAULT_TEMPLATES[input.type];
448
+ const template = input.template || deps.bosConfig?.create?.[input.type] || DEFAULT_TEMPLATES[input.type];
429
449
  const dest = input.type === "project" ? input.name! : input.type;
430
450
 
431
451
  try {
@@ -493,6 +513,11 @@ export default createPlugin({
493
513
 
494
514
  status: builder.status.handler(async ({ input }) => {
495
515
  const config = deps.bosConfig;
516
+
517
+ if (!config) {
518
+ return { endpoints: [] };
519
+ }
520
+
496
521
  const host = getHost();
497
522
  const remotes = getRemotes();
498
523
  const env = input.env;
@@ -582,6 +607,14 @@ export default createPlugin({
582
607
  register: builder.register.handler(async ({ input }) => {
583
608
  const { bosConfig } = deps;
584
609
 
610
+ if (!bosConfig) {
611
+ return {
612
+ status: "error" as const,
613
+ account: input.name,
614
+ error: "No bos.config.json found. Run from a BOS project directory.",
615
+ };
616
+ }
617
+
585
618
  const registerEffect = Effect.gen(function* () {
586
619
  yield* ensureNearCli;
587
620
 
@@ -625,6 +658,14 @@ export default createPlugin({
625
658
  secretsSync: builder.secretsSync.handler(async ({ input }) => {
626
659
  const { bosConfig } = deps;
627
660
 
661
+ if (!bosConfig) {
662
+ return {
663
+ status: "error" as const,
664
+ count: 0,
665
+ error: "No bos.config.json found. Run from a BOS project directory.",
666
+ };
667
+ }
668
+
628
669
  const syncEffect = Effect.gen(function* () {
629
670
  const novaConfig = yield* getNovaConfig;
630
671
  const nova = createNovaClient(novaConfig);
@@ -659,6 +700,13 @@ export default createPlugin({
659
700
  secretsSet: builder.secretsSet.handler(async ({ input }) => {
660
701
  const { bosConfig } = deps;
661
702
 
703
+ if (!bosConfig) {
704
+ return {
705
+ status: "error" as const,
706
+ error: "No bos.config.json found. Run from a BOS project directory.",
707
+ };
708
+ }
709
+
662
710
  const setEffect = Effect.gen(function* () {
663
711
  const novaConfig = yield* getNovaConfig;
664
712
  const nova = createNovaClient(novaConfig);
@@ -685,6 +733,14 @@ export default createPlugin({
685
733
  secretsList: builder.secretsList.handler(async () => {
686
734
  const { bosConfig } = deps;
687
735
 
736
+ if (!bosConfig) {
737
+ return {
738
+ status: "error" as const,
739
+ keys: [],
740
+ error: "No bos.config.json found. Run from a BOS project directory.",
741
+ };
742
+ }
743
+
688
744
  const listEffect = Effect.gen(function* () {
689
745
  const novaConfig = yield* getNovaConfig;
690
746
  const nova = createNovaClient(novaConfig);
@@ -722,6 +778,13 @@ export default createPlugin({
722
778
  secretsDelete: builder.secretsDelete.handler(async ({ input }) => {
723
779
  const { bosConfig } = deps;
724
780
 
781
+ if (!bosConfig) {
782
+ return {
783
+ status: "error" as const,
784
+ error: "No bos.config.json found. Run from a BOS project directory.",
785
+ };
786
+ }
787
+
725
788
  const deleteEffect = Effect.gen(function* () {
726
789
  const novaConfig = yield* getNovaConfig;
727
790
  const nova = createNovaClient(novaConfig);
@@ -853,6 +916,15 @@ export default createPlugin({
853
916
 
854
917
  gatewayDeploy: builder.gatewayDeploy.handler(async ({ input }) => {
855
918
  const { configDir, bosConfig } = deps;
919
+
920
+ if (!bosConfig) {
921
+ return {
922
+ status: "error" as const,
923
+ url: "",
924
+ error: "No bos.config.json found. Run from a BOS project directory.",
925
+ };
926
+ }
927
+
856
928
  const gatewayDir = `${configDir}/gateway`;
857
929
 
858
930
  const deployEffect = Effect.gen(function* () {
@@ -896,6 +968,14 @@ export default createPlugin({
896
968
 
897
969
  gatewaySync: builder.gatewaySync.handler(async () => {
898
970
  const { configDir, bosConfig } = deps;
971
+
972
+ if (!bosConfig) {
973
+ return {
974
+ status: "error" as const,
975
+ error: "No bos.config.json found. Run from a BOS project directory.",
976
+ };
977
+ }
978
+
899
979
  const wranglerPath = `${configDir}/gateway/wrangler.toml`;
900
980
 
901
981
  try {