@appdirect/sfb-toolkit 5.0.9 → 6.0.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.
Files changed (119) hide show
  1. package/.eslintrc +35 -35
  2. package/CHANGELOG.md +45 -0
  3. package/Dockerfile +2 -1
  4. package/agent/.cursor/rules/sfb-storefront.mdc +18 -0
  5. package/agent/.cursor/skills/sfb-custom-components/COMPONENT-CATALOG.md +130 -0
  6. package/agent/.cursor/skills/sfb-custom-components/SKILL.md +44 -0
  7. package/agent/.cursor/skills/sfb-localization-settings/SKILL.md +99 -0
  8. package/agent/.cursor/skills/sfb-theme-customize/SKILL.md +25 -0
  9. package/agent/.cursor/skills/sfb-toolkit-commands/SKILL.md +35 -0
  10. package/agent/AGENTS.md +222 -0
  11. package/agent/CLAUDE.md +20 -0
  12. package/bin/index.js +82 -100
  13. package/coverage/clover.xml +1937 -333
  14. package/coverage/coverage-final.json +41 -20
  15. package/coverage/lcov-report/{controllers/controllers-utils → config}/index.html +19 -19
  16. package/coverage/lcov-report/config/index.js.html +124 -0
  17. package/coverage/lcov-report/index.html +108 -78
  18. package/coverage/lcov-report/{constants → src/constants}/customUserAttributesMock.js.html +12 -12
  19. package/coverage/lcov-report/{constants → src/constants}/index.html +10 -10
  20. package/coverage/lcov-report/{constants → src/constants}/pageUrls.js.html +14 -14
  21. package/coverage/lcov-report/{constants → src/constants}/userMock.js.html +13 -13
  22. package/coverage/lcov-report/{controllers → src/controllers}/controllers-utils/assetsUtils.js.html +20 -20
  23. package/coverage/lcov-report/src/controllers/controllers-utils/index.html +131 -0
  24. package/coverage/lcov-report/src/controllers/controllers-utils/locale.js.html +115 -0
  25. package/coverage/lcov-report/{controllers → src/controllers}/data-filters/bootstrap-data-filter.js.html +15 -15
  26. package/coverage/lcov-report/{controllers → src/controllers}/data-filters/call-to-actions-filter.js.html +22 -22
  27. package/coverage/lcov-report/{controllers → src/controllers}/data-filters/index.html +37 -22
  28. package/coverage/lcov-report/src/controllers/data-filters/media-url-filter.js.html +394 -0
  29. package/coverage/lcov-report/{controllers → src/controllers}/index.html +27 -27
  30. package/coverage/lcov-report/{controllers → src/controllers}/index.js.html +159 -126
  31. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/ResultItem.js.html +43 -43
  32. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/SearchBar.js.html +22 -22
  33. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/index.html +28 -28
  34. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/item.js.html +28 -28
  35. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/container.js.html +31 -31
  36. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/data-view.js.html +29 -29
  37. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/header-view.js.html +35 -38
  38. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/index.html +45 -45
  39. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/search.js.html +54 -54
  40. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/index.html +22 -22
  41. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/pageUrl.js.html +17 -17
  42. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/roleType.js.html +14 -14
  43. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/searchType.js.html +17 -17
  44. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/debounce.js.html +15 -15
  45. package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/index.html +20 -20
  46. package/coverage/lcov-report/{middlewares → src/middlewares}/config.js.html +11 -11
  47. package/coverage/lcov-report/{middlewares → src/middlewares}/index.html +10 -10
  48. package/coverage/lcov-report/{tools → src/routes}/index.html +30 -30
  49. package/coverage/lcov-report/src/routes/media-proxy.js.html +613 -0
  50. package/coverage/lcov-report/src/tools/compile-styles.js.html +1018 -0
  51. package/coverage/lcov-report/src/tools/custom-components-export-compat-loader.js.html +745 -0
  52. package/coverage/lcov-report/src/tools/index.html +371 -0
  53. package/coverage/lcov-report/src/tools/prompt-questions.js.html +1117 -0
  54. package/coverage/lcov-report/{tools → src/tools}/proxy-fetch.js.html +15 -15
  55. package/coverage/lcov-report/src/tools/resolve-components-react.js.html +457 -0
  56. package/coverage/lcov-report/src/tools/sass-legacy-compat.js.html +1192 -0
  57. package/coverage/lcov-report/src/tools/toolkit-cli-argv.js.html +226 -0
  58. package/coverage/lcov-report/src/tools/toolkit-common-fun.js.html +1402 -0
  59. package/coverage/lcov-report/src/tools/toolkit-common-vars-namespace.js.html +403 -0
  60. package/coverage/lcov-report/src/tools/toolkit-common-vars.js.html +283 -0
  61. package/coverage/lcov-report/src/tools/toolkit-components-fun.js.html +1237 -0
  62. package/coverage/lcov-report/src/tools/toolkit-components-vars.js.html +232 -0
  63. package/coverage/lcov-report/src/tools/toolkit-install-agent-guidance.js.html +439 -0
  64. package/coverage/lcov-report/src/tools/toolkit-live-reload.js.html +688 -0
  65. package/coverage/lcov-report/src/tools/toolkit-path.js.html +184 -0
  66. package/coverage/lcov-report/src/tools/toolkit-spawn.js.html +199 -0
  67. package/coverage/lcov-report/src/tools/toolkit-v6-theme-risk.js.html +1039 -0
  68. package/coverage/lcov-report/src/tools/toolkit-zip-utils.js.html +190 -0
  69. package/coverage/lcov.info +3387 -727
  70. package/index.js +40 -20
  71. package/npm-shrinkwrap.json +5026 -15490
  72. package/package.json +49 -40
  73. package/readme.md +20 -1
  74. package/rspack-components.config.cjs +81 -0
  75. package/rspack-components.config.prod.cjs +71 -0
  76. package/rspack.config.cjs +25 -0
  77. package/rspack.shared.cjs +164 -0
  78. package/src/controllers/controllers-utils/locale.js +10 -0
  79. package/src/controllers/data-filters/media-url-filter.js +103 -0
  80. package/src/controllers/index.js +15 -4
  81. package/src/front-end-utils/dist/toolbar.bundle.js +1 -2
  82. package/src/front-end-utils/src/components/header-view.js +0 -1
  83. package/src/routes/index.js +2 -0
  84. package/src/routes/media-proxy.js +176 -0
  85. package/src/tools/compile-styles.js +311 -0
  86. package/src/tools/compiler-components-prod.js +32 -21
  87. package/src/tools/compiler-css.js +7 -7
  88. package/src/tools/custom-components-export-compat-loader.js +220 -0
  89. package/src/tools/resolve-components-react.js +124 -0
  90. package/src/tools/sass-legacy-compat.js +369 -0
  91. package/src/tools/toolkit-checkout.js +3 -6
  92. package/src/tools/toolkit-cli-argv.js +47 -0
  93. package/src/tools/toolkit-common-fun.js +149 -31
  94. package/src/tools/toolkit-common-utils.js +5 -3
  95. package/src/tools/toolkit-common-vars.js +4 -3
  96. package/src/tools/toolkit-components-copy.js +6 -4
  97. package/src/tools/toolkit-components-fun.js +6 -4
  98. package/src/tools/toolkit-config-setup.js +2 -1
  99. package/src/tools/toolkit-create.js +5 -7
  100. package/src/tools/toolkit-import.js +5 -6
  101. package/src/tools/toolkit-install-agent-guidance-cli.js +24 -0
  102. package/src/tools/toolkit-install-agent-guidance.js +118 -0
  103. package/src/tools/toolkit-install.js +8 -8
  104. package/src/tools/toolkit-live-reload.js +201 -0
  105. package/src/tools/toolkit-package.js +25 -7
  106. package/src/tools/toolkit-path.js +33 -0
  107. package/src/tools/toolkit-setup-e2e.js +2 -1
  108. package/src/tools/toolkit-setup.js +5 -1
  109. package/src/tools/toolkit-spawn.js +38 -0
  110. package/src/tools/toolkit-start.js +98 -54
  111. package/src/tools/toolkit-storybook.js +38 -19
  112. package/src/tools/toolkit-update.js +5 -3
  113. package/src/tools/toolkit-v6-theme-risk.js +318 -0
  114. package/themes-param.json +1 -0
  115. package/src/front-end-utils/dist/toolbar.bundle.js.LICENSE.txt +0 -52
  116. package/src/tools/gulp-tasks.js +0 -80
  117. package/webpack-components.config.cjs +0 -123
  118. package/webpack-components.config.prod.cjs +0 -113
  119. package/webpack.config.cjs +0 -25
