@stackbit/sdk 0.7.17-staging.1 → 1.0.0-develop.0

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.
@@ -42,7 +42,7 @@ import type { Config, StackbitConfigWithPaths, SSGRunOptions, Model, PageModel,
42
42
  import { extendModelsWithPresetsIds, loadPresets } from './presets-loader';
43
43
  import {
44
44
  LoadStackbitConfigResult,
45
- StopConfigWatch,
45
+ WithReloadAndDestroy,
46
46
  LATEST_STACKBIT_VERSION,
47
47
  STACKBIT_CONFIG_JS_FILES,
48
48
  STACKBIT_CONFIG_YAML_FILES,
@@ -53,11 +53,13 @@ import {
53
53
 
54
54
  const CONTENT_ENGINE_DEFAULT_PORT = 7070;
55
55
 
56
- export interface ConfigWithModelsPresetsResult {
56
+ export type ConfigWithModelsPresetsResult = {
57
57
  valid: boolean;
58
58
  config: Config | null;
59
59
  errors: ConfigError[];
60
- }
60
+ };
61
+
62
+ export type ConfigWithModelsPresetsResultWithReloadDestroy = WithReloadAndDestroy<ConfigWithModelsPresetsResult>;
61
63
 
62
64
  export async function loadConfigWithModelsPresetsAndValidate({
63
65
  dirPath,
@@ -73,7 +75,7 @@ export async function loadConfigWithModelsPresetsAndValidate({
73
75
  watchCallback?: (result: ConfigWithModelsPresetsResult) => void;
74
76
  logger?: Logger;
75
77
  isForcedGitCSI?: boolean;
76
- }): Promise<ConfigWithModelsPresetsResult & StopConfigWatch> {
78
+ }): Promise<ConfigWithModelsPresetsResultWithReloadDestroy> {
77
79
  const configResult = await loadConfigWithModels({
78
80
  dirPath,
79
81
  stackbitConfigESBuildOutDir,
@@ -87,18 +89,26 @@ export async function loadConfigWithModelsPresetsAndValidate({
87
89
  });
88
90
 
89
91
  const configLoaderResult = await processConfigLoaderResult({ configResult, dirPath, modelsSource, logger, isForcedGitCSI });
92
+ const reload = configResult.reload;
90
93
  return {
91
94
  ...configLoaderResult,
92
- stop: configResult.stop,
93
- reload: configResult.reload
95
+ destroy: configResult.destroy,
96
+ reload: reload
97
+ ? async () => {
98
+ const configResult = await reload();
99
+ return processConfigLoaderResult({ configResult, dirPath, modelsSource, logger, isForcedGitCSI });
100
+ }
101
+ : undefined
94
102
  };
95
103
  }
96
104
 
97
- export type ConfigWithModelsResult = {
105
+ export type LoadConfigWithModelsResult = {
98
106
  config: Config | null;
99
107
  errors: (ConfigLoadError | StackbitConfigNotFoundError | ModelLoadError | ConfigValidationError)[];
100
108
  };
101
109
 
110
+ export type LoadConfigWithModelsResultWithReloadDestroy = WithReloadAndDestroy<LoadConfigWithModelsResult>;
111
+
102
112
  export async function loadConfigWithModels({
103
113
  dirPath,
104
114
  stackbitConfigESBuildOutDir,
@@ -107,10 +117,10 @@ export async function loadConfigWithModels({
107
117
  }: {
108
118
  dirPath: string;
109
119
  stackbitConfigESBuildOutDir?: string;
110
- watchCallback?: (result: ConfigWithModelsResult) => void;
120
+ watchCallback?: (result: LoadConfigWithModelsResult) => void;
111
121
  logger?: Logger;
112
- }): Promise<ConfigWithModelsResult & StopConfigWatch> {
113
- const wrapConfigResult = async (configResult: LoadConfigResult): Promise<ConfigWithModelsResult> => {
122
+ }): Promise<LoadConfigWithModelsResultWithReloadDestroy> {
123
+ const wrapConfigResult = async (configResult: LoadConfigResult): Promise<LoadConfigWithModelsResult> => {
114
124
  if (!configResult.config) {
115
125
  return {
116
126
  config: null,
@@ -133,11 +143,17 @@ export async function loadConfigWithModels({
133
143
  });
134
144
 
135
145
  const wrappedResult = await wrapConfigResult(rawConfigResult);
146
+ const reload = rawConfigResult.reload;
136
147
 
137
148
  return {
138
149
  ...wrappedResult,
139
- stop: rawConfigResult.stop,
140
- reload: rawConfigResult.reload
150
+ destroy: rawConfigResult.destroy,
151
+ reload: reload
152
+ ? async () => {
153
+ const configResult = await reload();
154
+ return wrapConfigResult(configResult);
155
+ }
156
+ : undefined
141
157
  };
142
158
  }
143
159
 
@@ -151,6 +167,8 @@ export type LoadConfigResult =
151
167
  errors: (ConfigLoadError | StackbitConfigNotFoundError)[];
152
168
  };
153
169
 
170
+ export type LoadConfigResultWithReloadDestroy = WithReloadAndDestroy<LoadConfigResult>;
171
+
154
172
  export async function loadConfig({
155
173
  dirPath,
156
174
  stackbitConfigESBuildOutDir,
@@ -161,8 +179,8 @@ export async function loadConfig({
161
179
  stackbitConfigESBuildOutDir?: string;
162
180
  watchCallback?: (result: LoadConfigResult) => void;
163
181
  logger?: Logger;
164
- }): Promise<LoadConfigResult & StopConfigWatch> {
165
- const normalizeConfigResult = (rawConfigResult: StackbitConfigLoaderResult): LoadConfigResult => {
182
+ }): Promise<LoadConfigResultWithReloadDestroy> {
183
+ const normalizeConfigResult = (rawConfigResult: LoadConfigFromDirResult): LoadConfigResult => {
166
184
  if (!rawConfigResult.config) {
167
185
  return {
168
186
  config: null,
@@ -183,7 +201,7 @@ export async function loadConfig({
183
201
  dirPath,
184
202
  stackbitConfigESBuildOutDir,
185
203
  watchCallback: watchCallback
186
- ? async (rawConfigResult: StackbitConfigLoaderResult) => {
204
+ ? async (rawConfigResult: LoadConfigFromDirResult) => {
187
205
  const normalizedResult = await normalizeConfigResult(rawConfigResult);
188
206
  watchCallback(normalizedResult);
189
207
  }
@@ -192,11 +210,17 @@ export async function loadConfig({
192
210
  });
193
211
 
194
212
  const normalizedResult = await normalizeConfigResult(rawConfigResult);
213
+ const reload = rawConfigResult.reload;
195
214
 
196
215
  return {
197
216
  ...normalizedResult,
198
- stop: rawConfigResult.stop,
199
- reload: rawConfigResult.reload
217
+ destroy: rawConfigResult.destroy,
218
+ reload: reload
219
+ ? async () => {
220
+ const rawConfigResult = await reload();
221
+ return normalizeConfigResult(rawConfigResult);
222
+ }
223
+ : undefined
200
224
  };
201
225
  }
202
226
 
@@ -207,7 +231,7 @@ async function processConfigLoaderResult({
207
231
  logger,
208
232
  isForcedGitCSI
209
233
  }: {
210
- configResult: ConfigWithModelsResult;
234
+ configResult: LoadConfigWithModelsResult;
211
235
  dirPath: string;
212
236
  modelsSource?: ModelsSource;
213
237
  logger?: Logger;
@@ -305,7 +329,7 @@ export function validateAndNormalizeConfig(config: Config, isForcedGitCSI?: bool
305
329
  });
306
330
  }
307
331
 
308
- export type StackbitConfigLoaderResult =
332
+ export type LoadConfigFromDirResult =
309
333
  | {
310
334
  config: StackbitConfigWithPaths;
311
335
  error: null;
@@ -315,6 +339,8 @@ export type StackbitConfigLoaderResult =
315
339
  error: ConfigLoadError | StackbitConfigNotFoundError;
316
340
  };
317
341
 
342
+ export type LoadConfigFromDirResultWithReloadDestroy = WithReloadAndDestroy<LoadConfigFromDirResult>;
343
+
318
344
  export async function loadConfigFromDir({
319
345
  dirPath,
320
346
  stackbitConfigESBuildOutDir,
@@ -323,10 +349,10 @@ export async function loadConfigFromDir({
323
349
  }: {
324
350
  dirPath: string;
325
351
  stackbitConfigESBuildOutDir?: string;
326
- watchCallback?: (result: StackbitConfigLoaderResult) => void;
352
+ watchCallback?: (result: LoadConfigFromDirResult) => void;
327
353
  logger?: Logger;
328
- }): Promise<StackbitConfigLoaderResult & StopConfigWatch> {
329
- function wrapResult(result: LoadStackbitConfigResult, configFilePath: string): StackbitConfigLoaderResult {
354
+ }): Promise<LoadConfigFromDirResultWithReloadDestroy> {
355
+ function wrapResult(result: LoadStackbitConfigResult, configFilePath: string): LoadConfigFromDirResult {
330
356
  if (result.error) {
331
357
  return {
332
358
  config: null,
@@ -351,7 +377,6 @@ export async function loadConfigFromDir({
351
377
  logger?.debug(`loading Stackbit configuration from ${stackbitYamlPath}`);
352
378
  const result = await loadStackbitYamlFromDir(dirPath);
353
379
  let close: () => Promise<void> = async () => void 0;
354
- let reload: () => void = () => void 0;
355
380
  let stopped = false;
356
381
 
357
382
  if (watchCallback) {
@@ -387,15 +412,15 @@ export async function loadConfigFromDir({
387
412
  throttledFileChange.cancel();
388
413
  watcher.close();
389
414
  };
390
- reload = () => {
391
- throttledFileChange();
392
- };
393
415
  }
394
416
 
395
417
  return {
396
418
  ...wrapResult(result, stackbitYamlPath),
397
- stop: close,
398
- reload: reload
419
+ destroy: close,
420
+ reload: async () => {
421
+ const result = await loadStackbitYamlFromDir(dirPath);
422
+ return wrapResult(result, stackbitYamlPath);
423
+ }
399
424
  };
400
425
  }
401
426
  } catch (error: any) {
@@ -421,7 +446,17 @@ export async function loadConfigFromDir({
421
446
  }
422
447
  : undefined
423
448
  });
424
- return Object.assign(wrapResult(configResult, configFilePath), { stop: configResult.stop });
449
+ const reload = configResult.reload;
450
+ return {
451
+ ...wrapResult(configResult, configFilePath),
452
+ destroy: configResult.destroy,
453
+ reload: reload
454
+ ? async () => {
455
+ const result = await reload();
456
+ return wrapResult(result, configFilePath);
457
+ }
458
+ : undefined
459
+ };
425
460
  }
426
461
  } catch (error: any) {
427
462
  return {
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ export * from './consts';
9
9
  export * from './config/config-loader-static';
10
10
  export { loadPresets, getPresetDirs, extendModelsWithPresetsIds } from './config/presets-loader';
11
11
  export {
12
- StopConfigWatch,
12
+ DestroyConfigWatch,
13
13
  findStackbitConfigFile,
14
14
  isStackbitYamlFile,
15
15
  convertToYamlConfig,
@@ -23,10 +23,13 @@ export {
23
23
  export {
24
24
  loadConfig,
25
25
  LoadConfigResult,
26
+ LoadConfigResultWithReloadDestroy,
27
+ loadConfigFromDir,
28
+ LoadConfigFromDirResult,
29
+ LoadConfigFromDirResultWithReloadDestroy,
26
30
  loadConfigWithModelsPresetsAndValidate,
27
31
  ConfigWithModelsPresetsResult,
28
- loadConfigFromDir,
29
- StackbitConfigLoaderResult,
32
+ ConfigWithModelsPresetsResultWithReloadDestroy,
30
33
  mergeConfigModelsWithExternalModels
31
34
  } from './config/config-loader';
32
35
  export { validateConfig } from './config/config-validator';