From 683493de46ae0169139a813d006dd033b247e2f7 Mon Sep 17 00:00:00 2001 From: Shamiul Mowla Date: Wed, 17 Jan 2024 12:38:44 -0500 Subject: [PATCH] Enable dynamic slicing the component names retrieved from componentCreators --- scripts/helpers/customBuild.js | 6 +++--- test/unit/specs/core/componentCreators.spec.js | 14 +++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/helpers/customBuild.js b/scripts/helpers/customBuild.js index 3a5a614bc..5e85338a9 100644 --- a/scripts/helpers/customBuild.js +++ b/scripts/helpers/customBuild.js @@ -33,16 +33,16 @@ const componentNames = componentCreatorsContent.match(/create[A-Z]\w+/g); // Format component names for export const formattedComponentNames = componentNames.map(name => ({ - name: name.slice(6).toLowerCase(), + name: name.replace(/^create/, "").toLowerCase(), exportName: name, - filePath: name.slice(6) + filePath: name.replace(/^create/, "") })); // Extract required components from componentCreatorsContent const requiredComponents = componentCreatorsContent .match(/REQUIRED_COMPONENTS = \[[\s\S]*?\]/)[0] .match(/create[A-Z]\w+/g) - .map(component => component.slice(6).toLowerCase()); + .map(component => component.replace(/^create/, "").toLowerCase()); const argv = yargs(hideBin(process.argv)) .scriptName("build:custom") diff --git a/test/unit/specs/core/componentCreators.spec.js b/test/unit/specs/core/componentCreators.spec.js index 4bc719fd8..9f2542879 100644 --- a/test/unit/specs/core/componentCreators.spec.js +++ b/test/unit/specs/core/componentCreators.spec.js @@ -13,9 +13,17 @@ governing permissions and limitations under the License. import componentCreators from "../../../../src/core/componentCreators"; describe("componentCreators", () => { - it("is an array of component creators", () => { - expect(componentCreators).toEqual(jasmine.any(Array)); - componentCreators.forEach(componentCreator => { + it("is an object with arrays of component creators", () => { + expect(componentCreators).toEqual(jasmine.any(Object)); + expect(componentCreators.REQUIRED_COMPONENTS).toEqual(jasmine.any(Array)); + expect(componentCreators.OPTIONAL_COMPONENTS).toEqual(jasmine.any(Array)); + + const allComponentCreators = [ + ...componentCreators.REQUIRED_COMPONENTS, + ...componentCreators.OPTIONAL_COMPONENTS + ]; + + allComponentCreators.forEach(componentCreator => { expect(componentCreator).toEqual(jasmine.any(Function)); expect(componentCreator.namespace).toEqual(jasmine.any(String));