@wpnuxt/core 2.0.0-alpha.13 → 2.0.0-alpha.14

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/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.14",
4
4
  "configKey": "wpNuxt",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.0.0"
package/dist/module.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { consola } from 'consola';
1
2
  import { defu } from 'defu';
2
3
  import { promises, cpSync, existsSync, readdirSync, statSync, readFileSync, writeFileSync } from 'node:fs';
3
4
  import { writeFile, rename, readFile, mkdir } from 'node:fs/promises';
@@ -7,9 +8,8 @@ import { upperFirst } from 'scule';
7
8
  import { ref } from 'vue';
8
9
  import { parse, GraphQLError } from 'graphql';
9
10
  import { execSync } from 'node:child_process';
10
- import { consola } from 'consola';
11
11
 
12
- const version = "2.0.0-alpha.13";
12
+ const version = "2.0.0-alpha.14";
13
13
 
14
14
  function createModuleError(module, message) {
15
15
  return new Error(formatErrorMessage(module, message));
@@ -807,7 +807,7 @@ const module$1 = defineNuxtModule({
807
807
  },
808
808
  async setup(options, nuxt) {
809
809
  const startTime = (/* @__PURE__ */ new Date()).getTime();
810
- const wpNuxtConfig = loadConfig(options, nuxt);
810
+ const wpNuxtConfig = await loadConfig(options, nuxt);
811
811
  if (!wpNuxtConfig) {
812
812
  const logger2 = initLogger(false);
813
813
  logger2.warn("WordPress URL not configured. Skipping WPNuxt setup. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
@@ -950,7 +950,7 @@ const module$1 = defineNuxtModule({
950
950
  await runInstall(nuxt);
951
951
  }
952
952
  });
953
- function loadConfig(options, nuxt) {
953
+ async function loadConfig(options, nuxt) {
954
954
  const config = defu({
955
955
  wordpressUrl: process.env.WPNUXT_WORDPRESS_URL,
956
956
  graphqlEndpoint: process.env.WPNUXT_GRAPHQL_ENDPOINT,
@@ -962,6 +962,42 @@ function loadConfig(options, nuxt) {
962
962
  if (config.downloadSchema === void 0) {
963
963
  config.downloadSchema = true;
964
964
  }
965
+ if (!config.wordpressUrl?.trim()) {
966
+ if (nuxt.options._prepare) {
967
+ return null;
968
+ }
969
+ if (nuxt.options.dev && process.stdout.isTTY) {
970
+ const wordpressUrl = await consola.prompt(
971
+ "Enter your WordPress site URL (must have WPGraphQL installed):",
972
+ { type: "text", placeholder: "https://your-wordpress-site.com" }
973
+ );
974
+ if (wordpressUrl && typeof wordpressUrl === "string" && wordpressUrl.trim()) {
975
+ const validation = validateWordPressUrl(wordpressUrl);
976
+ if (validation.valid && validation.normalizedUrl) {
977
+ config.wordpressUrl = validation.normalizedUrl;
978
+ const envPath = join(nuxt.options.rootDir, ".env");
979
+ const envLine = `WPNUXT_WORDPRESS_URL=${validation.normalizedUrl}
980
+ `;
981
+ if (existsSync(envPath)) {
982
+ const existing = await readFile(envPath, "utf-8");
983
+ await atomicWriteFile(envPath, existing.trimEnd() + "\n" + envLine);
984
+ } else {
985
+ await atomicWriteFile(envPath, envLine);
986
+ }
987
+ consola.success(`WordPress URL saved to .env: ${validation.normalizedUrl}`);
988
+ } else {
989
+ throw createModuleError("core", `Invalid WordPress URL: ${validation.error}`);
990
+ }
991
+ } else {
992
+ throw createModuleError("core", "WordPress URL is required. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
993
+ }
994
+ } else {
995
+ throw createModuleError("core", "WordPress URL is required. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
996
+ }
997
+ }
998
+ if (config.wordpressUrl.endsWith("/")) {
999
+ throw createModuleError("core", `WordPress URL should not have a trailing slash: ${config.wordpressUrl}`);
1000
+ }
965
1001
  nuxt.options.runtimeConfig.public.wordpressUrl = config.wordpressUrl;
966
1002
  nuxt.options.runtimeConfig.public.wpNuxt = {
967
1003
  wordpressUrl: config.wordpressUrl,
@@ -975,15 +1011,6 @@ function loadConfig(options, nuxt) {
975
1011
  swr: config.cache?.swr ?? true
976
1012
  }
977
1013
  };
978
- if (!config.wordpressUrl?.trim()) {
979
- if (nuxt.options._prepare) {
980
- return null;
981
- }
982
- throw createModuleError("core", "WordPress URL is required. Set it in nuxt.config.ts or via WPNUXT_WORDPRESS_URL environment variable.");
983
- }
984
- if (config.wordpressUrl.endsWith("/")) {
985
- throw createModuleError("core", `WordPress URL should not have a trailing slash: ${config.wordpressUrl}`);
986
- }
987
1014
  return config;
988
1015
  }
989
1016
  const SERVER_OPTIONS_TEMPLATE = `import { defineGraphqlServerOptions } from '@wpnuxt/core/server-options'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.0.0-alpha.13",
3
+ "version": "2.0.0-alpha.14",
4
4
  "description": "Nuxt module for WordPress integration via GraphQL (WPGraphQL)",
5
5
  "keywords": [
6
6
  "nuxt",