@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.
- package/.eslintrc +35 -35
- package/CHANGELOG.md +32 -0
- package/Dockerfile +2 -1
- package/agent/.cursor/rules/sfb-storefront.mdc +17 -0
- package/agent/.cursor/skills/sfb-custom-components/COMPONENT-CATALOG.md +130 -0
- package/agent/.cursor/skills/sfb-custom-components/SKILL.md +43 -0
- package/agent/.cursor/skills/sfb-localization-settings/SKILL.md +29 -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 +160 -0
- package/agent/CLAUDE.md +19 -0
- package/bin/index.js +82 -100
- package/coverage/clover.xml +1921 -335
- 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 +1192 -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 +3356 -727
- package/index.js +40 -20
- package/npm-shrinkwrap.json +19445 -35435
- package/package.json +50 -41
- package/readme.md +23 -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/cors.js +29 -0
- 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 +66 -18
- 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
|
@@ -44,10 +44,7 @@ if(!validateFun.isValidFolderName(themeName)){
|
|
|
44
44
|
process.exit(1);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
spawn(
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
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: "
|
|
120
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
stdio: "inherit",
|
|
131
|
-
shell: true
|
|
168
|
+
spawnSyncNpm(["init", "-y"], {
|
|
169
|
+
cwd: ACTIVE_THEME_PATH,
|
|
170
|
+
stdio: "inherit",
|
|
132
171
|
})
|
|
133
172
|
}
|
|
134
173
|
}
|
|
@@ -274,13 +313,21 @@ const addMetadata = (metadata = {}, themePath) => {
|
|
|
274
313
|
}
|
|
275
314
|
|
|
276
315
|
const installSass = () => {
|
|
277
|
-
// install sass and sass-loader
|
|
278
|
-
|
|
279
|
-
|
|
316
|
+
// install sass-embedded and sass-loader into the active theme
|
|
317
|
+
spawnSyncNpm(
|
|
318
|
+
[
|
|
319
|
+
"i",
|
|
320
|
+
"-S",
|
|
321
|
+
`${SASS_MODULE}@${SASS_VERSION}`,
|
|
322
|
+
`${SASS_LOADER_MODULE}@${SASS_LOADER_VERSION}`,
|
|
323
|
+
"--omit=dev",
|
|
324
|
+
"--legacy-peer-deps",
|
|
325
|
+
],
|
|
326
|
+
{
|
|
280
327
|
cwd: ACTIVE_THEME_PATH,
|
|
281
328
|
stdio: "inherit",
|
|
282
|
-
|
|
283
|
-
|
|
329
|
+
}
|
|
330
|
+
)
|
|
284
331
|
}
|
|
285
332
|
|
|
286
333
|
const convertPascalCaseToKebabCase = (str) =>
|
|
@@ -305,6 +352,7 @@ module.exports = {
|
|
|
305
352
|
getThemeConfig,
|
|
306
353
|
licenseAgreement,
|
|
307
354
|
versionCheck,
|
|
355
|
+
isLocalPackageInstalled,
|
|
308
356
|
installSfbThemeComponents,
|
|
309
357
|
createPackageJson,
|
|
310
358
|
createThemeLogsFolder,
|
|
@@ -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(
|
|
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
|
-
|
|
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 = "
|
|
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 <
|
|
101
|
-
if (
|
|
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 =
|
|
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 <
|
|
365
|
-
if (
|
|
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 =
|
|
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
|
|
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
|
|
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(
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
145
|
-
['install', '--legacy-peer-deps'], {
|
|
145
|
+
spawnSyncNpm(["install", "--legacy-peer-deps"], {
|
|
146
146
|
cwd: themePath,
|
|
147
147
|
stdio: "inherit",
|
|
148
|
-
|
|
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
|
|
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
|
+
};
|
|
@@ -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
|
|