@@ -44,10 +44,7 @@ if(!validateFun.isValidFolderName(themeName)){
44
44
  process.exit(1);
45
45
  }
46
46
 
47
- spawn('node',
48
- [`"${TOOLKIT_PATH}/${COMPILERCSS_PATH}"`], {
49
- stdio: "inherit",
50
- shell: true
51
- }
52
- )
47
+ spawn(process.execPath, [`${TOOLKIT_PATH}/${COMPILERCSS_PATH}`], {
48
+ stdio: "inherit",
49
+ })
53
50
  })();
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Argv helpers for bin/index.js → toolkit script spawns (no shell).
3
+ * Keeps parity with the old shell:true templates without relying on quote-stripping.
4
+ */
5
+
6
+ const {
7
+ INDEX_EXPORT_COMMENT_OUT,
8
+ INDEX_EXPORT_REPLACE,
9
+ INDEX_EXPORT_NO_CHANGE,
10
+ } = require("./toolkit-components-vars");
11
+
12
+ /** Match prior `node script ${arg}` templates: missing values become the string "undefined". */
13
+ const normalizeRunScriptArg = (arg) =>
14
+ arg === undefined || arg === null ? "undefined" : String(arg);
15
+
16
+ /**
17
+ * Payload for toolkit-components-copy.js (process.argv[2]).
18
+ * Old shell:true wrapped a mangled JSON string and bash rewrote it into this shape.
19
+ * @returns {false|string} false → interactive mode ("false" after normalize)
20
+ */
21
+ const buildComponentsCopyPayload = (components, options = {}) => {
22
+ if (options[INDEX_EXPORT_REPLACE]) {
23
+ return JSON.stringify({ [INDEX_EXPORT_REPLACE]: components });
24
+ }
25
+ if (options[INDEX_EXPORT_COMMENT_OUT]) {
26
+ return JSON.stringify({ [INDEX_EXPORT_COMMENT_OUT]: components });
27
+ }
28
+ if (options[INDEX_EXPORT_NO_CHANGE]) {
29
+ return JSON.stringify({ [INDEX_EXPORT_NO_CHANGE]: components });
30
+ }
31
+ return false;
32
+ };
33
+
34
+ /**
35
+ * Single argv for toolkit-components-delete.js.
36
+ * Old: `node script ${process.argv.slice(3)}` → Array#toString → "-d,2_1_14,Faq".
37
+ */
38
+ const buildComponentsDeleteArg = (argvFromFlag = []) => argvFromFlag.toString();
39
+
40
+ module.exports = {
41
+ normalizeRunScriptArg,
42
+ buildComponentsCopyPayload,
43
+ buildComponentsDeleteArg,
44
+ INDEX_EXPORT_COMMENT_OUT,
45
+ INDEX_EXPORT_REPLACE,
46
+ INDEX_EXPORT_NO_CHANGE,
47
+ };
@@ -1,14 +1,24 @@
1
1
  const fs = require("fs-extra");
