@appdirect/sfb-toolkit 5.0.8 → 6.0.0

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 (120) hide show
  1. package/.eslintrc +35 -35
  2. package/CHANGELOG.md +32 -0
  3. package/Dockerfile +2 -1
  4. package/agent/.cursor/rules/sfb-storefront.mdc +17 -0
  5. package/agent/.cursor/skills/sfb-custom-components/COMPONENT-CATALOG.md +130 -0
  6. package/agent/.cursor/skills/sfb-custom-components/SKILL.md +43 -0
  7. package/agent/.cursor/skills/sfb-localization-settings/SKILL.md +29 -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 +160 -0
  11. package/agent/CLAUDE.md +19 -0
  12. package/bin/index.js +82 -100
  13. package/coverage/clover.xml +1921 -335
  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 +1192 -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 +3356 -727
  70. package/index.js +40 -20
  71. package/npm-shrinkwrap.json +19445 -35435
  72. package/package.json +50 -41
  73. package/readme.md +23 -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/cors.js +29 -0
  84. package/src/routes/index.js +2 -0
  85. package/src/routes/media-proxy.js +176 -0
  86. package/src/tools/compile-styles.js +311 -0
  87. package/src/tools/compiler-components-prod.js +32 -21
  88. package/src/tools/compiler-css.js +7 -7
  89. package/src/tools/custom-components-export-compat-loader.js +220 -0
  90. package/src/tools/resolve-components-react.js +124 -0
  91. package/src/tools/sass-legacy-compat.js +369 -0
  92. package/src/tools/toolkit-checkout.js +3 -6
  93. package/src/tools/toolkit-cli-argv.js +47 -0
  94. package/src/tools/toolkit-common-fun.js +66 -18
  95. package/src/tools/toolkit-common-utils.js +5 -3
  96. package/src/tools/toolkit-common-vars.js +4 -3
  97. package/src/tools/toolkit-components-copy.js +6 -4
  98. package/src/tools/toolkit-components-fun.js +6 -4
  99. package/src/tools/toolkit-config-setup.js +2 -1
  100. package/src/tools/toolkit-create.js +5 -7
  101. package/src/tools/toolkit-import.js +5 -6
  102. package/src/tools/toolkit-install-agent-guidance-cli.js +24 -0
  103. package/src/tools/toolkit-install-agent-guidance.js +118 -0
  104. package/src/tools/toolkit-install.js +8 -8
  105. package/src/tools/toolkit-live-reload.js +201 -0
  106. package/src/tools/toolkit-package.js +25 -7
  107. package/src/tools/toolkit-path.js +33 -0
  108. package/src/tools/toolkit-setup-e2e.js +2 -1
  109. package/src/tools/toolkit-setup.js +5 -1
  110. package/src/tools/toolkit-spawn.js +38 -0
  111. package/src/tools/toolkit-start.js +98 -54
  112. package/src/tools/toolkit-storybook.js +38 -19
  113. package/src/tools/toolkit-update.js +5 -3
  114. package/src/tools/toolkit-v6-theme-risk.js +318 -0
  115. package/themes-param.json +1 -0
  116. package/src/front-end-utils/dist/toolbar.bundle.js.LICENSE.txt +0 -52
  117. package/src/tools/gulp-tasks.js +0 -80
  118. package/webpack-components.config.cjs +0 -123
  119. package/webpack-components.config.prod.cjs +0 -113
  120. package/webpack.config.cjs +0 -25
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Opt-in preview live-reload for app-builder / iframe embeds.
3
+ * Off unless SFB_TOOLKIT_LIVE_RELOAD is "1" or "true".
4
+ */
5
+ const path = require("path");
6
+ const chokidar = require("chokidar");
7
+
8
+ const LIVE_RELOAD_PATH = "/__sfb_live_reload";
9
+ const ENV_KEY = "SFB_TOOLKIT_LIVE_RELOAD";
10
+ const BOOT_ID_STORAGE_KEY = "sfbToolkitLiveReloadBootId";
11
+ const CSS_DEBOUNCE_MS = 250;
12
+ const HEARTBEAT_MS = 15000;
13
+
14
+ const isLiveReloadEnabled = (env = process.env) => {
15
+ const raw = env[ENV_KEY];
16
+ if (raw == null || raw === "") {
17
+ return false;
18
+ }
19
+ const normalized = String(raw).trim().toLowerCase();
20
+ return normalized === "1" || normalized === "true";
21
+ };
22
+
23
+ const formatSse = (event, data) => {
24
+ const payload =
25
+ typeof data === "string" ? data : JSON.stringify(data == null ? {} : data);
26
+ return `event: ${event}\ndata: ${payload}\n\n`;
27
+ };
28
+
29
+ const shouldIgnoreCssWatchPath = filePath => {
30
+ const normalized = String(filePath).replace(/\\/g, "/");
31
+ if (normalized.includes("/customComponents/")) {
32
+ return true;
33
+ }
34
+ if (normalized.includes("/hot/")) {
35
+ return true;
36
+ }
37
+ if (/\.css\.map$/i.test(normalized)) {
38
+ return true;
39
+ }
40
+ return false;
41
+ };
42
+
43
+ const getLiveReloadClientScript = () => {
44
+ // Hardcoded constants only (no runtime interpolation) so the injected script
45
+ // is a fixed string — avoids CodeQL "improper code sanitization" on construction.
46
+ // Persist bootId BEFORE reload so a nodemon restart does not infinite-loop.
47
+ return `<script>(function(){try{if(typeof EventSource==="undefined")return;var PATH="/__sfb_live_reload";var KEY="sfbToolkitLiveReloadBootId";var notify=function(reason){try{if(window.parent&&window.parent!==window){window.parent.postMessage({source:"sfb-toolkit",type:"sfb-live-reload",reason:reason||"reload"},"*");}}catch(e){}};var reload=function(reason){notify(reason);window.location.reload();};var es=new EventSource(PATH);es.addEventListener("bootId",function(ev){var id=ev&&ev.data;if(!id)return;var prev=null;try{prev=sessionStorage.getItem(KEY);}catch(e){}try{sessionStorage.setItem(KEY,id);}catch(e){}if(prev&&prev!==id){reload("bootId");}});es.addEventListener("reload",function(ev){var reason="reload";try{var parsed=JSON.parse(ev.data||"{}");if(parsed&&parsed.reason)reason=parsed.reason;}catch(e){}reload(reason);});}catch(e){}})();</script>`;
48
+ };
49
+
50
+ const appendLiveReloadScript = html => {
51
+ if (!html || typeof html !== "string") {
52
+ return html;
53
+ }
54
+ const script = getLiveReloadClientScript();
55
+ const bodyClose = html.lastIndexOf("</body>");
56
+ if (bodyClose !== -1) {
57
+ return `${html.slice(0, bodyClose)}${script}${html.slice(bodyClose)}`;
58
+ }
59
+ return `${html}${script}`;
60
+ };
61
+
62
+ /**
63
+ * @param {{ themePath: string, debounceMs?: number, heartbeatMs?: number, chokidarWatch?: Function }} options
64
+ */
65
+ const createLiveReloadHub = ({
66
+ themePath,
67
+ debounceMs = CSS_DEBOUNCE_MS,
68
+ heartbeatMs = HEARTBEAT_MS,
69
+ chokidarWatch = chokidar.watch.bind(chokidar)
70
+ } = {}) => {
71
+ if (!themePath) {
72
+ throw new Error("createLiveReloadHub: themePath is required");
73
+ }
74
+
75
+ const bootId = Date.now().toString(36);
76
+ const clients = new Set();
77
+ let debounceTimer = null;
78
+ let heartbeatTimer = null;
79
+ let watcher = null;
80
+ let closed = false;
81
+
82
+ const write = (res, chunk) => {
83
+ try {
84
+ res.write(chunk);
85
+ } catch (_err) {
86
+ clients.delete(res);
87
+ }
88
+ };
89
+
90
+ const broadcast = (event, data) => {
91
+ const chunk = formatSse(event, data);
92
+ for (const res of [...clients]) {
93
+ write(res, chunk);
94
+ }
95
+ };
96
+
97
+ const scheduleCssReload = () => {
98
+ clearTimeout(debounceTimer);
99
+ debounceTimer = setTimeout(() => {
100
+ broadcast("reload", { reason: "css" });
101
+ }, debounceMs);
102
+ };
103
+
104
+ // Match compile-styles outputs: assets/css, header-footer (css next to scss),
105
+ // and theme components/*.css — not customComponents (Rspack HMR owns those).
106
+ const cssGlobs = [
107
+ path.join(themePath, "assets", "css", "**", "*.css"),
108
+ path.join(themePath, "header-footer", "**", "*.css"),
109
+ path.join(themePath, "components", "**", "*.css")
110
+ ];
111
+ watcher = chokidarWatch(cssGlobs, {
112
+ ignoreInitial: true,
113
+ ignored: filePath => shouldIgnoreCssWatchPath(filePath)
114
+ });
115
+ const onCssFile = filePath => {
116
+ if (shouldIgnoreCssWatchPath(filePath)) {
117
+ return;
118
+ }
119
+ scheduleCssReload();
120
+ };
121
+ watcher.on("add", onCssFile);
122
+ watcher.on("change", onCssFile);
123
+
124
+ heartbeatTimer = setInterval(() => {
125
+ for (const res of [...clients]) {
126
+ write(res, ": heartbeat\n\n");
127
+ }
128
+ }, heartbeatMs);
129
+ if (typeof heartbeatTimer.unref === "function") {
130
+ heartbeatTimer.unref();
131
+ }
132
+
133
+ const handle = (req, res) => {
134
+ if (closed) {
135
+ res.statusCode = 503;
136
+ res.end();
137
+ return;
138
+ }
139
+ res.writeHead(200, {
140
+ "Content-Type": "text/event-stream",
141
+ "Cache-Control": "no-cache, no-transform",
142
+ Connection: "keep-alive",
143
+ "X-Accel-Buffering": "no"
144
+ });
145
+ if (typeof res.flushHeaders === "function") {
146
+ res.flushHeaders();
147
+ }
148
+ clients.add(res);
149
+ write(res, formatSse("bootId", bootId));
150
+
151
+ const cleanup = () => {
152
+ clients.delete(res);
153
+ };
154
+ req.on("close", cleanup);
155
+ req.on("aborted", cleanup);
156
+ };
157
+
158
+ const close = async () => {
159
+ closed = true;
160
+ clearTimeout(debounceTimer);
161
+ if (heartbeatTimer) {
162
+ clearInterval(heartbeatTimer);
163
+ heartbeatTimer = null;
164
+ }
165
+ for (const res of [...clients]) {
166
+ try {
167
+ res.end();
168
+ } catch (_err) {
169
+ /* ignore */
170
+ }
171
+ }
172
+ clients.clear();
173
+ if (watcher) {
174
+ await watcher.close();
175
+ watcher = null;
176
+ }
177
+ };
178
+
179
+ return {
180
+ bootId,
181
+ path: LIVE_RELOAD_PATH,
182
+ handle,
183
+ broadcast,
184
+ close,
185
+ get clientCount() {
186
+ return clients.size;
187
+ }
188
+ };
189
+ };
190
+
191
+ module.exports = {
192
+ ENV_KEY,
193
+ LIVE_RELOAD_PATH,
194
+ BOOT_ID_STORAGE_KEY,
195
+ isLiveReloadEnabled,
196
+ getLiveReloadClientScript,
197
+ appendLiveReloadScript,
198
+ shouldIgnoreCssWatchPath,
199
+ createLiveReloadHub,
200
+ formatSse
201
+ };
@@ -1,11 +1,12 @@
1
- const { spawn } = require("child_process")
2
1
  const chalk = require("chalk")
