@woodsportal/hubspot-kit 1.0.34 → 1.0.36
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/CHANGELOG.md +14 -0
- package/dist/cli.js +170 -181
- package/dist/cli.js.map +1 -1
- package/package.json +2 -2
- package/scripts/node-loader-interop.mjs +20 -0
- package/scripts/run-dev.mjs +12 -75
- package/scripts/vite/consumer-react-aliases.js +31 -0
- package/scripts/vite/consumer-react-aliases.test.mjs +32 -0
- package/scripts/vite/create-dev-server-config.mjs +114 -0
- package/scripts/vite/ensure-dev-kit-shims.js +39 -14
- package/scripts/vite/ensure-dev-kit-shims.test.mjs +47 -0
- package/scripts/vite/react-dev-plugin-options.js +1 -1
- package/scripts/vite/resolve-from-project-root.js +14 -4
- package/vite/vite.config.dev.mjs +2 -81
package/dist/cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
|
|
13
13
|
// src/cli/program.ts
|
|
14
14
|
import { readFileSync as readFileSync16 } from "fs";
|
|
15
|
-
import { resolve as
|
|
15
|
+
import { resolve as resolve23 } from "path";
|
|
16
16
|
import { Command } from "commander";
|
|
17
17
|
|
|
18
18
|
// src/lib/config.ts
|
|
@@ -321,11 +321,11 @@ function isVerboseStepLog(ctx) {
|
|
|
321
321
|
return ctx.global.verbose === true && !ctx.global.quiet && !ctx.global.json;
|
|
322
322
|
}
|
|
323
323
|
async function yieldForSpinnerPaint() {
|
|
324
|
-
await new Promise((
|
|
325
|
-
setImmediate(
|
|
324
|
+
await new Promise((resolve24) => {
|
|
325
|
+
setImmediate(resolve24);
|
|
326
326
|
});
|
|
327
|
-
await new Promise((
|
|
328
|
-
setTimeout(
|
|
327
|
+
await new Promise((resolve24) => {
|
|
328
|
+
setTimeout(resolve24, 48);
|
|
329
329
|
});
|
|
330
330
|
}
|
|
331
331
|
async function runCliTasks(ctx, tasks, options = {}) {
|
|
@@ -801,15 +801,7 @@ function isUploadOnlyPreexistingProject(projectRoot, moduleArtifactDirs) {
|
|
|
801
801
|
import { existsSync as existsSync6 } from "fs";
|
|
802
802
|
import { platform } from "os";
|
|
803
803
|
import { resolve as resolve7 } from "path";
|
|
804
|
-
var CONSUMER_DEV_CONFIG = "vite.config.dev.mjs";
|
|
805
804
|
var VITE_JS_SEGMENTS = ["node_modules", "vite", "bin", "vite.js"];
|
|
806
|
-
function resolveDevViteConfigPath(projectRoot) {
|
|
807
|
-
const consumerConfig = resolve7(projectRoot, CONSUMER_DEV_CONFIG);
|
|
808
|
-
if (existsSync6(consumerConfig)) {
|
|
809
|
-
return consumerConfig;
|
|
810
|
-
}
|
|
811
|
-
return kitPath("vite", "vite.config.dev.mjs");
|
|
812
|
-
}
|
|
813
805
|
function isProjectViteInstalled(projectRoot) {
|
|
814
806
|
return existsSync6(resolve7(projectRoot, ...VITE_JS_SEGMENTS));
|
|
815
807
|
}
|
|
@@ -831,8 +823,18 @@ function resolveProjectViteSpawn(projectRoot) {
|
|
|
831
823
|
}
|
|
832
824
|
return null;
|
|
833
825
|
}
|
|
834
|
-
|
|
835
|
-
|
|
826
|
+
|
|
827
|
+
// src/lib/node-loader-interop.ts
|
|
828
|
+
var NODE_LTS_RECOMMENDED = "24";
|
|
829
|
+
function nodeLoaderInteropWarning() {
|
|
830
|
+
const [major, minor] = process.versions.node.split(".").map(Number);
|
|
831
|
+
if (major === 22 && minor >= 18) {
|
|
832
|
+
return `Node 22.18+ can fail loading Vite config (getStatus). Upgrade to Node ${NODE_LTS_RECOMMENDED} LTS or the latest Node 22 patch.`;
|
|
833
|
+
}
|
|
834
|
+
if (major === 23 && minor < 4) {
|
|
835
|
+
return `Node 23.0\u201323.3 can fail loading Vite config (getStatus). Upgrade to Node ${NODE_LTS_RECOMMENDED} LTS.`;
|
|
836
|
+
}
|
|
837
|
+
return null;
|
|
836
838
|
}
|
|
837
839
|
|
|
838
840
|
// src/cli/commands/doctor.ts
|
|
@@ -843,7 +845,7 @@ function checkNode() {
|
|
|
843
845
|
name: "node",
|
|
844
846
|
ok,
|
|
845
847
|
message: ok ? `Node ${process.versions.node}` : `Node ${process.versions.node} (need >= 20)`,
|
|
846
|
-
remediation: ok ? void 0 : "Install Node
|
|
848
|
+
remediation: ok ? void 0 : "Install Node 24 LTS (recommended) or Node 20 LTS.",
|
|
847
849
|
severity: "error"
|
|
848
850
|
};
|
|
849
851
|
}
|
|
@@ -1448,6 +1450,16 @@ function checkModuleConfigUiDeps(ctx) {
|
|
|
1448
1450
|
};
|
|
1449
1451
|
});
|
|
1450
1452
|
}
|
|
1453
|
+
function checkNodeLoaderInterop() {
|
|
1454
|
+
const warning = nodeLoaderInteropWarning();
|
|
1455
|
+
return {
|
|
1456
|
+
name: "node-loader-interop",
|
|
1457
|
+
ok: !warning,
|
|
1458
|
+
message: warning ?? `Node ${process.versions.node} (Vite config load OK)`,
|
|
1459
|
+
remediation: warning ?? void 0,
|
|
1460
|
+
severity: "warn"
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1451
1463
|
function checkViteInstalled(ctx) {
|
|
1452
1464
|
if (isThemeProject(ctx.config) && !existsSync7(resolve8(ctx.projectRoot, "vite.config.dev.mjs"))) {
|
|
1453
1465
|
return null;
|
|
@@ -1481,7 +1493,7 @@ async function gatherDoctorChecks(ctx) {
|
|
|
1481
1493
|
{
|
|
1482
1494
|
title: "Checking Node, Vite, and kit scripts",
|
|
1483
1495
|
task: async () => {
|
|
1484
|
-
checks.push(checkNode(), checkKitScripts());
|
|
1496
|
+
checks.push(checkNode(), checkNodeLoaderInterop(), checkKitScripts());
|
|
1485
1497
|
const uploadOnlyNote = checkUploadOnlyNote(ctx);
|
|
1486
1498
|
if (uploadOnlyNote) {
|
|
1487
1499
|
checks.push(uploadOnlyNote);
|
|
@@ -1892,71 +1904,48 @@ async function runBuild(ctx, options) {
|
|
|
1892
1904
|
}
|
|
1893
1905
|
|
|
1894
1906
|
// src/cli/commands/dev.ts
|
|
1895
|
-
import { existsSync as existsSync8 } from "fs";
|
|
1896
|
-
import { resolve as resolve11 } from "path";
|
|
1897
|
-
import { spawn } from "child_process";
|
|
1898
1907
|
async function runDev(ctx, options) {
|
|
1899
1908
|
const port = options.port ?? 3e3;
|
|
1909
|
+
const nodeWarning = nodeLoaderInteropWarning();
|
|
1910
|
+
if (nodeWarning) {
|
|
1911
|
+
ctx.logger.warn(nodeWarning);
|
|
1912
|
+
}
|
|
1900
1913
|
const env = {
|
|
1901
1914
|
...process.env,
|
|
1902
|
-
WP_HS_PROJECT_ROOT: ctx.projectRoot
|
|
1915
|
+
WP_HS_PROJECT_ROOT: ctx.projectRoot,
|
|
1916
|
+
WP_HS_DEV_PORT: String(port)
|
|
1903
1917
|
};
|
|
1904
|
-
const configPath = resolveDevViteConfigPath(ctx.projectRoot);
|
|
1905
|
-
const viteSpawn = resolveProjectViteSpawn(ctx.projectRoot);
|
|
1906
1918
|
if (ctx.global.dryRun) {
|
|
1907
|
-
|
|
1908
|
-
ctx.logger.info(`[dry-run] ${dryRunTarget} --config ${configPath} --port ${port}`);
|
|
1919
|
+
ctx.logger.info(`[dry-run] node ${kitPath("scripts", "run-dev.mjs")} (port ${port})`);
|
|
1909
1920
|
return ExitCode.SUCCESS;
|
|
1910
1921
|
}
|
|
1911
|
-
if (!
|
|
1922
|
+
if (!resolveProjectViteSpawn(ctx.projectRoot)) {
|
|
1912
1923
|
throw new WpHsError("vite is not installed in this project.", {
|
|
1913
1924
|
exitCode: ExitCode.PREREQUISITE,
|
|
1914
1925
|
remediation: "Run yarn install or npm install. If this is an older wp init project, add vite and peers to devDependencies (run wp init again or see @woodsportal/hubspot-kit templates)."
|
|
1915
1926
|
});
|
|
1916
1927
|
}
|
|
1917
|
-
const consumerConfig = resolve11(ctx.projectRoot, "vite.config.dev.mjs");
|
|
1918
|
-
if (!existsSync8(consumerConfig)) {
|
|
1919
|
-
throw new WpHsError("vite.config.dev.mjs is missing in the project root.", {
|
|
1920
|
-
exitCode: ExitCode.USER_ERROR,
|
|
1921
|
-
remediation: "Add vite.config.dev.mjs (see @woodsportal/hubspot-kit templates/module-hybrid-cdn)."
|
|
1922
|
-
});
|
|
1923
|
-
}
|
|
1924
1928
|
printWoodsCliDevBanner({
|
|
1925
1929
|
config: ctx.config,
|
|
1926
1930
|
port,
|
|
1927
1931
|
global: ctx.global
|
|
1928
1932
|
});
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
"--port",
|
|
1937
|
-
String(port),
|
|
1938
|
-
"--mode",
|
|
1939
|
-
"dev"
|
|
1940
|
-
],
|
|
1941
|
-
{
|
|
1942
|
-
cwd: ctx.projectRoot,
|
|
1943
|
-
env,
|
|
1944
|
-
stdio: "inherit"
|
|
1945
|
-
}
|
|
1946
|
-
);
|
|
1947
|
-
setImmediate(() => ensureHubSpotCliSetup(ctx, "local"));
|
|
1948
|
-
child.on("exit", (code) => {
|
|
1949
|
-
resolvePromise(code ?? ExitCode.USER_ERROR);
|
|
1950
|
-
});
|
|
1933
|
+
setImmediate(() => ensureHubSpotCliSetup(ctx, "local"));
|
|
1934
|
+
return runNodeScriptLongRunning(kitPath("scripts", "run-dev.mjs"), [], {
|
|
1935
|
+
cwd: ctx.projectRoot,
|
|
1936
|
+
env,
|
|
1937
|
+
logger: ctx.logger,
|
|
1938
|
+
dryRun: false,
|
|
1939
|
+
projectRoot: ctx.projectRoot
|
|
1951
1940
|
});
|
|
1952
1941
|
}
|
|
1953
1942
|
|
|
1954
1943
|
// src/cli/commands/deploy.ts
|
|
1955
|
-
import { resolve as
|
|
1944
|
+
import { resolve as resolve13 } from "path";
|
|
1956
1945
|
|
|
1957
1946
|
// src/lib/project-env-files.ts
|
|
1958
|
-
import { existsSync as
|
|
1959
|
-
import { resolve as
|
|
1947
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7, writeFileSync as writeFileSync2 } from "fs";
|
|
1948
|
+
import { resolve as resolve11 } from "path";
|
|
1960
1949
|
var ENV_LOCAL_FILE = ".env.local";
|
|
1961
1950
|
var ENV_GITIGNORE_LINES = [".env", ".env.*", "!.env*.example", ENV_LOCAL_FILE];
|
|
1962
1951
|
function parseEnvFile(content) {
|
|
@@ -1976,8 +1965,8 @@ function parseEnvFile(content) {
|
|
|
1976
1965
|
return result;
|
|
1977
1966
|
}
|
|
1978
1967
|
function readEnvLocal(projectRoot) {
|
|
1979
|
-
const path =
|
|
1980
|
-
if (!
|
|
1968
|
+
const path = resolve11(projectRoot, ENV_LOCAL_FILE);
|
|
1969
|
+
if (!existsSync8(path)) return {};
|
|
1981
1970
|
return parseEnvFile(readFileSync7(path, "utf8"));
|
|
1982
1971
|
}
|
|
1983
1972
|
function formatEnvLocal(entries) {
|
|
@@ -1997,8 +1986,8 @@ function formatEnvLocal(entries) {
|
|
|
1997
1986
|
`;
|
|
1998
1987
|
}
|
|
1999
1988
|
function writeEnvLocal(projectRoot, entries) {
|
|
2000
|
-
const path =
|
|
2001
|
-
const existing =
|
|
1989
|
+
const path = resolve11(projectRoot, ENV_LOCAL_FILE);
|
|
1990
|
+
const existing = existsSync8(path) ? parseEnvFile(readFileSync7(path, "utf8")) : {};
|
|
2002
1991
|
writeFileSync2(path, formatEnvLocal({ ...existing, ...entries }));
|
|
2003
1992
|
}
|
|
2004
1993
|
function mergeProjectEnv(projectRoot, base = process.env) {
|
|
@@ -2012,8 +2001,8 @@ function mergeProjectEnv(projectRoot, base = process.env) {
|
|
|
2012
2001
|
return merged;
|
|
2013
2002
|
}
|
|
2014
2003
|
function ensureEnvFilesGitignore(projectRoot) {
|
|
2015
|
-
const gitignorePath =
|
|
2016
|
-
const existing =
|
|
2004
|
+
const gitignorePath = resolve11(projectRoot, ".gitignore");
|
|
2005
|
+
const existing = existsSync8(gitignorePath) ? readFileSync7(gitignorePath, "utf8") : "";
|
|
2017
2006
|
const toAppend = ENV_GITIGNORE_LINES.filter((line) => !existing.includes(line)).join("\n");
|
|
2018
2007
|
if (!toAppend) return;
|
|
2019
2008
|
writeFileSync2(gitignorePath, `${existing.trimEnd()}
|
|
@@ -2024,14 +2013,14 @@ ${toAppend}
|
|
|
2024
2013
|
}
|
|
2025
2014
|
|
|
2026
2015
|
// src/cli/commands/upload.ts
|
|
2027
|
-
import { resolve as
|
|
2016
|
+
import { resolve as resolve12 } from "path";
|
|
2028
2017
|
async function uploadModuleOrTheme(ctx) {
|
|
2029
2018
|
if (isThemeProject(ctx.config)) {
|
|
2030
2019
|
const theme = ctx.config.theme;
|
|
2031
2020
|
if (!theme) {
|
|
2032
2021
|
throw new WpHsError("theme block missing in woodscli.json", { exitCode: ExitCode.USER_ERROR });
|
|
2033
2022
|
}
|
|
2034
|
-
const srcDir =
|
|
2023
|
+
const srcDir = resolve12(ctx.projectRoot, theme.srcDir);
|
|
2035
2024
|
await runCommandAsync("hs", ["cms", "upload", srcDir, theme.uploadPath], {
|
|
2036
2025
|
cwd: ctx.projectRoot,
|
|
2037
2026
|
projectRoot: ctx.projectRoot,
|
|
@@ -2041,7 +2030,7 @@ async function uploadModuleOrTheme(ctx) {
|
|
|
2041
2030
|
});
|
|
2042
2031
|
return `Uploaded theme ${srcDir} \u2192 ${theme.uploadPath}`;
|
|
2043
2032
|
}
|
|
2044
|
-
const outDir =
|
|
2033
|
+
const outDir = resolve12(ctx.projectRoot, ctx.config.module.outDir);
|
|
2045
2034
|
const uploadPath = ctx.config.module.uploadPath;
|
|
2046
2035
|
await runCommandAsync("hs", ["cms", "upload", outDir, uploadPath], {
|
|
2047
2036
|
cwd: ctx.projectRoot,
|
|
@@ -2209,7 +2198,7 @@ async function runDeploy(ctx, options) {
|
|
|
2209
2198
|
if (!ctx.global.json) {
|
|
2210
2199
|
printCommandDone(
|
|
2211
2200
|
ctx,
|
|
2212
|
-
`Deploy complete (${
|
|
2201
|
+
`Deploy complete (${resolve13(ctx.projectRoot, ctx.config.module.outDir)} \u2192 ${ctx.config.module.uploadPath})`
|
|
2213
2202
|
);
|
|
2214
2203
|
}
|
|
2215
2204
|
return ExitCode.SUCCESS;
|
|
@@ -2282,8 +2271,8 @@ async function runPublish(ctx, options) {
|
|
|
2282
2271
|
|
|
2283
2272
|
// src/cli/commands/audit.ts
|
|
2284
2273
|
import { createHash } from "crypto";
|
|
2285
|
-
import { cpSync, existsSync as
|
|
2286
|
-
import { resolve as
|
|
2274
|
+
import { cpSync, existsSync as existsSync9, mkdirSync as mkdirSync2, readFileSync as readFileSync8, readdirSync, rmSync, statSync } from "fs";
|
|
2275
|
+
import { resolve as resolve14, join as join2 } from "path";
|
|
2287
2276
|
var FORBIDDEN_SHIP_TOKENS = [
|
|
2288
2277
|
"ModuleConfigOverlay",
|
|
2289
2278
|
"module-config-store",
|
|
@@ -2295,7 +2284,7 @@ function hashFile(path) {
|
|
|
2295
2284
|
return createHash("sha256").update(readFileSync8(path)).digest("hex");
|
|
2296
2285
|
}
|
|
2297
2286
|
function walkFiles(dir) {
|
|
2298
|
-
if (!
|
|
2287
|
+
if (!existsSync9(dir)) return [];
|
|
2299
2288
|
const entries = readdirSync(dir);
|
|
2300
2289
|
const files = [];
|
|
2301
2290
|
for (const entry of entries) {
|
|
@@ -2311,8 +2300,8 @@ function walkFiles(dir) {
|
|
|
2311
2300
|
async function runAuditShipBundle(ctx) {
|
|
2312
2301
|
const root = ctx.projectRoot;
|
|
2313
2302
|
const targets = [
|
|
2314
|
-
|
|
2315
|
-
|
|
2303
|
+
resolve14(root, "dist/cdn"),
|
|
2304
|
+
resolve14(root, ctx.config.module.outDir)
|
|
2316
2305
|
];
|
|
2317
2306
|
const violations = [];
|
|
2318
2307
|
for (const dir of targets) {
|
|
@@ -2345,21 +2334,21 @@ async function runAuditBaselineCapture(ctx, options) {
|
|
|
2345
2334
|
const root = ctx.projectRoot;
|
|
2346
2335
|
const baseline = options.baselineDir ?? defaultBaselineDir(root, ctx.config);
|
|
2347
2336
|
const sources = [
|
|
2348
|
-
{ label: "cdn", path:
|
|
2349
|
-
{ label: "hubspot", path:
|
|
2337
|
+
{ label: "cdn", path: resolve14(root, "dist/cdn") },
|
|
2338
|
+
{ label: "hubspot", path: resolve14(root, ctx.config.module.outDir) }
|
|
2350
2339
|
];
|
|
2351
2340
|
if (ctx.global.dryRun) {
|
|
2352
2341
|
ctx.logger.info(`[dry-run] Would capture baseline to ${baseline}`);
|
|
2353
2342
|
return ExitCode.SUCCESS;
|
|
2354
2343
|
}
|
|
2355
2344
|
for (const { label, path } of sources) {
|
|
2356
|
-
if (!
|
|
2345
|
+
if (!existsSync9(path)) {
|
|
2357
2346
|
throw new WpHsError(`Cannot capture baseline \u2014 missing ${path}`, {
|
|
2358
2347
|
exitCode: ExitCode.USER_ERROR,
|
|
2359
2348
|
remediation: "Run wp build before wp audit baseline --capture."
|
|
2360
2349
|
});
|
|
2361
2350
|
}
|
|
2362
|
-
const target =
|
|
2351
|
+
const target = resolve14(baseline, label);
|
|
2363
2352
|
rmSync(target, { recursive: true, force: true });
|
|
2364
2353
|
mkdirSync2(baseline, { recursive: true });
|
|
2365
2354
|
cpSync(path, target, { recursive: true });
|
|
@@ -2375,13 +2364,13 @@ async function runAuditParity(ctx, options) {
|
|
|
2375
2364
|
const root = ctx.projectRoot;
|
|
2376
2365
|
const baseline = options.baselineDir ?? defaultBaselineDir(root, ctx.config);
|
|
2377
2366
|
const currentDirs = [
|
|
2378
|
-
{ label: "cdn", path:
|
|
2379
|
-
{ label: "hubspot", path:
|
|
2367
|
+
{ label: "cdn", path: resolve14(root, "dist/cdn") },
|
|
2368
|
+
{ label: "hubspot", path: resolve14(root, ctx.config.module.outDir) }
|
|
2380
2369
|
];
|
|
2381
2370
|
const mismatches = [];
|
|
2382
2371
|
for (const { label, path } of currentDirs) {
|
|
2383
|
-
const baselinePath =
|
|
2384
|
-
if (!
|
|
2372
|
+
const baselinePath = resolve14(baseline, label);
|
|
2373
|
+
if (!existsSync9(baselinePath)) {
|
|
2385
2374
|
ctx.logger.warn(`No baseline at ${baselinePath} \u2014 skipping ${label} parity`);
|
|
2386
2375
|
continue;
|
|
2387
2376
|
}
|
|
@@ -2396,8 +2385,8 @@ async function runAuditParity(ctx, options) {
|
|
|
2396
2385
|
}
|
|
2397
2386
|
for (const file of baselineFiles) {
|
|
2398
2387
|
const rel = file.replace(baselinePath, "");
|
|
2399
|
-
const current =
|
|
2400
|
-
if (!
|
|
2388
|
+
const current = resolve14(path, rel.slice(1));
|
|
2389
|
+
if (!existsSync9(current)) continue;
|
|
2401
2390
|
const bh = hashFile(file);
|
|
2402
2391
|
const ch = hashFile(current);
|
|
2403
2392
|
if (bh !== ch) {
|
|
@@ -2424,7 +2413,7 @@ var SECRET_PATTERNS = [
|
|
|
2424
2413
|
];
|
|
2425
2414
|
async function runAuditSecrets(ctx) {
|
|
2426
2415
|
const root = ctx.projectRoot;
|
|
2427
|
-
const scanRoots = ["src", "public", ".wphs/config"].map((d) =>
|
|
2416
|
+
const scanRoots = ["src", "public", ".wphs/config"].map((d) => resolve14(root, d));
|
|
2428
2417
|
const findings = [];
|
|
2429
2418
|
for (const dir of scanRoots) {
|
|
2430
2419
|
for (const file of walkFiles(dir)) {
|
|
@@ -2456,13 +2445,13 @@ async function runAuditSecrets(ctx) {
|
|
|
2456
2445
|
}
|
|
2457
2446
|
|
|
2458
2447
|
// src/cli/commands/init.ts
|
|
2459
|
-
import { cpSync as cpSync2, existsSync as
|
|
2460
|
-
import { basename as basename2, resolve as
|
|
2448
|
+
import { cpSync as cpSync2, existsSync as existsSync13, mkdirSync as mkdirSync4, readdirSync as readdirSync2, readFileSync as readFileSync11, writeFileSync as writeFileSync6 } from "fs";
|
|
2449
|
+
import { basename as basename2, resolve as resolve18 } from "path";
|
|
2461
2450
|
import * as p4 from "@clack/prompts";
|
|
2462
2451
|
|
|
2463
2452
|
// src/lib/init-router-scaffold.ts
|
|
2464
|
-
import { existsSync as
|
|
2465
|
-
import { resolve as
|
|
2453
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync3, readFileSync as readFileSync9, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
2454
|
+
import { resolve as resolve15 } from "path";
|
|
2466
2455
|
var ROUTER_FILES = [
|
|
2467
2456
|
"src/routes",
|
|
2468
2457
|
"src/routeTree.gen.ts",
|
|
@@ -2476,10 +2465,10 @@ function isModuleTemplate(template) {
|
|
|
2476
2465
|
return template === "module-hybrid-cdn" || template === "module-monolith";
|
|
2477
2466
|
}
|
|
2478
2467
|
function writeRouterConfig(targetDir, mode) {
|
|
2479
|
-
const configDir =
|
|
2468
|
+
const configDir = resolve15(targetDir, "src/config");
|
|
2480
2469
|
mkdirSync3(configDir, { recursive: true });
|
|
2481
2470
|
writeFileSync3(
|
|
2482
|
-
|
|
2471
|
+
resolve15(configDir, "router.ts"),
|
|
2483
2472
|
`/** Router history \u2014 set by \`wp init\`. Hash matches woodsportal-client-frontend (HubSpot CMS embeds). */
|
|
2484
2473
|
export type RouterHistoryMode = 'hash' | 'browser'
|
|
2485
2474
|
|
|
@@ -2489,7 +2478,7 @@ export const ROUTER_HISTORY: RouterHistoryMode = '${mode}'
|
|
|
2489
2478
|
}
|
|
2490
2479
|
function writeMountDevPreviewRouter(targetDir) {
|
|
2491
2480
|
writeFileSync3(
|
|
2492
|
-
|
|
2481
|
+
resolve15(targetDir, "src/portal/mount-dev-preview.tsx"),
|
|
2493
2482
|
`import { mountGreenfieldDev } from '../../.wphs/.kit-bootstrap-greenfield.tsx'
|
|
2494
2483
|
|
|
2495
2484
|
import { App } from '@/app'
|
|
@@ -2503,7 +2492,7 @@ export async function mountDevPreview() {
|
|
|
2503
2492
|
}
|
|
2504
2493
|
function writeMountDevPreviewSinglePage(targetDir) {
|
|
2505
2494
|
writeFileSync3(
|
|
2506
|
-
|
|
2495
|
+
resolve15(targetDir, "src/portal/mount-dev-preview.tsx"),
|
|
2507
2496
|
`import { mountGreenfieldDev } from '../../.wphs/.kit-bootstrap-greenfield.tsx'
|
|
2508
2497
|
|
|
2509
2498
|
import { StarterSinglePage } from '@/features/starter'
|
|
@@ -2517,7 +2506,7 @@ export async function mountDevPreview() {
|
|
|
2517
2506
|
}
|
|
2518
2507
|
function writeMountPortalRouter(targetDir) {
|
|
2519
2508
|
writeFileSync3(
|
|
2520
|
-
|
|
2509
|
+
resolve15(targetDir, "src/portal/mount-portal.tsx"),
|
|
2521
2510
|
`import ReactDOM from 'react-dom/client'
|
|
2522
2511
|
|
|
2523
2512
|
import { App } from '@/app'
|
|
@@ -2535,7 +2524,7 @@ export async function mountPortal() {
|
|
|
2535
2524
|
}
|
|
2536
2525
|
function writeMountPortalSinglePage(targetDir) {
|
|
2537
2526
|
writeFileSync3(
|
|
2538
|
-
|
|
2527
|
+
resolve15(targetDir, "src/portal/mount-portal.tsx"),
|
|
2539
2528
|
`import ReactDOM from 'react-dom/client'
|
|
2540
2529
|
|
|
2541
2530
|
import { StarterSinglePage } from '@/features/starter'
|
|
@@ -2552,8 +2541,8 @@ export async function mountPortal() {
|
|
|
2552
2541
|
);
|
|
2553
2542
|
}
|
|
2554
2543
|
function writeStarterSinglePage(targetDir) {
|
|
2555
|
-
const file =
|
|
2556
|
-
if (
|
|
2544
|
+
const file = resolve15(targetDir, "src/features/starter/components/starter-single-page.tsx");
|
|
2545
|
+
if (existsSync10(file)) {
|
|
2557
2546
|
return;
|
|
2558
2547
|
}
|
|
2559
2548
|
writeFileSync3(
|
|
@@ -2579,15 +2568,15 @@ export function StarterSinglePage() {
|
|
|
2579
2568
|
);
|
|
2580
2569
|
}
|
|
2581
2570
|
function removePath(targetDir, relativePath) {
|
|
2582
|
-
const full =
|
|
2583
|
-
if (!
|
|
2571
|
+
const full = resolve15(targetDir, relativePath);
|
|
2572
|
+
if (!existsSync10(full)) {
|
|
2584
2573
|
return;
|
|
2585
2574
|
}
|
|
2586
2575
|
rmSync2(full, { recursive: true, force: true });
|
|
2587
2576
|
}
|
|
2588
2577
|
function stripTanStackFromPackage(targetDir) {
|
|
2589
|
-
const pkgPath =
|
|
2590
|
-
if (!
|
|
2578
|
+
const pkgPath = resolve15(targetDir, "package.json");
|
|
2579
|
+
if (!existsSync10(pkgPath)) {
|
|
2591
2580
|
return;
|
|
2592
2581
|
}
|
|
2593
2582
|
const pkg = JSON.parse(readFileSync9(pkgPath, "utf8"));
|
|
@@ -2617,8 +2606,8 @@ function applyRouterScaffold(targetDir, mode, template) {
|
|
|
2617
2606
|
writeRouterConfig(targetDir, mode);
|
|
2618
2607
|
writeMountDevPreviewRouter(targetDir);
|
|
2619
2608
|
writeMountPortalRouter(targetDir);
|
|
2620
|
-
const featuresIndex =
|
|
2621
|
-
if (
|
|
2609
|
+
const featuresIndex = resolve15(targetDir, "src/features/starter/index.ts");
|
|
2610
|
+
if (existsSync10(featuresIndex)) {
|
|
2622
2611
|
let content = readFileSync9(featuresIndex, "utf8");
|
|
2623
2612
|
if (!content.includes("StarterSinglePage")) {
|
|
2624
2613
|
content = content.replace(
|
|
@@ -2631,15 +2620,15 @@ function applyRouterScaffold(targetDir, mode, template) {
|
|
|
2631
2620
|
}
|
|
2632
2621
|
|
|
2633
2622
|
// src/lib/cdn-github-setup.ts
|
|
2634
|
-
import { existsSync as
|
|
2635
|
-
import { resolve as
|
|
2623
|
+
import { existsSync as existsSync11, readFileSync as readFileSync10, writeFileSync as writeFileSync4 } from "fs";
|
|
2624
|
+
import { resolve as resolve16 } from "path";
|
|
2636
2625
|
import * as p3 from "@clack/prompts";
|
|
2637
2626
|
var PORTAL_CDN_PUBLISH_TOKEN_ENV = "PORTAL_CDN_PUBLISH_TOKEN";
|
|
2638
2627
|
var PORTAL_CDN_JSON = "portal.cdn.json";
|
|
2639
2628
|
var PLACEHOLDER_GITHUB = /your-org|your-portal-cdn-mirror/i;
|
|
2640
2629
|
function defaultPortalCdnJson() {
|
|
2641
2630
|
const examplePath = kitPath("templates", "shared", "portal.cdn.json.example");
|
|
2642
|
-
if (
|
|
2631
|
+
if (existsSync11(examplePath)) {
|
|
2643
2632
|
return JSON.parse(readFileSync10(examplePath, "utf8"));
|
|
2644
2633
|
}
|
|
2645
2634
|
return {
|
|
@@ -2651,8 +2640,8 @@ function defaultPortalCdnJson() {
|
|
|
2651
2640
|
};
|
|
2652
2641
|
}
|
|
2653
2642
|
function readPortalCdnJson(projectRoot) {
|
|
2654
|
-
const path =
|
|
2655
|
-
if (!
|
|
2643
|
+
const path = resolve16(projectRoot, PORTAL_CDN_JSON);
|
|
2644
|
+
if (!existsSync11(path)) return null;
|
|
2656
2645
|
try {
|
|
2657
2646
|
return JSON.parse(readFileSync10(path, "utf8"));
|
|
2658
2647
|
} catch {
|
|
@@ -2701,7 +2690,7 @@ function needsCdnGitHubSetup(projectRoot) {
|
|
|
2701
2690
|
function applyCdnGitHubSetup(projectRoot, input) {
|
|
2702
2691
|
const existing = readPortalCdnJson(projectRoot) ?? defaultPortalCdnJson();
|
|
2703
2692
|
const updated = portalCdnJsonFromGithub(input.github, existing);
|
|
2704
|
-
writeFileSync4(
|
|
2693
|
+
writeFileSync4(resolve16(projectRoot, PORTAL_CDN_JSON), `${JSON.stringify(updated, null, 2)}
|
|
2705
2694
|
`);
|
|
2706
2695
|
if (input.token?.trim()) {
|
|
2707
2696
|
writeEnvLocal(projectRoot, { [PORTAL_CDN_PUBLISH_TOKEN_ENV]: input.token.trim() });
|
|
@@ -2750,8 +2739,8 @@ function formatCdnSetupNote(_projectRoot) {
|
|
|
2750
2739
|
}
|
|
2751
2740
|
|
|
2752
2741
|
// src/lib/project-setup.ts
|
|
2753
|
-
import { copyFileSync, existsSync as
|
|
2754
|
-
import { basename, resolve as
|
|
2742
|
+
import { copyFileSync, existsSync as existsSync12, writeFileSync as writeFileSync5 } from "fs";
|
|
2743
|
+
import { basename, resolve as resolve17 } from "path";
|
|
2755
2744
|
function envFileForTier(tier) {
|
|
2756
2745
|
return tier === "dev" ? ".env.dev" : tier === "stg" ? ".env.stg" : ".env.prod";
|
|
2757
2746
|
}
|
|
@@ -2761,13 +2750,13 @@ function tiersToSetup(config, tier) {
|
|
|
2761
2750
|
}
|
|
2762
2751
|
function firstExisting(paths) {
|
|
2763
2752
|
for (const path of paths) {
|
|
2764
|
-
if (
|
|
2753
|
+
if (existsSync12(path)) return path;
|
|
2765
2754
|
}
|
|
2766
2755
|
return null;
|
|
2767
2756
|
}
|
|
2768
2757
|
function copyMissingFile(projectRoot, targetName, sourceCandidates, dryRun) {
|
|
2769
|
-
const target =
|
|
2770
|
-
if (
|
|
2758
|
+
const target = resolve17(projectRoot, targetName);
|
|
2759
|
+
if (existsSync12(target)) {
|
|
2771
2760
|
return { action: "skipped", path: targetName, detail: "already present" };
|
|
2772
2761
|
}
|
|
2773
2762
|
const source = firstExisting(sourceCandidates);
|
|
@@ -2789,8 +2778,8 @@ function copyMissingFile(projectRoot, targetName, sourceCandidates, dryRun) {
|
|
|
2789
2778
|
};
|
|
2790
2779
|
}
|
|
2791
2780
|
function writeMissingFile(projectRoot, targetName, content, dryRun) {
|
|
2792
|
-
const target =
|
|
2793
|
-
if (
|
|
2781
|
+
const target = resolve17(projectRoot, targetName);
|
|
2782
|
+
if (existsSync12(target)) {
|
|
2794
2783
|
return { action: "skipped", path: targetName, detail: "already present" };
|
|
2795
2784
|
}
|
|
2796
2785
|
if (!dryRun) {
|
|
@@ -2820,8 +2809,8 @@ function applyProjectSetup(ctx, options = {}) {
|
|
|
2820
2809
|
const templateDir = kitTemplateDir(config);
|
|
2821
2810
|
results.push(
|
|
2822
2811
|
copyMissingFile(projectRoot, HUBSPOT_CONFIG_FILE, [
|
|
2823
|
-
|
|
2824
|
-
|
|
2812
|
+
resolve17(projectRoot, HUBSPOT_CONFIG_EXAMPLE),
|
|
2813
|
+
resolve17(templateDir, HUBSPOT_CONFIG_EXAMPLE),
|
|
2825
2814
|
kitPath("templates", HUBSPOT_CONFIG_EXAMPLE)
|
|
2826
2815
|
], dryRun)
|
|
2827
2816
|
);
|
|
@@ -2830,8 +2819,8 @@ function applyProjectSetup(ctx, options = {}) {
|
|
|
2830
2819
|
const envExample = `${envFile}.example`;
|
|
2831
2820
|
results.push(
|
|
2832
2821
|
copyMissingFile(projectRoot, envFile, [
|
|
2833
|
-
|
|
2834
|
-
|
|
2822
|
+
resolve17(projectRoot, envExample),
|
|
2823
|
+
resolve17(sharedDir, envExample)
|
|
2835
2824
|
], dryRun)
|
|
2836
2825
|
);
|
|
2837
2826
|
}
|
|
@@ -2839,8 +2828,8 @@ function applyProjectSetup(ctx, options = {}) {
|
|
|
2839
2828
|
const mirror = config.cdn.mirror;
|
|
2840
2829
|
results.push(
|
|
2841
2830
|
copyMissingFile(projectRoot, mirror, [
|
|
2842
|
-
|
|
2843
|
-
|
|
2831
|
+
resolve17(projectRoot, `${mirror}.example`),
|
|
2832
|
+
resolve17(sharedDir, "portal.cdn.json.example")
|
|
2844
2833
|
], dryRun)
|
|
2845
2834
|
);
|
|
2846
2835
|
const buildIdFile = config.cdn.buildIdFile;
|
|
@@ -2855,15 +2844,15 @@ function applyProjectSetup(ctx, options = {}) {
|
|
|
2855
2844
|
}
|
|
2856
2845
|
for (const file of templateViteFiles(config)) {
|
|
2857
2846
|
results.push(
|
|
2858
|
-
copyMissingFile(projectRoot, file, [
|
|
2847
|
+
copyMissingFile(projectRoot, file, [resolve17(templateDir, file)], dryRun)
|
|
2859
2848
|
);
|
|
2860
2849
|
}
|
|
2861
2850
|
if (isModuleProject(config) && !isThemeProject(config)) {
|
|
2862
2851
|
const adapter = config.dev.adapter;
|
|
2863
|
-
const adapterPath =
|
|
2864
|
-
if (!
|
|
2865
|
-
const templateAdapter =
|
|
2866
|
-
if (
|
|
2852
|
+
const adapterPath = resolve17(projectRoot, adapter);
|
|
2853
|
+
if (!existsSync12(adapterPath)) {
|
|
2854
|
+
const templateAdapter = resolve17(templateDir, "wphs.adapter.ts");
|
|
2855
|
+
if (existsSync12(templateAdapter)) {
|
|
2867
2856
|
results.push(copyMissingFile(projectRoot, adapter, [templateAdapter], dryRun));
|
|
2868
2857
|
} else {
|
|
2869
2858
|
results.push({
|
|
@@ -2880,26 +2869,26 @@ function applyProjectSetup(ctx, options = {}) {
|
|
|
2880
2869
|
}
|
|
2881
2870
|
function copySharedSetupExamples(targetDir) {
|
|
2882
2871
|
const sharedDir = kitPath("templates", "shared");
|
|
2883
|
-
if (!
|
|
2872
|
+
if (!existsSync12(sharedDir)) return;
|
|
2884
2873
|
for (const name of [
|
|
2885
2874
|
".env.dev.example",
|
|
2886
2875
|
".env.stg.example",
|
|
2887
2876
|
".env.prod.example",
|
|
2888
2877
|
"portal.cdn.json.example"
|
|
2889
2878
|
]) {
|
|
2890
|
-
const src =
|
|
2891
|
-
const dest =
|
|
2892
|
-
if (
|
|
2879
|
+
const src = resolve17(sharedDir, name);
|
|
2880
|
+
const dest = resolve17(targetDir, name);
|
|
2881
|
+
if (existsSync12(src) && !existsSync12(dest)) {
|
|
2893
2882
|
copyFileSync(src, dest);
|
|
2894
2883
|
}
|
|
2895
2884
|
}
|
|
2896
2885
|
const hubspotExample = firstExisting([
|
|
2897
|
-
|
|
2886
|
+
resolve17(sharedDir, HUBSPOT_CONFIG_EXAMPLE),
|
|
2898
2887
|
kitPath("templates", HUBSPOT_CONFIG_EXAMPLE)
|
|
2899
2888
|
]);
|
|
2900
2889
|
if (!hubspotExample) return;
|
|
2901
|
-
const destHubspot =
|
|
2902
|
-
if (!
|
|
2890
|
+
const destHubspot = resolve17(targetDir, HUBSPOT_CONFIG_EXAMPLE);
|
|
2891
|
+
if (!existsSync12(destHubspot) && !existsSync12(resolve17(targetDir, HUBSPOT_CONFIG_FILE))) {
|
|
2903
2892
|
copyFileSync(hubspotExample, destHubspot);
|
|
2904
2893
|
}
|
|
2905
2894
|
}
|
|
@@ -2997,7 +2986,7 @@ function buildConfigForProject(template, projectName, router) {
|
|
|
2997
2986
|
return config;
|
|
2998
2987
|
}
|
|
2999
2988
|
function assertTargetDirIsScaffoldable(targetDir) {
|
|
3000
|
-
if (!
|
|
2989
|
+
if (!existsSync13(targetDir)) return;
|
|
3001
2990
|
const entries = readdirSync2(targetDir).filter((entry) => entry !== ".DS_Store");
|
|
3002
2991
|
if (entries.length > 0) {
|
|
3003
2992
|
throw new WpHsError(`Target directory is not empty: ${targetDir}`, {
|
|
@@ -3008,7 +2997,7 @@ function assertTargetDirIsScaffoldable(targetDir) {
|
|
|
3008
2997
|
}
|
|
3009
2998
|
function resolveInitTargetDir(options, interactiveName) {
|
|
3010
2999
|
if (options.directory) {
|
|
3011
|
-
return
|
|
3000
|
+
return resolve18(options.directory);
|
|
3012
3001
|
}
|
|
3013
3002
|
const parentDir = process.cwd();
|
|
3014
3003
|
const slug = options.name ?? interactiveName;
|
|
@@ -3022,7 +3011,7 @@ function resolveInitTargetDir(options, interactiveName) {
|
|
|
3022
3011
|
if (error) {
|
|
3023
3012
|
throw new WpHsError(error, { exitCode: ExitCode.USER_ERROR });
|
|
3024
3013
|
}
|
|
3025
|
-
return
|
|
3014
|
+
return resolve18(parentDir, slug);
|
|
3026
3015
|
}
|
|
3027
3016
|
async function runInit(ctx, options) {
|
|
3028
3017
|
const nonInteractive = ctx.global.ci || ctx.global.yes || ctx.global.json;
|
|
@@ -3095,7 +3084,7 @@ async function runInit(ctx, options) {
|
|
|
3095
3084
|
const slug = projectName ?? basename2(targetDir);
|
|
3096
3085
|
assertTargetDirIsScaffoldable(targetDir);
|
|
3097
3086
|
const templateDir = kitPath("templates", template);
|
|
3098
|
-
if (!
|
|
3087
|
+
if (!existsSync13(templateDir)) {
|
|
3099
3088
|
throw new WpHsError(`Template not found: ${template}`, { exitCode: ExitCode.USER_ERROR });
|
|
3100
3089
|
}
|
|
3101
3090
|
if (ctx.global.dryRun) {
|
|
@@ -3106,10 +3095,10 @@ async function runInit(ctx, options) {
|
|
|
3106
3095
|
cpSync2(templateDir, targetDir, { recursive: true });
|
|
3107
3096
|
copySharedSetupExamples(targetDir);
|
|
3108
3097
|
const config = buildConfigForProject(template, slug, router);
|
|
3109
|
-
writeFileSync6(
|
|
3098
|
+
writeFileSync6(resolve18(targetDir, WOODSCLI_CONFIG_FILE), `${JSON.stringify(config, null, 2)}
|
|
3110
3099
|
`);
|
|
3111
|
-
const pkgPath =
|
|
3112
|
-
if (
|
|
3100
|
+
const pkgPath = resolve18(targetDir, "package.json");
|
|
3101
|
+
if (existsSync13(pkgPath)) {
|
|
3113
3102
|
const pkg = JSON.parse(readFileSync11(pkgPath, "utf8"));
|
|
3114
3103
|
pkg.name = slug;
|
|
3115
3104
|
pkg.scripts = { ...pkg.scripts, ...TEMPLATE_SCRIPTS[template] };
|
|
@@ -3128,7 +3117,7 @@ async function runInit(ctx, options) {
|
|
|
3128
3117
|
logger: ctx.logger,
|
|
3129
3118
|
dryRun: false
|
|
3130
3119
|
});
|
|
3131
|
-
const gitignorePath =
|
|
3120
|
+
const gitignorePath = resolve18(targetDir, ".gitignore");
|
|
3132
3121
|
const gitignoreExtras = [
|
|
3133
3122
|
"hubspot.config.yml",
|
|
3134
3123
|
".wphs/config/module-config.local.json",
|
|
@@ -3141,7 +3130,7 @@ async function runInit(ctx, options) {
|
|
|
3141
3130
|
".wphs/.kit-bootstrap.tsx",
|
|
3142
3131
|
".wphs/.kit-bootstrap-greenfield.tsx"
|
|
3143
3132
|
];
|
|
3144
|
-
const existing =
|
|
3133
|
+
const existing = existsSync13(gitignorePath) ? readFileSync11(gitignorePath, "utf8") : "";
|
|
3145
3134
|
const toAppend = gitignoreExtras.filter((line) => !existing.includes(line)).join("\n");
|
|
3146
3135
|
if (toAppend) {
|
|
3147
3136
|
writeFileSync6(gitignorePath, `${existing.trimEnd()}
|
|
@@ -3182,14 +3171,14 @@ ${toAppend}
|
|
|
3182
3171
|
}
|
|
3183
3172
|
|
|
3184
3173
|
// src/cli/commands/migrate.ts
|
|
3185
|
-
import { cpSync as cpSync3, existsSync as
|
|
3186
|
-
import { join as join3, resolve as
|
|
3174
|
+
import { cpSync as cpSync3, existsSync as existsSync14, mkdirSync as mkdirSync5, readFileSync as readFileSync12, readdirSync as readdirSync3, renameSync, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "fs";
|
|
3175
|
+
import { join as join3, resolve as resolve19 } from "path";
|
|
3187
3176
|
var LEGACY_DIRS = [".dev", ".woodsportal"];
|
|
3188
3177
|
var LEGACY_BASELINE = ".wp-hs-baseline";
|
|
3189
3178
|
var LEGACY_BUILD_ID_FILE = ".portal-build-id";
|
|
3190
3179
|
var MODULE_BUILD_ID_FILE = ".module-build-id";
|
|
3191
3180
|
function readFirstNonCommentLine(filePath) {
|
|
3192
|
-
if (!
|
|
3181
|
+
if (!existsSync14(filePath)) return void 0;
|
|
3193
3182
|
const line = readFileSync12(filePath, "utf8").split("\n").map((l) => l.trim()).find((l) => l.length > 0 && !l.startsWith("#"));
|
|
3194
3183
|
return line || void 0;
|
|
3195
3184
|
}
|
|
@@ -3204,34 +3193,34 @@ function stripToBaseline(raw) {
|
|
|
3204
3193
|
}
|
|
3205
3194
|
async function runMigrate(ctx, _options = {}) {
|
|
3206
3195
|
const root = ctx.projectRoot;
|
|
3207
|
-
const wphsRoot =
|
|
3196
|
+
const wphsRoot = resolve19(root, WPHS_WORKSPACE_DIR);
|
|
3208
3197
|
const actions = [];
|
|
3209
3198
|
for (const legacy of LEGACY_DIRS) {
|
|
3210
|
-
const legacyPath =
|
|
3211
|
-
if (!
|
|
3199
|
+
const legacyPath = resolve19(root, legacy);
|
|
3200
|
+
if (!existsSync14(legacyPath)) continue;
|
|
3212
3201
|
actions.push(`Move ${legacy}/ \u2192 .wphs/`);
|
|
3213
3202
|
if (ctx.global.dryRun) continue;
|
|
3214
3203
|
mkdirSync5(join3(wphsRoot, "config"), { recursive: true });
|
|
3215
3204
|
mkdirSync5(join3(wphsRoot, "assets", "branding"), { recursive: true });
|
|
3216
3205
|
const localConfig = join3(legacyPath, "module-config.local.json");
|
|
3217
3206
|
const exampleConfig = join3(legacyPath, "module-config.example.json");
|
|
3218
|
-
if (
|
|
3207
|
+
if (existsSync14(localConfig)) {
|
|
3219
3208
|
cpSync3(localConfig, join3(wphsRoot, "config", "module-config.local.json"));
|
|
3220
3209
|
}
|
|
3221
|
-
if (
|
|
3210
|
+
if (existsSync14(exampleConfig)) {
|
|
3222
3211
|
cpSync3(exampleConfig, join3(wphsRoot, "config", "module-config.example.json"));
|
|
3223
3212
|
}
|
|
3224
3213
|
const branding = join3(legacyPath, "branding-assets");
|
|
3225
|
-
if (
|
|
3214
|
+
if (existsSync14(branding)) {
|
|
3226
3215
|
for (const file of readdirSync3(branding)) {
|
|
3227
3216
|
cpSync3(join3(branding, file), join3(wphsRoot, "assets", "branding", file));
|
|
3228
3217
|
}
|
|
3229
3218
|
}
|
|
3230
3219
|
rmSync3(legacyPath, { recursive: true, force: true });
|
|
3231
3220
|
}
|
|
3232
|
-
const legacyBaseline =
|
|
3221
|
+
const legacyBaseline = resolve19(root, LEGACY_BASELINE);
|
|
3233
3222
|
const targetBaseline = join3(wphsRoot, "audit", "baseline");
|
|
3234
|
-
if (
|
|
3223
|
+
if (existsSync14(legacyBaseline)) {
|
|
3235
3224
|
actions.push(`Move ${LEGACY_BASELINE}/ \u2192 .wphs/audit/baseline/`);
|
|
3236
3225
|
if (!ctx.global.dryRun) {
|
|
3237
3226
|
mkdirSync5(targetBaseline, { recursive: true });
|
|
@@ -3239,22 +3228,22 @@ async function runMigrate(ctx, _options = {}) {
|
|
|
3239
3228
|
rmSync3(legacyBaseline, { recursive: true, force: true });
|
|
3240
3229
|
}
|
|
3241
3230
|
}
|
|
3242
|
-
const legacyConfigPath2 =
|
|
3243
|
-
const woodscliPath =
|
|
3244
|
-
if (
|
|
3231
|
+
const legacyConfigPath2 = resolve19(root, LEGACY_WOODSPORTAL_HS_FILE);
|
|
3232
|
+
const woodscliPath = resolve19(root, WOODSCLI_CONFIG_FILE);
|
|
3233
|
+
if (existsSync14(legacyConfigPath2) && !existsSync14(woodscliPath)) {
|
|
3245
3234
|
actions.push(`Rename ${LEGACY_WOODSPORTAL_HS_FILE} \u2192 ${WOODSCLI_CONFIG_FILE}`);
|
|
3246
3235
|
if (!ctx.global.dryRun) {
|
|
3247
3236
|
renameSync(legacyConfigPath2, woodscliPath);
|
|
3248
3237
|
}
|
|
3249
|
-
} else if (
|
|
3238
|
+
} else if (existsSync14(legacyConfigPath2) && existsSync14(woodscliPath)) {
|
|
3250
3239
|
actions.push(`Remove duplicate ${LEGACY_WOODSPORTAL_HS_FILE}`);
|
|
3251
3240
|
if (!ctx.global.dryRun) {
|
|
3252
3241
|
rmSync3(legacyConfigPath2, { force: true });
|
|
3253
3242
|
}
|
|
3254
3243
|
}
|
|
3255
|
-
const legacyBuildIdPath =
|
|
3256
|
-
const moduleBuildIdPath =
|
|
3257
|
-
if (
|
|
3244
|
+
const legacyBuildIdPath = resolve19(root, LEGACY_BUILD_ID_FILE);
|
|
3245
|
+
const moduleBuildIdPath = resolve19(root, MODULE_BUILD_ID_FILE);
|
|
3246
|
+
if (existsSync14(legacyBuildIdPath) && !existsSync14(moduleBuildIdPath)) {
|
|
3258
3247
|
const baseline = stripToBaseline(readFirstNonCommentLine(legacyBuildIdPath)) ?? "v0.0.1-dev";
|
|
3259
3248
|
actions.push(`Migrate ${LEGACY_BUILD_ID_FILE} \u2192 ${MODULE_BUILD_ID_FILE} (baseline ${baseline})`);
|
|
3260
3249
|
if (!ctx.global.dryRun) {
|
|
@@ -3267,7 +3256,7 @@ ${baseline}
|
|
|
3267
3256
|
rmSync3(legacyBuildIdPath, { force: true });
|
|
3268
3257
|
}
|
|
3269
3258
|
}
|
|
3270
|
-
if (
|
|
3259
|
+
if (existsSync14(woodscliPath)) {
|
|
3271
3260
|
const raw = JSON.parse(readFileSync12(woodscliPath, "utf8"));
|
|
3272
3261
|
let configChanged = false;
|
|
3273
3262
|
if (raw?.dev?.moduleConfigDir && raw.dev.moduleConfigDir !== WPHS_WORKSPACE_DIR) {
|
|
@@ -3349,15 +3338,15 @@ async function runExamplesSmoke(ctx, options = {}) {
|
|
|
3349
3338
|
}
|
|
3350
3339
|
|
|
3351
3340
|
// src/cli/commands/fields.ts
|
|
3352
|
-
import { cpSync as cpSync4, existsSync as
|
|
3353
|
-
import { resolve as
|
|
3341
|
+
import { cpSync as cpSync4, existsSync as existsSync15, readFileSync as readFileSync14, writeFileSync as writeFileSync8 } from "fs";
|
|
3342
|
+
import { resolve as resolve20 } from "path";
|
|
3354
3343
|
async function runFieldsSync(ctx, options = {}) {
|
|
3355
3344
|
const direction = options.direction ?? "pull";
|
|
3356
|
-
const fieldsPath =
|
|
3357
|
-
const cacheDir =
|
|
3358
|
-
const cachePath =
|
|
3345
|
+
const fieldsPath = resolve20(ctx.projectRoot, ctx.config.dev.fieldsJson);
|
|
3346
|
+
const cacheDir = resolve20(ctx.projectRoot, ctx.config.dev.moduleConfigDir, "cache", "fields-sync");
|
|
3347
|
+
const cachePath = resolve20(cacheDir, "fields.json");
|
|
3359
3348
|
if (direction === "pull") {
|
|
3360
|
-
if (!
|
|
3349
|
+
if (!existsSync15(fieldsPath)) {
|
|
3361
3350
|
throw new WpHsError(`Missing ${ctx.config.dev.fieldsJson}`, {
|
|
3362
3351
|
exitCode: ExitCode.USER_ERROR,
|
|
3363
3352
|
remediation: "Add fields.json or run wp init."
|
|
@@ -3373,7 +3362,7 @@ async function runFieldsSync(ctx, options = {}) {
|
|
|
3373
3362
|
ctx.logger.success(`Cached fields \u2192 ${cachePath}`);
|
|
3374
3363
|
return ExitCode.SUCCESS;
|
|
3375
3364
|
}
|
|
3376
|
-
if (!
|
|
3365
|
+
if (!existsSync15(cachePath)) {
|
|
3377
3366
|
throw new WpHsError("No cached fields \u2014 run wp fields sync pull first.", {
|
|
3378
3367
|
exitCode: ExitCode.USER_ERROR
|
|
3379
3368
|
});
|
|
@@ -3388,8 +3377,8 @@ async function runFieldsSync(ctx, options = {}) {
|
|
|
3388
3377
|
}
|
|
3389
3378
|
|
|
3390
3379
|
// src/cli/commands/regression.ts
|
|
3391
|
-
import { existsSync as
|
|
3392
|
-
import { resolve as
|
|
3380
|
+
import { existsSync as existsSync16 } from "fs";
|
|
3381
|
+
import { resolve as resolve21 } from "path";
|
|
3393
3382
|
var LEGACY_SHIM_SCRIPTS = [
|
|
3394
3383
|
"build-cdn.mjs",
|
|
3395
3384
|
"run-vite-build.mjs",
|
|
@@ -3412,21 +3401,21 @@ async function runRegressionSmoke(ctx, options = {}) {
|
|
|
3412
3401
|
if (!validateOk) failures.push("wp config validate failed");
|
|
3413
3402
|
if (options.checkLegacyShims !== false) {
|
|
3414
3403
|
for (const script of LEGACY_SHIM_SCRIPTS) {
|
|
3415
|
-
const shim =
|
|
3404
|
+
const shim = resolve21(ctx.projectRoot, "scripts", script);
|
|
3416
3405
|
const kitScript = kitPath("scripts", script);
|
|
3417
|
-
const shimOk =
|
|
3406
|
+
const shimOk = existsSync16(shim) && existsSync16(kitScript);
|
|
3418
3407
|
checks.push({ name: `shim:${script}`, ok: shimOk });
|
|
3419
3408
|
if (!shimOk) failures.push(`Missing legacy shim or kit script: ${script}`);
|
|
3420
3409
|
}
|
|
3421
3410
|
}
|
|
3422
3411
|
for (const rel of FORBIDDEN_CONSUMER_PATHS) {
|
|
3423
|
-
const forbidden =
|
|
3424
|
-
const absent = !
|
|
3412
|
+
const forbidden = resolve21(ctx.projectRoot, rel);
|
|
3413
|
+
const absent = !existsSync16(forbidden);
|
|
3425
3414
|
checks.push({ name: `no-${rel}`, ok: absent });
|
|
3426
3415
|
if (!absent) failures.push(`Forbidden dev path still present: ${rel}`);
|
|
3427
3416
|
}
|
|
3428
|
-
const woodscliConfig =
|
|
3429
|
-
const configOk =
|
|
3417
|
+
const woodscliConfig = resolve21(ctx.projectRoot, WOODSCLI_CONFIG_FILE);
|
|
3418
|
+
const configOk = existsSync16(woodscliConfig);
|
|
3430
3419
|
checks.push({ name: WOODSCLI_CONFIG_FILE, ok: configOk });
|
|
3431
3420
|
if (!configOk) failures.push(`${WOODSCLI_CONFIG_FILE} missing`);
|
|
3432
3421
|
if (ctx.global.json) {
|
|
@@ -3539,8 +3528,8 @@ async function runSetup(ctx, options = {}) {
|
|
|
3539
3528
|
import * as p5 from "@clack/prompts";
|
|
3540
3529
|
|
|
3541
3530
|
// src/lib/hubspot-portals.ts
|
|
3542
|
-
import { existsSync as
|
|
3543
|
-
import { resolve as
|
|
3531
|
+
import { existsSync as existsSync17, readFileSync as readFileSync15 } from "fs";
|
|
3532
|
+
import { resolve as resolve22 } from "path";
|
|
3544
3533
|
function stripYamlScalar(value) {
|
|
3545
3534
|
const trimmed = value.trim();
|
|
3546
3535
|
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
@@ -3578,8 +3567,8 @@ function parseHubSpotConfigPortals(raw) {
|
|
|
3578
3567
|
return { defaultPortal, portals };
|
|
3579
3568
|
}
|
|
3580
3569
|
function readHubSpotPortals(projectRoot) {
|
|
3581
|
-
const configPath =
|
|
3582
|
-
if (!
|
|
3570
|
+
const configPath = resolve22(projectRoot, HUBSPOT_CONFIG_FILE);
|
|
3571
|
+
if (!existsSync17(configPath)) {
|
|
3583
3572
|
throw new WpHsError(`${HUBSPOT_CONFIG_FILE} not found in project root.`, {
|
|
3584
3573
|
exitCode: ExitCode.USER_ERROR,
|
|
3585
3574
|
remediation: "Run wp setup, then add your portal + PAT."
|
|
@@ -3715,7 +3704,7 @@ async function runWatch(ctx, options) {
|
|
|
3715
3704
|
// src/cli/program.ts
|
|
3716
3705
|
function readVersion() {
|
|
3717
3706
|
try {
|
|
3718
|
-
const pkg = JSON.parse(readFileSync16(
|
|
3707
|
+
const pkg = JSON.parse(readFileSync16(resolve23(getKitRoot(), "package.json"), "utf8"));
|
|
3719
3708
|
return pkg.version ?? "0.0.0";
|
|
3720
3709
|
} catch {
|
|
3721
3710
|
return "0.0.0";
|