@embeddable.com/sdk-react 2.2.20 → 2.2.22
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 +74 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +76 -5
- package/lib/index.js.map +1 -1
- package/lib/validate/usageValidator.d.ts +1 -0
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path$1 from 'node:path';
|
|
2
2
|
import { resolve, join } from 'node:path';
|
|
3
|
-
import * as fs$
|
|
3
|
+
import * as fs$2 from 'fs/promises';
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import * as vite from 'vite';
|
|
6
6
|
import viteReactPlugin from '@vitejs/plugin-react';
|
|
@@ -12,6 +12,7 @@ import traverse from '@babel/traverse';
|
|
|
12
12
|
import 'node:child_process';
|
|
13
13
|
import { z } from 'zod';
|
|
14
14
|
import { ALL_NATIVE_TYPES } from '@embeddable.com/core';
|
|
15
|
+
import * as fs$1 from 'fs';
|
|
15
16
|
|
|
16
17
|
var createContext = (pluginRoot, coreCtx) => {
|
|
17
18
|
coreCtx["sdk-react"] = {
|
|
@@ -715,11 +716,80 @@ const entrypointModifiers = [
|
|
|
715
716
|
styledComponentsEntrypointModifier,
|
|
716
717
|
];
|
|
717
718
|
|
|
719
|
+
const oraP$1 = import('ora');
|
|
720
|
+
function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
721
|
+
const files = fs$1.readdirSync(directory);
|
|
722
|
+
const result = [];
|
|
723
|
+
files.forEach((file) => {
|
|
724
|
+
const filePath = path.join(directory, file);
|
|
725
|
+
if (fs$1.statSync(filePath).isDirectory()) {
|
|
726
|
+
// Recursively check files in subdirectories
|
|
727
|
+
result.push(...findFilesWithWrongUsage(filePath, pattern, mustEndWith));
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
const fileContent = fs$1.readFileSync(filePath, "utf8");
|
|
731
|
+
if (fileContent.match(pattern)) {
|
|
732
|
+
result.push(filePath);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
});
|
|
736
|
+
return result.filter((file) => !mustEndWith.some((ending) => file.endsWith(ending)));
|
|
737
|
+
}
|
|
738
|
+
const regexDefineComponentFunction = /defineComponent(<\w+>)?\(/;
|
|
739
|
+
const regexDefineTypeFunction = /defineType\(/;
|
|
740
|
+
const regexDefineOptionFunction = /defineOption\(/;
|
|
741
|
+
const regexCubeFunction = /cube\(/;
|
|
742
|
+
const regexCubes = /cubes:/;
|
|
743
|
+
const usageValidator = async (directory) => {
|
|
744
|
+
let isValid = true;
|
|
745
|
+
const ora = (await oraP$1).default;
|
|
746
|
+
const progress = ora("React: function usage validating...").start();
|
|
747
|
+
// defineComponent function
|
|
748
|
+
const filesWithWrongDefineComponentFunctionUsage = findFilesWithWrongUsage(directory, regexDefineComponentFunction, [".emb.js", ".emb.ts"]);
|
|
749
|
+
if (filesWithWrongDefineComponentFunctionUsage.length) {
|
|
750
|
+
isValid = false;
|
|
751
|
+
progress.fail("React: defineComponent() usage is only allowed inside files with the extension .emb.(js|ts) files.\nFix the following files:\n" +
|
|
752
|
+
filesWithWrongDefineComponentFunctionUsage.join("\n"));
|
|
753
|
+
}
|
|
754
|
+
// defineType function
|
|
755
|
+
const filesWithWrongDefineTypeFunctionUsage = findFilesWithWrongUsage(directory, regexDefineTypeFunction, [".type.emb.js", ".type.emb.ts"]);
|
|
756
|
+
if (filesWithWrongDefineTypeFunctionUsage.length) {
|
|
757
|
+
isValid = false;
|
|
758
|
+
progress.fail("React: defineType() usage is only allowed inside files with the extension .type.emb.(js|ts) files.\nFix the following files:\n" +
|
|
759
|
+
filesWithWrongDefineTypeFunctionUsage.join("\n"));
|
|
760
|
+
}
|
|
761
|
+
// defineOption function
|
|
762
|
+
const filesWithWrongDefineOptionFunctionUsage = findFilesWithWrongUsage(directory, regexDefineOptionFunction, [".type.emb.js", ".type.emb.ts"]);
|
|
763
|
+
if (filesWithWrongDefineOptionFunctionUsage.length) {
|
|
764
|
+
isValid = false;
|
|
765
|
+
progress.fail("React: defineOption() usage is only allowed inside files with the extension .type.emb.(js|ts) files.\nFix the following files:\n" +
|
|
766
|
+
filesWithWrongDefineOptionFunctionUsage.join("\n"));
|
|
767
|
+
}
|
|
768
|
+
// cube function
|
|
769
|
+
const filesWithWrongCubeFunctionUsage = findFilesWithWrongUsage(directory, regexCubeFunction, [".cube.js", ".cube.ts"]);
|
|
770
|
+
if (filesWithWrongCubeFunctionUsage.length) {
|
|
771
|
+
isValid = false;
|
|
772
|
+
progress.fail("React: cube() usage is only allowed inside files with the extension .cube.(ts|js) files.\nFix the following files:\n" +
|
|
773
|
+
filesWithWrongCubeFunctionUsage.join("\n"));
|
|
774
|
+
}
|
|
775
|
+
// cube in yml or yaml files
|
|
776
|
+
const filesWithWrongCubeUsage = findFilesWithWrongUsage(directory, regexCubes, [".cube.yml", ".cube.yaml"]);
|
|
777
|
+
if (filesWithWrongCubeUsage.length) {
|
|
778
|
+
isValid = false;
|
|
779
|
+
progress.fail("React: cubes: usage is only allowed inside files with the extension .cube.(yml|yaml) files.\nFix the following files:\n" +
|
|
780
|
+
filesWithWrongCubeUsage.join("\n"));
|
|
781
|
+
}
|
|
782
|
+
isValid
|
|
783
|
+
? progress.succeed("React: function usage validated")
|
|
784
|
+
: process.exit(1);
|
|
785
|
+
};
|
|
786
|
+
|
|
718
787
|
const oraP = import('ora');
|
|
719
788
|
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
720
789
|
var generate = async (ctx) => {
|
|
721
790
|
var _a;
|
|
722
791
|
const ora = (await oraP).default;
|
|
792
|
+
await usageValidator(ctx.client.srcDir);
|
|
723
793
|
const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
724
794
|
await prepareEntrypoint(ctx, filesList);
|
|
725
795
|
let result;
|
|
@@ -729,7 +799,7 @@ var generate = async (ctx) => {
|
|
|
729
799
|
else {
|
|
730
800
|
const progress = ora("React: building components...").start();
|
|
731
801
|
result = await runViteBuild(ctx);
|
|
732
|
-
progress.succeed("React
|
|
802
|
+
progress.succeed("Building React components completed");
|
|
733
803
|
}
|
|
734
804
|
return result;
|
|
735
805
|
};
|
|
@@ -802,8 +872,8 @@ async function prepareEntrypoint(ctx, filesList) {
|
|
|
802
872
|
additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
|
|
803
873
|
}
|
|
804
874
|
}
|
|
805
|
-
const content = await fs$
|
|
806
|
-
await fs$
|
|
875
|
+
const content = await fs$2.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
876
|
+
await fs$2.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content
|
|
807
877
|
.replace(IMPORT_REPLACE_TOKEN, imports)
|
|
808
878
|
.replace(ERROR_FALLBACK_COMPONENT_IMPORT_TOKEN, errorBoundaryImport)
|
|
809
879
|
.replace(ERROR_FALLBACK_COMPONENT_TOKEN, errorFallbackComponent)
|