2
+ const path = require("path");
2
3
  const chalk = require("chalk");
3
4
  const packageJson = require("package-json");
4
- const { spawnSync } = require("child_process");
5
5
  const prompt = require("./prompt-questions");
6
+ const { spawnSyncNpm } = require("./toolkit-spawn");
6
7
 
7
8
  const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, BOOTSTRAP_FILES, CONFIG_PATH, THEME_COMPONENT_MODULE,
8
9
  THEME_COMPONENT_VERSION, ACTIVE_THEME_PATH, THEME_LOGS_PATH, THEME_LOGS_FILE_PATH, SASS_MODULE,
9
10
  SASS_VERSION, SASS_LOADER_MODULE, SASS_LOADER_VERSION } = require("./toolkit-common-vars");
10
11
 
11
12
  const { getCustomComponentsInfo } = require("./toolkit-components-fun");
13
+ const { PRE_UPGRADE_V6_NOTICE } = require("./toolkit-v6-theme-risk");
14
+
15
+ /**
16
+ * True when the package exists under node_modules.
17
+ * Prefer this over `npm ls` exit codes — `npm ls` is non-zero for unmet peers
18
+ * even when the package is installed (and our installs use --legacy-peer-deps).
19
+ */
20
+ const isLocalPackageInstalled = (moduleName, cwd = ACTIVE_THEME_PATH) =>
21
+ fs.existsSync(path.join(cwd, "node_modules", ...String(moduleName).split("/")));
12
22
 
13
23
  // function to remove project's folders (used to revert changes on error)
14
24
  const selfDestruction = (dir) => BOOTSTRAP_FOLDERS.forEach( file => fs.removeSync(`${dir}/${file}`));
@@ -50,6 +60,11 @@ const licenseAgreement = () => {
50
60
  );
51
61
  }
52
62
 
63
+ const majorFromVersion = (version) => {
64
+ const major = parseInt(String(version || "").split(".")[0], 10);
65
+ return Number.isFinite(major) ? major : 0;
66
+ };
67
+
53
68
  // verify local version with npm.js version
