@embeddable.com/sdk-core 3.2.2 → 3.3.1

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.js CHANGED
@@ -8,6 +8,7 @@ var crypto = require('node:crypto');
8
8
  var fs$2 = require('node:fs');
9
9
  var node = require('@stencil/core/sys/node');
10
10
  var compiler = require('@stencil/core/compiler');
11
+ var os$1 = require('node:os');
11
12
  var YAML = require('yaml');
12
13
  var url$2 = require('node:url');
13
14
  var path$2 = require('path');
@@ -17,7 +18,6 @@ var require$$3 = require('http');
17
18
  var require$$4 = require('https');
18
19
  var require$$0$1 = require('url');
19
20
  var require$$2$1 = require('fs');
20
- var os$1 = require('node:os');
21
21
  var axios = require('axios');
22
22
  var archiver = require('archiver');
23
23
  var ws = require('ws');
@@ -46,10 +46,10 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
46
46
  var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
47
47
  var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
48
48
  var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$2);
49
+ var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os$1);
49
50
  var YAML__namespace = /*#__PURE__*/_interopNamespaceDefault(YAML);
50
51
  var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url$2);
51
52
  var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path$2);
52
- var os__namespace = /*#__PURE__*/_interopNamespaceDefault(os$1);
53
53
  var archiver__namespace = /*#__PURE__*/_interopNamespaceDefault(archiver);
54
54
  var chokidar__namespace = /*#__PURE__*/_interopNamespaceDefault(chokidar);
55
55
 
@@ -405,11 +405,11 @@ async function generate$1(ctx) {
405
405
  const optionsFiles = await findFiles(ctx.client.srcDir, EMB_OPTIONS_FILE_REGEX);
406
406
  const typeImports = typeFiles
407
407
  .concat(optionsFiles)
408
- .map(([_fileName, filePath]) => `import './${path__namespace
408
+ .map(([_fileName, filePath]) => `import '../${path__namespace
409
409
  .relative(ctx.client.rootDir, filePath)
410
410
  .replaceAll("\\", "/")}';`)
411
411
  .join("\n");
412
- await fs__namespace.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx.outputOptions.typesEntryPointFilename), typeImports);
412
+ await fs__namespace.writeFile(path__namespace.resolve(ctx.client.buildDir, ctx.outputOptions.typesEntryPointFilename), typeImports);
413
413
  }
