Add WP REST API url directly from command line when "frontity create"

Context

Our users are getting a difficult step to solve when they create their first project with frontity. It is not clear the URL of the WP REST API that should be set in the frontity.settings.js under the wp-source package configuration

There are also some community threads regarding this:

The DevRel team will improve the docs but we could also…

Description

Setting the state.source.api value from the command line to improve the developer experience when creating Frontity projects

Possible solution

When we do npx frontity create my-frontity-project one of the questions that the CLI could ask could be:

(wpUrl) → What is the URL of the homepage of your Wordpress site (default=https://test.frontity.io/) ?
(isWpCom) → Is it a Wordpress.com site  (y/N)?

Use Case 1

  • isWpCom=no
  • wpUrl=https://test.frontity.io/

state.source.api = https://test.frontity.io/wp-json/

Use Case 2

  • wpUrl=https://juanmaguitarblog.wordpress.com/
  • isWpCom=yes (in this case this value could be automatically detected and avoid the second question)

state.source.api = https://wordpress.com/posts/juanmaguitarblog.wordpress.com/wp-json/

Use Case 3

  • wpUrl=https://instajuegos.home.blog/
  • isWpCom=yes

(This specific combination of home.blog + isWpCom=yes will result in a wordpress.com subdomain format of REST API)

state.source.api = https://public-api.wordpress.com/wp/v2/sites/instajuegos.home.blog/posts/

Use Case 4

  • wpUrl=https://mycoolwpsite.com
  • isWpCom=yes (Paid plan w/ custom domain: Personal, Business…)

state.source.api = https://mycoolwpsite.com/wp-json/

Use Case 5

  • wpUrl=https://mycoolwpsite.wpcomstaging.com
  • isWpCom=yes (Business plan w/ plugins installed w/o custom domain)

state.source.api = https://mycoolwpsite.wpcomstaging.com/wp-json/

Use Case 6

  • wpUrl=https://localhost:4000
  • isWpCom=no

state.source.api = http://localhost:4000/wp-json

This is a very good idea. Could we also avoid the prompt by adding a command line switch such as npx frontity create my-frontity-project -a https://test.frontity.io/wp-json/?

How about also a -noprompt switch which will default to the mars-theme and reply N to the email signup question?

1 Like

I like it :+1:

There’s already a --no-prompt option, isnt’ there? → https://docs.frontity.org/frontity-cli/create

Maybe I should read the docs a bit more carefully! :laughing:

2 Likes