54
69
  const versionCheck = () => {
55
70
  return new Promise(
@@ -60,7 +75,13 @@ const versionCheck = () => {
60
75
  try {
61
76
  const npmPackageJSON = await packageJson('@appdirect/sfb-toolkit');
62
77
  if(currentPackageJSON.version !== npmPackageJSON.version){
63
- console.log(`\n Newer version of sfb-toolkit is available: \n\n Your version: ${currentPackageJSON.version.red} \n Latest version: ${npmPackageJSON.version} \n\n Run \`npm install -g @appdirect/sfb-toolkit\` to install the latest version\n`);
78
+ let message = `\n Newer version of sfb-toolkit is available: \n\n Your version: ${currentPackageJSON.version.red} \n Latest version: ${npmPackageJSON.version} \n\n Run \`npm install -g @appdirect/sfb-toolkit\` to install the latest version\n`;
79
+ const localMajor = majorFromVersion(currentPackageJSON.version);
80
+ const latestMajor = majorFromVersion(npmPackageJSON.version);
81
+ if (latestMajor >= 6 && localMajor < 6) {
82
+ message += `\n ${PRE_UPGRADE_V6_NOTICE}\n`;
83
+ }
84
+ console.log(message);
64
85
  }
65
86
  } catch (e) {}
66
87
  resolve(clearTimeout(watch));
@@ -112,23 +133,41 @@ const installSfbThemeComponents = () => {
112
133
 
113
134
  createThemeLogsFolder();
114
135
 
115
- // check if sfb-theme-components is installed otherwise install it
116
- spawnSync('npm',
117
- [`ls ${THEME_COMPONENT_MODULE} 2>&1 | (findstr ${THEME_COMPONENT_MODULE} || grep ${THEME_COMPONENT_MODULE}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -E ${THEME_COMPONENT_MODULE}@${THEME_COMPONENT_VERSION} --omit=dev --legacy-peer-deps`], {
136
+ // Log npm ls for diagnostics, but decide install from node_modules (not ls exit code)
137
+ const listed = spawnSyncNpm(
138
+ ["ls", THEME_COMPONENT_MODULE, "--depth=0"],
139
+ {
118
140
  cwd: ACTIVE_THEME_PATH,
119
- stdio: "inherit",
120
- shell: true
121
- })
141
+ stdio: ["ignore", "pipe", "pipe"],
142
+ encoding: "utf8",
143
+ }
144
+ );
145
+ const output = `${listed.stdout || ""}${listed.stderr || ""}`;
146
+ try {
147
+ fs.writeFileSync(THEME_LOGS_FILE_PATH, output);
148
+ } catch (_) {
149
+ /* best-effort log */
150
+ }
151
+ if (!isLocalPackageInstalled(THEME_COMPONENT_MODULE)) {
152
+ spawnSyncNpm(
153
+ [
154
+ "i",
155
+ "-E",
156
+ `${THEME_COMPONENT_MODULE}@${THEME_COMPONENT_VERSION}`,
157
+ "--omit=dev",
158
+ "--legacy-peer-deps",
159
+ ],
160
+ { cwd: ACTIVE_THEME_PATH, stdio: "inherit" }
161
+ );
162
+ }
122
163
  }
123
164
 
124
165
  const createPackageJson = () => {
125
166
  // check if package.json exists otherwise create it
126
167
  if(!fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`)) {
127
- spawnSync('npm',
128
- [`init -y`], {
129
- cwd: ACTIVE_THEME_PATH,
130
- stdio: "inherit",
131
- shell: true
168
+ spawnSyncNpm(["init", "-y"], {
169
+ cwd: ACTIVE_THEME_PATH,
170
+ stdio: "inherit",
132
171
  })
133
172
  }
134
173
  }
@@ -166,6 +205,82 @@ const getToolkitVersionUsedToCreateTheme = () => {
166
205
  return themePackageJson.metadata?.toolkitVersion;
167
206
  }
168
207
 
208
+ /**
209
+ * Apply / insert custom-component override attrs on base.html content.
210
+ * Never prepends free-floating attrs when `data-sfb-theme-components-version` is missing
211
+ * (indexOf -1 previously wrote garbage before <!doctype html>).
212
+ */
213
+ const applyCustomComponentOverrideAttributes = (
214
+ data,
215
+ { overridesJavaScript = [], overridesSass = [], userDefinedCustomComponents = [] } = {},
216
+ sfbThemeComponentsVersion = "latest"
217
+ ) => {
218
+ // Remove corrupt free-floating attrs left by older toolkit bugs
219
+ data = data.replace(
220
+ /^(?:\s*data-custom-components-(?:overrides-js|overrides-scss|user-defined)="[^"]*"\s*\n)+/,
221
+ ""
222
+ );
223
+
224
+ const js = overridesJavaScript.join(",");
225
+ const scss = overridesSass.join(",");
226
+ const userDefined = userDefinedCustomComponents.join(",");
227
+ const overrideBlock =
228
+ `data-custom-components-overrides-js="${js}"` +
229
+ `\n data-custom-components-overrides-scss="${scss}"` +
230
+ `\n data-custom-components-user-defined="${userDefined}"`;
231
+
232
+ if (data.includes("data-custom-components-overrides-js")) {
233
+ data = data.replace(
234
+ /data-custom-components-overrides-js=".*"/,
235
+ `data-custom-components-overrides-js="${js}"`
236
+ );
237
+ data = data.replace(
238
+ /data-custom-components-overrides-scss=".*"/,
239
+ `data-custom-components-overrides-scss="${scss}"`
240
+ );
241
+ data = data.replace(
242
+ /data-custom-components-user-defined=".*"/,
243
+ `data-custom-components-user-defined="${userDefined}"`
244
+ );
245
+ return data;
246
+ }
247
+
248
+ const versionAttrIndex = data.indexOf("data-sfb-theme-components-version");
249
+ if (versionAttrIndex >= 0) {
250
+ return (
251
+ data.substring(0, versionAttrIndex) +
252
+ `${overrideBlock}\n ` +
253
+ data.substring(versionAttrIndex)
254
+ );
255
+ }
256
+
257
+ // Existing <ad-theme> without version attr: inject into that tag (do not insert a second one)
258
+ if (/<ad-theme\b/i.test(data)) {
259
+ return data.replace(/<ad-theme\b([\s\S]*?)>/i, (match, inner) => {
260
+ const trimmedInner = inner.replace(/\s*$/, "");
261
+ return (
262
+ `<ad-theme${trimmedInner}` +
263
+ `\n ${overrideBlock}` +
264
+ `\n data-sfb-theme-components-version="${sfbThemeComponentsVersion}">`
265
+ );
266
+ });
267
+ }
268
+
269
+ const headCloseIndex = data.indexOf("</head>");
270
+ if (headCloseIndex < 0) {
271
+ return data;
272
+ }
273
+
274
+ const adTheme =
275
+ ` <ad-theme` +
276
+ `\n data-custom-components="true"` +
277
+ `\n ${overrideBlock}` +
278
+ `\n data-sfb-theme-components-version="${sfbThemeComponentsVersion}">` +
279
+ `\n </ad-theme>\n`;
280
+
281
+ return data.substring(0, headCloseIndex) + adTheme + data.substring(headCloseIndex);
282
+ };
283
+
169
284
  const updateCustomComponentsMetadata = (data) => {
170
285
  const hasPackageJson = fs.existsSync(`${ACTIVE_THEME_PATH}/package.json`);
171
286
  if (hasPackageJson) {
@@ -182,19 +297,12 @@ const updateCustomComponentsMetadata = (data) => {
182
297
  data = data.replace(/data-sfb-theme-components-version=".*"/, `data-sfb-theme-components-version="${sfbThemeComponentsVersion}"`);
183
298
  }
184
299
  if (customComponents) {
185
- const { overridesJavaScript, overridesSass, userDefinedCustomComponents } = getCustomComponentsInfo();
186
- if(data.includes("data-custom-components-overrides-js")) {
187
- data = data.replace(/data-custom-components-overrides-js=".*"/, `data-custom-components-overrides-js="${overridesJavaScript.join(',')}"`);
188
- data = data.replace(/data-custom-components-overrides-scss=".*"/, `data-custom-components-overrides-scss="${overridesSass.join(',')}"`);
189
- data = data.replace(/data-custom-components-user-defined=".*"/, `data-custom-components-user-defined="${userDefinedCustomComponents.join(',')}"`);
190
- } else {
191
- const start = data.indexOf('data-sfb-theme-components-version');
192
- data = data.substring(0, start)
193
- + `data-custom-components-overrides-js="${overridesJavaScript.join(',')}"`
194
- + `\n data-custom-components-overrides-scss="${overridesSass.join(',')}"`
195
- + `\n data-custom-components-user-defined="${userDefinedCustomComponents.join(',')}"\n `
196
- + data.substring(start);
197
- }
300
+ const overrides = getCustomComponentsInfo();
301
+ data = applyCustomComponentOverrideAttributes(
302
+ data,
303
+ overrides,
304
+ sfbThemeComponentsVersion || "latest"
305
+ );
198
306
  }
199
307
  }
200
308
  return data;
@@ -274,13 +382,21 @@ const addMetadata = (metadata = {}, themePath) => {
274
382
  }
275
383
 
276
384
  const installSass = () => {
277
- // install sass and sass-loader
278
- spawnSync('npm',
279
- [`i -S ${SASS_MODULE}@${SASS_VERSION} ${SASS_LOADER_MODULE}@${SASS_LOADER_VERSION} --omit=dev --legacy-peer-deps`], {
385
+ // install sass-embedded and sass-loader into the active theme
386
+ spawnSyncNpm(
387
+ [
388
+ "i",
389
+ "-S",
390
+ `${SASS_MODULE}@${SASS_VERSION}`,
391
+ `${SASS_LOADER_MODULE}@${SASS_LOADER_VERSION}`,
392
+ "--omit=dev",
393
+ "--legacy-peer-deps",
394
+ ],
395
+ {
280
396
  cwd: ACTIVE_THEME_PATH,
281
397
  stdio: "inherit",
282
- shell: true
283
- })
398
+ }
399
+ )
284
400
  }
285
401
 
286
402
  const convertPascalCaseToKebabCase = (str) =>
@@ -305,11 +421,13 @@ module.exports = {
305
421
  getThemeConfig,
306
422
  licenseAgreement,
307
423
  versionCheck,
424
+ isLocalPackageInstalled,
308
425
  installSfbThemeComponents,
309
426
  createPackageJson,
310
427
  createThemeLogsFolder,
311
428
  createCustomThemePacakgeJson,
312
429
  updateCustomComponentsMetadata,
430
+ applyCustomComponentOverrideAttributes,
313
431
  addMetadata,
314
432
  installSass,
315
433
  isProjectsFolder,
@@ -2,12 +2,14 @@ const chalk = require("chalk");
2
2
  const path = require("path");
3
3
  const { isProjectsFolder } = require("./toolkit-common-fun");
4
4
 
5
+ const EXTENSIONS_PATH_RE = /extensions[\\/][a-zA-Z-0-9]*/gm;
6
+ const EXTENSIONS_FOLDER_RE = /extensions[\\/]?[a-zA-Z-0-9]*/gm;
7
+
5
8
  const isInsideCreatedExtension = (currentPath) => {
6
9
  if (!currentPath) {
7
10
  return false;
8
11
  }
9
- const [extensionsPathMatch] =
10
- currentPath.match(/extensions\/[a-zA-Z-0-9]*/gm) || [];
12
+ const [extensionsPathMatch] = currentPath.match(EXTENSIONS_PATH_RE) || [];
11
13
 
12
14
  return !!extensionsPathMatch;
13
15
  };
@@ -17,7 +19,7 @@ const isInsideExtensionsFolder = () => {
17
19
  const previousDir = path.resolve(currentDir, "../");
18
20
  const previousDirName = path.basename(previousDir);
19
21
 
20
- const [pathMatch] = currentDir.match(/extensions\/?[a-zA-Z-0-9]*/gm) || [];
22
+ const [pathMatch] = currentDir.match(EXTENSIONS_FOLDER_RE) || [];
21
23
  const isPrevDirRootFolder = isProjectsFolder(previousDir);
22
24
  const isPrevDirExtensionsFolder = previousDirName === "extensions";
23
25
 
@@ -16,10 +16,11 @@ 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
18
  const THEME_COMPONENT_VERSION = "2.1.14";
19
- const SASS_MODULE = "sass";
20
- const SASS_VERSION = "1.57.1";
19
+ const SASS_MODULE = "sass-embedded";
20
+ // Exact pin: >=1.92 changes mixed-decls order (CSS cascade regressions in themes).
21
+ const SASS_VERSION = "1.89.2";
21
22
  const SASS_LOADER_MODULE = "sass-loader";
22
- const SASS_LOADER_VERSION = "10.1.1";
23
+ const SASS_LOADER_VERSION = "16.0.5";
23
24
 
24
25
  let WORKSPACE_CONFIG;
25
26
  try {
@@ -83,7 +83,7 @@ const getPathToFile = (path) => {
83
83
  } else if(fs.existsSync(indexJsFile)) {
84
84
  fullPath = indexJsFile;
85
85
  } else {
86
- const split = fullPath.split('/');
86
+ const split = String(fullPath).replace(/\\/g, '/').split('/');
87
87
  split[split.length - 1] = `_${split[split.length - 1]}.scss`;
88
88
  const updatedPathToFile = split.join('/');
89
89
  if(fs.existsSync(updatedPathToFile)) {
@@ -95,14 +95,16 @@ const getPathToFile = (path) => {
95
95
  }
96
96
 
97
97
  const constructPath = (currentPath, goToRelativePath) => {
98
+ // Normalize Windows `\` so slash-index math matches Unix behavior
99
+ const normalizedCurrentPath = String(currentPath).replace(/\\/g, '/');
98
100
  const levelsToGoUp = (goToRelativePath.match(/\.\.\//g) || []).length + 1;
99
101
  const currentPathDepthIndices = [];
100
- for(let i=0; i < currentPath.length; i++) {
101
- if (currentPath[i] === '/') {
102
+ for(let i=0; i < normalizedCurrentPath.length; i++) {
103
+ if (normalizedCurrentPath[i] === '/') {
102
104
  currentPathDepthIndices.push(i);
103
105
  }
104
106
  }
105
- const newCurrentPath = currentPath.slice(0, currentPathDepthIndices[currentPathDepthIndices.length - levelsToGoUp]);
107
+ const newCurrentPath = normalizedCurrentPath.slice(0, currentPathDepthIndices[currentPathDepthIndices.length - levelsToGoUp]);
106
108
  const newGoToPath = goToRelativePath.replace(/\.+\//g, '');
107
109
  return getPathToFile(`${newCurrentPath}/${newGoToPath}`);
108
110
  }
@@ -347,7 +347,7 @@ const getPathToFile = (path) => {
347
347
  } else if(fs.existsSync(indexJsFile)) {
348
348
  fullPath = indexJsFile;
349
349
  } else {
350
- const split = fullPath.split('/');
350
+ const split = String(fullPath).replace(/\\/g, '/').split('/');
351
351
  split[split.length - 1] = `_${split[split.length - 1]}.scss`;
352
352
  const updatedPathToFile = split.join('/');
353
353
  if(fs.existsSync(updatedPathToFile)) {
@@ -359,14 +359,16 @@ const getPathToFile = (path) => {
359
359
  }
360
360
 
361
361
  const constructPath = (currentPath, goToRelativePath) => {
362
+ // Normalize Windows `\` so slash-index math matches Unix behavior
363
+ const normalizedCurrentPath = String(currentPath).replace(/\\/g, '/');
362
364
  const levelsToGoUp = (goToRelativePath && goToRelativePath.match(/\.\.\//g) || []).length + 1;
363
365
  const currentPathDepthIndices = [];
364
- for(let i=0; i < currentPath.length; i++) {
365
- if (currentPath[i] === '/') {
366
+ for(let i=0; i < normalizedCurrentPath.length; i++) {
367
+ if (normalizedCurrentPath[i] === '/') {
366
368
  currentPathDepthIndices.push(i);
367
369
  }
368
370
  }
369
- const newCurrentPath = currentPath.slice(0, currentPathDepthIndices[currentPathDepthIndices.length - levelsToGoUp]);
371
+ const newCurrentPath = normalizedCurrentPath.slice(0, currentPathDepthIndices[currentPathDepthIndices.length - levelsToGoUp]);
370
372
  const newGoToPath = goToRelativePath && goToRelativePath.replace(/\.+\//g, '');
371
373
  return getPathToFile(`${newCurrentPath}/${newGoToPath}`);
372
374
  }
@@ -7,6 +7,7 @@ const { TOOLKIT_GLOBAL_CONFIG} = require("./toolkit-common-vars")
7
7
  const { CURRENT_PATH, TOOLKIT_PATH, BOOTSTRAP_FOLDERS, CONFIG_PATH, PAGE_OBJECTS_SUFFIX } = require("./toolkit-common-vars");
8
8
  const { selfDestruction, shouldBeProjectFolder, getAvailableFolderWithPrompt, versionCheck } = require("./toolkit-common-fun");
9
9
  const { LOCAL_CONFIG } = require("./toolkit-config");
10
+ const { projectNameFromPath } = require("./toolkit-path");
10
11
  const projectName = process.argv[2];
11
12
  const themeName = process.argv[3];
12
13
 
@@ -36,7 +37,7 @@ let freshLocalConfig = {
36
37
  // if provided with command, set the pointer on the provided name
37
38
  projectPath = await getAvailableFolderWithPrompt(CURRENT_PATH, projectName, "ProjectName");
38
39
 
39
- freshLocalConfig.projectName = projectPath.replace(`${CURRENT_PATH}/`, "");
40
+ freshLocalConfig.projectName = projectNameFromPath(projectPath, CURRENT_PATH);
40
41
 
41
42
  // create bootstrap folders
42
43
  BOOTSTRAP_FOLDERS.forEach(folderName => {
@@ -7,6 +7,7 @@ const chalk = require("chalk");
7
7
  const { CURRENT_PATH, TOOLKIT_PATH, COMMAND_PARAM, COMPILERCSS_PATH, PAGE_OBJECTS_SUFFIX } = require("./toolkit-common-vars");
8
8
  const { shouldBeProjectFolder, getAvailableFolderWithPrompt, createCustomThemePacakgeJson, addMetadata } = require("./toolkit-common-fun");
9
9
  const { LOCAL_CONFIG } = require("./toolkit-config");
10
+ const { themeNameFromPath } = require("./toolkit-path");
10
11
 
11
12
  shouldBeProjectFolder(true);
12
13
 
@@ -66,7 +67,7 @@ shouldBeProjectFolder(true);
66
67
  try {
67
68
  const projectData = LOCAL_CONFIG.read();
68
69
  const userAnswer = await prompt.ask(["MarketplacePath"]);
69
- const newThemeName = themesPath.replace(`${CURRENT_PATH}/themes/`, "");
70
+ const newThemeName = themeNameFromPath(themesPath, CURRENT_PATH);
70
71
  const newNamespace = {
71
72
  themeName: newThemeName,
72
73
  marketplacePath: userAnswer.MarketplacePath,
@@ -119,10 +120,7 @@ shouldBeProjectFolder(true);
119
120
  console.error(chalk.red(` ERROR: Unable to save metadata due to: ${err}`));
120
121
  }
121
122
 
122
- spawn('node',
123
- [`"${TOOLKIT_PATH}/${COMPILERCSS_PATH}"`], {
124
- stdio: "inherit",
125
- shell: true
126
- }
127
- )
123
+ spawn(process.execPath, [`${TOOLKIT_PATH}/${COMPILERCSS_PATH}`], {
124
+ stdio: "inherit",
125
+ })
128
126
  })();
@@ -1,13 +1,14 @@
1
1
  const fs = require("fs");
2
2
  const extract = require('extract-zip');
3
3
  const path = require('path');
4
- const { spawnSync } = require("child_process");
5
4
  const { shouldBeProjectFolder, getAvailableFolderWithPrompt } = require("./toolkit-common-fun");
5
+ const { spawnSyncNpm } = require("./toolkit-spawn");
6
6
  const { CURRENT_PATH, PAGE_OBJECTS_SUFFIX } = require("./toolkit-common-vars");
7
7
  const chalk = require("chalk");
8
8
  const prompt = require("./prompt-questions");
9
9
  const { LOCAL_CONFIG } = require("./toolkit-config");
10
10
  const { extractCustomComponentsZipToThemeRoot } = require("./toolkit-components-fun");
11
+ const { themeNameFromPath } = require("./toolkit-path");
11
12
 
12
13
  shouldBeProjectFolder(true);
13
14
 
@@ -141,12 +142,10 @@ const areDependenciesPresentInPackageJson = (themePath) => {
141
142
 
142
143
  const installDependencies = (themePath) => {
143
144
  console.log(chalk.yellow(" Please wait while we install your dependencies. \n"));
144
- spawnSync('npm',
145
- ['install', '--legacy-peer-deps'], {
145
+ spawnSyncNpm(["install", "--legacy-peer-deps"], {
146
146
  cwd: themePath,
147
147
  stdio: "inherit",
148
- shell: true
149
- });
148
+ })
150
149
  }
151
150
 
152
151
  (async () => {
@@ -166,7 +165,7 @@ const installDependencies = (themePath) => {
166
165
  const themePath = await getAvailableFolderWithPrompt(`${CURRENT_PATH}/themes`, themeName, "ThemeName")
167
166
 
168
167
  // Get new theme name if path for previous theme name is already taken
169
- const updatedThemeName = themePath.replace(`${CURRENT_PATH}/themes/`, "");
168
+ const updatedThemeName = themeNameFromPath(themePath, CURRENT_PATH);
170
169
 
171
170
  await extractTheme(themeZipFilePath, themePath);
172
171
 
@@ -0,0 +1,24 @@
1
+ const chalk = require("chalk");
2
+ const { CURRENT_PATH } = require("./toolkit-common-vars");
3
+ const { shouldBeProjectFolder } = require("./toolkit-common-fun");
4
+ const { installAgentGuidance } = require("./toolkit-install-agent-guidance");
5
+
6
+ shouldBeProjectFolder(true);
7
+
8
+ const result = installAgentGuidance(CURRENT_PATH);
9
+ if (!result.ok) {
10
+ console.error(
11
+ chalk.red(
12
+ ` ERROR: Unable to install AI agent guidance${
13
+ result.error ? `: ${result.error}` : "."
14
+ }`
15
+ )
16
+ );
17
+ process.exit(1);
18
+ }
19
+
20
+ console.log(
21
+ chalk.green(
22
+ `\n AI agent guidance is ready in ${result.targetRoot} (AGENTS.md, CLAUDE.md, .cursor/, .claude/skills/).\n`
23
+ )
24
+ );
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Copy AI agent guidance from the toolkit package into a workspace root
3
+ * (AGENTS.md, CLAUDE.md, .cursor + .claude skills) so Cursor / Claude / Codex
4
+ * share the same Storefront Builder instructions.
5
+ */
6
+ const path = require("path");
7
+ const fs = require("fs-extra");
8
+ const chalk = require("chalk");
9
+ const { TOOLKIT_PATH } = require("./toolkit-common-vars");
10
+
11
+ const AGENT_SOURCE_DIR = path.join(TOOLKIT_PATH, "agent");
12
+
13
+ const GUIDANCE_ROOT_FILES = ["AGENTS.md", "CLAUDE.md"];
14
+
15
+ const SKILL_NAMES = [
16
+ "sfb-toolkit-commands",
17
+ "sfb-theme-customize",
18
+ "sfb-custom-components",
19
+ "sfb-localization-settings"
20
+ ];
21
+
22
+ const backupIfExists = (filePath, log) => {
23
+ if (!fs.existsSync(filePath)) {
24
+ return;
25
+ }
26
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
27
+ const backupPath = `${filePath}.bak-${stamp}`;
28
+ fs.copySync(filePath, backupPath);
29
+ log(
30
+ chalk.yellow(
31
+ ` Backed up existing ${path.basename(filePath)} → ${path.basename(backupPath)}`
32
+ )
33
+ );
34
+ };
35
+
36
+ const copySkillsTo = (skillsSourceDir, targetSkillsDir) => {
37
+ if (!fs.existsSync(skillsSourceDir)) {
38
+ return;
39
+ }
40
+ fs.ensureDirSync(targetSkillsDir);
41
+ for (const name of SKILL_NAMES) {
42
+ const from = path.join(skillsSourceDir, name);
43
+ if (fs.existsSync(from)) {
44
+ fs.copySync(from, path.join(targetSkillsDir, name), { overwrite: true });
45
+ }
46
+ }
47
+ };
48
+
49
+ /**
50
+ * @param {string} targetRoot workspace folder that contains .sfbconfig / themes
51
+ * @param {{ log?: (msg: string) => void }} [options]
52
+ * @returns {{ ok: boolean, targetRoot: string, error?: string }}
53
+ */
54
+ const installAgentGuidance = (targetRoot, options = {}) => {
55
+ const log = options.log || console.log;
56
+
57
+ if (!targetRoot || typeof targetRoot !== "string") {
58
+ return { ok: false, targetRoot: targetRoot || "", error: "missing targetRoot" };
59
+ }
60
+
61
+ const absoluteRoot = path.resolve(targetRoot);
62
+
63
+ if (!fs.existsSync(AGENT_SOURCE_DIR)) {
64
+ const error = `agent guidance source missing at ${AGENT_SOURCE_DIR}`;
65
+ console.error(chalk.yellow(` WARNING: ${error}`));
66
+ return { ok: false, targetRoot: absoluteRoot, error };
67
+ }
68
+
69
+ try {
70
+ fs.ensureDirSync(absoluteRoot);
71
+
72
+ for (const file of GUIDANCE_ROOT_FILES) {
73
+ const dest = path.join(absoluteRoot, file);
74
+ backupIfExists(dest, log);
75
+ const from = path.join(AGENT_SOURCE_DIR, file);
76
+ if (fs.existsSync(from)) {
77
+ fs.copySync(from, dest, { overwrite: true });
78
+ }
79
+ }
80
+
81
+ const cursorFrom = path.join(AGENT_SOURCE_DIR, ".cursor");
82
+ if (fs.existsSync(cursorFrom)) {
83
+ // Rules
84
+ const rulesFrom = path.join(cursorFrom, "rules");
85
+ if (fs.existsSync(rulesFrom)) {
86
+ fs.copySync(rulesFrom, path.join(absoluteRoot, ".cursor", "rules"), {
87
+ overwrite: true
88
+ });
89
+ }
90
+ // Cursor skills
91
+ copySkillsTo(
92
+ path.join(cursorFrom, "skills"),
93
+ path.join(absoluteRoot, ".cursor", "skills")
94
+ );
95
+ }
96
+
97
+ // Claude Code skills (same playbooks)
98
+ copySkillsTo(
99
+ path.join(AGENT_SOURCE_DIR, ".cursor", "skills"),
100
+ path.join(absoluteRoot, ".claude", "skills")
101
+ );
102
+
103
+ log(chalk.green(" Installed AI agent guidance (AGENTS.md)"));
104
+ return { ok: true, targetRoot: absoluteRoot };
105
+ } catch (err) {
106
+ console.error(
107
+ chalk.yellow(` WARNING: Unable to install AI agent guidance: ${err.message || err}`)
108
+ );
109
+ return { ok: false, targetRoot: absoluteRoot, error: String(err.message || err) };
110
+ }
111
+ };
112
+
113
+ module.exports = {
114
+ AGENT_SOURCE_DIR,
115
+ GUIDANCE_ROOT_FILES,
116
+ SKILL_NAMES,
117
+ installAgentGuidance
118
+ };