2
+ const path = require("path")
3
3
 
4
4
  const PACKFONTS_PATH = "src/tools/package-fonts.js"
5
5
  const ZIPTHEME_PATH = "src/tools/zip-theme.js"
6
6
  const COMPILECOMPONENTS_PATH = "src/tools/compiler-components-prod.js"
7
7
  const prompt = require("./prompt-questions")
8
8
  const fs = require("fs-extra")
9
+ const { spawnSyncNode } = require("./toolkit-spawn")
9
10
 
10
11
  const fsProm = fs.promises
11
12
  const yaml = require("js-yaml")
@@ -20,6 +21,7 @@ const {
20
21
  } = require("./toolkit-common-vars")
21
22
  const { shouldBeProjectFolder, addMetadata } = require("./toolkit-common-fun")
22
23
  const { extractCustomComponentsZipToThemeRoot } = require("./toolkit-components-fun")
24
+ const { printV6ThemeRiskWarnings } = require("./toolkit-v6-theme-risk")
23
25
 
24
26
  shouldBeProjectFolder(true)
25
27
 
@@ -63,7 +65,9 @@ const includeSettings = async shouldIncludeSettings => {
63
65
  let shouldIncludeTranslations = true
64
66
  let shouldIncludeSettings = true
65
67
 
68
+ // Extract before risk scan so zip-only themes expose customComponents/ for shim detection
66
69
  await extractCustomComponentsZipToThemeRoot()
70
+ printV6ThemeRiskWarnings()
67
71
 
68
72
  addMetadata();
69
73
 
@@ -77,11 +81,25 @@ const includeSettings = async shouldIncludeSettings => {
77
81
  if (translationsError) return
78
82
  }
79
83
 
80
- spawn(
81
- `node "${TOOLKIT_PATH}/${COMPILECOMPONENTS_PATH}" && node "${TOOLKIT_PATH}/${COMPILERCSS_PATH}" && node "${TOOLKIT_PATH}/${PACKFONTS_PATH}" && node "${TOOLKIT_PATH}/${ZIPTHEME_PATH}" ${shouldIncludeTranslations} ${shouldIncludeSettings}`,
82
- {
83
- stdio: "inherit",
84
- shell: true
84
+ // Sequential Node scripts (no shell) — works on Windows and avoids DEP0190
85
+ const steps = [
86
+ [path.join(TOOLKIT_PATH, COMPILECOMPONENTS_PATH)],
87
+ [path.join(TOOLKIT_PATH, COMPILERCSS_PATH)],
88
+ [path.join(TOOLKIT_PATH, PACKFONTS_PATH)],
89
+ [
90
+ path.join(TOOLKIT_PATH, ZIPTHEME_PATH),
91
+ String(shouldIncludeTranslations),
92
+ String(shouldIncludeSettings),
93
+ ],
94
+ ]
95
+ for (const args of steps) {
96
+ const result = spawnSyncNode(args, { stdio: "inherit" })
97
+ if (result.status) {
98
+ process.exit(result.status)
85
99
  }
86
- )
100
+ if (result.error) {
101
+ console.error(result.error)
102
+ process.exit(1)
103
+ }
104
+ }
87
105
  })()
