@appdirect/sfb-toolkit 4.0.20 → 4.0.24
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/bin/index.js +93 -4
- package/config/index.js +1 -1
- package/coverage/clover.xml +2 -2
- package/coverage/lcov-report/constants/customUserAttributesMock.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/pageUrls.js.html +1 -1
- package/coverage/lcov-report/constants/userMock.js.html +1 -1
- package/coverage/lcov-report/controllers/controllers-utils/assetsUtils.js.html +1 -1
- package/coverage/lcov-report/controllers/controllers-utils/index.html +1 -1
- package/coverage/lcov-report/controllers/data-filters/bootstrap-data-filter.js.html +1 -1
- package/coverage/lcov-report/controllers/data-filters/call-to-actions-filter.js.html +1 -1
- package/coverage/lcov-report/controllers/data-filters/index.html +1 -1
- package/coverage/lcov-report/controllers/index.html +1 -1
- package/coverage/lcov-report/controllers/index.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/ResultItem.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/SearchBar.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/index.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/base/item.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/container.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/data-view.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/header-view.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/index.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/components/search.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/index.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/pageUrl.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/roleType.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/constants/searchType.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/utils/debounce.js.html +1 -1
- package/coverage/lcov-report/front-end-utils/src/utils/index.html +1 -1
- package/coverage/lcov-report/index.html +1 -1
- package/coverage/lcov-report/middlewares/config.js.html +1 -1
- package/coverage/lcov-report/middlewares/index.html +1 -1
- package/coverage/lcov-report/tools/index.html +1 -1
- package/coverage/lcov-report/tools/proxy-fetch.js.html +1 -1
- package/customComponents/index.js +10 -2
- package/npm-shrinkwrap.json +314 -128
- package/package.json +4 -4
- package/readme.md +9 -0
- package/src/boilerplates/AddComponent/AddComponent.jsx +234 -0
- package/src/boilerplates/AddComponent/styles/AddComponent.scss +47 -0
- package/src/tools/.sfbconfig +1 -1
- package/src/tools/package-fonts.js +1 -1
- package/src/tools/prompt-questions.js +109 -14
- package/src/tools/toolkit-common-fun.js +41 -15
- package/src/tools/toolkit-common-vars-namespace.js +106 -0
- package/src/tools/toolkit-common-vars.js +2 -2
- package/src/tools/toolkit-components-add.js +334 -0
- package/src/tools/toolkit-components-copy.js +390 -0
- package/src/tools/toolkit-components-delete.js +370 -0
- package/src/tools/toolkit-components-fun.js +126 -7
- package/src/tools/toolkit-components-info.js +6 -4
- package/src/tools/toolkit-components-vars.js +50 -0
- package/src/tools/toolkit-components.js +1 -1
- package/src/tools/toolkit-create-extension.js +1 -1
- package/src/tools/toolkit-create.js +2 -3
- package/src/tools/toolkit-import.js +182 -0
- package/src/tools/toolkit-install.js +6 -5
- package/src/tools/toolkit-mock.js +1 -1
- package/src/tools/toolkit-package.js +3 -0
- package/src/tools/toolkit-setup.js +1 -1
- package/src/tools/toolkit-start.js +4 -1
- package/src/tools/toolkit-storybook.js +136 -48
- package/src/tools/toolkit-zip-utils.js +35 -0
- package/src/tools/zip-theme.js +62 -50
- package/themes-config.json +0 -7
- package/customComponents/atoms/label/Label.jsx +0 -20
- package/customComponents/atoms/label/stories/Label.story.mdx +0 -20
- package/customComponents/atoms/label/styles/Label.scss +0 -4
- package/customComponents/components/atoms-showcase-custom/AtomsShowcaseCustom.jsx +0 -8
- package/customComponents/components/atoms-showcase-custom/stories/AtomsShowcaseCustom.story.mdx +0 -17
- package/customComponents/components/atoms-showcase-modules/AtomsShowcaseModules.jsx +0 -223
- package/customComponents/components/atoms-showcase-modules/stories/AtomsShowcaseModules.story.mdx +0 -49
- package/customComponents/components/index.js +0 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const chalk = require("chalk");
|
|
2
|
+
|
|
3
|
+
const { ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
|
|
4
|
+
|
|
5
|
+
const NAMESPACE_FILE_PATHS = {
|
|
6
|
+
"NAMESPACES.home": `${ACTIVE_THEME_PATH}/content/pages/home/home.html`,
|
|
7
|
+
"NAMESPACES.listing": `${ACTIVE_THEME_PATH}/content/pages/listing/listing.html`,
|
|
8
|
+
"NAMESPACES.bundle": `${ACTIVE_THEME_PATH}/content/pages/bundle/bundle.html`,
|
|
9
|
+
"NAMESPACES.profile": `${ACTIVE_THEME_PATH}/content/pages/profile/profile.html`,
|
|
10
|
+
"NAMESPACES.profileEditions": `${ACTIVE_THEME_PATH}/content/pages/profile/profile-editions.html`,
|
|
11
|
+
"NAMESPACES.profileFeatures": `${ACTIVE_THEME_PATH}/content/pages/profile/profile-features.html`,
|
|
12
|
+
"NAMESPACES.help": `${ACTIVE_THEME_PATH}/content/pages/help/help.html`,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS = {
|
|
16
|
+
"NAMESPACES.home": "home",
|
|
17
|
+
"NAMESPACES.profile": "profile",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const PAGE_NAME_TO_NAMESPACE = {
|
|
21
|
+
none: "none",
|
|
22
|
+
home: "NAMESPACES.home",
|
|
23
|
+
listing: "NAMESPACES.listing",
|
|
24
|
+
bundle: "NAMESPACES.bundle",
|
|
25
|
+
profile: "NAMESPACES.profile",
|
|
26
|
+
profileEditions: "NAMESPACES.profileEditions",
|
|
27
|
+
profileFeatures: "NAMESPACES.profileFeatures",
|
|
28
|
+
help: "NAMESPACES.help",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const PAGE_NAME_AND_ORDERABLE_TYPE_PROMPT = [
|
|
32
|
+
{
|
|
33
|
+
name: chalk.yellowBright("Do nothing"),
|
|
34
|
+
value: null,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "Home page (orderable)",
|
|
38
|
+
value: {
|
|
39
|
+
namespace: "NAMESPACES.home",
|
|
40
|
+
orderable: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "Home page (non-orderable)",
|
|
45
|
+
value: {
|
|
46
|
+
namespace: "NAMESPACES.home",
|
|
47
|
+
orderable: false,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "Listing page (non-orderable)",
|
|
52
|
+
value: {
|
|
53
|
+
namespace: "NAMESPACES.listing",
|
|
54
|
+
orderable: false,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "Product Bundle page (non-orderable)",
|
|
59
|
+
value: {
|
|
60
|
+
namespace: "NAMESPACES.bundle",
|
|
61
|
+
orderable: false,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "Product Profile page (orderable)",
|
|
66
|
+
value: {
|
|
67
|
+
namespace: "NAMESPACES.profile",
|
|
68
|
+
orderable: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "Product Profile page (non-orderable)",
|
|
73
|
+
value: {
|
|
74
|
+
namespace: "NAMESPACES.profile",
|
|
75
|
+
orderable: false,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "Product Profile Editions & Pricing page (non-orderable)",
|
|
80
|
+
value: {
|
|
81
|
+
namespace: "NAMESPACES.profileEditions",
|
|
82
|
+
orderable: false,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "Product Profile Feature Details page (non-orderable)",
|
|
87
|
+
value: {
|
|
88
|
+
namespace: "NAMESPACES.profileFeatures",
|
|
89
|
+
orderable: false,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "FAQ page (non-orderable)",
|
|
94
|
+
value: {
|
|
95
|
+
namespace: "NAMESPACES.help",
|
|
96
|
+
orderable: false,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
PAGE_NAME_AND_ORDERABLE_TYPE_PROMPT,
|
|
103
|
+
NAMESPACE_FILE_PATHS,
|
|
104
|
+
NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS,
|
|
105
|
+
PAGE_NAME_TO_NAMESPACE,
|
|
106
|
+
};
|
|
@@ -15,7 +15,7 @@ const THEME_TEMPLATES_CONFIG_PATH = `${TOOLKIT_PATH}/themes-config.json`;
|
|
|
15
15
|
const THEME_TEMPLATES = JSON.parse(fs.readFileSync(THEME_TEMPLATES_CONFIG_PATH));
|
|
16
16
|
const PAGE_OBJECTS_SUFFIX = "/api/internal/storefront/v1";
|
|
17
17
|
const THEME_COMPONENT_MODULE = "@appdirect/sfb-theme-components";
|
|
18
|
-
const THEME_COMPONENT_VERSION = "0.0.
|
|
18
|
+
const THEME_COMPONENT_VERSION = "0.0.352";
|
|
19
19
|
const SASS_MODULE = "sass";
|
|
20
20
|
const SASS_VERSION = "1.57.1";
|
|
21
21
|
const SASS_LOADER_MODULE = "sass-loader";
|
|
@@ -27,7 +27,7 @@ try {
|
|
|
27
27
|
} catch (e) {
|
|
28
28
|
WORKSPACE_CONFIG = {}
|
|
29
29
|
}
|
|
30
|
-
const ACTIVE_THEME = WORKSPACE_CONFIG.theme || "
|
|
30
|
+
const ACTIVE_THEME = WORKSPACE_CONFIG.theme || "plaza";
|
|
31
31
|
const ACTIVE_THEME_PATH = `${CURRENT_PATH}/themes/${ACTIVE_THEME}`;
|
|
32
32
|
const THEME_LOGS_PATH = `${CURRENT_PATH}/theme-logs`;
|
|
33
33
|
const THEME_LOGS_FILE_PATH = `${THEME_LOGS_PATH}/${ACTIVE_THEME}`;
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/* eslint-disable no-unused-expressions, no-param-reassign */
|
|
2
|
+
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const chalk = require("chalk");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const crypto = require("crypto");
|
|
7
|
+
|
|
8
|
+
const prompt = require("./prompt-questions");
|
|
9
|
+
const { ACTIVE_THEME_PATH, TOOLKIT_PATH } = require("./toolkit-common-vars");
|
|
10
|
+
const {
|
|
11
|
+
NAMESPACE_FILE_PATHS,
|
|
12
|
+
NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS,
|
|
13
|
+
PAGE_NAME_TO_NAMESPACE,
|
|
14
|
+
} = require("./toolkit-common-vars-namespace");
|
|
15
|
+
const { customComponentsEnabled } = require("./toolkit-components-fun");
|
|
16
|
+
const {
|
|
17
|
+
convertPascalCaseToKebabCase,
|
|
18
|
+
convertPascalCaseToCamelCase,
|
|
19
|
+
convertPascalCaseToSentenceCase,
|
|
20
|
+
} = require("./toolkit-common-fun");
|
|
21
|
+
const { COMPONENTS_NOT_INSTALLED_ERROR } = require("./toolkit-components-vars");
|
|
22
|
+
|
|
23
|
+
const SETTINGS_PATH = `${ACTIVE_THEME_PATH}/settings.json`;
|
|
24
|
+
|
|
25
|
+
const BOILERPLATE_PATH = `${TOOLKIT_PATH}/src/boilerplates`;
|
|
26
|
+
const DESTINATION_PATH = `${ACTIVE_THEME_PATH}/customComponents/components`.replaceAll("\\", "/");
|
|
27
|
+
const DESTINATION_INDEX_FILE = `${ACTIVE_THEME_PATH}/customComponents/index.js`;
|
|
28
|
+
|
|
29
|
+
const BOILERPLATE_COMPONENT_NAME = "AddComponent";
|
|
30
|
+
const BOILERPLATE_FOLDER = "AddComponent/";
|
|
31
|
+
const BOILERPLATE_JSX = `AddComponent.jsx`;
|
|
32
|
+
const BOILERPLATE_SCSS = `styles/AddComponent.scss`;
|
|
33
|
+
|
|
34
|
+
const COMPONENT_NAME_PASCAL_CASE = "{{COMPONENT_NAME_PASCAL_CASE}}";
|
|
35
|
+
const COMPONENT_NAME_CAMEL_CASE = "{{COMPONENT_NAME_CAMEL_CASE}}";
|
|
36
|
+
const COMPONENT_NAME_SENTENCE_CASE = "{{COMPONENT_NAME_SENTENCE_CASE}}";
|
|
37
|
+
const COMPONENT_ORDERABLE_NAMESPACE_IMPORT =
|
|
38
|
+
"{{COMPONENT_ORDERABLE_NAMESPACE_IMPORT}}";
|
|
39
|
+
const COMPONENT_ORDERABLE_SECTION = "{{COMPONENT_ORDERABLE_SECTION}}";
|
|
40
|
+
|
|
41
|
+
const formattedComponentStatusWithPath = ({
|
|
42
|
+
data,
|
|
43
|
+
statusMessage,
|
|
44
|
+
componentPath,
|
|
45
|
+
maxStringLength = 30,
|
|
46
|
+
}) => {
|
|
47
|
+
const formattingOffset =
|
|
48
|
+
maxStringLength + 20 <= 50 ? 50 : maxStringLength + 20;
|
|
49
|
+
console.log(
|
|
50
|
+
chalk.green(
|
|
51
|
+
`${data.padEnd(formattingOffset, ".")}[${statusMessage}][${chalk.dim(
|
|
52
|
+
componentPath
|
|
53
|
+
)}]`
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const addOrderableComponentToSettingsFile = (namespace, componentName) => {
|
|
59
|
+
const componentObjectTemplate = {
|
|
60
|
+
name: componentName,
|
|
61
|
+
id: `${componentName}:orderable:${crypto.randomUUID()}`,
|
|
62
|
+
isVisible: true,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const settings = fs.readJsonSync(SETTINGS_PATH);
|
|
67
|
+
|
|
68
|
+
const orderablePageSettingsKey =
|
|
69
|
+
NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS[namespace];
|
|
70
|
+
|
|
71
|
+
const orderableComponentsInPage =
|
|
72
|
+
settings?.pages?.[orderablePageSettingsKey]?.orderableComponents;
|
|
73
|
+
|
|
74
|
+
if (orderableComponentsInPage) {
|
|
75
|
+
orderableComponentsInPage.push(componentObjectTemplate);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fs.writeJsonSync(SETTINGS_PATH, settings, { spaces: 2 });
|
|
79
|
+
|
|
80
|
+
console.log(
|
|
81
|
+
chalk.green(
|
|
82
|
+
`Orderable component [${componentName}] added to ${orderablePageSettingsKey} page through settings.json`
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(
|
|
87
|
+
chalk.red(
|
|
88
|
+
`ERROR: Unable to add component to settings.json file due to ${e}`
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const addNonOrderableComponentToHtmlFile = (namespace, componentName) => {
|
|
96
|
+
const blockStart = "{% block";
|
|
97
|
+
const blockEnd = "{% endblock %}";
|
|
98
|
+
const NON_ORDERABLE_COMPONENT_TEMPLATE = `\u0009<component name="${componentName}" id="${componentName}1"></component>`;
|
|
99
|
+
|
|
100
|
+
const htmlPage = NAMESPACE_FILE_PATHS[namespace];
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const fileContent = fs.readFileSync(htmlPage, "utf8");
|
|
104
|
+
const lines = fileContent.split("\n");
|
|
105
|
+
|
|
106
|
+
let startIndex = -1;
|
|
107
|
+
let endIndex = -1;
|
|
108
|
+
|
|
109
|
+
// insert component inside the content block
|
|
110
|
+
lines.forEach((line, index) => {
|
|
111
|
+
// gets the last block in the page
|
|
112
|
+
if (line.includes(blockStart)) {
|
|
113
|
+
startIndex = index;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (line.includes(blockEnd)) {
|
|
117
|
+
endIndex = index;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
|
|
122
|
+
lines.splice(endIndex, 0, NON_ORDERABLE_COMPONENT_TEMPLATE);
|
|
123
|
+
fs.writeFileSync(htmlPage, lines.join("\n"));
|
|
124
|
+
} else {
|
|
125
|
+
throw Error("Cannot find content block in the html page");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
console.log(
|
|
129
|
+
chalk.green(
|
|
130
|
+
`Non-orderable component [${componentName}] added to ${htmlPage}`
|
|
131
|
+
)
|
|
132
|
+
);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
console.error(
|
|
135
|
+
chalk.red(
|
|
136
|
+
`ERROR: ${componentName} cannot be added to ${htmlPage} due to ${e}`
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const addComponentRendering = (pageNameAndOrderableType, componentName) => {
|
|
144
|
+
const { namespace, orderable } = pageNameAndOrderableType;
|
|
145
|
+
|
|
146
|
+
if (orderable) {
|
|
147
|
+
addOrderableComponentToSettingsFile(namespace, componentName);
|
|
148
|
+
} else {
|
|
149
|
+
addNonOrderableComponentToHtmlFile(namespace, componentName);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const updateOrderableSection = (fileContent, pageNameAndOrderableType) => {
|
|
154
|
+
const { namespace, orderable } = pageNameAndOrderableType || {};
|
|
155
|
+
|
|
156
|
+
if (orderable) {
|
|
157
|
+
const orderableSectionNamespaceImportTemplate = `import { NAMESPACES } from '@appdirect/sfb-theme-components/src/constants/namespaces';\n`;
|
|
158
|
+
const orderableSectionTemplate = `\n\u0009orderableSection: [ ${namespace} ],`;
|
|
159
|
+
|
|
160
|
+
fileContent = fileContent.replace(
|
|
161
|
+
COMPONENT_ORDERABLE_NAMESPACE_IMPORT,
|
|
162
|
+
orderableSectionNamespaceImportTemplate
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
fileContent = fileContent.replace(
|
|
166
|
+
COMPONENT_ORDERABLE_SECTION,
|
|
167
|
+
orderableSectionTemplate
|
|
168
|
+
);
|
|
169
|
+
} else {
|
|
170
|
+
fileContent = fileContent.replace(COMPONENT_ORDERABLE_NAMESPACE_IMPORT, "");
|
|
171
|
+
fileContent = fileContent.replace(COMPONENT_ORDERABLE_SECTION, "");
|
|
172
|
+
}
|
|
173
|
+
return fileContent;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const addComponentFromBoilerplate = (
|
|
177
|
+
newComponentName,
|
|
178
|
+
newComponentFolderName,
|
|
179
|
+
pageNameAndOrderableType
|
|
180
|
+
) => {
|
|
181
|
+
const boilerplateFolderPath = path.join(BOILERPLATE_PATH, BOILERPLATE_FOLDER);
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
// jsx
|
|
185
|
+
let fileContentJsx = fs.readFileSync(
|
|
186
|
+
path.join(boilerplateFolderPath, BOILERPLATE_JSX),
|
|
187
|
+
"utf8"
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
fileContentJsx = fileContentJsx.replaceAll(
|
|
191
|
+
COMPONENT_NAME_PASCAL_CASE,
|
|
192
|
+
newComponentName
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
fileContentJsx = fileContentJsx.replaceAll(
|
|
196
|
+
COMPONENT_NAME_SENTENCE_CASE,
|
|
197
|
+
convertPascalCaseToSentenceCase(newComponentName)
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
fileContentJsx = updateOrderableSection(
|
|
201
|
+
fileContentJsx,
|
|
202
|
+
pageNameAndOrderableType
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const newFilePathJsx = path.join(
|
|
206
|
+
DESTINATION_PATH,
|
|
207
|
+
newComponentFolderName,
|
|
208
|
+
BOILERPLATE_JSX.replace(BOILERPLATE_COMPONENT_NAME, newComponentName)
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
fs.outputFileSync(newFilePathJsx, fileContentJsx);
|
|
212
|
+
|
|
213
|
+
// add rendering: orderable to settings.json; non-orderable to HTML file
|
|
214
|
+
if (pageNameAndOrderableType) {
|
|
215
|
+
addComponentRendering(pageNameAndOrderableType, newComponentName);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// scss
|
|
219
|
+
let fileContentScss = fs.readFileSync(
|
|
220
|
+
path.join(boilerplateFolderPath, BOILERPLATE_SCSS),
|
|
221
|
+
"utf8"
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
const newFilePathScss = path.join(
|
|
225
|
+
DESTINATION_PATH,
|
|
226
|
+
newComponentFolderName,
|
|
227
|
+
BOILERPLATE_SCSS.replace(BOILERPLATE_COMPONENT_NAME, newComponentName)
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
fileContentScss = fileContentScss.replaceAll(
|
|
231
|
+
COMPONENT_NAME_CAMEL_CASE,
|
|
232
|
+
convertPascalCaseToCamelCase(newComponentName)
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
fs.outputFileSync(newFilePathScss, fileContentScss);
|
|
236
|
+
|
|
237
|
+
formattedComponentStatusWithPath({
|
|
238
|
+
data: newComponentName,
|
|
239
|
+
statusMessage: "ADDED",
|
|
240
|
+
componentPath: `${DESTINATION_PATH}/${newComponentFolderName}`,
|
|
241
|
+
});
|
|
242
|
+
// FIXME: write translations for UI editor settings
|
|
243
|
+
} catch (err) {
|
|
244
|
+
console.error(
|
|
245
|
+
chalk.red(` ERROR: Unable to create component from boilerplate ${err}`)
|
|
246
|
+
);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
(async () => {
|
|
252
|
+
const args = process.argv.slice(2);
|
|
253
|
+
|
|
254
|
+
const [componentNameFromCommand, page, orderable] = args;
|
|
255
|
+
|
|
256
|
+
const isCustomComponentsEnabled = await customComponentsEnabled();
|
|
257
|
+
|
|
258
|
+
if (!isCustomComponentsEnabled) {
|
|
259
|
+
console.log(COMPONENTS_NOT_INSTALLED_ERROR);
|
|
260
|
+
process.exit(1);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ComponentName
|
|
264
|
+
let componentName;
|
|
265
|
+
if (
|
|
266
|
+
prompt.validateFun.isComponentNameValidAndAvailable(
|
|
267
|
+
componentNameFromCommand
|
|
268
|
+
)
|
|
269
|
+
) {
|
|
270
|
+
componentName = componentNameFromCommand;
|
|
271
|
+
} else {
|
|
272
|
+
const answer = await prompt.ask(["ComponentName"]);
|
|
273
|
+
componentName = answer.ComponentName;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// PageNameAndOrderableType
|
|
277
|
+
let pageNameAndOrderableType;
|
|
278
|
+
const pageName = PAGE_NAME_TO_NAMESPACE[page];
|
|
279
|
+
const isOrderable = orderable === "true";
|
|
280
|
+
|
|
281
|
+
// page not provided in CLI param, ask for it
|
|
282
|
+
if (page === "undefined") {
|
|
283
|
+
console.log(`You can optionally add the component to a page as orderable or non-orderable.
|
|
284
|
+
\nFor more information, please see our documentation:
|
|
285
|
+
\u2022 Orderable: ${chalk.underline.bold(
|
|
286
|
+
"https://developer.appdirect.com/storefront/how-tos/components/storefront-custom-components-layout"
|
|
287
|
+
)}
|
|
288
|
+
\u2022 Non-orderable: ${chalk.underline.bold(
|
|
289
|
+
"https://developer.appdirect.com/storefront/how-tos/components/storefront-custom-components-add"
|
|
290
|
+
)}\n`);
|
|
291
|
+
|
|
292
|
+
const answer = await prompt.ask(["PageNameAndOrderableType"]);
|
|
293
|
+
|
|
294
|
+
pageNameAndOrderableType = answer.PageNameAndOrderableType;
|
|
295
|
+
} else if (page === "none") {
|
|
296
|
+
// page set to none in CLI param, don't ask, don't add
|
|
297
|
+
pageNameAndOrderableType = null;
|
|
298
|
+
} else if (isOrderable && !NAMESPACE_ORDERABLE_PAGE_SETTINGS_KEYS[pageName]) {
|
|
299
|
+
// page set to a valid value in CLI param, but orderable does not apply
|
|
300
|
+
console.log(
|
|
301
|
+
chalk.red(
|
|
302
|
+
"ERROR: Only [home] and [profile] page can have orderable components."
|
|
303
|
+
)
|
|
304
|
+
);
|
|
305
|
+
process.exit(1);
|
|
306
|
+
} else {
|
|
307
|
+
// page set to a valid value in CLI param
|
|
308
|
+
pageNameAndOrderableType = {
|
|
309
|
+
namespace: pageName,
|
|
310
|
+
orderable: isOrderable,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const newComponentFolderName = convertPascalCaseToKebabCase(componentName);
|
|
315
|
+
|
|
316
|
+
addComponentFromBoilerplate(
|
|
317
|
+
componentName,
|
|
318
|
+
newComponentFolderName,
|
|
319
|
+
pageNameAndOrderableType
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
try {
|
|
323
|
+
// write export in components/index.js
|
|
324
|
+
const exportStringTemplate = `\nexport { default as ${componentName} } from './components/${newComponentFolderName}/${componentName}';`;
|
|
325
|
+
fs.appendFileSync(DESTINATION_INDEX_FILE, exportStringTemplate);
|
|
326
|
+
} catch (e) {
|
|
327
|
+
console.error(
|
|
328
|
+
chalk.red(
|
|
329
|
+
`ERROR: Unable to export component in ${DESTINATION_INDEX_FILE} due to ${e}`
|
|
330
|
+
)
|
|
331
|
+
);
|
|
332
|
+
process.exit(1);
|
|
333
|
+
}
|
|
334
|
+
})();
|