414
414
  async function build$1(ctx) {
415
415
  var _a;
@@ -418,7 +418,7 @@ async function build$1(ctx) {
418
418
  build: {
419
419
  emptyOutDir: false,
420
420
  lib: {
421
- entry: path__namespace.resolve(ctx.client.rootDir, ctx.outputOptions.typesEntryPointFilename),
421
+ entry: path__namespace.resolve(ctx.client.buildDir, ctx.outputOptions.typesEntryPointFilename),
422
422
  formats: ["es"],
423
423
  fileName: "embeddable-types",
424
424
  },
@@ -434,7 +434,7 @@ async function build$1(ctx) {
434
434
  });
435
435
  }
436
436
  async function cleanup$1(ctx) {
437
- await fs__namespace.rm(path__namespace.resolve(ctx.client.rootDir, "embeddable-types-entry-point.js"));
437
+ await fs__namespace.rm(path__namespace.resolve(ctx.client.buildDir, "embeddable-types-entry-point.js"));
438
438
  }
439
439
 
440
440
  var prepare = async (ctx) => {
@@ -537,11 +537,142 @@ async function generateSourceMap(ctx, pluginName) {
537
537
  await fs__namespace.rm(tmpComponentDir, { recursive: true });
538
538
  }
539
539
 
540
+ const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embeddable");
541
+ const CREDENTIALS_FILE = path__namespace.resolve(CREDENTIALS_DIR, "credentials");
542
+
543
+ const oraP$3 = import('ora');
544
+ let ora$2;
545
+ const checkNodeVersion$1 = async () => {
546
+ ora$2 = (await oraP$3).default;
547
+ ora$2("Checking node version...");
548
+ const [major, minor] = process.versions.node.split(".").map(Number);
549
+ const engines = require("../package.json").engines.node;
550
+ const [minMajor, minMinor] = engines
551
+ .split(".")
552
+ .map((v) => v.replace(/[^\d]/g, ""))
553
+ .map(Number);
554
+ if (major < minMajor || (major === minMajor && minor < minMinor)) {
555
+ ora$2({
556
+ text: `Node version ${minMajor}.${minMinor} or higher is required. You are running ${major}.${minor}.`,
557
+ color: "red",
558
+ }).fail();
559
+ process.exit(1);
560
+ }
561
+ };
562
+ /**
563
+ * Get the value of a process argument by key
564
+ * Example: getArgumentByKey("--email") or getArgumentByKey(["--email", "-e"])
565
+ * @param key The key to search for in the process arguments
566
+ * @returns
567
+ */
568
+ const getArgumentByKey = (key) => {
569
+ if (Array.isArray(key)) {
570
+ for (const k of key) {
571
+ if (process.argv.includes(k)) {
572
+ const index = process.argv.indexOf(k);
573
+ return index !== -1 ? process.argv[index + 1] : undefined;
574
+ }
575
+ }
576
+ return undefined;
577
+ }
578
+ const index = process.argv.indexOf(key);
579
+ return index !== -1 ? process.argv[index + 1] : undefined;
580
+ };
581
+ const SUCCESS_FLAG_FILE = `${CREDENTIALS_DIR}/success`;
582
+ /**
583
+ * Store a flag in the credentials directory to indicate a successful build
584
+ * This is used to determine if the build was successful or not
585
+ */
586
+ const storeBuildSuccessFlag = async () => {
587
+ try {
588
+ await fs__namespace.access(CREDENTIALS_DIR);
589
+ }
590
+ catch (_e) {
591
+ await fs__namespace.mkdir(CREDENTIALS_DIR);
592
+ }
593
+ await fs__namespace.writeFile(SUCCESS_FLAG_FILE, "true");
594
+ };
595
+ /**
596
+ * Remove the success flag from the credentials directory
597
+ */
598
+ const removeBuildSuccessFlag = async () => {
599
+ try {
600
+ await fs__namespace.unlink(SUCCESS_FLAG_FILE);
601
+ }
602
+ catch (_e) { }
603
+ };
604
+ /**
605
+ * Check if the build was successful
606
+ */
607
+ const checkBuildSuccess = async () => {
608
+ try {
609
+ await fs__namespace.access(SUCCESS_FLAG_FILE);
610
+ return true;
611
+ }
612
+ catch (_e) {
613
+ return false;
614
+ }
615
+ };
616
+ const getPackageVersion = (packageName) => {
617
+ const packageJsonPath = path$1.join(process.cwd(), "node_modules", packageName, "package.json");
618
+ try {
619
+ const packageJson = require(packageJsonPath);
620
+ return packageJson.version;
621
+ }
622
+ catch (e) {
623
+ return undefined;
624
+ }
625
+ };
626
+
540
627
  var cleanup = async (ctx) => {
541
628
  await extractBuild(ctx);
542
629
  await removeObsoleteDir(ctx.client.buildDir);
543
630
  await moveBuildTOBuildDir(ctx);
544
631
  };
632
+ async function createManifest({ ctx, typesFileName, metaFileName, editorsMetaFileName, stencilWrapperFileName, }) {
633
+ var _a, _b, _c, _d;
634
+ const packageNames = [
635
+ "@embeddable.com/core",
636
+ "@embeddable.com/react",
637
+ "@embeddable.com/sdk-core",
638
+ "@embeddable.com/sdk-react",
639
+ "@embeddable.com/sdk-utils",
640
+ ];
641
+ const sdkVersions = packageNames.reduce((acc, packageName) => {
642
+ const version = getPackageVersion(packageName);
643
+ if (version) {
644
+ acc[packageName] = version;
645
+ }
646
+ return acc;
647
+ }, {});
648
+ // identify user's package manager and its version
649
+ let packageManager = "npm";
650
+ if ((_a = process.env.npm_config_user_agent) === null || _a === void 0 ? void 0 : _a.includes("yarn")) {
651
+ packageManager = "yarn";
652
+ }
653
+ if ((_b = process.env.npm_config_user_agent) === null || _b === void 0 ? void 0 : _b.includes("pnpm")) {
654
+ packageManager = "pnpm";
655
+ }
656
+ const packageManagerVersion = ((_d = (_c = process.env.npm_config_user_agent) === null || _c === void 0 ? void 0 : _c.match(/(\d+\.\d+\.\d+)/)) === null || _d === void 0 ? void 0 : _d[0]) ||
657
+ "unknown";
658
+ // write manifest file with files with hash
659
+ const manifest = {
660
+ entryFiles: {
661
+ "embeddable-types.js": typesFileName,
662
+ "embeddable-components-meta.js": metaFileName,
663
+ "embeddable-editors-meta.js": editorsMetaFileName,
664
+ "embeddable-wrapper.esm.js": stencilWrapperFileName,
665
+ },
666
+ metadata: {
667
+ nodeVersion: process.version,
668
+ platform: process.platform,
669
+ sdkVersions,
670
+ packageManager,
671
+ packageManagerVersion,
672
+ },
673
+ };
674
+ await fs__namespace.writeFile(path__namespace.join(ctx.client.tmpDir, "embeddable-manifest.json"), JSON.stringify(manifest));
675
+ }
545
676
  async function extractBuild(ctx) {
546
677
  const [[, stencilWrapperFilePath]] = await findFiles(ctx.client.stencilBuild, /embeddable-wrapper.esm-[a-z0-9]+\.js/);
547
678
  const stencilWrapperFileName = path__namespace.basename(stencilWrapperFilePath);
@@ -555,16 +686,13 @@ async function extractBuild(ctx) {
555
686
  const [[, editorsMetaFilePath]] = await findFiles(ctx.client.buildDir, /embeddable-editors-meta-[a-z0-9]+\.js/);
556
687
  const editorsMetaFileName = path__namespace.basename(editorsMetaFilePath);
557
688
  await fs__namespace.rename(editorsMetaFilePath, path__namespace.join(ctx.client.tmpDir, editorsMetaFileName));
558
- // write manifest file with files with hash
559
- const manifest = {
560
- entryFiles: {
561
- "embeddable-types.js": typesFileName,
562
- "embeddable-components-meta.js": metaFileName,
563
- "embeddable-editors-meta.js": editorsMetaFileName,
564
- "embeddable-wrapper.esm.js": stencilWrapperFileName,
565
- },
566
- };
567
- await fs__namespace.writeFile(path__namespace.join(ctx.client.tmpDir, "embeddable-manifest.json"), JSON.stringify(manifest));
689
+ await createManifest({
690
+ ctx,
691
+ typesFileName,
692
+ metaFileName,
693
+ editorsMetaFileName,
694
+ stencilWrapperFileName,
695
+ });
568
696
  }
569
697
  async function removeObsoleteDir(dir) {
570
698
  await fs__namespace.rm(dir, { recursive: true });
@@ -4810,7 +4938,7 @@ var z = /*#__PURE__*/Object.freeze({
4810
4938
 
4811
4939
  const CUBE_YAML_FILE_REGEX = /^(.*)\.cube\.ya?ml$/;
4812
4940
  const SECURITY_CONTEXT_FILE_REGEX = /^(.*)\.sc\.ya?ml$/;
4813
- const checkNodeVersion$1 = () => {
4941
+ const checkNodeVersion = () => {
4814
4942
  const [major, minor] = process.versions.node.split(".").map(Number);
4815
4943
  const engines = require("../package.json").engines.node;
4816
4944
  const [minMajor, minMinor] = engines.split(".").map(Number);
@@ -4819,7 +4947,7 @@ const checkNodeVersion$1 = () => {
4819
4947
  }
4820
4948
  };
4821
4949
  var validate = async (ctx, exitIfInvalid = true) => {
4822
- checkNodeVersion$1();
4950
+ checkNodeVersion();
4823
4951
  const ora = (await import('ora')).default;
4824
4952
  const spinnerValidate = ora("Data model validation...").start();
4825
4953
  const filesList = await findFiles(ctx.client.srcDir, CUBE_YAML_FILE_REGEX);
@@ -20151,9 +20279,6 @@ var rollbar = Rollbar;
20151
20279
 
20152
20280
  var Rollbar$1 = /*@__PURE__*/getDefaultExportFromCjs(rollbar);
20153
20281
 
20154
- const CREDENTIALS_DIR = path__namespace.resolve(os__namespace.homedir(), ".embeddable");
20155
- const CREDENTIALS_FILE = path__namespace.resolve(CREDENTIALS_DIR, "credentials");
20156
-
20157
20282
  class InvalidTokenError extends Error {
20158
20283
  }
20159
20284
  InvalidTokenError.prototype.name = "InvalidTokenError";
@@ -20288,83 +20413,9 @@ async function getUserData() {
20288
20413
  }
20289
20414
  }
20290
20415
 
20291
- const oraP$3 = import('ora');
20292
- let ora$2;
20293
- const checkNodeVersion = async () => {
20294
- ora$2 = (await oraP$3).default;
20295
- ora$2("Checking node version...");
20296
- const [major, minor] = process.versions.node.split(".").map(Number);
20297
- const engines = require("../package.json").engines.node;
20298
- const [minMajor, minMinor] = engines
20299
- .split(".")
20300
- .map((v) => v.replace(/[^\d]/g, ""))
20301
- .map(Number);
20302
- if (major < minMajor || (major === minMajor && minor < minMinor)) {
20303
- ora$2({
20304
- text: `Node version ${minMajor}.${minMinor} or higher is required. You are running ${major}.${minor}.`,
20305
- color: "red",
20306
- }).fail();
20307
- process.exit(1);
20308
- }
20309
- };
20310
- /**
20311
- * Get the value of a process argument by key
20312
- * Example: getArgumentByKey("--email") or getArgumentByKey(["--email", "-e"])
20313
- * @param key The key to search for in the process arguments
20314
- * @returns
20315
- */
20316
- const getArgumentByKey = (key) => {
20317
- if (Array.isArray(key)) {
20318
- for (const k of key) {
20319
- if (process.argv.includes(k)) {
20320
- const index = process.argv.indexOf(k);
20321
- return index !== -1 ? process.argv[index + 1] : undefined;
20322
- }
20323
- }
20324
- return undefined;
20325
- }
20326
- const index = process.argv.indexOf(key);
20327
- return index !== -1 ? process.argv[index + 1] : undefined;
20328
- };
20329
- const SUCCESS_FLAG_FILE = `${CREDENTIALS_DIR}/success`;
20330
- /**
20331
- * Store a flag in the credentials directory to indicate a successful build
20332
- * This is used to determine if the build was successful or not
20333
- */
20334
- const storeBuildSuccessFlag = async () => {
20335
- try {
20336
- await fs__namespace.access(CREDENTIALS_DIR);
20337
- }
20338
- catch (_e) {
20339
- await fs__namespace.mkdir(CREDENTIALS_DIR);
20340
- }
20341
- await fs__namespace.writeFile(SUCCESS_FLAG_FILE, "true");
20342
- };
20343
- /**
20344
- * Remove the success flag from the credentials directory
20345
- */
20346
- const removeBuildSuccessFlag = async () => {
20347
- try {
20348
- await fs__namespace.unlink(SUCCESS_FLAG_FILE);
20349
- }
20350
- catch (_e) { }
20351
- };
20352
- /**
20353
- * Check if the build was successful
20354
- */
20355
- const checkBuildSuccess = async () => {
20356
- try {
20357
- await fs__namespace.access(SUCCESS_FLAG_FILE);
20358
- return true;
20359
- }
20360
- catch (_e) {
20361
- return false;
20362
- }
20363
- };
20364
-
20365
20416
  var build = async () => {
20366
20417
  try {
20367
- checkNodeVersion();
20418
+ checkNodeVersion$1();
20368
20419
  removeBuildSuccessFlag();
20369
20420
  const config = await provideConfig();
20370
20421
  await validate(config);
@@ -20476,7 +20527,7 @@ var push = async () => {
20476
20527
  var _a, _b;
20477
20528
  let spinnerPushing;
20478
20529
  try {
20479
- checkNodeVersion();
20530
+ checkNodeVersion$1();
20480
20531
  const isBuildSuccess = await checkBuildSuccess();
20481
20532
  if (!isBuildSuccess) {
20482
20533
  console.error("Build failed or not completed. Please run `embeddable:build` first.");
@@ -20662,24 +20713,48 @@ let browserWindow = null;
20662
20713
  let ora;
20663
20714
  let previewWorkspace;
20664
20715
  const SERVER_PORT = 8926;
20716
+ const BUILD_DEV_DIR = ".embeddable-dev-build";
20665
20717
  const buildWebComponent = async (config) => {
20666
20718
  await generate(config, "sdk-react");
20667
20719
  };
20720
+ const addToGitingore = async () => {
20721
+ try {
20722
+ const fs = require("fs").promises;
20723
+ const gitignorePath = path__namespace$1.resolve(process.cwd(), ".gitignore");
20724
+ const gitignoreContent = await fs.readFile(gitignorePath, "utf8");
20725
+ if (!gitignoreContent.includes(BUILD_DEV_DIR)) {
20726
+ await fs.appendFile(gitignorePath, `\n${BUILD_DEV_DIR}\n`);
20727
+ }
20728
+ }
20729
+ catch (e) {
20730
+ // ignore
20731
+ }
20732
+ };
20668
20733
  var dev = async () => {
20669
20734
  var _a;
20670
- checkNodeVersion();
20735
+ checkNodeVersion$1();
20736
+ addToGitingore();
20671
20737
  const http = require("http");
20672
20738
  ora = (await oraP).default;
20673
20739
  process.on("warning", (e) => console.warn(e.stack));
20674
20740
  const logger = node.createNodeLogger({ process });
20675
20741
  const sys = node.createNodeSys({ process });
20742
+ const defaultConfig = await provideConfig();
20743
+ const buildDir = path__namespace$1.resolve(defaultConfig.client.rootDir, ".embeddable-dev-build");
20676
20744
  const config = {
20745
+ ...defaultConfig,
20677
20746
  dev: {
20678
20747
  watch: true,
20679
20748
  logger,
20680
20749
  sys,
20681
20750
  },
20682
- ...(await provideConfig()),
20751
+ client: {
20752
+ ...defaultConfig.client,
20753
+ buildDir: buildDir,
20754
+ componentDir: path__namespace$1.resolve(buildDir, "component"),
20755
+ stencilBuild: path__namespace$1.resolve(buildDir, "dist", "embeddable-wrapper"),
20756
+ tmpDir: path__namespace$1.resolve(defaultConfig.client.rootDir, ".embeddable-dev-tmp"),
20757
+ },
20683
20758
  };
20684
20759
  await prepare(config);
20685
20760
  const finalhandler = require("finalhandler");