@embeddable.com/sdk-react 2.2.31 → 2.2.32
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 +47 -0
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +47 -0
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -831,6 +831,27 @@ function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
|
831
831
|
});
|
|
832
832
|
return result.filter((file) => !mustEndWith.some((ending) => file.endsWith(ending)));
|
|
833
833
|
}
|
|
834
|
+
function findTypeNames(directory) {
|
|
835
|
+
const files = fs__namespace$1.readdirSync(directory);
|
|
836
|
+
const typeNames = [];
|
|
837
|
+
files.forEach((file) => {
|
|
838
|
+
const filePath = path__namespace.join(directory, file);
|
|
839
|
+
if (fs__namespace$1.statSync(filePath).isDirectory()) {
|
|
840
|
+
// Recursively check files in subdirectories
|
|
841
|
+
typeNames.push(...findTypeNames(filePath));
|
|
842
|
+
}
|
|
843
|
+
else {
|
|
844
|
+
const fileContent = fs__namespace$1.readFileSync(filePath, "utf8");
|
|
845
|
+
const regexDefineTypeFunctionTypeName = /defineType\(["'](.*?)["']\,/g;
|
|
846
|
+
const matches = fileContent.match(regexDefineTypeFunctionTypeName) || [];
|
|
847
|
+
const extractedContent = matches.map((match) => match.slice(12, -2))[0];
|
|
848
|
+
if (extractedContent) {
|
|
849
|
+
typeNames.push({ file: filePath, typeName: extractedContent });
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
return typeNames;
|
|
854
|
+
}
|
|
834
855
|
const regexDefineComponentFunction = /defineComponent(<\w+>)?\(/;
|
|
835
856
|
const regexDefineTypeFunction = /defineType\(/;
|
|
836
857
|
const regexDefineOptionFunction = /defineOption\(/;
|
|
@@ -875,6 +896,32 @@ const usageValidator = async (directory) => {
|
|
|
875
896
|
progress.fail("React: cubes: usage is only allowed inside files with the extension .cube.(yml|yaml) files.\nFix the following files:\n" +
|
|
876
897
|
filesWithWrongCubeUsage.join("\n"));
|
|
877
898
|
}
|
|
899
|
+
const typeNames = findTypeNames(directory);
|
|
900
|
+
// check for definedTypes using a native typeNames
|
|
901
|
+
const duplicatedNativeTypeNames = typeNames.filter((item) => core.ALL_NATIVE_TYPES.includes(item.typeName));
|
|
902
|
+
if (duplicatedNativeTypeNames.length) {
|
|
903
|
+
isValid = false;
|
|
904
|
+
progress.fail("React: defineType() can't be used with the same typeName as the nativeTypes. Fix the following files:\n" +
|
|
905
|
+
duplicatedNativeTypeNames
|
|
906
|
+
.map((dtn) => `${dtn.typeName} (file: ${dtn.file})`)
|
|
907
|
+
.join("\n"));
|
|
908
|
+
}
|
|
909
|
+
// check for duplicated typeNames
|
|
910
|
+
const duplicatedTypeNames = typeNames.filter((item, index) => {
|
|
911
|
+
return typeNames.some((otherItem, otherIndex) => {
|
|
912
|
+
if (index !== otherIndex) {
|
|
913
|
+
return item.typeName === otherItem.typeName;
|
|
914
|
+
}
|
|
915
|
+
return false;
|
|
916
|
+
});
|
|
917
|
+
});
|
|
918
|
+
if (duplicatedTypeNames.length) {
|
|
919
|
+
isValid = false;
|
|
920
|
+
progress.fail("React: defineType() must be used with a unique typeName. Fix the following files:\n" +
|
|
921
|
+
duplicatedTypeNames
|
|
922
|
+
.map((dtn) => `${dtn.typeName} (file: ${dtn.file})`)
|
|
923
|
+
.join("\n"));
|
|
924
|
+
}
|
|
878
925
|
isValid
|
|
879
926
|
? progress.succeed("React: function usage validated")
|
|
880
927
|
: process.exit(1);
|