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

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

Use Case 4

  • 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