@embeddable.com/sdk-core 3.14.0-next.2 → 3.14.0-next.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/lib/index.esm.js CHANGED
@@ -21860,8 +21860,8 @@ async function selectWorkspace(ora, ctx, token) {
21860
21860
 
21861
21861
  // grab cube files
21862
21862
  const CUBE_FILES = /^(.*)\.cube\.(ya?ml|js)$/;
21863
- // grab security context and client context files
21864
- const PRESET_FILES = /^(.*)\.(sc|cc)\.ya?ml$/;
21863
+ const CLIENT_CONTEXT_FILES = /^(.*)\.cc\.ya?ml$/;
21864
+ const SECURITY_CONTEXT_FILES = /^(.*)\.sc\.ya?ml$/;
21865
21865
  var push = async () => {
21866
21866
  var _a;
21867
21867
  await initLogger("push");
@@ -21958,11 +21958,15 @@ async function buildArchive(config) {
21958
21958
  const filesList = [];
21959
21959
  if (config.pushModels) {
21960
21960
  const cubeFilesList = await findFiles(config.client.modelsSrc || config.client.srcDir, CUBE_FILES);
21961
- const contextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, PRESET_FILES);
21961
+ const clientContextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, CLIENT_CONTEXT_FILES);
21962
+ const securityContextFilesList = await findFiles(config.client.presetsSrc || config.client.srcDir, SECURITY_CONTEXT_FILES);
21962
21963
  filesList.push(...cubeFilesList.map((entry) => [
21963
21964
  path.basename(entry[1]),
21964
21965
  entry[1],
21965
- ]), ...contextFilesList.map((entry) => [
21966
+ ]), ...clientContextFilesList.map((entry) => [
21967
+ path.basename(entry[1]),
21968
+ entry[1],
21969
+ ]), ...securityContextFilesList.map((entry) => [
21966
21970
  path.basename(entry[1]),
21967
21971
  entry[1],
21968
21972
  ]));
@@ -22121,13 +22125,6 @@ var dev = async () => {
22121
22125
  }
22122
22126
  }
22123
22127
  workspacePreparation.succeed("Workspace is ready");
22124
- const { themeWatcher, lifecycleWatcher } = await buildGlobalHooks(config);
22125
- if (themeWatcher) {
22126
- await globalHookWatcher(themeWatcher, config);
22127
- }
22128
- if (lifecycleWatcher) {
22129
- await globalHookWatcher(lifecycleWatcher, config);
22130
- }
22131
22128
  const server = http.createServer(async (request, res) => {
22132
22129
  var _a;
22133
22130
  res.setHeader("Access-Control-Allow-Origin", "*");
@@ -22150,6 +22147,7 @@ var dev = async () => {
22150
22147
  catch (_b) { }
22151
22148
  serve(request, res, done);
22152
22149
  });
22150
+ const { themeWatcher, lifecycleWatcher } = await buildGlobalHooks(config);
22153
22151
  wss = new WebSocketServer({ server });
22154
22152
  server.listen(SERVER_PORT, async () => {
22155
22153
  const watchers = [];
@@ -22170,27 +22168,34 @@ var dev = async () => {
22170
22168
  metaFileName: "embeddable-components-meta.js",
22171
22169
  editorsMetaFileName: "embeddable-editors-meta.js",
22172
22170
  });
22173
- await sendDataModelsAndContextsChanges(config);
22174
- for (const getPlugin of config.plugins) {
22175
- const plugin = getPlugin();
22176
- breadcrumbs.push("validate plugin");
22177
- await plugin.validate(config);
22178
- breadcrumbs.push("build plugin");
22179
- const watcher = await plugin.build(config);
22180
- breadcrumbs.push("configure watcher");
22181
- await configureWatcher(watcher, config);
22182
- watchers.push(watcher);
22183
- }
22184
- const dataModelAndSecurityContextWatch = await dataModelAndSecurityContextWatcher(config);
22185
- const customGlobalCssWatch = globalCssWatcher(config);
22186
- watchers.push(dataModelAndSecurityContextWatch);
22187
- watchers.push(customGlobalCssWatch);
22188
- if (themeWatcher) {
22189
- watchers.push(themeWatcher);
22171
+ await sendBuildChanges(config);
22172
+ if (config.pushComponents) {
22173
+ for (const getPlugin of config.plugins) {
22174
+ const plugin = getPlugin();
22175
+ breadcrumbs.push("validate plugin");
22176
+ await plugin.validate(config);
22177
+ breadcrumbs.push("build plugin");
22178
+ const watcher = await plugin.build(config);
22179
+ breadcrumbs.push("configure watcher");
22180
+ await configureWatcher(watcher, config);
22181
+ watchers.push(watcher);
22182
+ }
22183
+ const customGlobalCssWatch = globalCssWatcher(config);
22184
+ watchers.push(customGlobalCssWatch);
22185
+ if (themeWatcher) {
22186
+ await globalHookWatcher(themeWatcher, config);
22187
+ watchers.push(themeWatcher);
22188
+ }
22189
+ if (lifecycleWatcher) {
22190
+ await globalHookWatcher(lifecycleWatcher, config);
22191
+ watchers.push(lifecycleWatcher);
22192
+ }
22190
22193
  }
22191
- if (lifecycleWatcher) {
22192
- watchers.push(lifecycleWatcher);
22194
+ else {
22195
+ await openDevWorkspacePage(config.previewBaseUrl);
22193
22196
  }
22197
+ const cubeSecurityContextAndClientContextWatch = await cubeSecurityContextAndClientContextWatcher(config);
22198
+ watchers.push(cubeSecurityContextAndClientContextWatch);
22194
22199
  });
22195
22200
  }
22196
22201
  catch (error) {
@@ -22253,31 +22258,45 @@ const onBuildStart = async (ctx) => {
22253
22258
  }
22254
22259
  sendMessage("componentsBuildStart", { changedFiles });
22255
22260
  };
22261
+ const openDevWorkspacePage = async (previewBaseUrl) => {
22262
+ const open = (await import('open')).default;
22263
+ return await open(`${previewBaseUrl}/workspace/${previewWorkspace}`);
22264
+ };
22256
22265
  const onBundleBuildEnd = async (ctx) => {
22257
22266
  if (!onlyTypesChanged() || changedFiles.length === 0) {
22258
22267
  await buildWebComponent(ctx);
22259
22268
  }
22260
22269
  if (browserWindow == null) {
22261
- const open = (await import('open')).default;
22262
- browserWindow = await open(`${ctx.previewBaseUrl}/workspace/${previewWorkspace}`);
22270
+ browserWindow = await openDevWorkspacePage(ctx.previewBaseUrl);
22263
22271
  }
22264
22272
  else {
22265
22273
  sendMessage("componentsBuildSuccess");
22266
22274
  }
22267
22275
  };
22268
- const dataModelAndSecurityContextWatcher = async (ctx) => {
22269
- const [modelsFiles, presetsFiles] = await Promise.all([
22270
- fg("**/*.cube.{yaml,yml,js}", {
22271
- cwd: ctx.client.modelsSrc,
22272
- absolute: true,
22273
- }),
22274
- fg("**/*.{sc,cc}.{yaml,yml}", {
22276
+ const cubeSecurityContextAndClientContextWatcher = async (ctx) => {
22277
+ let filesToWatch = [];
22278
+ if (ctx.pushComponents) {
22279
+ const clientContextFiles = await fg("**/*.cc.{yaml,yml}", {
22275
22280
  cwd: ctx.client.presetsSrc,
22276
22281
  absolute: true,
22277
- }),
22278
- ]);
22279
- const fsWatcher = chokidar.watch([...modelsFiles, ...presetsFiles], chokidarWatchOptions);
22280
- fsWatcher.on("all", () => sendDataModelsAndContextsChanges(ctx));
22282
+ });
22283
+ filesToWatch = [...filesToWatch, ...clientContextFiles];
22284
+ }
22285
+ if (ctx.pushModels) {
22286
+ const [cubeFiles, securityContextFiles] = await Promise.all([
22287
+ fg("**/*.cube.{yaml,yml,js}", {
22288
+ cwd: ctx.client.modelsSrc,
22289
+ absolute: true,
22290
+ }),
22291
+ fg("**/*.sc.{yaml,yml}", {
22292
+ cwd: ctx.client.presetsSrc,
22293
+ absolute: true,
22294
+ }),
22295
+ ]);
22296
+ filesToWatch = [...filesToWatch, ...cubeFiles, ...securityContextFiles];
22297
+ }
22298
+ const fsWatcher = chokidar.watch(filesToWatch, chokidarWatchOptions);
22299
+ fsWatcher.on("all", () => sendBuildChanges(ctx));
22281
22300
  return fsWatcher;
22282
22301
  };
22283
22302
  const globalCssWatcher = (ctx) => {
@@ -22287,33 +22306,46 @@ const globalCssWatcher = (ctx) => {
22287
22306
  });
22288
22307
  return fsWatcher;
22289
22308
  };
22290
- const sendDataModelsAndContextsChanges = async (ctx) => {
22291
- sendMessage("dataModelsAndOrSecurityContextUpdateStart");
22309
+ const sendBuildChanges = async (ctx) => {
22292
22310
  const isValid = await validate(ctx);
22293
- if (isValid) {
22294
- const token = await getToken();
22295
- const sending = ora("Synchronising data models and/or security contexts...").start();
22296
- const cubeFilesList = await findFiles(ctx.client.modelsSrc, CUBE_FILES);
22297
- const contextFilesList = await findFiles(ctx.client.presetsSrc, PRESET_FILES);
22311
+ if (!isValid) {
22312
+ return sendMessage("dataModelsAndOrSecurityContextUpdateError");
22313
+ }
22314
+ const sending = ora("Synchronising data models and/or security contexts...").start();
22315
+ let filesList = [];
22316
+ if (ctx.pushComponents) {
22317
+ const clientContextFilesList = await findFiles(ctx.client.presetsSrc, CLIENT_CONTEXT_FILES);
22298
22318
  // Map the files to include their full filenames
22299
- const filesList = [...cubeFilesList, ...contextFilesList].map((entry) => [path.basename(entry[1]), entry[1]]);
22300
- // add manifest to the archive
22301
- filesList.push([
22302
- "embeddable-manifest.json",
22303
- path.resolve(ctx.client.buildDir, "embeddable-manifest.json"),
22304
- ]);
22305
- await archive({
22306
- ctx,
22307
- filesList,
22308
- isDev: true,
22309
- });
22310
- await sendBuild(ctx, { workspaceId: previewWorkspace, token });
22311
- sending.succeed(`Data models and/or security context synchronized`);
22312
- sendMessage("dataModelsAndOrSecurityContextUpdateSuccess");
22319
+ const clientContextFileList = [...clientContextFilesList].map((entry) => [path.basename(entry[1]), entry[1]]);
22320
+ filesList = [...clientContextFileList];
22313
22321
  }
22314
- else {
22315
- sendMessage("dataModelsAndOrSecurityContextUpdateError");
22322
+ if (ctx.pushModels) {
22323
+ const cubeFilesList = await findFiles(ctx.client.modelsSrc, CUBE_FILES);
22324
+ const securityContextFilesList = await findFiles(ctx.client.presetsSrc, SECURITY_CONTEXT_FILES);
22325
+ // Map the files to include their full filenames
22326
+ const cubeAndSecurityContextFileList = [
22327
+ ...cubeFilesList,
22328
+ ...securityContextFilesList,
22329
+ ].map((entry) => [path.basename(entry[1]), entry[1]]);
22330
+ filesList = [
22331
+ ...filesList,
22332
+ ...cubeAndSecurityContextFileList,
22333
+ // add manifest to the archive
22334
+ [
22335
+ "embeddable-manifest.json",
22336
+ path.resolve(ctx.client.buildDir, "embeddable-manifest.json"),
22337
+ ],
22338
+ ];
22316
22339
  }
22340
+ const token = await getToken();
22341
+ await archive({
22342
+ ctx,
22343
+ filesList,
22344
+ isDev: true,
22345
+ });
22346
+ await sendBuild(ctx, { workspaceId: previewWorkspace, token });
22347
+ sending.succeed(`Data models and/or security context synchronized`);
22348
+ sendMessage("dataModelsAndOrSecurityContextUpdateSuccess");
22317
22349
  };
22318
22350
  const onClose = async (server, sys, watchers, config) => {
22319
22351
  server.close();
@@ -22335,20 +22367,21 @@ const onClose = async (server, sys, watchers, config) => {
22335
22367
  const getPreviewWorkspace = async (startedOra, ctx) => {
22336
22368
  const token = await getToken();
22337
22369
  const params = minimist(process.argv.slice(2));
22338
- let primaryWorkspace = params.w || params.workspace;
22339
- if (!primaryWorkspace) {
22370
+ let primaryWorkspaceId = params.w || params.workspace;
22371
+ if (!primaryWorkspaceId) {
22340
22372
  startedOra.stop(); // Stop current Ora, otherwise the last option will get hidden by it.
22341
22373
  const { workspaceId } = await selectWorkspace(ora, ctx, token);
22342
- primaryWorkspace = workspaceId;
22374
+ primaryWorkspaceId = workspaceId;
22343
22375
  startedOra.start();
22344
22376
  }
22345
22377
  try {
22346
22378
  const instanceUrl = process.env.CUBE_CLOUD_ENDPOINT;
22347
- const response = await axios.get(`${ctx.pushBaseUrl}/workspace/dev-workspace`, {
22348
- params: {
22349
- primaryWorkspace,
22350
- instanceUrl,
22351
- },
22379
+ const response = await axios.post(`${ctx.pushBaseUrl}/workspace/dev-workspace`, {
22380
+ primaryWorkspaceId,
22381
+ instanceUrl,
22382
+ pushModels: ctx.pushModels,
22383
+ pushComponents: ctx.pushComponents,
22384
+ }, {
22352
22385
  headers: {
22353
22386
  Authorization: `Bearer ${token}`,
22354
22387
  },