@embeddable.com/sdk-core 3.14.7-next.2 → 4.0.0-next.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.
package/src/dev.ts CHANGED
@@ -53,65 +53,14 @@ let browserWindow: ChildProcess | null = null;
53
53
 
54
54
  let previewWorkspace: string;
55
55
 
56
- // Build coordination to prevent duplicate plugin builds
57
- let pluginBuildInProgress = false;
58
- let pendingPluginBuilds: (() => Promise<void>)[] = [];
59
-
60
56
  const SERVER_PORT = 8926;
61
57
  const BUILD_DEV_DIR = ".embeddable-dev-build";
62
- // NOTE: for backward compatibility, keep the file name as global.css
63
- const CUSTOM_CANVAS_CSS = "/global.css";
58
+ const CUSTOM_CANVAS_CSS = "/custom-canvas.css";
64
59
 
65
60
  export const buildWebComponent = async (config: any) => {
66
61
  await generate(config, "sdk-react");
67
62
  };
68
63
 
69
- const executePluginBuilds = async (
70
- config: ResolvedEmbeddableConfig,
71
- watchers: Array<RollupWatcher | FSWatcher>,
72
- ) => {
73
- if (pluginBuildInProgress) {
74
- // If a plugin build is already in progress, queue this one
75
- return new Promise<void>((resolve) => {
76
- pendingPluginBuilds.push(async () => {
77
- await doPluginBuilds(config, watchers);
78
- resolve();
79
- });
80
- });
81
- } else {
82
- // Start the plugin build immediately
83
- await doPluginBuilds(config, watchers);
84
- }
85
- };
86
-
87
- const doPluginBuilds = async (
88
- config: ResolvedEmbeddableConfig,
89
- watchers: Array<RollupWatcher | FSWatcher>,
90
- ) => {
91
- pluginBuildInProgress = true;
92
-
93
- try {
94
- for (const getPlugin of config.plugins) {
95
- const plugin = getPlugin();
96
-
97
- await plugin.validate(config);
98
- const watcher = await plugin.build(config);
99
- await configureWatcher(watcher as RollupWatcher, config);
100
- watchers.push(watcher as RollupWatcher);
101
- }
102
- } finally {
103
- pluginBuildInProgress = false;
104
-
105
- // Process any pending builds
106
- if (pendingPluginBuilds.length > 0) {
107
- const nextBuild = pendingPluginBuilds.shift();
108
- if (nextBuild) {
109
- await nextBuild();
110
- }
111
- }
112
- }
113
- };
114
-
115
64
  const addToGitingore = async () => {
116
65
  try {
117
66
  const gitignorePath = path.resolve(process.cwd(), ".gitignore");
@@ -265,8 +214,17 @@ export default async () => {
265
214
  await sendBuildChanges(config);
266
215
 
267
216
  if (config.pushComponents) {
268
- breadcrumbs.push("build plugins with coordination");
269
- await executePluginBuilds(config, watchers);
217
+ for (const getPlugin of config.plugins) {
218
+ const plugin = getPlugin();
219
+
220
+ breadcrumbs.push("validate plugin");
221
+ await plugin.validate(config);
222
+ breadcrumbs.push("build plugin");
223
+ const watcher = await plugin.build(config);
224
+ breadcrumbs.push("configure watcher");
225
+ await configureWatcher(watcher as RollupWatcher, config);
226
+ watchers.push(watcher as RollupWatcher);
227
+ }
270
228
 
271
229
  const customCanvasCssWatch = globalCustomCanvasWatcher(config);
272
230
  watchers.push(customCanvasCssWatch);
package/src/push.test.ts CHANGED
@@ -151,7 +151,7 @@ describe("push", () => {
151
151
 
152
152
  expect(archiveMock.pipe).toHaveBeenCalled();
153
153
  expect(archiveMock.file).toHaveBeenCalledWith("src/custom-canvas.css", {
154
- name: "global.css",
154
+ name: "custom-canvas.css",
155
155
  });
156
156
  expect(archiveMock.directory).toHaveBeenCalledWith("buildDir", false);
157
157
  expect(archiveMock.finalize).toHaveBeenCalled();
@@ -248,10 +248,10 @@ describe("push", () => {
248
248
 
249
249
  // Should include component build directory
250
250
  expect(mockArchiver.directory).toHaveBeenCalled();
251
- // Should not include model files (except global.css which is part of components)
251
+ // Should not include model files (except custom-canvas.css which is part of components)
252
252
  expect(mockArchiver.file).toHaveBeenCalledTimes(2);
253
253
  expect(mockArchiver.file).toHaveBeenCalledWith(expect.anything(), {
254
- name: "global.css",
254
+ name: "custom-canvas.css",
255
255
  });
256
256
  });
257
257
  });
@@ -452,11 +452,11 @@ describe("push", () => {
452
452
  testConfig.client.buildDir,
453
453
  false
454
454
  );
455
- // Should include global.css
455
+ // Should include custom-canvas.css
456
456
  expect(mockArchiver.file).toHaveBeenCalledWith(
457
457
  testConfig.client.customCanvasCss,
458
458
  {
459
- name: "global.css",
459
+ name: "custom-canvas.css",
460
460
  }
461
461
  );
462
462
  // Should include all model files
@@ -505,11 +505,11 @@ describe("push", () => {
505
505
  testConfig.client.buildDir,
506
506
  false
507
507
  );
508
- // Should include global.css
508
+ // Should include custom-canvas.css
509
509
  expect(mockArchiver.file).toHaveBeenCalledWith(
510
510
  testConfig.client.customCanvasCss,
511
511
  {
512
- name: "global.css",
512
+ name: "custom-canvas.css",
513
513
  }
514
514
  );
515
515
  // Should only find client context files
package/src/push.ts CHANGED
@@ -36,7 +36,7 @@ export default async () => {
36
36
 
37
37
  if (!isBuildSuccess && config.pushComponents) {
38
38
  console.error(
39
- "Build failed or not completed. Please run `embeddable:build` first.",
39
+ "Build failed or not completed. Please run `embeddable:build` first."
40
40
  );
41
41
  process.exit(1);
42
42
  }
@@ -52,7 +52,7 @@ export default async () => {
52
52
  `Authentication failure. Server responded with: "${error.response?.data?.errorMessage}".
53
53
  Ensure that your API key is valid for the region specified in the embeddable.config.ts|js file.
54
54
  You are using the following region: ${config.region.replace("legacy-", "")} (${config.previewBaseUrl.replace("https://", "")} via ${config.pushBaseUrl})
55
- Read more about deployment regions at https://docs.embeddable.com/deployment/deployment-regions`,
55
+ Read more about deployment regions at https://docs.embeddable.com/deployment/deployment-regions`
56
56
  );
57
57
  process.exit(1);
58
58
  }
@@ -76,7 +76,7 @@ Read more about deployment regions at https://docs.embeddable.com/deployment/dep
76
76
  const { workspaceId, name: workspaceName } = await selectWorkspace(
77
77
  ora,
78
78
  config,
79
- token,
79
+ token
80
80
  );
81
81
 
82
82
  const workspacePreviewUrl = `${config.previewBaseUrl}/workspace/${workspaceId}`;
@@ -85,7 +85,7 @@ Read more about deployment regions at https://docs.embeddable.com/deployment/dep
85
85
  breadcrumbs.push("build archive");
86
86
  await buildArchive(config);
87
87
  spinnerPushing.info(
88
- `Publishing to ${workspaceName} using ${workspacePreviewUrl}...`,
88
+ `Publishing to ${workspaceName} using ${workspacePreviewUrl}...`
89
89
  );
90
90
 
91
91
  breadcrumbs.push("send build");
@@ -93,7 +93,7 @@ Read more about deployment regions at https://docs.embeddable.com/deployment/dep
93
93
 
94
94
  publishedSectionFeedback(config, spinnerPushing);
95
95
  spinnerPushing.succeed(
96
- `Published to ${workspaceName} using ${workspacePreviewUrl}`,
96
+ `Published to ${workspaceName} using ${workspacePreviewUrl}`
97
97
  );
98
98
  } catch (error: any) {
99
99
  spinnerPushing?.fail("Publishing failed");
@@ -106,7 +106,7 @@ Read more about deployment regions at https://docs.embeddable.com/deployment/dep
106
106
 
107
107
  const publishedSectionFeedback = (
108
108
  config: ResolvedEmbeddableConfig,
109
- spinnerPushing: Ora,
109
+ spinnerPushing: Ora
110
110
  ) => {
111
111
  config.pushModels && spinnerPushing.succeed("Models published");
112
112
  config.pushComponents && spinnerPushing.succeed("Components published");
@@ -115,7 +115,7 @@ const publishedSectionFeedback = (
115
115
  async function pushByApiKey(
116
116
  config: ResolvedEmbeddableConfig,
117
117
  spinner: any,
118
- cubeVersion?: string,
118
+ cubeVersion?: string
119
119
  ) {
120
120
  const apiKey = getArgumentByKey(["--api-key", "-k"]);
121
121
 
@@ -128,7 +128,7 @@ async function pushByApiKey(
128
128
 
129
129
  if (!email || !/\S+@\S+\.\S+/.test(email)) {
130
130
  spinner.fail(
131
- "Invalid email provided. Please provide a valid email using --email (-e) flag",
131
+ "Invalid email provided. Please provide a valid email using --email (-e) flag"
132
132
  );
133
133
  process.exit(1);
134
134
  }
@@ -172,7 +172,7 @@ export async function buildArchive(config: ResolvedEmbeddableConfig) {
172
172
 
173
173
  if (!config.pushModels && !config.pushComponents) {
174
174
  spinnerArchive.fail(
175
- "Cannot push: both pushModels and pushComponents are disabled",
175
+ "Cannot push: both pushModels and pushComponents are disabled"
176
176
  );
177
177
  process.exit(1);
178
178
  }
@@ -182,12 +182,12 @@ export async function buildArchive(config: ResolvedEmbeddableConfig) {
182
182
  if (config.pushModels) {
183
183
  const cubeFilesList = await findFiles(
184
184
  config.client.modelsSrc || config.client.srcDir,
185
- CUBE_FILES,
185
+ CUBE_FILES
186
186
  );
187
187
 
188
188
  const securityContextFilesList = await findFiles(
189
189
  config.client.presetsSrc || config.client.srcDir,
190
- SECURITY_CONTEXT_FILES,
190
+ SECURITY_CONTEXT_FILES
191
191
  );
192
192
 
193
193
  filesList.push(
@@ -199,21 +199,21 @@ export async function buildArchive(config: ResolvedEmbeddableConfig) {
199
199
  ...securityContextFilesList.map((entry): [string, string] => [
200
200
  path.basename(entry[1]),
201
201
  entry[1],
202
- ]),
202
+ ])
203
203
  );
204
204
  }
205
205
 
206
206
  if (config.pushComponents) {
207
207
  const clientContextFilesList = await findFiles(
208
208
  config.client.presetsSrc || config.client.srcDir,
209
- CLIENT_CONTEXT_FILES,
209
+ CLIENT_CONTEXT_FILES
210
210
  );
211
211
 
212
212
  filesList.push(
213
213
  ...clientContextFilesList.map((entry): [string, string] => [
214
214
  path.basename(entry[1]),
215
215
  entry[1],
216
- ]),
216
+ ])
217
217
  );
218
218
  }
219
219
 
@@ -240,9 +240,8 @@ export async function archive(args: {
240
240
  archive.pipe(output);
241
241
  if (!isDev) {
242
242
  archive.directory(ctx.client.buildDir, false);
243
- // NOTE: for backward compatibility, keep the file name as global.css
244
243
  archive.file(ctx.client.customCanvasCss, {
245
- name: "global.css",
244
+ name: "custom-canvas.css",
246
245
  });
247
246
  }
248
247
 
@@ -261,7 +260,7 @@ export async function archive(args: {
261
260
 
262
261
  export async function createFormData(
263
262
  filePath: string,
264
- metadata: Record<string, any>,
263
+ metadata: Record<string, any>
265
264
  ) {
266
265
  const { FormData, Blob } = await import("formdata-node");
267
266
  const { fileFromPath } = await import("formdata-node/file-from-path");
@@ -285,7 +284,7 @@ export async function sendBuildByApiKey(
285
284
  email,
286
285
  message,
287
286
  cubeVersion,
288
- }: { apiKey: string; email: string; message?: string; cubeVersion?: string },
287
+ }: { apiKey: string; email: string; message?: string; cubeVersion?: string }
289
288
  ) {
290
289
  const form = await createFormData(ctx.client.archiveFile, {
291
290
  pushModels: ctx.pushModels,
@@ -298,7 +297,7 @@ export async function sendBuildByApiKey(
298
297
  const response = await uploadFile(
299
298
  form,
300
299
  `${ctx.pushBaseUrl}/api/v1/bundle/upload`,
301
- apiKey,
300
+ apiKey
302
301
  );
303
302
  await fs.rm(ctx.client.archiveFile);
304
303
 
@@ -317,7 +316,7 @@ export async function sendBuild(
317
316
  token: string;
318
317
  message?: string;
319
318
  cubeVersion?: string;
320
- },
319
+ }
321
320
  ) {
322
321
  const form = await createFormData(ctx.client.archiveFile, {
323
322
  pushModels: ctx.pushModels,
@@ -330,7 +329,7 @@ export async function sendBuild(
330
329
  await uploadFile(
331
330
  form,
332
331
  `${ctx.pushBaseUrl}/bundle/${workspaceId}/upload`,
333
- token,
332
+ token
334
333
  );
335
334
 
336
335
  await fs.rm(ctx.client.archiveFile);