@@ -0,0 +1,33 @@
1
+ const path = require("path");
2
+
3
+ /** Normalize separators so Windows `\` and Unix `/` compare/replace safely. */
4
+ const toPosixPath = (filePath = "") => String(filePath).replace(/\\/g, "/");
5
+
6
+ /**
7
+ * Theme folder name from a theme path under workspace/themes.
8
+ * Avoids fragile `${cwd}/themes/` string replaces when separators differ.
9
+ */
10
+ const themeNameFromPath = (themePath, workspacePath) => {
11
+ const themesRoot = path.resolve(workspacePath, "themes");
12
+ const resolvedTheme = path.resolve(themePath);
13
+ const relative = path.relative(themesRoot, resolvedTheme);
14
+ if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
15
+ return path.basename(resolvedTheme);
16
+ }
17
+ return relative.split(path.sep)[0];
18
+ };
19
+
20
+ /** Project folder name from an absolute project path under the workspace. */
21
+ const projectNameFromPath = (projectPath, workspacePath) => {
22
+ const relative = path.relative(path.resolve(workspacePath), path.resolve(projectPath));
23
+ if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) {
24
+ return path.basename(path.resolve(projectPath));
25
+ }
26
+ return relative.split(path.sep)[0];
27
+ };
28
+
29
+ module.exports = {
30
+ toPosixPath,
31
+ themeNameFromPath,
32
+ projectNameFromPath,
33
+ };
@@ -17,6 +17,7 @@ const {
17
17
  versionCheck
18
18
  } = require("./toolkit-common-fun")
