@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.
- package/.eslintrc +35 -35
- package/CHANGELOG.md +45 -0
- package/Dockerfile +2 -1
- package/agent/.cursor/rules/sfb-storefront.mdc +18 -0
- package/agent/.cursor/skills/sfb-custom-components/COMPONENT-CATALOG.md +130 -0
- package/agent/.cursor/skills/sfb-custom-components/SKILL.md +44 -0
- package/agent/.cursor/skills/sfb-localization-settings/SKILL.md +99 -0
- package/agent/.cursor/skills/sfb-theme-customize/SKILL.md +25 -0
- package/agent/.cursor/skills/sfb-toolkit-commands/SKILL.md +35 -0
- package/agent/AGENTS.md +222 -0
- package/agent/CLAUDE.md +20 -0
- package/bin/index.js +82 -100
- package/coverage/clover.xml +1937 -333
- package/coverage/coverage-final.json +41 -20
- package/coverage/lcov-report/{controllers/controllers-utils → config}/index.html +19 -19
- package/coverage/lcov-report/config/index.js.html +124 -0
- package/coverage/lcov-report/index.html +108 -78
- package/coverage/lcov-report/{constants → src/constants}/customUserAttributesMock.js.html +12 -12
- package/coverage/lcov-report/{constants → src/constants}/index.html +10 -10
- package/coverage/lcov-report/{constants → src/constants}/pageUrls.js.html +14 -14
- package/coverage/lcov-report/{constants → src/constants}/userMock.js.html +13 -13
- package/coverage/lcov-report/{controllers → src/controllers}/controllers-utils/assetsUtils.js.html +20 -20
- package/coverage/lcov-report/src/controllers/controllers-utils/index.html +131 -0
- package/coverage/lcov-report/src/controllers/controllers-utils/locale.js.html +115 -0
- package/coverage/lcov-report/{controllers → src/controllers}/data-filters/bootstrap-data-filter.js.html +15 -15
- package/coverage/lcov-report/{controllers → src/controllers}/data-filters/call-to-actions-filter.js.html +22 -22
- package/coverage/lcov-report/{controllers → src/controllers}/data-filters/index.html +37 -22
- package/coverage/lcov-report/src/controllers/data-filters/media-url-filter.js.html +394 -0
- package/coverage/lcov-report/{controllers → src/controllers}/index.html +27 -27
- package/coverage/lcov-report/{controllers → src/controllers}/index.js.html +159 -126
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/ResultItem.js.html +43 -43
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/SearchBar.js.html +22 -22
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/index.html +28 -28
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/base/item.js.html +28 -28
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/container.js.html +31 -31
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/data-view.js.html +29 -29
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/header-view.js.html +35 -38
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/index.html +45 -45
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/components/search.js.html +54 -54
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/index.html +22 -22
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/pageUrl.js.html +17 -17
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/roleType.js.html +14 -14
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/constants/searchType.js.html +17 -17
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/debounce.js.html +15 -15
- package/coverage/lcov-report/{front-end-utils → src/front-end-utils}/src/utils/index.html +20 -20
- package/coverage/lcov-report/{middlewares → src/middlewares}/config.js.html +11 -11
- package/coverage/lcov-report/{middlewares → src/middlewares}/index.html +10 -10
- package/coverage/lcov-report/{tools → src/routes}/index.html +30 -30
- package/coverage/lcov-report/src/routes/media-proxy.js.html +613 -0
- package/coverage/lcov-report/src/tools/compile-styles.js.html +1018 -0
- package/coverage/lcov-report/src/tools/custom-components-export-compat-loader.js.html +745 -0
- package/coverage/lcov-report/src/tools/index.html +371 -0
- package/coverage/lcov-report/src/tools/prompt-questions.js.html +1117 -0
- package/coverage/lcov-report/{tools → src/tools}/proxy-fetch.js.html +15 -15
- package/coverage/lcov-report/src/tools/resolve-components-react.js.html +457 -0
- package/coverage/lcov-report/src/tools/sass-legacy-compat.js.html +1192 -0
- package/coverage/lcov-report/src/tools/toolkit-cli-argv.js.html +226 -0
- package/coverage/lcov-report/src/tools/toolkit-common-fun.js.html +1402 -0
- package/coverage/lcov-report/src/tools/toolkit-common-vars-namespace.js.html +403 -0
- package/coverage/lcov-report/src/tools/toolkit-common-vars.js.html +283 -0
- package/coverage/lcov-report/src/tools/toolkit-components-fun.js.html +1237 -0
- package/coverage/lcov-report/src/tools/toolkit-components-vars.js.html +232 -0
- package/coverage/lcov-report/src/tools/toolkit-install-agent-guidance.js.html +439 -0
- package/coverage/lcov-report/src/tools/toolkit-live-reload.js.html +688 -0
- package/coverage/lcov-report/src/tools/toolkit-path.js.html +184 -0
- package/coverage/lcov-report/src/tools/toolkit-spawn.js.html +199 -0
- package/coverage/lcov-report/src/tools/toolkit-v6-theme-risk.js.html +1039 -0
- package/coverage/lcov-report/src/tools/toolkit-zip-utils.js.html +190 -0
- package/coverage/lcov.info +3387 -727
- package/index.js +40 -20
- package/npm-shrinkwrap.json +5026 -15490
- package/package.json +49 -40
- package/readme.md +20 -1
- package/rspack-components.config.cjs +81 -0
- package/rspack-components.config.prod.cjs +71 -0
- package/rspack.config.cjs +25 -0
- package/rspack.shared.cjs +164 -0
- package/src/controllers/controllers-utils/locale.js +10 -0
- package/src/controllers/data-filters/media-url-filter.js +103 -0
- package/src/controllers/index.js +15 -4
- package/src/front-end-utils/dist/toolbar.bundle.js +1 -2
- package/src/front-end-utils/src/components/header-view.js +0 -1
- package/src/routes/index.js +2 -0
- package/src/routes/media-proxy.js +176 -0
- package/src/tools/compile-styles.js +311 -0
- package/src/tools/compiler-components-prod.js +32 -21
- package/src/tools/compiler-css.js +7 -7
- package/src/tools/custom-components-export-compat-loader.js +220 -0
- package/src/tools/resolve-components-react.js +124 -0
- package/src/tools/sass-legacy-compat.js +369 -0
- package/src/tools/toolkit-checkout.js +3 -6
- package/src/tools/toolkit-cli-argv.js +47 -0
- package/src/tools/toolkit-common-fun.js +149 -31
- package/src/tools/toolkit-common-utils.js +5 -3
- package/src/tools/toolkit-common-vars.js +4 -3
- package/src/tools/toolkit-components-copy.js +6 -4
- package/src/tools/toolkit-components-fun.js +6 -4
- package/src/tools/toolkit-config-setup.js +2 -1
- package/src/tools/toolkit-create.js +5 -7
- package/src/tools/toolkit-import.js +5 -6
- package/src/tools/toolkit-install-agent-guidance-cli.js +24 -0
- package/src/tools/toolkit-install-agent-guidance.js +118 -0
- package/src/tools/toolkit-install.js +8 -8
- package/src/tools/toolkit-live-reload.js +201 -0
- package/src/tools/toolkit-package.js +25 -7
- package/src/tools/toolkit-path.js +33 -0
- package/src/tools/toolkit-setup-e2e.js +2 -1
- package/src/tools/toolkit-setup.js +5 -1
- package/src/tools/toolkit-spawn.js +38 -0
- package/src/tools/toolkit-start.js +98 -54
- package/src/tools/toolkit-storybook.js +38 -19
- package/src/tools/toolkit-update.js +5 -3
- package/src/tools/toolkit-v6-theme-risk.js +318 -0
- package/themes-param.json +1 -0
- package/src/front-end-utils/dist/toolbar.bundle.js.LICENSE.txt +0 -52
- package/src/tools/gulp-tasks.js +0 -80
- package/webpack-components.config.cjs +0 -123
- package/webpack-components.config.prod.cjs +0 -113
- package/webpack.config.cjs +0 -25
|
@@ -2,7 +2,7 @@ const fs = require("fs-extra");
|
|
|
2
2
|
const chalk = require("chalk");
|
|
3
3
|
const prompt = require("./prompt-questions");
|
|
4
4
|
const { shouldBeProjectFolder, createPackageJson, updateCustomComponentsMetadata } = require("./toolkit-common-fun");
|
|
5
|
-
const {
|
|
5
|
+
const { spawnNpm } = require("./toolkit-spawn");
|
|
6
6
|
const { COMMAND_PARAM, ACTIVE_THEME_PATH } = require("./toolkit-common-vars");
|
|
7
7
|
const { customComponentsEnabled } = require("./toolkit-components-fun");
|
|
8
8
|
|
|
@@ -23,13 +23,13 @@ const checkCommandParam = async () => {
|
|
|
23
23
|
|
|
24
24
|
createPackageJson();
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
).on(
|
|
26
|
+
spawnNpm(
|
|
27
|
+
["install", "--save", npmModule, "--production"],
|
|
28
|
+
{
|
|
29
|
+
cwd: ACTIVE_THEME_PATH,
|
|
30
|
+
stdio: "inherit",
|
|
31
|
+
}
|
|
32
|
+
).on("exit", async () => {
|
|
33
33
|
if (npmModule.includes('@appdirect/sfb-theme-components')) {
|
|
34
34
|
const baseFilePath = `${ACTIVE_THEME_PATH}/content/layout/base.html`;
|
|
35
35
|
|
|
@@ -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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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
|
|
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 {
|
|
3
|
-
|
|
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
|
|
10
|
+
const { printV6ThemeRiskWarnings } = require("./toolkit-v6-theme-risk")
|
|
11
|
+
const { spawnNode } = require("./toolkit-spawn")
|
|
7
12
|
|
|
8
13
|
const shouldIgnoreMessage = (data) => {
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
]
|
|
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
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
[
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
134
|
-
"npx",
|
|
146
|
+
spawnSyncNpx(
|
|
135
147
|
[
|
|
136
|
-
"start-storybook
|
|
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
|
})();
|