fix: local site url from env + cwd
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { basename, join } from "node:path";
|
||||||
import { consola } from "consola";
|
import { consola } from "consola";
|
||||||
import prompts from "prompts";
|
import prompts from "prompts";
|
||||||
import type { WPopContext } from "../lib/context";
|
import type { WPopContext } from "../lib/context";
|
||||||
@@ -74,7 +74,7 @@ export async function sync(context: WPopContext, options: SyncOptions): Promise<
|
|||||||
|
|
||||||
let localSiteurl: string | undefined;
|
let localSiteurl: string | undefined;
|
||||||
if (components.has("database") && !options.skipSearchReplace) {
|
if (components.has("database") && !options.skipSearchReplace) {
|
||||||
localSiteurl = await readLocalOption(context, "siteurl");
|
localSiteurl = resolveLocalSiteurl(context) ?? (await readLocalOption(context, "siteurl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const component of CONTENT_SYNC_COMPONENTS) {
|
for (const component of CONTENT_SYNC_COMPONENTS) {
|
||||||
@@ -382,6 +382,19 @@ async function runSearchReplace(
|
|||||||
await run(context, "wp", ["cache", "flush"], { cwd: context.cwd });
|
await run(context, "wp", ["cache", "flush"], { cwd: context.cwd });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resolveLocalSiteurl(context: WPopContext): string | undefined {
|
||||||
|
const protocol = process.env.WEBSIMPLE_STACK_PROTOCOL?.trim();
|
||||||
|
const domain = process.env.WEBSIMPLE_STACK_DOMAIN?.trim();
|
||||||
|
if (!protocol || !domain) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const subdomain = basename(context.cwd);
|
||||||
|
if (!subdomain) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return `${protocol}://${subdomain}.${domain}`;
|
||||||
|
}
|
||||||
|
|
||||||
async function readLocalOption(context: WPopContext, option: string): Promise<string | undefined> {
|
async function readLocalOption(context: WPopContext, option: string): Promise<string | undefined> {
|
||||||
const result = await run(context, "wp", ["option", "get", option], {
|
const result = await run(context, "wp", ["option", "get", option], {
|
||||||
capture: true,
|
capture: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user