19
19
  const { LOCAL_CONFIG } = require("./toolkit-config")
20
+ const { projectNameFromPath } = require("./toolkit-path")
20
21
 
21
22
  const projectName = COMMAND_PARAM // [optional] project name
22
23
 
@@ -37,7 +38,7 @@ const freshLocalConfig = {
37
38
  "ProjectName"
38
39
  )
39
40
 
40
- freshLocalConfig.projectName = projectPath.replace(`${CURRENT_PATH}/`, "")
41
+ freshLocalConfig.projectName = projectNameFromPath(projectPath, CURRENT_PATH)
41
42
 
42
43
  // create bootstrap folders
43
44
  BOOTSTRAP_FOLDERS.forEach(folderName => {
@@ -7,6 +7,8 @@ const { CURRENT_PATH, TOOLKIT_PATH, COMMAND_PARAM, BOOTSTRAP_FOLDERS, CONFIG_PAT
7
7
  const { selfDestruction, filesCounter, shouldBeProjectFolder, getAvailableFolderWithPrompt,
8
8
  licenseAgreement, versionCheck, createCustomThemePacakgeJson, addMetadata } = require("./toolkit-common-fun");
9
9
  const { LOCAL_CONFIG } = require("./toolkit-config");
10
+ const { projectNameFromPath } = require("./toolkit-path");
11
+ const { installAgentGuidance } = require("./toolkit-install-agent-guidance");
10
12
  const projectName = COMMAND_PARAM; // [optional] project name
11
13
 
12
14
  let freshLocalConfig = {
@@ -47,7 +49,7 @@ let userThemeAnswer;
47
49
  break;
48
50
  }
49
51
 
50
- freshLocalConfig.projectName = projectPath.replace(`${CURRENT_PATH}/`, "");
52
+ freshLocalConfig.projectName = projectNameFromPath(projectPath, CURRENT_PATH);
51
53
 
52
54
  // create bootstrap folders
53
55
  BOOTSTRAP_FOLDERS.forEach(folderName => {
@@ -141,6 +143,8 @@ let userThemeAnswer;
141
143
  console.error(chalk.red(` ERROR: Unable to save metadata due to: ${err}`));
142
144
  }
143
145
 
146
+ installAgentGuidance(projectPath);
147
+
144
148
  console.log(chalk.green(` Theme location: ${projectPath}/`))
145
149
  console.log(chalk.green(` Configuration file location: ${projectPath}/config/`))
146
150
  console.log(chalk.green(`\n All done! You can start your server by running \`sfb-toolkit start\` inside the project root folder: ${projectPath}\n`));
@@ -0,0 +1,38 @@
1
+ const { spawn, spawnSync } = require("child_process");
2
+
3
+ const isWindows = process.platform === "win32";
4
+
5
+ /** Windows needs npm.cmd / npx.cmd when shell is false (avoids DEP0190). */
6
+ const npmCommand = () => (isWindows ? "npm.cmd" : "npm");
7
+ const npxCommand = () => (isWindows ? "npx.cmd" : "npx");
8
+
9
+ const defaultOpts = (opts = {}) => ({
10
+ stdio: "inherit",
11
+ windowsHide: true,
12
+ ...opts,
13
+ });
14
+
15
+ const spawnNpm = (args, opts) => spawn(npmCommand(), args, defaultOpts(opts));
16
+ const spawnSyncNpm = (args, opts) =>
17
+ spawnSync(npmCommand(), args, defaultOpts(opts));
18
+ const spawnNpx = (args, opts) => spawn(npxCommand(), args, defaultOpts(opts));
19
+ const spawnSyncNpx = (args, opts) =>
20
+ spawnSync(npxCommand(), args, defaultOpts(opts));
21
+
22
+ /** Prefer the current Node binary so Windows does not depend on PATH `node`. */
23
+ const spawnNode = (args, opts) =>
24
+ spawn(process.execPath, args, defaultOpts(opts));
25
+ const spawnSyncNode = (args, opts) =>
26
+ spawnSync(process.execPath, args, defaultOpts(opts));
27
+
28
+ module.exports = {
29
+ isWindows,
30
+ npmCommand,
31
+ npxCommand,
32
+ spawnNpm,
33
+ spawnSyncNpm,
34
+ spawnNpx,
35
+ spawnSyncNpx,
36
+ spawnNode,
37
+ spawnSyncNode,
38
+ };
@@ -1,60 +1,104 @@
1
1
  const NODEMON_PATH = "node_modules/nodemon/bin/nodemon.js"
2
- const { spawn } = require("child_process")
3
- const { TOOLKIT_PATH, COMPILERCSS_PATH, ACTIVE_THEME_PATH } = require("./toolkit-common-vars")
2
+ const {
3
+ TOOLKIT_PATH,
4
+ COMPILERCSS_PATH,
5
+ ACTIVE_THEME,
6
+ CURRENT_PATH
7
+ } = require("./toolkit-common-vars")
4
8
  const { shouldBeProjectFolder, versionCheck } = require("./toolkit-common-fun")
5
9
  const { extractCustomComponentsZipToThemeRoot } = require("./toolkit-components-fun")
6
- const config = require(`${TOOLKIT_PATH}/config`)
10
+ const { printV6ThemeRiskWarnings } = require("./toolkit-v6-theme-risk")
11
+ const { spawnNode } = require("./toolkit-spawn")
7
12
 
8
13
  const shouldIgnoreMessage = (data) => {
9
- if (process.env.verboseToolkitOutput) {
10
- return false;
14
+ if (process.env.verboseToolkitOutput) {
15
+ return false
16
+ }
17
+
18
+ const dataStr = `${data}`
19
+ return [
20
+ "Browserslist: caniuse-lite is outdated.",
21
+ "[BABEL] Note: The code generator has deoptimised",
22
+ "localization file sfb-toolkit-assets not found"
23
+ ].some((token) => dataStr.startsWith(token))
24
+ }
25
+
26
+ shouldBeProjectFolder(true)
27
+
28
+ ;(async () => {
29
+ await versionCheck()
30
+ // Extract before risk scan so zip-only themes expose customComponents/ for shim detection
31
+ await extractCustomComponentsZipToThemeRoot()
32
+ printV6ThemeRiskWarnings()
33
+
34
+ const themeWatchPath = `themes/${ACTIVE_THEME}/`
35
+ const themeIgnorePath = `themes/${ACTIVE_THEME}/assets/js/`
36
+
37
+ const toolkitStartProcess = spawnNode(
38
+ [
39
+ `${TOOLKIT_PATH}/${NODEMON_PATH}`,
40
+ `${TOOLKIT_PATH}/index.js`,
41
+ "-e",
42
+ "js,mjs,json,yml",
43
+ "--watch",
44
+ themeWatchPath,
45
+ "--ignore",
46
+ themeIgnorePath
47
+ ],
48
+ {
49
+ cwd: CURRENT_PATH,
50
+ stdio: ["inherit", "pipe", "pipe"]
11
51
  }
12
-
13
- const dataStr = `${data}`;
14
- return [
15
- 'Browserslist: caniuse-lite is outdated.',
16
- '[BABEL] Note: The code generator has deoptimised',
17
- 'localization file sfb-toolkit-assets not found'
18
- ].some(
19
- (token) => dataStr.startsWith(token)
20
- );
21
- };
22
-
23
- shouldBeProjectFolder(true);
24
-
25
- (async () => {
26
- await versionCheck();
27
-
28
- await extractCustomComponentsZipToThemeRoot()
29
-
30
- const toolkitStartProcess = spawn('node',
31
- [`"${TOOLKIT_PATH}/${NODEMON_PATH}" "${TOOLKIT_PATH}/index.js" -e js,mjs,json,yml --watch themes/${config.theme}/ --ignore themes/${config.theme}/assets/js/`], {
32
- shell: true
33
- }
34
- );
35
-
36
- toolkitStartProcess.stdout.on('data', (data) => {
37
- if (!shouldIgnoreMessage(data)) {
38
- console.log(`${data}`);
39
- }
40
- });
41
- toolkitStartProcess.stderr.on('data', (data) => {
42
- if (!shouldIgnoreMessage(data)) {
43
- console.error(`${data}`);
44
- }
45
- });
46
- toolkitStartProcess.on('close', (code) => {
47
- console.log(`toolkit process exited with code ${code}`);
48
- });
49
-
50
- spawn('node',
51
- [`"${TOOLKIT_PATH}/${COMPILERCSS_PATH}" --ignore themes/${config.theme}/assets/js/*`], {
52
- stdio: "inherit",
53
- shell: true,
54
- env: {
55
- ...process.env,
56
- RUNDEVSERVER: "true"
57
- }
58
- }
59
- );
60
- })();
52
+ )
53
+
54
+ toolkitStartProcess.stdout.on("data", (data) => {
55
+ if (!shouldIgnoreMessage(data)) {
56
+ process.stdout.write(data)
57
+ }
58
+ })
59
+ toolkitStartProcess.stderr.on("data", (data) => {
60
+ if (!shouldIgnoreMessage(data)) {
61
+ process.stderr.write(data)
62
+ }
63
+ })
64
+
65
+ const cssWatchProcess = spawnNode(
66
+ [
67
+ `${TOOLKIT_PATH}/${COMPILERCSS_PATH}`,
68
+ "--ignore",
69
+ `themes/${ACTIVE_THEME}/assets/js/*`
70
+ ],
71
+ {
72
+ cwd: CURRENT_PATH,
73
+ stdio: "inherit",
74
+ env: {
75
+ ...process.env,
76
+ RUNDEVSERVER: "true"
77
+ }
78
+ }
79
+ )
80
+
81
+ const shutdown = (code = 0) => {
82
+ if (toolkitStartProcess && !toolkitStartProcess.killed) {
83
+ toolkitStartProcess.kill("SIGTERM")
84
+ }
85
+ if (cssWatchProcess && !cssWatchProcess.killed) {
86
+ cssWatchProcess.kill("SIGTERM")
87
+ }
88
+ process.exit(code)
89
+ }
90
+
91
+ toolkitStartProcess.on("close", (code) => {
92
+ console.log(`toolkit process exited with code ${code}`)
93
+ shutdown(code || 0)
94
+ })
95
+
96
+ cssWatchProcess.on("close", (code) => {
97
+ if (code && code !== 0) {
98
+ console.error(`css watch process exited with code ${code}`)
99
+ }
100
+ })
101
+
102
+ process.on("SIGINT", () => shutdown(0))
103
+ process.on("SIGTERM", () => shutdown(0))
104
+ })()
@@ -1,11 +1,12 @@
1
1
  const fs = require("fs-extra");
2
2
  const chalk = require("chalk");
3
- const { spawnSync } = require("child_process");
4
3
  const {
5
4
  shouldBeProjectFolder,
6
5
  installSfbThemeComponents,
7
6
  createPackageJson,
7
+ isLocalPackageInstalled,
8
8
  } = require("./toolkit-common-fun");
9
+ const { spawnSyncNpm, spawnSyncNpx } = require("./toolkit-spawn");
9
10
  const {
10
11
  ACTIVE_THEME_PATH,
11
12
  THEME_LOGS_FILE_PATH,
@@ -88,9 +89,9 @@ const storybookDependencies = [
88
89
  "react@16.14.0",
89
90
  "react-content-loader@5.1.4",
90
91
  "react-dom@16.14.0",
91
- `sass@${SASS_VERSION}`,
92
+ `sass-embedded@${SASS_VERSION}`,
92
93
  `sass-loader@${SASS_LOADER_VERSION}`,
93
- ].join(" ");
94
+ ];
94
95
 
95
96
  (() => {
96
97
  // Handle newly created themes without Storybook configured.
@@ -117,28 +118,46 @@ const storybookDependencies = [
117
118
  );
118
119
  }
119
120
 
120
- // check if storybook module is installed otherwise install storybook dependencies
121
- spawnSync(
122
- "npm",
123
- [
124
- `ls ${STORYBOOK_MODULE} 2>&1 | (findstr ${STORYBOOK_MODULE} || grep ${STORYBOOK_MODULE}) > ${THEME_LOGS_FILE_PATH} 2>&1 || npm i -S ${storybookDependencies} --legacy-peer-deps --production`,
125
- ],
126
- {
127
- cwd: ACTIVE_THEME_PATH,
128
- stdio: "inherit",
129
- shell: true,
130
- }
131
- );
121
+ // Log npm ls for diagnostics, but decide install from node_modules (not ls exit code)
122
+ const listed = spawnSyncNpm(["ls", STORYBOOK_MODULE, "--depth=0"], {
123
+ cwd: ACTIVE_THEME_PATH,
124
+ stdio: ["ignore", "pipe", "pipe"],
125
+ encoding: "utf8",
126
+ });
127
+ const output = `${listed.stdout || ""}${listed.stderr || ""}`;
128
+ try {
129
+ fs.writeFileSync(THEME_LOGS_FILE_PATH, output);
130
+ } catch (_) {
131
+ /* best-effort log */
132
+ }
133
+ if (!isLocalPackageInstalled(STORYBOOK_MODULE)) {
134
+ spawnSyncNpm(
135
+ [
136
+ "i",
137
+ "-S",
138
+ ...storybookDependencies,
139
+ "--legacy-peer-deps",
140
+ "--production",
141
+ ],
142
+ { cwd: ACTIVE_THEME_PATH, stdio: "inherit" }
143
+ );
144
+ }
132
145
 
133
- spawnSync(
134
- "npx",
146
+ spawnSyncNpx(
135
147
  [
136
- "start-storybook -p 6099 -c node_modules/@appdirect/sfb-theme-components/.storybook/ -s node_modules/@appdirect/sfb-theme-components/docs/images --loglevel silent",
148
+ "start-storybook",
149
+ "-p",
150
+ "6099",
151
+ "-c",
152
+ "node_modules/@appdirect/sfb-theme-components/.storybook/",
153
+ "-s",
154
+ "node_modules/@appdirect/sfb-theme-components/docs/images",
155
+ "--loglevel",
156
+ "silent",
137
157
  ],
138
158
  {
139
159
  cwd: ACTIVE_THEME_PATH,
140
160
  stdio: "inherit",
141
- shell: true,
142
161
  }
143
162
  );
144
163
  })();
@@ -5,15 +5,17 @@ const chalk = require("chalk");
5
5
  const { shouldBeProjectFolder } = require("./toolkit-common-fun");
6
6
  const { PAGE_OBJECTS_SUFFIX } = require("./toolkit-common-vars");
7
7
  const { LOCAL_CONFIG } = require("./toolkit-config");
8
+ const { printV6ThemeRiskWarnings } = require("./toolkit-v6-theme-risk");
8
9
 
9
10
  shouldBeProjectFolder(true);
10
11
 
11
12
  (async () => {
13
+ printV6ThemeRiskWarnings();
12
14
  let newConfig = {};
13
15
  try {
14
16
  const projectData = LOCAL_CONFIG.read();
15
- const currentNamespace = projectData.namespaces.find( namespace => namespace.themeName === projectData.current);
16
- const otherNamespaces = projectData.namespaces.filter( namespace => namespace.themeName !== projectData.current);
17
+ const currentNamespace = projectData.namespaces.find(namespace => namespace.themeName === projectData.current);
18
+ const otherNamespaces = projectData.namespaces.filter(namespace => namespace.themeName !== projectData.current);
17
19
  console.log(`\n Update configuration for ${projectData.current.yellow}:`)
18
20
  const userAnswer = await prompt.ask(["MarketplacePath"], [{name:"MarketplacePath", default: currentNamespace.marketplacePath}]);
19
21
  const updatedNamespace = {
@@ -45,4 +47,4 @@ shouldBeProjectFolder(true);
45
47
  process.exit(1);
46
48
  }
47
49
  console.log(chalk.green(`\n Configuration for ${newConfig.current.yellow} updated.\n`));
48
- })();
50
+ })();