Init commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
24
README.md
Normal file
24
README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
## WordPress Backend
|
||||
|
||||
Before you install WordPress, make sure you have all the required software installed for your operating system.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
* **OS X:** You'll need [Homebrew](https://brew.sh/) and [Yarn](https://yarnpkg.com/en/) installed.
|
||||
* **Windows:** To install under Windows you need to be running the _64-bit version of Windows 10 Anniversary Update or later (build 1607+)_. The [Linux Subsystem for Windows](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide) should be installed and enabled before proceeding. Then, you'll need the prerequisites for Ubuntu Linux, detailed below, set up.
|
||||
* **Ubuntu Linux:** You'll need the latest version of NodeJS, Yarn and debconf-utils installed first. Follow this [simple guide](https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions) to get the latest version of NodeJS installed. Install the rest of the packages using the `apt-get` package manager. _Note: During the WordPress installation, you may be asked to enter the root password at the prompt due to the use of the `sudo` command_
|
||||
|
||||
### Install
|
||||
|
||||
The following command will get WordPress running locally on your machine, along with the WordPress plugins you'll need to create and serve custom data via the WP REST API.
|
||||
|
||||
```zsh
|
||||
> yarn install && yarn start
|
||||
```
|
||||
|
||||
When the installation process completes successfully:
|
||||
|
||||
* The WordPress REST API is available at [http://localhost:8080](http://localhost:8080)
|
||||
* The WordPress GraphQL API is available at [http://localhost:8080/graphql](http://localhost:8080/graphql)
|
||||
* The WordPress admin is at [http://localhost:8080/wp-admin/](http://localhost:8080/wp-admin/)
|
||||
|
||||
236
RoboFile.php
Normal file
236
RoboFile.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase, WordPress.Files.FileName.InvalidClassFileName
|
||||
|
||||
define( 'PROJECT_DIR', dirname( __FILE__ ) );
|
||||
define( 'TMP_DIR', PROJECT_DIR . '/tmp' );
|
||||
define( 'WP_DIR', PROJECT_DIR . '/wordpress' );
|
||||
|
||||
/**
|
||||
* This is project's console commands configuration for Robo task runner.
|
||||
*
|
||||
* @see http://robo.li/
|
||||
*/
|
||||
class RoboFile extends \Robo\Tasks {
|
||||
|
||||
/**
|
||||
* Set up WordPress.
|
||||
*
|
||||
* @param array $opts Options
|
||||
* @return void
|
||||
*/
|
||||
public function wordpressSetup(
|
||||
$opts = [
|
||||
'wp-user' => 'saburly4dm1n',
|
||||
'wp-pw' => 'U2r6axymsh4be2',
|
||||
'wp-theme-dir' => 'saburly-headless',
|
||||
'wp-theme-name' => 'Saburly Headless WP',
|
||||
'wp-email' => 'info@saburly.com',
|
||||
'wp-db-name' => 'wp_saburly',
|
||||
'wp-description' => 'We love beautiful code',
|
||||
'wp-plugins' => [],
|
||||
]
|
||||
) {
|
||||
$confirm = $this->io()->confirm( 'This will replace your current ' .
|
||||
'WordPress install. Are you sure you want to do this?', false );
|
||||
|
||||
if ( ! $confirm ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$uname = php_uname();
|
||||
$is_darwin = ( strpos( $uname, 'Darwin' ) === 0 );
|
||||
$config_db_answer = $this->ask(
|
||||
"Do you have an existing database you'd like to use and configure yourself? (y/n): "
|
||||
);
|
||||
$db_ip = '';
|
||||
$db_pass = '';
|
||||
if ( 'y' === $config_db_answer ) {
|
||||
$db_ip = $this->ask( 'Database IP address (press Enter for default value [0.0.0.0]): ' );
|
||||
$db_pass = $this->ask( 'Database root password (press Enter for default value [root]): ' );
|
||||
if ( $is_darwin ) {
|
||||
$this->_exec( 'mysql.server start' );
|
||||
} else {
|
||||
$this->_exec( 'sudo service mysql start' );
|
||||
}
|
||||
} else {
|
||||
if ( $is_darwin ) {
|
||||
$this->_exec( 'brew install mysql' );
|
||||
$this->_exec( 'mysql.server start' );
|
||||
$this->_exec( './mysql_config.sh' );
|
||||
} else {
|
||||
$this->_exec(
|
||||
"echo 'mysql-server mysql-server/root_password_again password root' | sudo debconf-set-selections"
|
||||
);
|
||||
$this->_exec(
|
||||
"echo 'mysql-server mysql-server/root_password_again password root' | sudo debconf-set-selections"
|
||||
);
|
||||
$this->_exec( 'sudo apt-get -y install mysql-server' );
|
||||
$this->_exec( 'sudo usermod -d /var/lib/mysql/ mysql' );
|
||||
$this->_exec( 'sudo service mysql start' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !$db_pass || strlen( $db_pass ) === 0 ) {
|
||||
$db_pass = 'root';
|
||||
}
|
||||
|
||||
if ( !$db_ip || strlen( $db_ip ) === 0 ) {
|
||||
$db_ip = '0.0.0.0';
|
||||
}
|
||||
|
||||
$this->_exec(
|
||||
'mysql -uroot -p' . $db_pass . ' -h ' . $db_ip . " -e 'create user if not exists "
|
||||
. $opts['wp-db-name'] . "'"
|
||||
);
|
||||
$this->_exec(
|
||||
'mysql -uroot -p' . $db_pass . ' -h ' . $db_ip
|
||||
. " -e 'create database if not exists " . $opts['wp-db-name'] . "'"
|
||||
);
|
||||
$this->_exec(
|
||||
'mysql -uroot -p' . $db_pass . ' -h ' . $db_ip . ' -e "grant all privileges on ' . $opts['wp-db-name']
|
||||
. '.* to ' . $opts['wp-db-name'] . "@localhost identified by '" . $opts['wp-db-name'] . "'\""
|
||||
);
|
||||
|
||||
$this->_exec( 'mysql -uroot -p' . $db_pass . ' -h ' . $db_ip . " -e 'flush privileges'" );
|
||||
|
||||
$this->wp( 'core download --version=4.9.5 --locale=en_US --force' );
|
||||
$this->wp(
|
||||
'core config --dbname=' . $opts['wp-db-name'] . ' --dbuser=' . $opts['wp-db-name'] . ' --dbpass='
|
||||
. $opts['wp-db-name'] . ' --dbhost=' . $db_ip
|
||||
);
|
||||
$this->wp( 'db drop --yes' );
|
||||
$this->wp( 'db create' );
|
||||
|
||||
$install_command = implode( ' ', [
|
||||
'core install',
|
||||
'--url=localhost:8080',
|
||||
'--title="' . $opts['wp-theme-name'] . '"',
|
||||
'--admin_user="' . $opts['wp-user'] . '"',
|
||||
'--admin_password="' . $opts['wp-pw'] . '"',
|
||||
'--admin_email="' . $opts['wp-email'] . '"',
|
||||
'--skip-email',
|
||||
] );
|
||||
|
||||
$this->wp( $install_command );
|
||||
|
||||
$this->wp( 'theme activate ' . $opts['wp-theme-dir'] );
|
||||
$this->wp( 'theme delete twentyfourteen' );
|
||||
$this->wp( 'theme delete twentyfifteen' );
|
||||
$this->wp( 'theme delete twentysixteen' );
|
||||
$this->wp( 'theme delete twentyseventeen' );
|
||||
|
||||
$this->wp( 'plugin delete akismet' );
|
||||
$this->wp( 'plugin delete hello' );
|
||||
|
||||
if ( is_array( $opts['wp-plugins'] ) && count( $opts['wp-plugins'] ) > 0 ) {
|
||||
$installed_plugin_directories = $opts['wp-plugins'];
|
||||
} else {
|
||||
$installed_plugins = array_filter( glob( WP_DIR . '/wp-content/plugins/*' ), 'is_dir' );
|
||||
$installed_plugin_directories = array_filter(
|
||||
str_replace(
|
||||
WP_DIR . '/wp-content/plugins/',
|
||||
'',
|
||||
$installed_plugins
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( count( $installed_plugin_directories ) > 0 ) {
|
||||
$plugins_command = 'plugin activate ' . ( implode( ' ', $installed_plugin_directories ) );
|
||||
$this->wp( $plugins_command );
|
||||
}
|
||||
|
||||
// Sync ACF
|
||||
$this->wp( 'acf sync' );
|
||||
|
||||
// Pretty URL structure required for wp-json path to work correctly
|
||||
$this->wp( 'rewrite structure "/%year%/%monthnum%/%day%/%postname%/"' );
|
||||
|
||||
// Set the site description
|
||||
$this->wp( 'option update blogdescription "' . $opts['wp-description'] . '"' );
|
||||
|
||||
// Update the Hello World post
|
||||
$this->wp(
|
||||
'post update 1 wp-content/themes/saburly-headless/post-content/sample-post.txt '.
|
||||
'--post_title="Sample Post" --post_name=sample-post'
|
||||
);
|
||||
|
||||
// Create homepage content
|
||||
$this->wp(
|
||||
'post create wp-content/themes/saburly-headless/post-content/welcome.txt '.
|
||||
'--post_type=page --post_status=publish --post_name=welcome '.
|
||||
'--post_title="Congratulations!"'
|
||||
);
|
||||
|
||||
// Update the default 'Uncategorized' category name to make it more menu-friendly
|
||||
$this->wp( 'term update category 1 --name="Sample Category"' );
|
||||
|
||||
// Set up example menu
|
||||
$this->wp( 'menu create "Header Menu"' );
|
||||
$this->wp( 'menu item add-post header-menu 1' );
|
||||
$this->wp( 'menu item add-post header-menu 2' );
|
||||
$this->wp( 'menu item add-term header-menu category 1' );
|
||||
$this->wp( 'menu location assign header-menu header-menu' );
|
||||
|
||||
$this->io()->success(
|
||||
'Great. You can now log into WordPress at: http://localhost:8080/wp-admin ('
|
||||
. $opts['wp-user'] . '/' . $opts['wp-pw'] . ')'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start WordPress server.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function server() {
|
||||
$this->wp( 'server' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import WordPress data.
|
||||
*
|
||||
* @param array $opts options
|
||||
* @return void
|
||||
*/
|
||||
public function wordpressImport( $opts = [
|
||||
'migratedb-license' => null,
|
||||
'migratedb-from' => null,
|
||||
] ) {
|
||||
if ( isset( $opts['migratedb-license'] ) ) {
|
||||
$this->wp( 'migratedb setting update license ' . $opts['migratedb-license'] );
|
||||
} else {
|
||||
$this->say( 'WP Migrate DB Pro: no license available. Please set migratedb-license in the robo.yml file.' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $opts['migratedb-from'] ) ) {
|
||||
$command = 'WPMDB_EXCLUDE_RESIZED_MEDIA=1 wp migratedb pull ';
|
||||
$command .= $opts['migratedb-from'];
|
||||
$command .= ' --backup=prefix ';
|
||||
$command .= ' --media=compare ';
|
||||
$this->io()->success( 'About to run data migration from ' . $opts['migratedb-from'] );
|
||||
$this->taskExec( $command )->run();
|
||||
// Set siteurl and home
|
||||
$this->wp( 'option update siteurl http://localhost:8080' );
|
||||
$this->wp( 'option update home http://localhost:8080' );
|
||||
} else {
|
||||
$this->say(
|
||||
'WP Migrate DB Pro: No source installation specified. Please set migratedb-from in the robo.yml file.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run WordPress task.
|
||||
*
|
||||
* @param arr $arg Arguments
|
||||
* @return void
|
||||
*/
|
||||
public function wp( $arg ) {
|
||||
$this->taskExec( 'wp' )
|
||||
->dir( WP_DIR )
|
||||
->rawArg( $arg )
|
||||
->run();
|
||||
}
|
||||
}
|
||||
23
install.sh
Executable file
23
install.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
||||
# Install PHP and PHP MySQL Plugin
|
||||
sudo apt-get -y install php php-mysql mysql-client
|
||||
# Download and install wp-cli
|
||||
wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
|
||||
sudo chmod +x wp-cli.phar
|
||||
sudo mv wp-cli.phar /usr/local/bin/wp
|
||||
# Download and install robo
|
||||
wget http://robo.li/robo.phar
|
||||
sudo mv robo.phar /usr/bin/robo && sudo chmod +x /usr/bin/robo
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# Download and install wp-cli
|
||||
brew install wp-cli
|
||||
# Download and install wget
|
||||
brew install wget
|
||||
# Download and install robo
|
||||
wget http://robo.li/robo.phar
|
||||
sudo mv robo.phar /usr/local/bin/robo && sudo chmod +x /usr/local/bin/robo
|
||||
else
|
||||
echo "Sorry, this installation script only works on Mac OS X and Ubuntu Linux. Looks like your operating system is $OSTYPE."
|
||||
fi
|
||||
12
itermocil.yml
Normal file
12
itermocil.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
windows:
|
||||
- name: WordPress + React
|
||||
# Create a symlink in your home directory to the actual location of your code
|
||||
# ln -s ~/path/to/code/for/saburly-wp .
|
||||
root: ~/saburly-wp/
|
||||
layout: main-vertical
|
||||
panes:
|
||||
- wp server
|
||||
- commands:
|
||||
- cd frontend && yarn install && yarn run dev
|
||||
name: 'git'
|
||||
- git status
|
||||
15
mysql_config.sh
Executable file
15
mysql_config.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# If there's no password set for MySQL (first-time install), add one and cleanup
|
||||
if mysql -uroot; then
|
||||
mysql -uroot <<_EOF_
|
||||
UPDATE mysql.user SET authentication_string=PASSWORD('root') WHERE User='root';
|
||||
DELETE FROM mysql.user WHERE User='';
|
||||
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
|
||||
DROP DATABASE IF EXISTS test;
|
||||
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';
|
||||
FLUSH PRIVILEGES;
|
||||
_EOF_
|
||||
fi
|
||||
fi
|
||||
8
package.json
Normal file
8
package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "saburly-headless",
|
||||
"version": "0.1.0",
|
||||
"repository": "git@gitlab.com:website-saburly/v2-backend.git",
|
||||
"author": "Saburly",
|
||||
"license": "UNLICENSED",
|
||||
"private": true
|
||||
}
|
||||
98
phpcs.xml
Normal file
98
phpcs.xml
Normal file
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="PHPCS Config">
|
||||
<!--
|
||||
See also:
|
||||
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
|
||||
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage
|
||||
-->
|
||||
<description>PHP coding standards configuration.</description>
|
||||
|
||||
<!-- Command line args, compare to: /vendor/bin/phpcs -(v)s -extensions=php -colors -->
|
||||
<arg value="s"/> <!-- Show sniffs report. -->
|
||||
<arg name="colors"/> <!-- Use colors in reports. -->
|
||||
<arg name="extensions" value="php,dist" /> <!-- Sniff these file types. -->
|
||||
|
||||
<!--
|
||||
============================================================================
|
||||
PSR-2 ruleset:
|
||||
https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/ruleset.xml
|
||||
-->
|
||||
<rule ref="PSR2">
|
||||
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceAfterOpenBracket" />
|
||||
<exclude name="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket" />
|
||||
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen" />
|
||||
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose" />
|
||||
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
|
||||
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
|
||||
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
|
||||
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
|
||||
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
|
||||
<exclude name="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen" />
|
||||
<exclude name="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose" />
|
||||
<exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen" />
|
||||
<exclude name="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose" />
|
||||
<exclude name="Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma" />
|
||||
<exclude name="Squiz.Strings.ConcatenationSpacing.PaddingFound" />
|
||||
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeEquals" />
|
||||
<exclude name="PSR2.Namespaces.UseDeclaration.MultipleDeclarations" />
|
||||
<exclude name="Squiz.PHP.DisallowMultipleAssignments" />
|
||||
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
|
||||
</rule>
|
||||
|
||||
<rule ref="PSR2.ControlStructures.ControlStructureSpacing">
|
||||
<properties>
|
||||
<property name="requiredSpacesAfterOpen" value="1" />
|
||||
<property name="requiredSpacesBeforeClose" value="1" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!--
|
||||
============================================================================
|
||||
WordPress rulesets:
|
||||
WordPress-Extra: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Extra/ruleset.xml
|
||||
WordPress-VIP: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-VIP/ruleset.xml
|
||||
https://vip.wordpress.com/documentation/code-review-what-we-look-for
|
||||
-->
|
||||
<rule ref="WordPress-Extra">
|
||||
<!-- Allow spaces -->
|
||||
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed" />
|
||||
<exclude name="WordPress.VIP.SuperGlobalInputUsage.AccessDetected" />
|
||||
<exclude name="WordPress.WhiteSpace.OperatorSpacing" />
|
||||
</rule>
|
||||
|
||||
<rule ref="WordPress-VIP" />
|
||||
|
||||
<!--
|
||||
============================================================================
|
||||
Documentation rulesets:
|
||||
WordPress-Docs: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress-Docs/ruleset.xml
|
||||
https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/php/
|
||||
Generic Commenting: https://github.com/squizlabs/PHP_CodeSniffer/tree/master/src/Standards/Generic/Sniffs/Commenting
|
||||
-->
|
||||
<rule ref="WordPress-Docs">
|
||||
<!-- Do not enforce having a file comment for each file. -->
|
||||
<exclude name="Squiz.Commenting.FileComment" />
|
||||
<!-- Don't require full stop in comments. -->
|
||||
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" />
|
||||
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
|
||||
<!-- Don't require comment capitalization. -->
|
||||
<exclude name="Generic.Commenting.DocComment.LongNotCapital" />
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.Commenting">
|
||||
<exclude name="Generic.Commenting.DocComment.MissingShort" />
|
||||
<exclude name="Generic.Commenting.Fixme" />
|
||||
<exclude name="Generic.Commenting.Todo" />
|
||||
</rule>
|
||||
|
||||
<!--
|
||||
============================================================================
|
||||
Special or one-off rules.
|
||||
-->
|
||||
|
||||
<!-- Normalize all require/require_onces to use statement, not function, syntax. -->
|
||||
<rule ref="PEAR.Files.IncludingFile.BracketsNotRequired" />
|
||||
|
||||
<!-- Require short array syntax -->
|
||||
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
|
||||
</ruleset>
|
||||
19
robo.yml
Normal file
19
robo.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
command:
|
||||
wordpress:
|
||||
setup:
|
||||
options:
|
||||
wp-user: saburly4dm1n
|
||||
wp-pw: U2r6axymsh4be2
|
||||
wp-theme-dir: saburly-headless
|
||||
wp-theme-name: Saburly Headless WP
|
||||
wp-email: info@saburly.com
|
||||
wp-db-name: wp_saburly
|
||||
wp-description: We love beautiful code
|
||||
# wp-plugins is optional
|
||||
# If not set, Robo will activate all the plugins that are installed.
|
||||
# wp-plugins:
|
||||
import:
|
||||
options:
|
||||
migratedb-license:
|
||||
# Use http vs https to avoid SSL error https://deliciousbrains.com/wp-migrate-db-pro/doc/ssl-errors/
|
||||
migratedb-from:
|
||||
3
wp-cli.yml
Normal file
3
wp-cli.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
path: ./wordpress
|
||||
server:
|
||||
host: 127.0.0.1
|
||||
Reference in New Issue
Block a user